Skip to content
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

ENH: Timestamp.__sub__(datetimelike) support non-nano #47346

Merged
merged 3 commits into from
Jun 15, 2022

Conversation

jbrockmendel
Copy link
Member

With mixed resos, cast to the lower reso, and only if doing so is lossless.

# case with non-lossy rounding
ts = ts_tz

# choose a unit for `other` that doesn't match ts_tz's
Copy link
Member

@mroeschke mroeschke Jun 14, 2022

Choose a reason for hiding this comment

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

Mind expanding on this comment that reso parameterization does test the > and < test?

assert result.value == 0
assert result._reso == min(ts._reso, other._reso)

# TODO: clarify in message that add/sub is allowed only when lossless?
Copy link
Member

@mroeschke mroeschke Jun 14, 2022

Choose a reason for hiding this comment

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

+ 1

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Also regarding the "losslessly" error message, would nice to clarify the loss e.g. f"Could not losslessly covert {reso1} to {reso2}. {mod} {reso1} would be lost"

@jbrockmendel
Copy link
Member Author

updated. getting the mod info in the exception message would be a bit of a hassle, so punting on that for now

@mroeschke mroeschke added this to the 1.5 milestone Jun 15, 2022
@mroeschke mroeschke added Numeric Operations Arithmetic, Comparison, and Logical operations Non-Nano datetime64/timedelta64 with non-nanosecond resolution labels Jun 15, 2022
@mroeschke mroeschke merged commit f7be58a into pandas-dev:main Jun 15, 2022
@jbrockmendel jbrockmendel deleted the nano-addsub-2 branch June 15, 2022 16:44
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
* ENH: Timestamp +- timedeltalike scalar support non-nano

* ENH: Timestamp.__sub__(datetime) with non-nano

* better exception message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Non-Nano datetime64/timedelta64 with non-nanosecond resolution Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants