Skip to content

Fix: recognize data type in parse method table - #17946

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
Lynn-Inf:fix/table-parse
Aug 6, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
Lynn-Inf:fix/table-parse

Conversation

@Lynn-Inf

@Lynn-Inf Lynn-Inf commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

As title.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 6, 2026
@Lynn-Inf
Lynn-Inf requested a review from wangq8 August 6, 2026 09:17
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The table logic now detects native Python and NumPy types, handles missing numeric and datetime values as None, and avoids storing failed string conversions in typed Elasticsearch fields.

Changes

Typed table values

Layer / File(s) Summary
Native type inference and conversion
rag/app/table.py
The table logic detects native booleans, integers, floats, datetimes, and missing values. Conversion maps missing floats and pd.NaT to None.
Typed metadata storage
rag/app/table.py
String values are skipped for non-text Elasticsearch fields. Non-string values remain stored, and skipped strings remain available as text content.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: wangq8

Poem

A rabbit checks each typed row,
Where dates and numbers now clearly show.
Missing bits turn into None,
Stray strings leave typed fields alone.
Text still keeps what storage skips—
Neat little hops through table tips!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description uses “As title” and does not explain the problem, purpose, or background context required by the template. Describe the problem being fixed, the intended behavior, and the relevant background context for reviewers.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: data type recognition in the table parse method.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Lynn-Inf Lynn-Inf added the ci Continue Integration label Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rag/app/table.py`:
- Around line 420-424: Remove the stale two-line comment immediately after the
logging.warning call in the conversion-failure handling block; keep the existing
arr[i] = None assignment and warning behavior unchanged.
- Around line 613-622: Update the typed-field handling around row[col_name] to
log each skipped string value at debug or warning level, including the field
name and expected type but never the raw cell content. Preserve storing
non-string values in stored[fld] and continue omitting string values from the
typed field.
- Around line 368-369: Update the missing-value type checks in rag/app/table.py
at lines 368-369 and 411-413 to accept both built-in float and np.floating
values. Ensure NumPy floating NaNs are skipped during inference and converted to
None, matching the existing behavior for built-in floats.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f65219c5-357f-422f-8071-24e5337a58a7

📥 Commits

Reviewing files that changed from the base of the PR and between 23b20a0 and a25f158.

📒 Files selected for processing (1)
  • rag/app/table.py

Comment thread rag/app/table.py
Comment on lines +368 to +369
if isinstance(a, float) and pd.isna(a):
continue # skip NaN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

python - <<'PY'
import numpy as np
import pandas as pd

value = np.float32(np.nan)
assert not isinstance(value, float)
assert isinstance(value, np.floating)
assert pd.isna(value)
print("np.float32 NaN requires np.floating handling.")
PY

rg -n -C 3 --glob '*.py' 'column_data_type\(|np\.float32|np\.floating|pd\.isna' rag test

Repository: infiniflow/ragflow

Length of output: 275


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file location =="
git ls-files | grep -F 'rag/app/table.py' || true

echo "== relevant lines =="
if [ -f rag/app/table.py ]; then
  sed -n '340,430p' rag/app/table.py | cat -n | sed 's/^/rag/app/table.py:/'
fi

echo "== numpy/pandas import pattern =="
sed -n '1,80p' rag/app/table.py | cat -n | sed 's/^/rag/app/table.py:/'

echo "== broader usage of the relevant patterns in Python files =="
rg -n -C 2 --glob '*.py' 'isinstance\([^)]*(?:float|pd\.isna|isna)|column_data_type\(|np\.float32' rag test || true

Repository: infiniflow/ragflow

Length of output: 267


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant lines =="
sed -n '340,430p' rag/app/table.py | nl -ba | sed 's/^/rag\/app\/table.py:/'

echo "== imports =="
sed -n '1,80p' rag/app/table.py | nl -ba | sed 's/^/rag\/app\/table.py:/'

echo "== targeted pattern usage =="
rg -n -C 2 --glob '*.py' 'isinstance\([^)]*(?:float|pd\.isna|isna)|column_data_type\(|np\.float32' rag test || true

echo "== numpy behavior probe =="
python3 - <<'PY'
import numbers
import numpy as np

for value in [float('nan'), np.float32(np.nan), np.float64(np.nan)]:
    print(type(value).__name__, isinstance(value, float), isinstance(value, np.floating), isinstance(value, numbers.Real), np.isnan(value))
PY

Repository: infiniflow/ragflow

Length of output: 217


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant lines =="
sed -n '340,430p' rag/app/table.py | awk '{printf "rag/app/table.py:%d:%s\n", NR+339, $0}'

echo "== imports =="
sed -n '1,80p' rag/app/table.py | awk '{printf "rag/app/table.py:%d:%s\n", NR, $0}'

echo "== targeted pattern usage =="
rg -n -C 2 --glob '*.py' 'isinstance\([^)]*(?:float|pd\.isna|isna)|column_data_type\(|np\.float32' rag test || true

echo "== numpy behavior probe =="
python3 - <<'PY'
import numbers
import numpy as np

for value in [float('nan'), np.float32(np.nan), np.float64(np.nan)]:
    print(type(value).__name__, isinstance(value, float), isinstance(value, np.floating), isinstance(value, numbers.Real), np.isnan(value))
PY

Repository: infiniflow/ragflow

Length of output: 34697


Handle missing NumPy floating scalars consistently.

np.float32(np.nan) is counted as a float, but the missing-value checks only accept built-in float. Include np.floating in both checks so missing NumPy floats skip inference and convert to None.

Proposed change
-        if isinstance(a, float) and pd.isna(a):
+        if isinstance(a, (float, np.floating)) and pd.isna(a):
             continue  # skip NaN
...
-        if isinstance(arr[i], float) and pd.isna(arr[i]):
+        if isinstance(arr[i], (float, np.floating)) and pd.isna(arr[i]):
             arr[i] = None
             continue
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if isinstance(a, float) and pd.isna(a):
continue # skip NaN
if isinstance(a, (float, np.floating)) and pd.isna(a):
continue # skip NaN
Suggested change
if isinstance(a, float) and pd.isna(a):
continue # skip NaN
if isinstance(arr[i], (float, np.floating)) and pd.isna(arr[i]):
arr[i] = None
continue
📍 Affects 1 file
  • rag/app/table.py#L368-L369 (this comment)
  • rag/app/table.py#L411-L413
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/app/table.py` around lines 368 - 369, Update the missing-value type
checks in rag/app/table.py at lines 368-369 and 411-413 to accept both built-in
float and np.floating values. Ensure NumPy floating NaNs are skipped during
inference and converted to None, matching the existing behavior for built-in
floats.

Comment thread rag/app/table.py
Comment on lines 420 to +424
arr[i] = None
logging.warning(f"Column {i}: {e}")
# Keep original value from openpyxl/pandas instead of dropping to None.
# This preserves cells (e.g. text in numeric columns) that would
# otherwise be silently discarded by forced column-level conversion.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the stale conversion-failure comment.

Line 420 sets arr[i] = None. Lines 422-424 state that the function preserves the original value. The comment describes behavior that this function does not implement.

As per coding guidelines, remove stale documentation and commented-out code instead of preserving it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/app/table.py` around lines 420 - 424, Remove the stale two-line comment
immediately after the logging.warning call in the conversion-failure handling
block; keep the existing arr[i] = None assignment and warning behavior
unchanged.

Source: Coding guidelines

Comment thread rag/app/table.py
Comment on lines +613 to +622
val = row[col_name]
# If a string value ended up in a non-text column,
# it was preserved from a failed conversion in
# column_data_type. Skip storing in the typed ES
# field to avoid type mapping errors; the value is
# already in text_fields for chunk content.
if isinstance(val, str):
pass
else:
stored[fld] = val

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Log typed-field string skips without logging cell content.

This new path silently omits a string from typed ES metadata. Add a debug or warning log with the field name and type. Do not include the raw cell value.

Proposed change
 if isinstance(val, str):
-    pass
+    logger.debug("Skipping string value for typed table field %s", fld)
 else:
     stored[fld] = val

As per coding guidelines, add logging for new flows.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
val = row[col_name]
# If a string value ended up in a non-text column,
# it was preserved from a failed conversion in
# column_data_type. Skip storing in the typed ES
# field to avoid type mapping errors; the value is
# already in text_fields for chunk content.
if isinstance(val, str):
pass
else:
stored[fld] = val
val = row[col_name]
# If a string value ended up in a non-text column,
# it was preserved from a failed conversion in
# column_data_type. Skip storing in the typed ES
# field to avoid type mapping errors; the value is
# already in text_fields for chunk content.
if isinstance(val, str):
logger.debug("Skipping string value for typed table field %s", fld)
else:
stored[fld] = val
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/app/table.py` around lines 613 - 622, Update the typed-field handling
around row[col_name] to log each skipped string value at debug or warning level,
including the field name and expected type but never the raw cell content.
Preserve storing non-string values in stored[fld] and continue omitting string
values from the typed field.

Source: Coding guidelines

@yuzhichang

yuzhichang commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

Suggest keep go port synced in the same PR.

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (97f9ae5) to head (a25f158).
⚠️ Report is 23 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17946   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Lynn-Inf

Lynn-Inf commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Suggest keep go port synced in the same PR.

Go already does plain text — no fix needed.

@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this improvement! The native type checking is a clear upgrade over the regex-only approach, and handling NaN/NaT properly avoids subtle bugs with openpyxl/pandas data.

A few observations:

Type checking order ✅ — bool is checked before int, which is correct since bool is a subclass of int in Python. Good catch.

NaN/NaT handling — The pd.isna() checks in both the type-detection loop and the conversion loop are appropriate. The datetime + pd.isna() guard handles pd.NaT correctly.

Defensive string guard in chunk() — Skipping string values in non-text typed columns is a reasonable safeguard against ES type mapping errors. However, the pass-then-else pattern is a bit awkward stylistically:

if isinstance(val, str):
    pass
else:
    stored[fld] = val

Could be simplified to:

if not isinstance(val, str):
    stored[fld] = val

Misleading comment placement — The comment block:

# Keep original value from openpyxl/pandas instead of dropping to None.
# This preserves cells (e.g. text in numeric columns) that would
# otherwise be silently discarded by forced column-level conversion.

is placed right after arr[i] = None, which reads as if the value is being preserved when it is actually being dropped to None. The comment appears to describe the downstream effect in the chunk function, not the current line. Consider clarifying or relocating the comment.

Large int overflow check — int(a) > 2**63 - 1 in the type-detection loop works, but will raise ValueError if the native int is actually larger than what Python can represent as int (unlikely in practice but worth noting).

No tests — This parser code is tricky and has had subtle type-detection bugs before. A few unit tests covering mixed-type columns, boolean cells, datetime cells, and NaN cells would be valuable.

Overall LGTM with minor nits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants