Skip to content

CLN: remove _try_coerce_result altogether #27683

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

Merged
merged 15 commits into from
Aug 5, 2019

Conversation

jbrockmendel
Copy link
Member

Following #27628, we can now remove _try_coerce_result altogether.

The step after this removes _try_cast_result.

@jreback jreback added Clean Internals Related to non-user accessible pandas implementation labels Aug 1, 2019
@jreback jreback added this to the 1.0 milestone Aug 1, 2019
@@ -452,6 +453,16 @@ def wrapper(*args, **kwargs):
def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
assert kind in ["transform", "aggregate"]

if is_datetime64tz_dtype(values):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't do this here and rather handle at a higher level as datetime64 is caught below for some operations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later in this function it checks for datetime64 to exclude add/prod/cumsum/cumprod, but there is nowhere else in this module where we handle datetime64tz AFAICT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my point is that this is not the right place to handle this. if you want to transform the input then let it pass thru or raise a NotImplementedError then that is fine, but the way you are writing it is is very diffferent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all aggregate and transform calls go through here, so this is the only place AFAICT that we can do this without having to duplicate it for every calling function. If there is a better place, can you be more specific?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing my point. I have no problem handling this in this function. What you wrote returns early, bypassing all of the logic that handles all of the other dtypes. So it needs to be integrated there OR handled at a higher level on a NotImplementedError raise.

This function becomes even harder to understand with this addition. In theory you could also split this function up more logically. There are a number of solutions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edited to do what I think you're suggesting.

the method could use a good refactor, agreed. separate pass.

@@ -452,6 +453,16 @@ def wrapper(*args, **kwargs):
def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
assert kind in ["transform", "aggregate"]

if is_datetime64tz_dtype(values):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing my point. I have no problem handling this in this function. What you wrote returns early, bypassing all of the logic that handles all of the other dtypes. So it needs to be integrated there OR handled at a higher level on a NotImplementedError raise.

This function becomes even harder to understand with this addition. In theory you could also split this function up more logically. There are a number of solutions.

@jbrockmendel
Copy link
Member Author

@jreback is this closer to what you had in mind?

# TODO: possible need to reshape? kludge can be avoided when
# 2D EA is allowed.
values = values.view("M8[ns]")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move the is_datetimelike and is_numeric checks up here and de-duplicate as needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. not much de-duplication available. in another pass we can separate out some of the casting from the everything-else and see if there is de-duplication available in algos or something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fair, that routine likely needs some cleaning at some point

@jreback jreback merged commit f6ade9b into pandas-dev:master Aug 5, 2019
@jbrockmendel jbrockmendel deleted the coerce6 branch August 5, 2019 14:33
quintusdias pushed a commit to quintusdias/pandas_dev that referenced this pull request Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants