From 7f47208f489d03bb79d21134cff7900604a8bb11 Mon Sep 17 00:00:00 2001 From: Adetoro Akinola Date: Tue, 1 Aug 2023 08:29:06 -0500 Subject: [PATCH 1/5] details on weekday argument for DateOffset docs --- pandas/_libs/tslibs/offsets.pyx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 84b102bd4a262..9d3d637efd097 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1373,7 +1373,25 @@ class DateOffset(RelativeDeltaOffset, metaclass=OffsetMeta): previous midnight. **kwds Temporal parameter that add to or replace the offset value. + weekday : int {0, 1, ..., 6}, default 0 + A specific integer for the day of the week. + - 0 is Monday + - 1 is Tuesday + - 2 is Wednesday + - 3 is Thursday + - 4 is Friday + - 5 is Saturday + - 6 is Sunday. + Instead Weekday type from dateutil.relativedelta can be used. + - MO is Monday + - TU is Tuesday + - WE is Wednesday + - TH is Thursday + - FR is Friday + - SA is Saturday + - SU is Sunday. + Parameters that **add** to the offset (like Timedelta): - years From 5e6cbf288f9b722e3cf010a217d8177c1ef352c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:20:38 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 9d3d637efd097..117433eaf2cac 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1391,7 +1391,7 @@ class DateOffset(RelativeDeltaOffset, metaclass=OffsetMeta): - FR is Friday - SA is Saturday - SU is Sunday. - + Parameters that **add** to the offset (like Timedelta): - years From 3e4dbd718fe4d86a42314845c0ff64ad2b1601c8 Mon Sep 17 00:00:00 2001 From: Adetoro Akinola Date: Thu, 3 Aug 2023 10:39:22 -0500 Subject: [PATCH 3/5] details on weekday argument for DateOffset docs --- pandas/_libs/tslibs/offsets.pyx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 84b102bd4a262..466e069524a5d 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1373,6 +1373,24 @@ class DateOffset(RelativeDeltaOffset, metaclass=OffsetMeta): previous midnight. **kwds Temporal parameter that add to or replace the offset value. + weekday : int {0, 1, ..., 6}, default 0 + A specific integer for the day of the week. + - 0 is Monday + - 1 is Tuesday + - 2 is Wednesday + - 3 is Thursday + - 4 is Friday + - 5 is Saturday + - 6 is Sunday + + Instead Weekday type from dateutil.relativedelta can be used. + - MO is Monday + - TU is Tuesday + - WE is Wednesday + - TH is Thursday + - FR is Friday + - SA is Saturday + - SU is Sunday. Parameters that **add** to the offset (like Timedelta): From 79f64958e987287906bf6723d4a6f495cb5e8395 Mon Sep 17 00:00:00 2001 From: Adetoro Akinola Date: Mon, 14 Aug 2023 15:22:30 -0500 Subject: [PATCH 4/5] Fixed DatetimeIndex.tz_convert() .freq attribute --- pandas/core/arrays/datetimes.py | 9 +++++---- pandas/tests/indexes/datetimes/test_timezones.py | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 8ad51e4a90027..be7b36e4b282c 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -824,7 +824,8 @@ def _local_timestamps(self) -> npt.NDArray[np.int64]: def tz_convert(self, tz) -> Self: """ - Convert tz-aware Datetime Array/Index from one time zone to another. + Convert tz-aware Datetime Array/Index from one time zone to another + and sets frequency to None. Parameters ---------- @@ -866,7 +867,7 @@ def tz_convert(self, tz) -> Self: DatetimeIndex(['2014-08-01 02:00:00-05:00', '2014-08-01 03:00:00-05:00', '2014-08-01 04:00:00-05:00'], - dtype='datetime64[ns, US/Central]', freq='H') + dtype='datetime64[ns, US/Central]') With the ``tz=None``, we can remove the timezone (after converting to UTC if necessary): @@ -884,7 +885,7 @@ def tz_convert(self, tz) -> Self: DatetimeIndex(['2014-08-01 07:00:00', '2014-08-01 08:00:00', '2014-08-01 09:00:00'], - dtype='datetime64[ns]', freq='H') + dtype='datetime64[ns]') """ tz = timezones.maybe_get_tz(tz) @@ -896,7 +897,7 @@ def tz_convert(self, tz) -> Self: # No conversion since timestamps are all UTC to begin with dtype = tz_to_dtype(tz, unit=self.unit) - return self._simple_new(self._ndarray, dtype=dtype, freq=self.freq) + return self._simple_new(self._ndarray, dtype=dtype) @dtl.ravel_compat def tz_localize( diff --git a/pandas/tests/indexes/datetimes/test_timezones.py b/pandas/tests/indexes/datetimes/test_timezones.py index 6f3c83b999e94..8bda33f9b4ae7 100644 --- a/pandas/tests/indexes/datetimes/test_timezones.py +++ b/pandas/tests/indexes/datetimes/test_timezones.py @@ -102,6 +102,12 @@ def test_tz_convert_nat(self): expected = ["2010-12-01 11:00", "2010-12-02 11:00", pd.NaT] tm.assert_index_equal(idx, DatetimeIndex(expected, tz="US/Eastern")) + def test_tz_convert_freq(self): + i = date_range("2020-03-27 06:00", freq="D", periods=5, tz="Europe/Berlin") + + i2 = i.tz_convert("UTC") + assert i2.freq is None + @pytest.mark.parametrize("prefix", ["", "dateutil/"]) def test_dti_tz_convert_compat_timestamp(self, prefix): strdates = ["1/1/2012", "3/1/2012", "4/1/2012"] @@ -880,7 +886,7 @@ def test_dti_tz_conversion_freq(self, tz_naive_fixture): t3 = DatetimeIndex(["2019-01-01 10:00"], freq="H") assert t3.tz_localize(tz=tz_naive_fixture).freq == t3.freq t4 = DatetimeIndex(["2019-01-02 12:00"], tz="UTC", freq="T") - assert t4.tz_convert(tz="UTC").freq == t4.freq + assert t4.tz_convert(tz="UTC").freq is None def test_drop_dst_boundary(self): # see gh-18031 From f38a42ca705b7e4da4cdc8650e6cb44ab603f550 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 20:52:28 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7c0f443f71b39..02a58c626b08e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1374,7 +1374,7 @@ class DateOffset(RelativeDeltaOffset, metaclass=OffsetMeta): **kwds Temporal parameter that add to or replace the offset value. weekday : int {0, 1, ..., 6}, default 0 - + A specific integer for the day of the week. - 0 is Monday - 1 is Tuesday