Skip to content

Commit ff84f69

Browse files
REGR: resampling DataFrame with DateTimeIndex with empty groups and uint8, uint16 or uint32 columns incorrectly raising RuntimeError (#44828)
1 parent a2316f3 commit ff84f69

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

doc/source/whatsnew/v1.3.5.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717
- Fixed regression in :meth:`Series.equals` when comparing floats with dtype object to None (:issue:`44190`)
1818
- Fixed regression in :func:`merge_asof` raising error when array was supplied as join key (:issue:`42844`)
19+
- Fixed regression when resampling :class:`DataFrame` with :class:`DateTimeIndex` with empty groups and ``uint8``, ``uint16`` or ``uint32`` columns incorrectly raising ``RuntimeError`` (:issue:`43329`)
1920
- Fixed regression in creating a :class:`DataFrame` from a timezone-aware :class:`Timestamp` scalar near a Daylight Savings Time transition (:issue:`42505`)
2021
- Fixed performance regression in :func:`read_csv` (:issue:`44106`)
2122
- Fixed regression in :meth:`Series.duplicated` and :meth:`Series.drop_duplicates` when Series has :class:`Categorical` dtype with boolean categories (:issue:`44351`)

pandas/core/groupby/ops.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,10 @@ def _call_cython_op(
500500
elif is_bool_dtype(dtype):
501501
values = values.astype("int64")
502502
elif is_integer_dtype(dtype):
503-
# e.g. uint8 -> uint64, int16 -> int64
504-
dtype_str = dtype.kind + "8"
505-
values = values.astype(dtype_str, copy=False)
503+
# GH#43329 If the dtype is explicitly of type uint64 the type is not
504+
# changed to prevent overflow.
505+
if dtype != np.uint64:
506+
values = values.astype(np.int64, copy=False)
506507
elif is_numeric:
507508
if not is_complex_dtype(dtype):
508509
values = ensure_float64(values)

pandas/tests/resample/test_datetime_index.py

+24
Original file line numberDiff line numberDiff line change
@@ -1828,3 +1828,27 @@ def test_resample_aggregate_functions_min_count(func):
18281828
index=DatetimeIndex(["2020-03-31"], dtype="datetime64[ns]", freq="Q-DEC"),
18291829
)
18301830
tm.assert_series_equal(result, expected)
1831+
1832+
1833+
def test_resample_unsigned_int(any_unsigned_int_numpy_dtype):
1834+
# gh-43329
1835+
df = DataFrame(
1836+
index=date_range(start="2000-01-01", end="2000-01-03 23", freq="12H"),
1837+
columns=["x"],
1838+
data=[0, 1, 0] * 2,
1839+
dtype=any_unsigned_int_numpy_dtype,
1840+
)
1841+
df = df.loc[(df.index < "2000-01-02") | (df.index > "2000-01-03"), :]
1842+
1843+
if any_unsigned_int_numpy_dtype == "uint64":
1844+
with pytest.raises(RuntimeError, match="empty group with uint64_t"):
1845+
result = df.resample("D").max()
1846+
else:
1847+
result = df.resample("D").max()
1848+
1849+
expected = DataFrame(
1850+
[1, np.nan, 0],
1851+
columns=["x"],
1852+
index=date_range(start="2000-01-01", end="2000-01-03 23", freq="D"),
1853+
)
1854+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)