-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: use BlockManager.apply in csv code #36150
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
@@ -588,7 +588,7 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"): | |||
|
|||
# use native type formatting for datetime/tz/timedelta | |||
if self.is_datelike: | |||
values = self.to_native_types() | |||
values = self.to_native_types().values |
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.
.to_numpy() ?
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.
no, to_native_types returns a Block
@@ -2403,7 +2404,8 @@ def fillna(self, value, **kwargs): | |||
def to_native_types(self, na_rep="NaT", **kwargs): |
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.
can you now type all of these to return a Block?
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.
sure
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.
actually adding this makes mypy complain about signature mismatch, rather not futz with it ATM
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.
Thanks! A small comment about moving the apply call into managers.py
pandas/io/formats/csvs.py
Outdated
res = mgr.apply( | ||
"to_native_types", | ||
na_rep=self.na_rep, | ||
float_format=self.float_format, | ||
decimal=self.decimal, | ||
date_format=self.date_format, | ||
quoting=self.quoting, | ||
) |
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.
Suggestion: add a BlockManager.to_native_types, and put the above lines in there. That makes it easier to override this (that's what I am doing in the ArrayManager POC, and was thinking to split that out)
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.
Go for it
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.
I think that fits perfectly in this PR
@jbrockmendel needs a rebase, but I agree @jorisvandenbossche suggsetion might be good in this PR |
just rebased. i encourage @jorisvandenbossche to push the edit he has in mind |
thanks @jbrockmendel yeah agree that followups to push down to_native_types makes sense |
This doesn't get rid of internals usage entirely, but makes that access 1 layer less deep