Skip to content

Commit 7d7d139

Browse files
committed
Merge branch 'main' into daydst2
2 parents 141d3a8 + 2f3b0ed commit 7d7d139

37 files changed

+516
-228
lines changed

doc/source/whatsnew/v2.2.0.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ For example:
234234
Other Deprecations
235235
^^^^^^^^^^^^^^^^^^
236236
- Changed :meth:`Timedelta.resolution_string` to return ``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns`` instead of ``H``, ``T``, ``S``, ``L``, ``U``, and ``N``, for compatibility with respective deprecations in frequency aliases (:issue:`52536`)
237+
- Deprecated :meth:`Index.format`, use ``index.astype(str)`` or ``index.map(formatter)`` instead (:issue:`55413`)
237238
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_clipboard`. (:issue:`54229`)
238239
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_csv` except ``path_or_buf``. (:issue:`54229`)
239240
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_dict`. (:issue:`54229`)
@@ -261,6 +262,7 @@ Other Deprecations
261262
- Deprecated the extension test classes ``BaseNoReduceTests``, ``BaseBooleanReduceTests``, and ``BaseNumericReduceTests``, use ``BaseReduceTests`` instead (:issue:`54663`)
262263
- Deprecated the option ``mode.data_manager`` and the ``ArrayManager``; only the ``BlockManager`` will be available in future versions (:issue:`55043`)
263264
- Deprecating downcasting the results of :meth:`DataFrame.fillna`, :meth:`Series.fillna`, :meth:`DataFrame.ffill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill`, :meth:`Series.bfill` in object-dtype cases. To opt in to the future version, use ``pd.set_option("future.no_silent_downcasting", True)`` (:issue:`54261`)
265+
-
264266

265267
.. ---------------------------------------------------------------------------
266268
.. _whatsnew_220.performance:
@@ -285,17 +287,20 @@ Bug fixes
285287
Categorical
286288
^^^^^^^^^^^
287289
- :meth:`Categorical.isin` raising ``InvalidIndexError`` for categorical containing overlapping :class:`Interval` values (:issue:`34974`)
290+
- Bug in :meth:`CategoricalDtype.__eq__` returning false for unordered categorical data with mixed types (:issue:`55468`)
288291
-
289292

290293
Datetimelike
291294
^^^^^^^^^^^^
292295
- Bug in :meth:`DatetimeIndex.union` returning object dtype for tz-aware indexes with the same timezone but different units (:issue:`55238`)
293-
-
296+
- Bug in :meth:`Tick.delta` with very large ticks raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`)
297+
- Bug in addition or subtraction of very large :class:`Tick` objects with :class:`Timestamp` or :class:`Timedelta` objects raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`)
298+
294299

295300
Timedelta
296301
^^^^^^^^^
302+
- Bug in :class:`Timedelta` construction raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`)
297303
- Bug in rendering (``__repr__``) of :class:`TimedeltaIndex` and :class:`Series` with timedelta64 values with non-nanosecond resolution entries that are all multiples of 24 hours failing to use the compact representation used in the nanosecond cases (:issue:`55405`)
298-
-
299304

300305
Timezones
301306
^^^^^^^^^
@@ -352,7 +357,7 @@ I/O
352357

353358
Period
354359
^^^^^^
355-
-
360+
- Bug in :class:`Period` addition silently wrapping around instead of raising ``OverflowError`` (:issue:`55503`)
356361
-
357362

358363
Plotting

pandas/_libs/tslibs/offsets.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,12 @@ cdef class Tick(SingleConstructorOffset):
964964

965965
@property
966966
def delta(self):
967-
return self.n * Timedelta(self._nanos_inc)
967+
try:
968+
return self.n * Timedelta(self._nanos_inc)
969+
except OverflowError as err:
970+
# GH#55503 as_unit will raise a more useful OutOfBoundsTimedelta
971+
Timedelta(self).as_unit("ns")
972+
raise AssertionError("This should not be reached.")
968973

969974
@property
970975
def nanos(self) -> int64_t:

pandas/_libs/tslibs/period.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ cdef class _Period(PeriodMixin):
18151815

18161816
def _add_timedeltalike_scalar(self, other) -> "Period":
18171817
cdef:
1818-
int64_t inc
1818+
int64_t inc, ordinal
18191819

18201820
if not self._dtype._is_tick_like():
18211821
raise IncompatibleFrequency("Input cannot be converted to "
@@ -1837,8 +1837,8 @@ cdef class _Period(PeriodMixin):
18371837
except ValueError as err:
18381838
raise IncompatibleFrequency("Input cannot be converted to "
18391839
f"Period(freq={self.freqstr})") from err
1840-
# TODO: overflow-check here
1841-
ordinal = self.ordinal + inc
1840+
with cython.overflowcheck(True):
1841+
ordinal = self.ordinal + inc
18421842
return Period(ordinal=ordinal, freq=self.freq)
18431843

18441844
def _add_offset(self, other) -> "Period":
@@ -1851,6 +1851,7 @@ cdef class _Period(PeriodMixin):
18511851
ordinal = self.ordinal + other.n
18521852
return Period(ordinal=ordinal, freq=self.freq)
18531853

1854+
@cython.overflowcheck(True)
18541855
def __add__(self, other):
18551856
if not is_period_object(self):
18561857
# cython semantics; this is analogous to a call to __radd__

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ class Timedelta(_Timedelta):
17841784
)
17851785

17861786
# GH43764, convert any input to nanoseconds first and then
1787-
# create the timestamp. This ensures that any potential
1787+
# create the timedelta. This ensures that any potential
17881788
# nanosecond contributions from kwargs parsed as floats
17891789
# are taken into consideration.
17901790
seconds = int((
@@ -1797,12 +1797,24 @@ class Timedelta(_Timedelta):
17971797
) * 1_000_000_000
17981798
)
17991799

1800-
value = np.timedelta64(
1801-
int(kwargs.get("nanoseconds", 0))
1802-
+ int(kwargs.get("microseconds", 0) * 1_000)
1803-
+ int(kwargs.get("milliseconds", 0) * 1_000_000)
1804-
+ seconds
1805-
)
1800+
ns = kwargs.get("nanoseconds", 0)
1801+
us = kwargs.get("microseconds", 0)
1802+
ms = kwargs.get("milliseconds", 0)
1803+
try:
1804+
value = np.timedelta64(
1805+
int(ns)
1806+
+ int(us * 1_000)
1807+
+ int(ms * 1_000_000)
1808+
+ seconds
1809+
)
1810+
except OverflowError as err:
1811+
# GH#55503
1812+
msg = (
1813+
f"seconds={seconds}, milliseconds={ms}, "
1814+
f"microseconds={us}, nanoseconds={ns}"
1815+
)
1816+
raise OutOfBoundsTimedelta(msg) from err
1817+
18061818
if unit in {"Y", "y", "M"}:
18071819
raise ValueError(
18081820
"Units 'M', 'Y', and 'y' are no longer supported, as they do not "

pandas/_libs/tslibs/tzconversion.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,11 @@ timedelta-like}
425425
return result.base # .base to get underlying ndarray
426426

427427

428-
cdef Py_ssize_t bisect_right_i8(int64_t *data, int64_t val, Py_ssize_t n):
428+
cdef Py_ssize_t bisect_right_i8(
429+
const int64_t *data,
430+
int64_t val,
431+
Py_ssize_t n
432+
) noexcept:
429433
# Caller is responsible for checking n > 0
430434
# This looks very similar to local_search_right in the ndarray.searchsorted
431435
# implementation.
@@ -463,7 +467,7 @@ cdef str _render_tstamp(int64_t val, NPY_DATETIMEUNIT creso):
463467

464468
cdef _get_utc_bounds(
465469
ndarray[int64_t] vals,
466-
int64_t* tdata,
470+
const int64_t* tdata,
467471
Py_ssize_t ntrans,
468472
const int64_t[::1] deltas,
469473
NPY_DATETIMEUNIT creso,

pandas/core/dtypes/dtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def __eq__(self, other: object) -> bool:
456456

457457
# With object-dtype we need a comparison that identifies
458458
# e.g. int(2) as distinct from float(2)
459-
return hash(self) == hash(other)
459+
return set(left) == set(right)
460460

461461
def __repr__(self) -> str_type:
462462
if self.categories is None:

0 commit comments

Comments
 (0)