Skip to content

Commit 15abeb5

Browse files
committed
- adding a test for rounding sum
1 parent 3e107f3 commit 15abeb5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pandas/core/window/rolling.py

+3
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,9 @@ def _validate(self):
18841884
else:
18851885
self._win_freq_i8 = freq.nanos
18861886

1887+
if self._on.dtype == "M8[us]":
1888+
self._win_freq_i8 /= 1000
1889+
18871890
# min_periods must be an integer
18881891
if self.min_periods is None:
18891892
self.min_periods = 1

pandas/tests/window/test_rolling.py

+21
Original file line numberDiff line numberDiff line change
@@ -1950,3 +1950,24 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype):
19501950
op2 = getattr(rolling2, kernel)
19511951
expected = op2(*arg2, numeric_only=numeric_only)
19521952
tm.assert_series_equal(result, expected)
1953+
1954+
1955+
def test_rolling_rolling_sum_window_microseconds_confilict_timestamp():
1956+
# GH#55106
1957+
df_time = DataFrame(
1958+
{"B": [0, 1, 2, 4, 5, 6]},
1959+
index=[
1960+
Timestamp("20130101 09:00:00"),
1961+
Timestamp("20130101 09:00:02"),
1962+
Timestamp("20130101 09:00:03"),
1963+
Timestamp("20130101 09:00:06"),
1964+
Timestamp("20130101 09:00:07"),
1965+
Timestamp("20130101 09:00:08"),
1966+
],
1967+
)
1968+
sum_in_nanosecs = df_time.rolling("1s").sum()
1969+
# micro seconds / milliseconds should not breaks the correct rolling
1970+
df_time.index = df_time.index.as_unit("us")
1971+
sum_in_microsecs = df_time.rolling("1s").sum()
1972+
sum_in_microsecs.index = sum_in_microsecs.index.as_unit("ns")
1973+
tm.assert_frame_equal(sum_in_nanosecs, sum_in_microsecs)

0 commit comments

Comments
 (0)