Skip to content
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

BUG: .rolling() returns incorrect values when ts index is not nano seconds #55173

Merged
merged 20 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@
import pandas # isort:skip

# version = '%s r%s' % (pandas.__version__, svn_version())
version = str(pandas.__version__)
# version = str(pandas.__version__)

version = str(pandas.__version__).split("+")[0]
hkhojasteh marked this conversation as resolved.
Show resolved Hide resolved

# The full version, including alpha/beta/rc tags.
release = version
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,9 @@ def _validate(self):
else:
self._win_freq_i8 = freq.nanos

if self._on.dtype == "M8[us]":
self._win_freq_i8 /= 1000

hkhojasteh marked this conversation as resolved.
Show resolved Hide resolved
# min_periods must be an integer
if self.min_periods is None:
self.min_periods = 1
Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,3 +1950,24 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype):
op2 = getattr(rolling2, kernel)
expected = op2(*arg2, numeric_only=numeric_only)
tm.assert_series_equal(result, expected)


def test_rolling_rolling_sum_window_microseconds_confilict_timestamp():
hkhojasteh marked this conversation as resolved.
Show resolved Hide resolved
# GH#55106
df_time = DataFrame(
{"B": [0, 1, 2, 4, 5, 6]},
index=[
Timestamp("20130101 09:00:00"),
Timestamp("20130101 09:00:02"),
Timestamp("20130101 09:00:03"),
Timestamp("20130101 09:00:06"),
Timestamp("20130101 09:00:07"),
Timestamp("20130101 09:00:08"),
],
)
hkhojasteh marked this conversation as resolved.
Show resolved Hide resolved
sum_in_nanosecs = df_time.rolling("1s").sum()
# micro seconds / milliseconds should not breaks the correct rolling
df_time.index = df_time.index.as_unit("us")
sum_in_microsecs = df_time.rolling("1s").sum()
sum_in_microsecs.index = sum_in_microsecs.index.as_unit("ns")
tm.assert_frame_equal(sum_in_nanosecs, sum_in_microsecs)