-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: Add defaultdict support for dtype in read_csv #46051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -471,6 +471,9 @@ def _clean_mapping(self, mapping): | |||
if isinstance(col, int) and col not in self.orig_names: | |||
col = self.orig_names[col] | |||
clean[col] = v | |||
if isinstance(mapping, defaultdict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also support defaultdicts directly instead of converting here. but this simplifies adding support for converters to and also we do not have to keep defaultdicts in mind every time we casses the dtypes
cool can you rebase |
dtype["b.1"] = "int64" | ||
parser = all_parsers | ||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
expected = DataFrame({"a": [1], "b": 2.0, "a.1": [3], "b.2": [4.0], "b.1": [5]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you miss the [] on "b", looks different but dont think there is a reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot it yes, but does not really make a difference.
Added nevertheless to be more consistent
# Conflicts: # doc/source/whatsnew/v1.5.0.rst
� Conflicts: � doc/source/whatsnew/v1.5.0.rst
this looked fine, can you merge master @phofl |
Done |
thanks @phofl very nice as always! |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.