fix(text): normalize ArrowDtype string and categorical columns - #220
Merged
Merged
Conversation
Whitespace stripping, sentinel normalization, fix_dtypes and the profile's text issues skipped two kinds of text column: - pd.ArrowDtype(pa.string()) (pandas >= 2): _is_stringlike_dtype only knew object and StringDtype. It now accepts Arrow string/large_string/string_view. Type inference parses through a string[pyarrow] view, because Arrow-backed parse results lack arithmetic the numeric check relies on (e.g. `%`), so the column cleans exactly like the same data as string[pyarrow]. - Categorical columns: categories with text are repaired too, and the column keeps its categorical dtype and `ordered` flag. Values are normalized like the equivalent object column (same counts); categories that become equal merge and sentinel categories disappear. fix_dtypes still leaves categoricals alone, and the profile reports their whitespace/sentinel issues without a dtype suggestion. fd.clean_text's default column selection uses the same text-dtype check. Closes #212
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 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 |
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pd.ArrowDtype(pa.string())columns (pandas ≥ 2) now go through whitespace stripping, sentinel normalization,fix_dtypesand profile issue detection, just like the same data asstring[pyarrow]._is_stringlike_dtypealso accepts Arrowstring,large_stringandstring_view.string[pyarrow]view, because Arrow-backed parse results don't implement the arithmetic the numeric check uses. Without the view, simply marking these columns as text crashesfix_dtypeswithNotImplementedError: mod not implemented.Categorical columns with text categories are now repaired, and they keep the categorical dtype and the
orderedflag. This follows the choice made for #212." a "and"a"), and sentinel categories are removed.fix_dtypesstill leaves categoricals alone, andfd.profilereports their whitespace and sentinel issues without suggesting a dtype.fd.clean_textnow picks its default columns with the same text-dtype check.docs/cleaning-engine.mdnotes which column types are repaired.Issue repro on this branch
Python 3.12 / pandas 2.3.3 (the Arrow case is pandas ≥ 2 only; categorical output is the same on pandas 1.5.3):
Tests
tests/test_strings.py:string[pyarrow]give the same values and actions for text, numeric-looking and date-looking columns.orderedflag, gets merged categories and correct counts, and ends up with the same values as the object column.tests/test_profile.py: profile issues for categorical and Arrow string columns.Local lane
pytest -m "not online and not large"on Python 3.12 (numpy 2.5) and Python 3.9 (pandas 1.5.3) passes, except the five sandbox tests that also fail locally onmain(they need an installed package).ruff check .andmypy src/freshdatapass.Closes #212