From 3e107f3f9963ab8c0e7c180b7a6e6eee419bf646 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Sat, 16 Sep 2023 15:52:24 +0000 Subject: [PATCH 01/15] Fix rolling microseconds for sum --- doc/source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index accbff596b12d..8b060e40aedd8 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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] # The full version, including alpha/beta/rc tags. release = version From 15abeb528b0ab44a18348f6c6059d5f0c3f25791 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Sat, 16 Sep 2023 16:26:13 +0000 Subject: [PATCH 02/15] - adding a test for rounding sum --- pandas/core/window/rolling.py | 3 +++ pandas/tests/window/test_rolling.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index becbba703f92c..214d309956e51 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -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 + # min_periods must be an integer if self.min_periods is None: self.min_periods = 1 diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 3fe922539780d..f30427a57d62f 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -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(): + # 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"), + ], + ) + 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) From bc28f3f242d7a57a479e48a68ffb138e934aba8e Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Tue, 19 Sep 2023 20:43:17 +0200 Subject: [PATCH 03/15] Update pandas/tests/window/test_rolling.py Co-authored-by: Joris Van den Bossche --- pandas/tests/window/test_rolling.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index f30427a57d62f..bc99e63d63fc6 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1954,17 +1954,7 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype): def test_rolling_rolling_sum_window_microseconds_confilict_timestamp(): # 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"), - ], - ) + df = DataFrame({"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5)) 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") From dede3b60c0dc51dd7526fc2d0793ac6af740ea94 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Tue, 19 Sep 2023 20:59:39 +0200 Subject: [PATCH 04/15] Update test_rolling.py the df variable name fixed in the test --- pandas/tests/window/test_rolling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index bc99e63d63fc6..06032cbcebbc9 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1954,7 +1954,7 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype): def test_rolling_rolling_sum_window_microseconds_confilict_timestamp(): # GH#55106 - df = DataFrame({"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5)) + df_time = DataFrame({"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5)) 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") From ba9cf75f67114de8c0370288573196959680ce1f Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Tue, 19 Sep 2023 19:33:43 +0000 Subject: [PATCH 05/15] Reverted version varialbe in doc/source/conf.py --- doc/source/conf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 8b060e40aedd8..accbff596b12d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -172,9 +172,7 @@ import pandas # isort:skip # version = '%s r%s' % (pandas.__version__, svn_version()) -# version = str(pandas.__version__) - -version = str(pandas.__version__).split("+")[0] +version = str(pandas.__version__) # The full version, including alpha/beta/rc tags. release = version From 0a0b938d8e873332d2498a4264c60faad76b7715 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Tue, 19 Sep 2023 19:57:44 +0000 Subject: [PATCH 06/15] Units generalised to us/ms/s and test parameterised --- pandas/core/window/rolling.py | 6 +++++- pandas/tests/window/test_rolling.py | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 214d309956e51..2d5fe7b8112ea 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1885,7 +1885,11 @@ def _validate(self): self._win_freq_i8 = freq.nanos if self._on.dtype == "M8[us]": - self._win_freq_i8 /= 1000 + self._win_freq_i8 /= 1e3 + elif self._on.dtype == "M8[ms]": + self._win_freq_i8 /= 1e6 + elif self._on.dtype == "M8[s]": + self._win_freq_i8 /= 1e9 # min_periods must be an integer if self.min_periods is None: diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 06032cbcebbc9..d24d0cdeca542 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1952,12 +1952,15 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype): tm.assert_series_equal(result, expected) -def test_rolling_rolling_sum_window_microseconds_confilict_timestamp(): +@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) +def test_rolling_rolling_sum_window_microseconds_confilict_timestamp(unit): # GH#55106 - df_time = DataFrame({"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5)) + df_time = DataFrame( + {"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5) + ) 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") + df_time.index = df_time.index.as_unit(unit) 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) From 4fd40eb7ed3b8926103476f5a45e327e79870405 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Fri, 22 Sep 2023 21:48:02 +0200 Subject: [PATCH 07/15] Rolling max tests added, related to #55026 --- pandas/tests/window/test_rolling.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index d24d0cdeca542..e3df003d09cba 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1964,3 +1964,24 @@ def test_rolling_rolling_sum_window_microseconds_confilict_timestamp(unit): 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) + +@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) +def test_rolling_rolling_max_window_nanoseconds_confilict_timestamp(unit): + # GH#55026 + window = Timedelta(days=4) + + ref_dates = date_range("2023-01-01", "2023-01-10", unit="ns") + ref_series = Series(0, index=ref_dates) + ref_series.iloc[0] = 1 + ref_max_series = ref_series.rolling(window).max() + + dates = date_range("2023-01-01", "2023-01-10", unit=unit) + series = Series(0, index=dates) + series.iloc[0] = 1 + max_series = series.rolling(window).max() + + ref_df = DataFrame(ref_max_series) + df = DataFrame(max_series) + df.index = df.index.as_unit("ns") + + tm.assert_frame_equal(ref_df, df) From 43b2ccbef778b15c954dda8981867268731ca9de Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Sat, 30 Sep 2023 11:13:36 +0000 Subject: [PATCH 08/15] whatsnew note for 2.1.2 added --- doc/source/whatsnew/v2.1.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index 1a25b848e0f84..049506fa6bc9e 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -15,6 +15,7 @@ Fixed regressions ~~~~~~~~~~~~~~~~~ - Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.MonthBegin` (:issue:`55271`) - Fixed bug where PDEP-6 warning about setting an item of an incompatible dtype was being shown when creating a new conditional column (:issue:`55025`) +- Fixed bug in :class:`pandas.core.window.Rolling` where df.rolling does not work with 'datetime64[us]', 'datetime64[ms]', and 'datetime64[s]' index types for rolling functions (:issue:`55026`, :issue:`55106`, :issue:`55299`) - .. --------------------------------------------------------------------------- From 2b6458e7ca41a13fc531f2919f436963cf067723 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Mon, 2 Oct 2023 19:47:47 +0200 Subject: [PATCH 09/15] Update doc/source/whatsnew/v2.1.2.rst Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/whatsnew/v2.1.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index 049506fa6bc9e..822f4120eb643 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -15,7 +15,7 @@ Fixed regressions ~~~~~~~~~~~~~~~~~ - Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.MonthBegin` (:issue:`55271`) - Fixed bug where PDEP-6 warning about setting an item of an incompatible dtype was being shown when creating a new conditional column (:issue:`55025`) -- Fixed bug in :class:`pandas.core.window.Rolling` where df.rolling does not work with 'datetime64[us]', 'datetime64[ms]', and 'datetime64[s]' index types for rolling functions (:issue:`55026`, :issue:`55106`, :issue:`55299`) +- Fixed bug in :class:`pandas.core.window.Rolling` where non-nanosecond ``on`` would produce incorrect results (:issue:`55026`, :issue:`55106`, :issue:`55299`) - .. --------------------------------------------------------------------------- From 710a7e15f4c104ee52de3a32438a43f4fa3dcc2b Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Tue, 3 Oct 2023 00:21:56 +0000 Subject: [PATCH 10/15] UTC timezone for _index_array of rolling --- pandas/core/window/rolling.py | 9 +++++++++ pandas/tests/window/test_rolling.py | 15 +++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 0aee818e7a633..6005cc9d0bc6d 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -405,6 +405,15 @@ def _index_array(self): # TODO: why do we get here with e.g. MultiIndex? if needs_i8_conversion(self._on.dtype): idx = cast("PeriodIndex | DatetimeIndex | TimedeltaIndex", self._on) + if (type(idx) == DatetimeIndex) and (idx.T.tz is not None): + if idx.T.unit == "s": + return idx.asi8 * int(1e9) + elif idx.T.unit == "ms": + return idx.asi8 * int(1e6) + elif idx.T.unit == "us": + return idx.asi8 * int(1e3) + elif idx.T.unit == "ns": + return idx.asi8 return idx.asi8 return None diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index e3df003d09cba..eb1fa8bc5c777 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1953,29 +1953,32 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype): @pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) -def test_rolling_rolling_sum_window_microseconds_confilict_timestamp(unit): +@pytest.mark.parametrize("tz", [None, "UTC"]) +def test_rolling_rolling_sum_window_microseconds_conflict_timestamp(unit, tz): # GH#55106 df_time = DataFrame( - {"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5) + {"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5, tz=tz) ) sum_in_nanosecs = df_time.rolling("1s").sum() - # micro seconds / milliseconds should not breaks the correct rolling + # microseconds / milliseconds should not break the correct rolling df_time.index = df_time.index.as_unit(unit) 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) + @pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) -def test_rolling_rolling_max_window_nanoseconds_confilict_timestamp(unit): +@pytest.mark.parametrize("tz", [None, "UTC"]) +def test_rolling_rolling_max_window_nanoseconds_conflict_timestamp(unit, tz): # GH#55026 window = Timedelta(days=4) - ref_dates = date_range("2023-01-01", "2023-01-10", unit="ns") + ref_dates = date_range("2023-01-01", "2023-01-10", unit="ns", tz=tz) ref_series = Series(0, index=ref_dates) ref_series.iloc[0] = 1 ref_max_series = ref_series.rolling(window).max() - dates = date_range("2023-01-01", "2023-01-10", unit=unit) + dates = date_range("2023-01-01", "2023-01-10", unit=unit, tz=tz) series = Series(0, index=dates) series.iloc[0] = 1 max_series = series.rolling(window).max() From a6a4d30ae5620f5dfec3ed64683db5cefb8aca73 Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Tue, 3 Oct 2023 10:30:39 +0000 Subject: [PATCH 11/15] Validating tz-aware data Data conversion removed Tests merged --- pandas/core/window/rolling.py | 24 +++++++++--------------- pandas/tests/window/test_rolling.py | 18 ++++++------------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 6005cc9d0bc6d..dfef5ed79ba49 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -112,6 +112,8 @@ from pandas.core.generic import NDFrame from pandas.core.groupby.ops import BaseGrouper +from pandas.core.arrays.datetimelike import dtype_to_unit + class BaseWindow(SelectionMixin): """Provides utilities for performing windowing operations.""" @@ -405,15 +407,6 @@ def _index_array(self): # TODO: why do we get here with e.g. MultiIndex? if needs_i8_conversion(self._on.dtype): idx = cast("PeriodIndex | DatetimeIndex | TimedeltaIndex", self._on) - if (type(idx) == DatetimeIndex) and (idx.T.tz is not None): - if idx.T.unit == "s": - return idx.asi8 * int(1e9) - elif idx.T.unit == "ms": - return idx.asi8 * int(1e6) - elif idx.T.unit == "us": - return idx.asi8 * int(1e3) - elif idx.T.unit == "ns": - return idx.asi8 return idx.asi8 return None @@ -1898,12 +1891,13 @@ def _validate(self): else: self._win_freq_i8 = freq.nanos - if self._on.dtype == "M8[us]": - self._win_freq_i8 /= 1e3 - elif self._on.dtype == "M8[ms]": - self._win_freq_i8 /= 1e6 - elif self._on.dtype == "M8[s]": - self._win_freq_i8 /= 1e9 + unit = dtype_to_unit(self._on.dtype) + if unit == "us": + self._win_freq_i8 /= 1e3 + elif unit == "ms": + self._win_freq_i8 /= 1e6 + elif unit == "s": + self._win_freq_i8 /= 1e9 # min_periods must be an integer if self.min_periods is None: diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index eb1fa8bc5c777..b4f6fde6850a2 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1953,9 +1953,9 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype): @pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) -@pytest.mark.parametrize("tz", [None, "UTC"]) -def test_rolling_rolling_sum_window_microseconds_conflict_timestamp(unit, tz): - # GH#55106 +@pytest.mark.parametrize("tz", [None, "UTC", "Europe/Prague"]) +def test_rolling_timedelta_window_non_nanoseconds(unit, tz): + # Test Sum, GH#55106 df_time = DataFrame( {"A": range(5)}, index=date_range("2013-01-01", freq="1s", periods=5, tz=tz) ) @@ -1966,22 +1966,16 @@ def test_rolling_rolling_sum_window_microseconds_conflict_timestamp(unit, tz): sum_in_microsecs.index = sum_in_microsecs.index.as_unit("ns") tm.assert_frame_equal(sum_in_nanosecs, sum_in_microsecs) - -@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) -@pytest.mark.parametrize("tz", [None, "UTC"]) -def test_rolling_rolling_max_window_nanoseconds_conflict_timestamp(unit, tz): - # GH#55026 - window = Timedelta(days=4) - + # Test max, GH#55026 ref_dates = date_range("2023-01-01", "2023-01-10", unit="ns", tz=tz) ref_series = Series(0, index=ref_dates) ref_series.iloc[0] = 1 - ref_max_series = ref_series.rolling(window).max() + ref_max_series = ref_series.rolling(Timedelta(days=4)).max() dates = date_range("2023-01-01", "2023-01-10", unit=unit, tz=tz) series = Series(0, index=dates) series.iloc[0] = 1 - max_series = series.rolling(window).max() + max_series = series.rolling(Timedelta(days=4)).max() ref_df = DataFrame(ref_max_series) df = DataFrame(max_series) From f62e4846475e6a144e53ca9130f5c71d6524f93b Mon Sep 17 00:00:00 2001 From: Hadi Abdi Khojasteh Date: Sat, 14 Oct 2023 05:01:00 +0000 Subject: [PATCH 12/15] Conversion replaced by Timedelta.as_unit --- pandas/core/window/rolling.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index dfef5ed79ba49..a26c62e6bae95 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -21,6 +21,7 @@ from pandas._libs.tslibs import ( BaseOffset, + Timedelta, to_offset, ) import pandas._libs.window.aggregations as window_aggregations @@ -1889,15 +1890,8 @@ def _validate(self): self._on.freq.nanos / self._on.freq.n ) else: - self._win_freq_i8 = freq.nanos - unit = dtype_to_unit(self._on.dtype) - if unit == "us": - self._win_freq_i8 /= 1e3 - elif unit == "ms": - self._win_freq_i8 /= 1e6 - elif unit == "s": - self._win_freq_i8 /= 1e9 + self._win_freq_i8 = Timedelta(freq).as_unit(unit)._value # min_periods must be an integer if self.min_periods is None: From da3d7ea3f7f18399f611e68ae8d60375bbca4016 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 25 Oct 2023 22:06:00 +0200 Subject: [PATCH 13/15] fixes for failing tests --- pandas/core/window/rolling.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index a26c62e6bae95..c5048596d5ec2 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1890,8 +1890,12 @@ def _validate(self): self._on.freq.nanos / self._on.freq.n ) else: - unit = dtype_to_unit(self._on.dtype) - self._win_freq_i8 = Timedelta(freq).as_unit(unit)._value + try: + unit = dtype_to_unit(self._on.dtype) + except TypeError: + # if not a datetime dtype, eg for empty dataframes + unit = "ns" + self._win_freq_i8 = Timedelta(freq.nanos).as_unit(unit)._value # min_periods must be an integer if self.min_periods is None: From e3d93b0c5f73d29e99bb12f9f41dc09bd38760c2 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 25 Oct 2023 22:09:59 +0200 Subject: [PATCH 14/15] update whatsnew --- doc/source/whatsnew/v2.1.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index e153c95db09f1..418f3abe30647 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -14,7 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ - Fixed regression in :meth:`DataFrame.join` where result has missing values and dtype is arrow backed string (:issue:`55348`) -- Fixed regression in :class:`pandas.core.window.Rolling` where non-nanosecond ``on`` would produce incorrect results (:issue:`55026`, :issue:`55106`, :issue:`55299`) +- Fixed regression in :meth:`~DataFrame.rolling` where non-nanosecond index or ``on`` column would produce incorrect results (:issue:`55026`, :issue:`55106`, :issue:`55299`) - Fixed regression in :meth:`DataFrame.resample` which was extrapolating back to ``origin`` when ``origin`` was outside its bounds (:issue:`55064`) - Fixed regression in :meth:`DataFrame.sort_index` which was not sorting correctly when the index was a sliced :class:`MultiIndex` (:issue:`55379`) - Fixed performance regression with wide DataFrames, typically involving methods where all columns were accessed individually (:issue:`55256`, :issue:`55245`) From 11ceb3a8dcd5e8c13c67af9e99a20934a048fe49 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 25 Oct 2023 22:15:06 +0200 Subject: [PATCH 15/15] type checking --- pandas/core/window/rolling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index c5048596d5ec2..f90863a8ea1ef 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1891,7 +1891,7 @@ def _validate(self): ) else: try: - unit = dtype_to_unit(self._on.dtype) + unit = dtype_to_unit(self._on.dtype) # type: ignore[arg-type] except TypeError: # if not a datetime dtype, eg for empty dataframes unit = "ns"