BUG: Timedelta.round() raises ZeroDivisionError when internal unit is 's' and target frequency is sub-second#64836
Conversation
… 's' and target frequency is sub-second
|
|
||
| def test_round_freq_finer_than_resolution(self): | ||
| # GH#64828 | ||
| td = Timedelta(1.0, unit="days") |
There was a problem hiding this comment.
can you assert td.unit == "s"
| _Timedelta td_ns | ||
|
|
||
| unit = get_unit_for_round(freq, self._creso) | ||
| if unit == 0: |
There was a problem hiding this comment.
i think it would be simpler to match the Timestamp._round version:
freq = to_offset(freq, is_period=False)
nanos = get_unit_for_round(freq, self._creso)
if nanos == 0:
if freq.nanos == 0:
raise ValueError("Division by zero in rounding")
# e.g. self.unit == "s" and sub-second freq
return self
| ~~~~~~~~~~~~~~~~~ | ||
| - Fixed regression in :meth:`HDFStore.select` where the ``where`` clause on a datetime index silently returned empty results when the index had non-nanosecond resolution (:issue:`64310`) | ||
| - Fixed regression in :meth:`Series.interpolate` where ``limit_direction="both"`` with ``limit`` greater than the Series length raised ``ValueError`` (:issue:`64322`) | ||
| - Fixed regression in :meth:`Timedelta.round`, :meth:`Timedelta.floor`, and :meth:`Timedelta.ceil` raising ``ZeroDivisionError`` for sub-second ``freq`` (:issue:`64828`) |
There was a problem hiding this comment.
3.0.2 was released today. this will need to be moved to the 3.1 file
|
@jbrockmendel Thank you for your reviews! I applied those. |
| ndarray[int64_t] arr | ||
|
|
||
| unit = get_unit_for_round(freq, self._creso) | ||
| from pandas._libs.tslibs.offsets import to_offset |
There was a problem hiding this comment.
can you cimport this at the top?
There was a problem hiding this comment.
other than this LGTM. ping on green
There was a problem hiding this comment.
@jbrockmendel I moved cimport to the top. Thank you.
| from pandas._libs.tslibs.offsets import ( | ||
| Day, | ||
| to_offset, | ||
| ) |
There was a problem hiding this comment.
i think to_offset needs to be a cimport or else you get a circular import problem
|
thanks @kjmin622 |
|
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
|
@kjmin622 can you handle the backport; follow the instructions above |
…-comparison * upstream/main: PERF: use lookup instead of hash_inner_join for merge with unique right keys (pandas-dev#64691) BUG : update `SeriesGroupBy.ohlc()` to honor `as_index=False` (pandas-dev#65141) PERF: Use DataFrame-level reductions in DataFrame.agg with list of funcs (pandas-dev#65031) DOC: document required external libraries in read_* I/O docstrings (pandas-dev#65143) DOC: improve MultiIndex.is_monotonic_increasing/decreasing docstrings (pandas-dev#65154) BUG: Raise ValueError for non-boolean numeric_only in DataFrame/Series reductions (GH#53098) (pandas-dev#65131) BUG: Timedelta.round() raises ZeroDivisionError when internal unit is 's' and target frequency is sub-second (pandas-dev#64836) ENH: Add replace method to Index (closes pandas-dev#19495) (pandas-dev#65099) PERF: improve StringArray.isna (pandas-dev#57733) BUG: read parquet files with older pytz (DEP: keep lower pytz minimum version) (pandas-dev#65133) DEPR: deprecate dates-with-datetime64 in _maybe_downcast_for_indexing (pandas-dev#64871) DOC: note that DataFrame.values is not writeable (pandas-dev#65142) CLN: Update groupby observed defaults (pandas-dev#65148) PERF: avoid materializing values[indexer] in Block.setitem (pandas-dev#64251) DOC: update GroupBy.sum/min/max See Also sections (pandas-dev#65144)
… 's' and target frequency is sub-second (pandas-dev#64836) (cherry picked from commit 16ca7d9)
|
@jbrockmendel I have submitted a backport PR. #65201 |
…oDivisionError when internal unit is 's' and target frequency is sub-second) (#65201)
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.AGENTS.md.