diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 84b102bd4a262..02a58c626b08e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1373,6 +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): 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