BUG: fix read_csv pyarrow engine column-name and dtype handling#65859
Draft
jbrockmendel wants to merge 3 commits into
Draft
BUG: fix read_csv pyarrow engine column-name and dtype handling#65859jbrockmendel wants to merge 3 commits into
jbrockmendel wants to merge 3 commits into
Conversation
Brings the pyarrow engine's header/dtype handling in line with the
other engines:
- duplicated column names are now mangled to "x.1"-style names,
mirroring the algorithm in pandas._libs.parsers.TextReader
(including dtype-key propagation to mangled names, GH#35211)
- empty header fields become "Unnamed: {i}" placeholder names
- an unnamed index_col now produces an unnamed index level instead
of an index named ""
- non-dict dtype with index_col no longer raises AttributeError
- defaultdict dtype now applies its default to unlisted columns
(GH#41574)
Un-xfails the 30 tests these bugs were responsible for.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- narrow self.names for pyright in defaultdict dtype block - test_dtype_all_columns: xfail object-index case only under infer_string; xfail check_orig=False object case unconditionally Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Audit of the
@xfail_pyarrowtests inpandas/tests/io/parserfound ~30 cases caused by a handful ofArrowParserWrapperbugs rather than pyarrow limitations. This fixes them and un-xfails the affected tests:"x.1"-style names, mirroring the dedup algorithm inpandas._libs.parsers.TextReaderline-for-line, including the dtype-key propagation from original to mangled names (BUG: in read_excel for mangled columns only the original/first column dtype is correct, col.N is not parsed correctly #35211, BUG: read_csv now errors with non-dict dtype and same-name columns #42022) and the named-before-unnamed loop order. Previously the pyarrow engine returned frames with duplicate columns, which also brokeindex_col("Found non-unique column index")."Unnamed: {i}"placeholder names instead of""(Three or more unnamed fields block loc assignment #13017).index_colnow produces an unnamed index level instead of an index named"".dtypetogether withindex_colno longer raisesAttributeError: type object 'str' has no attribute 'get'.defaultdictdtypenow applies its default to columns not explicitly listed (ENH: support defaultdict in read_csv dtype parameter #41574).One parametrization stays xfailed with a narrower conditional mark:
test_dtype_all_columns[object], where scalardtype=objectis also applied to the index column (thestrvariant passes).No user-facing behavior changes for the other engines; the test diff is marker removals only.
🤖 Generated with Claude Code