Skip to content

REF: simplify Timedelta arithmetic methods #33978

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 5 commits into from
May 6, 2020

Conversation

jbrockmendel
Copy link
Member

In particular this avoids the "_typ" checks which go through python-space

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Seems like a nice clean-up! Added some questions

# Series, DataFrame, ...
if other._typ == 'dateoffset' and hasattr(other, 'delta'):
# Tick offset; this op will raise TypeError
return other.delta * self
Copy link
Member

Choose a reason for hiding this comment

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

This part is covered by rmul of DateOffset?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will go through DateOffset.__rmul__ which will raise TypeError (correctly), yes.

# i.e. np.nan, but also catch np.float64("NaN") which would
# otherwise get caught by the hasattr(other, "dtype") branch
# incorrectly return a np.timedelta64 object.
return NaT
Copy link
Member

Choose a reason for hiding this comment

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

not checking this, does that give a change in behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

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

the util.is_nan case is subsumed by the is_float_object case on L1351

Copy link
Member

Choose a reason for hiding this comment

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

OK, I see!

# i.e. np.nan, but also catch np.float64("NaN") which would
# otherwise get caught by the hasattr(other, "dtype") branch
# incorrectly return a np.timedelta64 object.
return NaT
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Member Author

Choose a reason for hiding this comment

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

same here, subsumed by the is_float_object case on L1370

@jreback jreback added Clean Timedelta Timedelta data type labels May 5, 2020
@jreback jreback added this to the 1.1 milestone May 5, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

lgtm. merge on green.

@jbrockmendel
Copy link
Member Author

de facto green as of 3 hours ago, Travis icon hasnt updated

@jorisvandenbossche jorisvandenbossche merged commit 8771c25 into pandas-dev:master May 6, 2020
@jbrockmendel jbrockmendel deleted the ref-td-arith branch May 6, 2020 14:11
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants