-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: Fix dt64[non_nano] + some_offsets incorrectly rounding #62383
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
base: main
Are you sure you want to change the base?
Changes from 19 commits
184ad31
0f088f5
f8e31d4
259a5e4
9c95525
dcf4dfc
4a4d976
ba029d1
e27110a
4f2dced
c6c2fad
00ad36c
87cbc42
e4b91c4
b6f945d
1b571f7
6722152
3f5af74
9372a88
2730c89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| NaT, | ||
| NaTType, | ||
| Resolution, | ||
| Timedelta, | ||
| Timestamp, | ||
| astype_overflowsafe, | ||
| fields, | ||
|
|
@@ -70,6 +71,7 @@ | |
|
|
||
| from pandas.tseries.frequencies import get_period_alias | ||
| from pandas.tseries.offsets import ( | ||
| DateOffset, | ||
| Day, | ||
| Tick, | ||
| ) | ||
|
|
@@ -93,7 +95,6 @@ | |
|
|
||
| from pandas import ( | ||
| DataFrame, | ||
| Timedelta, | ||
| ) | ||
| from pandas.core.arrays import PeriodArray | ||
|
|
||
|
|
@@ -817,7 +818,34 @@ def _add_offset(self, offset: BaseOffset) -> Self: | |
| result = type(self)._from_sequence(res_values, dtype=self.dtype) | ||
|
|
||
| else: | ||
| units = [ | ||
| "ns", | ||
| "us", | ||
| "ms", | ||
| "s", | ||
| ] | ||
| res_unit = self.unit | ||
| if type(offset) is DateOffset: | ||
| nano = offset.kwds.get("nanoseconds", 0) | ||
| micro = offset.kwds.get("microseconds", 0) | ||
| if nano: | ||
| res_unit = "ns" | ||
| elif micro and self.unit != "ns": | ||
| res_unit = "us" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. side-note for another PR: might be worth defining a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing that out. would it make sense to open an issue for it or would you prefer I handle it directly in a follow up PR? |
||
| if ( | ||
| hasattr(offset, "offset") | ||
| and offset.offset is not None | ||
| and not isinstance(offset, Tick) | ||
|
||
| ): | ||
| offset_td = Timedelta(offset.offset) | ||
| if offset_td.value != 0: | ||
| offset_unit = offset_td.unit | ||
| idx_self = units.index(self.unit) | ||
| idx_offset = units.index(offset_unit) | ||
| res_unit = units[min(idx_self, idx_offset)] | ||
| result = type(self)._simple_new(res_values, dtype=res_values.dtype) | ||
| result = result.as_unit(res_unit) | ||
|
|
||
| if offset.normalize: | ||
| result = result.normalize() | ||
| result._freq = None | ||
|
|
||
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.
this is a bit tricky. if the attribute exists and is zero, we still want the high resolution. its only if the attribute doesn't exist that we want the lower unit