From 460afc2f9d76b85f5954103f1752a660a192c7b5 Mon Sep 17 00:00:00 2001 From: jrmylow Date: Thu, 11 Jan 2024 21:58:51 +1100 Subject: [PATCH 1/6] pandas-dev#56147 removed offset and year end interaction --- pandas/core/arrays/datetimes.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index a4d01dd6667f6..c03b0d48fe643 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2770,16 +2770,12 @@ def _generate_range( else: end = None + # GH #56134 fix bug in end of interval if start and not offset.is_on_offset(start): # Incompatible types in assignment (expression has type "datetime", # variable has type "Optional[Timestamp]") start = offset.rollforward(start) # type: ignore[assignment] - elif end and not offset.is_on_offset(end): - # Incompatible types in assignment (expression has type "datetime", - # variable has type "Optional[Timestamp]") - end = offset.rollback(end) # type: ignore[assignment] - # Unsupported operand types for < ("Timestamp" and "None") if periods is None and end < start and offset.n >= 0: # type: ignore[operator] end = None From b27bb1ace1be2e109a77a85d44ed833a24c17da6 Mon Sep 17 00:00:00 2001 From: jrmylow Date: Thu, 11 Jan 2024 22:02:36 +1100 Subject: [PATCH 2/6] pandas-dev#56134 test --- pandas/tests/indexes/datetimes/test_date_range.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 024f37ee5b710..c4a592cb816ca 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -1703,3 +1703,18 @@ def test_date_range_freqstr_matches_offset(self, freqstr, offset): idx2 = date_range(start=sdate, end=edate, freq=offset) assert len(idx1) == len(idx2) assert idx1.freq == idx2.freq + + def test_date_range_partial_day_year_end(self, unit): + # GH#56134 + rng = date_range( + start="2021-12-31 00:00:01", + end="2023-10-31 00:00:00", + freq="YE", + unit=unit, + ) + exp = DatetimeIndex( + ["2021-12-31 00:00:01", "2022-12-31 00:00:01"], + dtype=f"M8[{unit}]", + freq="YE", + ) + tm.assert_index_equal(rng, exp) \ No newline at end of file From 1228d9ec6ec641a2e1add12d16fbc6cbd97eca4b Mon Sep 17 00:00:00 2001 From: jrmylow Date: Thu, 11 Jan 2024 22:04:26 +1100 Subject: [PATCH 3/6] documentation update --- doc/source/whatsnew/v2.3.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.3.0.rst b/doc/source/whatsnew/v2.3.0.rst index 7b53ddb3923f0..4919f3cd36036 100644 --- a/doc/source/whatsnew/v2.3.0.rst +++ b/doc/source/whatsnew/v2.3.0.rst @@ -209,6 +209,7 @@ Styler Other ^^^^^ +- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`) .. ***DO NOT USE THIS SECTION*** From 0614cce4beddadce2aae97048a3318930459fd4b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:10:35 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/indexes/datetimes/test_date_range.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index c4a592cb816ca..ec158f7b194a0 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -1717,4 +1717,4 @@ def test_date_range_partial_day_year_end(self, unit): dtype=f"M8[{unit}]", freq="YE", ) - tm.assert_index_equal(rng, exp) \ No newline at end of file + tm.assert_index_equal(rng, exp) From de14fa9ec24664377a6724a441f396c2f9c5dfaa Mon Sep 17 00:00:00 2001 From: jrmylow Date: Thu, 11 Jan 2024 23:28:13 +1100 Subject: [PATCH 5/6] updated documentation --- doc/source/whatsnew/v2.3.0.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.3.0.rst b/doc/source/whatsnew/v2.3.0.rst index 4919f3cd36036..75f68e1bd0a48 100644 --- a/doc/source/whatsnew/v2.3.0.rst +++ b/doc/source/whatsnew/v2.3.0.rst @@ -119,7 +119,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ -- +- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`) - Timedelta @@ -209,7 +209,6 @@ Styler Other ^^^^^ -- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`) .. ***DO NOT USE THIS SECTION*** From 8818e6548d99b8eddd1f33b9782817187c2b38cf Mon Sep 17 00:00:00 2001 From: jrmylow Date: Thu, 11 Jan 2024 23:28:33 +1100 Subject: [PATCH 6/6] deleted redundant comment --- pandas/core/arrays/datetimes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index c03b0d48fe643..8a9b19dc7934f 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2770,7 +2770,6 @@ def _generate_range( else: end = None - # GH #56134 fix bug in end of interval if start and not offset.is_on_offset(start): # Incompatible types in assignment (expression has type "datetime", # variable has type "Optional[Timestamp]")