Repository navigation
Fix: recognize data type in parse method table - #17946
Conversation
📝 WalkthroughWalkthroughThe table logic now detects native Python and NumPy types, handles missing numeric and datetime values as ChangesTyped table values
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
rag/app/table.py
| if isinstance(a, float) and pd.isna(a): | ||
| continue # skip NaN |
There was a problem hiding this comment.
🎯 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 testRepository: 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 || trueRepository: 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))
PYRepository: 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))
PYRepository: 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.
| if isinstance(a, float) and pd.isna(a): | |
| continue # skip NaN | |
| if isinstance(a, (float, np.floating)) and pd.isna(a): | |
| continue # skip NaN |
| 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.
| 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. |
There was a problem hiding this comment.
📐 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
| 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 |
There was a problem hiding this comment.
📐 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] = valAs 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.
| 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
|
Suggest keep go port synced in the same PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Go already does plain text — no fix needed. |
|
LGTM |
wangq8
left a comment
There was a problem hiding this comment.
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] = valCould be simplified to:
if not isinstance(val, str):
stored[fld] = valMisleading 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.
Summary
As title.