Skip to content

ENH: implement Timedelta._as_unit #47162

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 1 commit into from
May 31, 2022
Merged

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@jreback jreback added Timedelta Timedelta data type Non-Nano datetime64/timedelta64 with non-nanosecond resolution labels May 29, 2022
@@ -954,7 +954,7 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
case NPY_FR_s:
// special case where we can simplify many expressions bc per_sec=1

per_day = 86400000LL;
per_day = 86400LL;
Copy link
Member

Choose a reason for hiding this comment

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

Did this fix a bug somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

turns out not to be relevant, could actually get rid of per_day here entirely

assert rt.value == td.value
assert rt._reso == td._reso

def test_as_unit_overflows(self):
Copy link
Member

Choose a reason for hiding this comment

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

Just confirming aloud, based on the multiplication operation we can't get to a state where underflowing occurs (and therefore can't test that)?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is all in integers, so i dont think underflows are an issue

td._as_unit("ms", round_ok=False)

def test_as_unit_non_nano(self):
# case where we are going neither to nor from nano
Copy link
Member

Choose a reason for hiding this comment

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

Not really sure what neither to nor means (if it's an idiom)

Copy link
Member Author

Choose a reason for hiding this comment

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

"not to nano" and "not from nano"

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.

So _as_unit will be used separately from _as_reso in the future?

@jbrockmendel
Copy link
Member Author

So _as_unit will be used separately from _as_reso in the future?

Yes _as_unit is the one that will eventually be user-facing. Just didnt want to make it public yet in case we want to change the name

@mroeschke mroeschke added this to the 1.5 milestone May 31, 2022
@mroeschke mroeschke merged commit a4e3338 into pandas-dev:main May 31, 2022
@jbrockmendel jbrockmendel deleted the enh-as_reso branch May 31, 2022 20:39
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
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 Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants