diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index c8e67710c85a9..31bb358b51b88 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -612,7 +612,7 @@ financial applications. See the :ref:`Time Series section `. rng = pd.date_range("1/1/2012", periods=100, freq="s") ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng) - ts.resample("5Min").sum() + ts.resample("5min").sum() :meth:`Series.tz_localize` localizes a time series to a time zone: diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 0f0e6271d8329..46a794d1c3783 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -1645,7 +1645,7 @@ Basics ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng) - ts.resample("5Min").sum() + ts.resample("5min").sum() The ``resample`` function is very flexible and allows you to specify many different parameters to control the frequency conversion and resampling @@ -1657,11 +1657,11 @@ a method of the returned object, including ``sum``, ``mean``, ``std``, ``sem``, .. ipython:: python - ts.resample("5Min").mean() + ts.resample("5min").mean() - ts.resample("5Min").ohlc() + ts.resample("5min").ohlc() - ts.resample("5Min").max() + ts.resample("5min").max() For downsampling, ``closed`` can be set to 'left' or 'right' to specify which @@ -1669,9 +1669,9 @@ end of the interval is closed: .. ipython:: python - ts.resample("5Min", closed="right").mean() + ts.resample("5min", closed="right").mean() - ts.resample("5Min", closed="left").mean() + ts.resample("5min", closed="left").mean() Parameters like ``label`` are used to manipulate the resulting labels. ``label`` specifies whether the result is labeled with the beginning or @@ -1679,9 +1679,9 @@ the end of the interval. .. ipython:: python - ts.resample("5Min").mean() # by default label='left' + ts.resample("5min").mean() # by default label='left' - ts.resample("5Min", label="left").mean() + ts.resample("5min", label="left").mean() .. warning:: diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index d9ab0452c8334..f912601daaf26 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -619,6 +619,41 @@ For example: pd.date_range('2020-01-01', periods=3, freq='QE-NOV') +Deprecate lowercase strings ``'w'``, ``'m'``, ``'q'``, etc. and uppercase strings ``'H'``, ``'MIN'``, ``'S'``, etc. for time series, period, and timedelta +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Previously, both ``'h'`` and ``'H'`` were allowed for 'hour' offset/period alias. We now require the case to be correct - check the :ref:`offset aliases ` and the :ref:`period aliases ` parts of the docs and make sure you're using the correct one (:issue:`56346`) + +Deprecated lowercase strings in favour of uppercase strings denoting: + +- period aliases weekly, monthly and bigger frequency +- offsets aliases representing :class:`DateOffset` subclasses that are a week or bigger (``Week``, ``MonthBegin``, ``MonthEnd``, etc.) +- timedelta units for week, month or bigger + +Deprecated uppercase strings in favour of lowercase strings denoting: + +- period aliases hourly, minutely or smaller frequency +- offsets aliases representing :class:`DateOffset` subclasses that are an hour or smaller (``Hour``, ``Minute``, etc.) +- timedelta units for hour, minute or smaller + +For example: + +*Previous behavior*: + +.. code-block:: ipython + + In [9]: pd.date_range('2020-01-01', periods=3, freq='H') + Out[9]: + DatetimeIndex(['2020-01-01 00:00:00', '2020-01-01 01:00:00', + '2020-01-01 02:00:00'], + dtype='datetime64[ns]', freq='H') + +*Future behavior*: + +.. ipython:: python + + pd.date_range('2020-01-01', periods=3, freq='h') + Deprecated automatic downcasting ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 52e1133e596c5..93a899c38c795 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -407,8 +407,10 @@ cdef dict c_DEPR_ABBREVS = { "L": "ms", "l": "ms", "U": "us", + "US": "us", "u": "us", "N": "ns", + "NS": "ns", "n": "ns", } @@ -509,7 +511,7 @@ class Resolution(Enum): warnings.warn( f"\'{freq}\' is deprecated and will be removed in a future " f"version. Please use \'{abbrev}\' " - "instead of \'{freq}\'.", + f"instead of \'{freq}\'.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e96a905367f69..d5093db86bc69 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1796,7 +1796,7 @@ cdef class BusinessDay(BusinessMixin): s -= hrs * 3600 mts = int(s / 60) if mts != 0: - off_str += str(mts) + "Min" + off_str += str(mts) + "min" s -= mts * 60 if s != 0: off_str += str(s) + "s" @@ -4702,14 +4702,13 @@ _lite_rule_alias = { "BYE": "BYE-DEC", # BYearEnd(month=12), "BYS": "BYS-JAN", # BYearBegin(month=1), - "Min": "min", "min": "min", "ms": "ms", "us": "us", "ns": "ns", } -_dont_uppercase = _dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s"} +_dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s"} INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" @@ -4913,7 +4912,15 @@ cpdef to_offset(freq, bint is_period=False): stacklevel=find_stack_level(), ) name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) - + if name == "w"or name == "d": + warnings.warn( + f"\'{name}\' is deprecated and will be removed in " + f"a future version, please use \'{name.upper()}\' " + f"instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = name.upper() if sep != "" and not sep.isspace(): raise ValueError("separator must be spaces") prefix = _lite_rule_alias.get(name) or name diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index f6c69cf6d3875..ef53b85ed706a 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -719,15 +719,24 @@ cpdef inline str parse_timedelta_unit(str unit): return "ns" elif unit == "M": return unit - elif unit in c_DEPR_ABBREVS: + elif unit.upper() == "MIN" and unit.lower() != unit: warnings.warn( f"\'{unit}\' is deprecated and will be removed in a " - f"future version. Please use \'{c_DEPR_ABBREVS.get(unit)}\' " + f"future version. Please use \'{unit.lower()}\' " f"instead of \'{unit}\'.", FutureWarning, stacklevel=find_stack_level(), ) - unit = c_DEPR_ABBREVS[unit] + unit = unit.lower() + elif unit.upper() in c_DEPR_ABBREVS and unit != c_DEPR_ABBREVS.get(unit.upper()): + warnings.warn( + f"\'{unit}\' is deprecated and will be removed in a " + f"future version. Please use \'{c_DEPR_ABBREVS.get(unit.upper())}\' " + f"instead of \'{unit}\'.", + FutureWarning, + stacklevel=find_stack_level(), + ) + unit = c_DEPR_ABBREVS[unit.upper()] try: return timedelta_abbrevs[unit.lower()] except KeyError: diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 84e642f47417b..395fce5629724 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -716,7 +716,7 @@ def test_astype_ignores_errors_for_extension_dtypes(self, data, dtype, errors): def test_astype_tz_conversion(self): # GH 35973 - val = {"tz": date_range("2020-08-30", freq="d", periods=2, tz="Europe/London")} + val = {"tz": date_range("2020-08-30", freq="D", periods=2, tz="Europe/London")} df = DataFrame(val) result = df.astype({"tz": "datetime64[ns, Europe/Berlin]"}) @@ -727,7 +727,7 @@ def test_astype_tz_conversion(self): @pytest.mark.parametrize("tz", ["UTC", "Europe/Berlin"]) def test_astype_tz_object_conversion(self, tz): # GH 35973 - val = {"tz": date_range("2020-08-30", freq="d", periods=2, tz="Europe/London")} + val = {"tz": date_range("2020-08-30", freq="D", periods=2, tz="Europe/London")} expected = DataFrame(val) # convert expected to object dtype from other tz str (independently tested) diff --git a/pandas/tests/frame/methods/test_at_time.py b/pandas/tests/frame/methods/test_at_time.py index 1ebe9920933d1..b207d4c4bdde7 100644 --- a/pandas/tests/frame/methods/test_at_time.py +++ b/pandas/tests/frame/methods/test_at_time.py @@ -58,7 +58,7 @@ def test_at_time_midnight(self, frame_or_series): def test_at_time_nonexistent(self, frame_or_series): # time doesn't exist - rng = date_range("1/1/2012", freq="23Min", periods=384) + rng = date_range("1/1/2012", freq="23min", periods=384) ts = DataFrame(np.random.default_rng(2).standard_normal(len(rng)), rng) ts = tm.get_obj(ts, frame_or_series) rs = ts.at_time("16:00") diff --git a/pandas/tests/frame/methods/test_reindex.py b/pandas/tests/frame/methods/test_reindex.py index 76d80e87bdeb5..f4211f6ca67ad 100644 --- a/pandas/tests/frame/methods/test_reindex.py +++ b/pandas/tests/frame/methods/test_reindex.py @@ -787,7 +787,9 @@ def test_reindex_axes(self): index=[datetime(2012, 1, 1), datetime(2012, 1, 2), datetime(2012, 1, 3)], columns=["a", "b", "c"], ) - time_freq = date_range("2012-01-01", "2012-01-03", freq="d") + msg = "'d' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + time_freq = date_range("2012-01-01", "2012-01-03", freq="d") some_cols = ["a", "b"] index_freq = df.reindex(index=time_freq).index.freq diff --git a/pandas/tests/indexes/datetimes/methods/test_repeat.py b/pandas/tests/indexes/datetimes/methods/test_repeat.py index 92501755f8c5b..32e4fb041ba29 100644 --- a/pandas/tests/indexes/datetimes/methods/test_repeat.py +++ b/pandas/tests/indexes/datetimes/methods/test_repeat.py @@ -63,7 +63,7 @@ def test_repeat(self, tz_naive_fixture, unit): reps = 2 msg = "the 'axis' parameter is not supported" - rng = date_range(start="2016-01-01", periods=2, freq="30Min", tz=tz, unit=unit) + rng = date_range(start="2016-01-01", periods=2, freq="30min", tz=tz, unit=unit) expected_rng = DatetimeIndex( [ diff --git a/pandas/tests/indexes/datetimes/methods/test_round.py b/pandas/tests/indexes/datetimes/methods/test_round.py index cde4a3a65804d..4a53d4e8d0513 100644 --- a/pandas/tests/indexes/datetimes/methods/test_round.py +++ b/pandas/tests/indexes/datetimes/methods/test_round.py @@ -42,7 +42,7 @@ def test_round_invalid(self, freq, error_msg): def test_round(self, tz_naive_fixture, unit): tz = tz_naive_fixture - rng = date_range(start="2016-01-01", periods=5, freq="30Min", tz=tz, unit=unit) + rng = date_range(start="2016-01-01", periods=5, freq="30min", tz=tz, unit=unit) elt = rng[1] expected_rng = DatetimeIndex( @@ -104,7 +104,7 @@ def test_round4(self, tz_naive_fixture): def test_no_rounding_occurs(self, tz_naive_fixture): # GH 21262 tz = tz_naive_fixture - rng = date_range(start="2016-01-01", periods=5, freq="2Min", tz=tz) + rng = date_range(start="2016-01-01", periods=5, freq="2min", tz=tz) expected_rng = DatetimeIndex( [ diff --git a/pandas/tests/indexes/period/methods/test_asfreq.py b/pandas/tests/indexes/period/methods/test_asfreq.py index 865bae69d91c7..db0909288b758 100644 --- a/pandas/tests/indexes/period/methods/test_asfreq.py +++ b/pandas/tests/indexes/period/methods/test_asfreq.py @@ -19,7 +19,7 @@ def test_asfreq(self): pi3 = period_range(freq="M", start="1/1/2001", end="1/1/2001") pi4 = period_range(freq="D", start="1/1/2001", end="1/1/2001") pi5 = period_range(freq="h", start="1/1/2001", end="1/1/2001 00:00") - pi6 = period_range(freq="Min", start="1/1/2001", end="1/1/2001 00:00") + pi6 = period_range(freq="min", start="1/1/2001", end="1/1/2001 00:00") pi7 = period_range(freq="s", start="1/1/2001", end="1/1/2001 00:00:00") assert pi1.asfreq("Q", "s") == pi2 @@ -27,35 +27,35 @@ def test_asfreq(self): assert pi1.asfreq("M", "start") == pi3 assert pi1.asfreq("D", "StarT") == pi4 assert pi1.asfreq("h", "beGIN") == pi5 - assert pi1.asfreq("Min", "s") == pi6 + assert pi1.asfreq("min", "s") == pi6 assert pi1.asfreq("s", "s") == pi7 assert pi2.asfreq("Y", "s") == pi1 assert pi2.asfreq("M", "s") == pi3 assert pi2.asfreq("D", "s") == pi4 assert pi2.asfreq("h", "s") == pi5 - assert pi2.asfreq("Min", "s") == pi6 + assert pi2.asfreq("min", "s") == pi6 assert pi2.asfreq("s", "s") == pi7 assert pi3.asfreq("Y", "s") == pi1 assert pi3.asfreq("Q", "s") == pi2 assert pi3.asfreq("D", "s") == pi4 assert pi3.asfreq("h", "s") == pi5 - assert pi3.asfreq("Min", "s") == pi6 + assert pi3.asfreq("min", "s") == pi6 assert pi3.asfreq("s", "s") == pi7 assert pi4.asfreq("Y", "s") == pi1 assert pi4.asfreq("Q", "s") == pi2 assert pi4.asfreq("M", "s") == pi3 assert pi4.asfreq("h", "s") == pi5 - assert pi4.asfreq("Min", "s") == pi6 + assert pi4.asfreq("min", "s") == pi6 assert pi4.asfreq("s", "s") == pi7 assert pi5.asfreq("Y", "s") == pi1 assert pi5.asfreq("Q", "s") == pi2 assert pi5.asfreq("M", "s") == pi3 assert pi5.asfreq("D", "s") == pi4 - assert pi5.asfreq("Min", "s") == pi6 + assert pi5.asfreq("min", "s") == pi6 assert pi5.asfreq("s", "s") == pi7 assert pi6.asfreq("Y", "s") == pi1 @@ -70,7 +70,7 @@ def test_asfreq(self): assert pi7.asfreq("M", "s") == pi3 assert pi7.asfreq("D", "s") == pi4 assert pi7.asfreq("h", "s") == pi5 - assert pi7.asfreq("Min", "s") == pi6 + assert pi7.asfreq("min", "s") == pi6 msg = "How must be one of S or E" with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index 892eb7b4a00d1..8c89401f6d034 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -531,7 +531,7 @@ def test_period_range_length(self): pi = period_range(freq="h", start="1/1/2001", end="12/31/2001 23:00") assert len(pi) == 365 * 24 - pi = period_range(freq="Min", start="1/1/2001", end="1/1/2001 23:59") + pi = period_range(freq="min", start="1/1/2001", end="1/1/2001 23:59") assert len(pi) == 24 * 60 pi = period_range(freq="s", start="1/1/2001", end="1/1/2001 23:59:59") diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 77b8e76894647..e30798dceb328 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -87,7 +87,7 @@ def test_values(self): period_range(freq="M", start="1/1/2001", end="1/1/2002"), period_range(freq="D", start="12/1/2001", end="6/1/2001"), period_range(freq="h", start="12/31/2001", end="1/1/2002 23:00"), - period_range(freq="Min", start="12/31/2001", end="1/1/2002 00:20"), + period_range(freq="min", start="12/31/2001", end="1/1/2002 00:20"), period_range( freq="s", start="12/31/2001 00:00:00", end="12/31/2001 00:05:00" ), diff --git a/pandas/tests/indexes/period/test_period_range.py b/pandas/tests/indexes/period/test_period_range.py index 6f8e6d07da8bf..01417fa07e228 100644 --- a/pandas/tests/indexes/period/test_period_range.py +++ b/pandas/tests/indexes/period/test_period_range.py @@ -215,7 +215,7 @@ def test_constructor_U(self): ], ) def test_a_deprecated_from_time_series(self, freq, freq_depr): - # GH#52536 + # GH#52536,GH#56346 msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " f"future version. Please use '{freq[1:]}' instead." diff --git a/pandas/tests/indexes/timedeltas/test_scalar_compat.py b/pandas/tests/indexes/timedeltas/test_scalar_compat.py index 9f0552f8baa90..c08748172fe41 100644 --- a/pandas/tests/indexes/timedeltas/test_scalar_compat.py +++ b/pandas/tests/indexes/timedeltas/test_scalar_compat.py @@ -49,7 +49,7 @@ def test_tdi_total_seconds_all_nat(self): tm.assert_series_equal(result, expected) def test_tdi_round(self): - td = timedelta_range(start="16801 days", periods=5, freq="30Min") + td = timedelta_range(start="16801 days", periods=5, freq="30min") elt = td[1] expected_rng = TimedeltaIndex( diff --git a/pandas/tests/indexes/timedeltas/test_timedelta_range.py b/pandas/tests/indexes/timedeltas/test_timedelta_range.py index f22bdb7a90516..a4999dd2e609d 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta_range.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta_range.py @@ -88,6 +88,15 @@ def test_timedelta_range_H_T_deprecated(self, freq, msg_freq): expected = timedelta_range(start="0 days", end="4 days", freq=freq) tm.assert_index_equal(result, expected) + @pytest.mark.parametrize("freq_depr", ["H", "MIN", "Min", "S", "Us", "NS"]) + def test_timedelta_range_uppercase_freq_deprecated(self, freq_depr): + # GH#56346 + expected = to_timedelta(np.arange(5), unit=freq_depr.lower()) + to_timedelta(np.arange(5), unit="m") + with tm.assert_produces_warning(FutureWarning, match=freq_depr): + result = to_timedelta(np.arange(5), unit=freq_depr) + tm.assert_index_equal(result, expected) + def test_errors(self): # not enough params msg = ( diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 49776d532db1d..c6d4bd02f54d0 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -221,7 +221,9 @@ def test_to_csv_na_rep_nullable_string(self, nullable_string_dtype): def test_to_csv_date_format(self): # GH 10209 df_sec = DataFrame({"A": pd.date_range("20130101", periods=5, freq="s")}) - df_day = DataFrame({"A": pd.date_range("20130101", periods=5, freq="d")}) + msg = "'d' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + df_day = DataFrame({"A": pd.date_range("20130101", periods=5, freq="d")}) expected_rows = [ ",A", diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index b6fa90edbf106..f35f93af0279a 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -31,7 +31,7 @@ def df_schema(): { "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), + "C": pd.date_range("2016-01-01", freq="D", periods=4), "D": pd.timedelta_range("1h", periods=4, freq="min"), }, index=pd.Index(range(4), name="idx"), @@ -44,12 +44,12 @@ def df_table(): { "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), + "C": pd.date_range("2016-01-01", freq="D", periods=4), "D": pd.timedelta_range("1h", periods=4, freq="min"), "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), "G": [1.0, 2.0, 3, 4.0], - "H": pd.date_range("2016-01-01", freq="d", periods=4, tz="US/Central"), + "H": pd.date_range("2016-01-01", freq="D", periods=4, tz="US/Central"), }, index=pd.Index(range(4), name="idx"), ) @@ -681,7 +681,7 @@ class TestTableOrientReader: {"ints": [1, 2, 3, 4]}, {"objects": ["a", "b", "c", "d"]}, {"objects": ["1", "2", "3", "4"]}, - {"date_ranges": pd.date_range("2016-01-01", freq="d", periods=4)}, + {"date_ranges": pd.date_range("2016-01-01", freq="D", periods=4)}, {"categoricals": pd.Series(pd.Categorical(["a", "b", "c", "c"]))}, { "ordered_cats": pd.Series( @@ -693,7 +693,7 @@ class TestTableOrientReader: {"bools": [True, False, False, True]}, { "timezones": pd.date_range( - "2016-01-01", freq="d", periods=4, tz="US/Central" + "2016-01-01", freq="D", periods=4, tz="US/Central" ) # added in # GH 35973 }, ], @@ -732,7 +732,7 @@ def test_read_json_table_orient_raises(self, index_nm): {"ints": [1, 2, 3, 4]}, {"objects": ["a", "b", "c", "d"]}, {"objects": ["1", "2", "3", "4"]}, - {"date_ranges": pd.date_range("2016-01-01", freq="d", periods=4)}, + {"date_ranges": pd.date_range("2016-01-01", freq="D", periods=4)}, {"categoricals": pd.Series(pd.Categorical(["a", "b", "c", "c"]))}, { "ordered_cats": pd.Series( @@ -744,7 +744,7 @@ def test_read_json_table_orient_raises(self, index_nm): {"bools": [True, False, False, True]}, { "timezones": pd.date_range( - "2016-01-01", freq="d", periods=4, tz="US/Central" + "2016-01-01", freq="D", periods=4, tz="US/Central" ) # added in # GH 35973 }, ], @@ -766,15 +766,15 @@ def test_read_json_table_period_orient(self, index_nm, vals): pd.Index(range(4)), pd.date_range( "2020-08-30", - freq="d", + freq="D", periods=4, )._with_freq(None), pd.date_range( - "2020-08-30", freq="d", periods=4, tz="US/Central" + "2020-08-30", freq="D", periods=4, tz="US/Central" )._with_freq(None), pd.MultiIndex.from_product( [ - pd.date_range("2020-08-30", freq="d", periods=2, tz="US/Central"), + pd.date_range("2020-08-30", freq="D", periods=2, tz="US/Central"), ["x", "y"], ], ), @@ -784,10 +784,10 @@ def test_read_json_table_period_orient(self, index_nm, vals): "vals", [ {"floats": [1.1, 2.2, 3.3, 4.4]}, - {"dates": pd.date_range("2020-08-30", freq="d", periods=4)}, + {"dates": pd.date_range("2020-08-30", freq="D", periods=4)}, { "timezones": pd.date_range( - "2020-08-30", freq="d", periods=4, tz="Europe/London" + "2020-08-30", freq="D", periods=4, tz="Europe/London" ) }, ], @@ -804,12 +804,12 @@ def test_comprehensive(self): { "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), + "C": pd.date_range("2016-01-01", freq="D", periods=4), # 'D': pd.timedelta_range('1h', periods=4, freq='min'), "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), "G": [1.1, 2.2, 3.3, 4.4], - "H": pd.date_range("2016-01-01", freq="d", periods=4, tz="US/Central"), + "H": pd.date_range("2016-01-01", freq="D", periods=4, tz="US/Central"), "I": [True, False, False, True], }, index=pd.Index(range(4), name="idx"), diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 112172656b6ec..882a174386d90 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -125,7 +125,7 @@ def test_tsplot_period(self, freq): _check_plot_works(ser.plot, ax=ax) @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_tsplot_datetime(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -208,7 +208,7 @@ def test_line_plot_period_mlt_series(self, frqncy): _check_plot_works(s.plot, s.index.freq.rule_code) @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_line_plot_datetime_series(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -244,7 +244,7 @@ def test_line_plot_period_mlt_frame(self, frqncy): @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_line_plot_datetime_frame(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -258,7 +258,7 @@ def test_line_plot_datetime_frame(self, freq): _check_plot_works(df.plot, freq) @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_line_plot_inferred_freq(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -572,13 +572,13 @@ def test_finder_annual(self): @pytest.mark.slow def test_finder_minutely(self): nminutes = 50 * 24 * 60 - rng = date_range("1/1/1999", freq="Min", periods=nminutes) + rng = date_range("1/1/1999", freq="min", periods=nminutes) ser = Series(np.random.default_rng(2).standard_normal(len(rng)), rng) _, ax = mpl.pyplot.subplots() ser.plot(ax=ax) xaxis = ax.get_xaxis() rs = xaxis.get_majorticklocs()[0] - xp = Period("1/1/1999", freq="Min").ordinal + xp = Period("1/1/1999", freq="min").ordinal assert rs == xp diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 9cd51b95d6efd..1db214edafde2 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -363,7 +363,7 @@ def test_resample_empty_dtypes(index, dtype, resample_method): empty_series_dti = Series([], index, dtype) with tm.assert_produces_warning(warn, match=msg): - rs = empty_series_dti.resample("d", group_keys=False) + rs = empty_series_dti.resample("D", group_keys=False) try: getattr(rs, resample_method)() except DataError: diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index c5ef0f39ece19..d3b008457baa0 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -50,7 +50,7 @@ def _simple_date_range_series(start, end, freq="D"): def test_custom_grouper(unit): - index = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="Min") + index = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="min") dti = index.as_unit(unit) s = Series(np.array([1] * len(dti)), index=dti, dtype="int64") @@ -121,7 +121,7 @@ def test_custom_grouper_df(unit): ], ) def test_resample_basic(closed, expected, unit): - index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="Min") + index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") s = Series(range(len(index)), index=index) s.index.name = "index" s.index = s.index.as_unit(unit) @@ -156,11 +156,11 @@ def test_resample_integerarray(unit): def test_resample_basic_grouper(unit): - index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="Min") + index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") s = Series(range(len(index)), index=index) s.index.name = "index" s.index = s.index.as_unit(unit) - result = s.resample("5Min").last() + result = s.resample("5min").last() grouper = Grouper(freq=Minute(5), closed="left", label="left") expected = s.groupby(grouper).agg(lambda x: x.iloc[-1]) tm.assert_series_equal(result, expected) @@ -176,7 +176,7 @@ def test_resample_basic_grouper(unit): def test_resample_string_kwargs(keyword, value, unit): # see gh-19303 # Check that wrong keyword argument strings raise an error - index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="Min") + index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") series = Series(range(len(index)), index=index) series.index.name = "index" series.index = series.index.as_unit(unit) @@ -188,7 +188,7 @@ def test_resample_string_kwargs(keyword, value, unit): def test_resample_how(downsample_method, unit): if downsample_method == "ohlc": pytest.skip("covered by test_resample_how_ohlc") - index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="Min") + index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") s = Series(range(len(index)), index=index) s.index.name = "index" s.index = s.index.as_unit(unit) @@ -209,7 +209,7 @@ def test_resample_how(downsample_method, unit): def test_resample_how_ohlc(unit): - index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="Min") + index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") s = Series(range(len(index)), index=index) s.index.name = "index" s.index = s.index.as_unit(unit) @@ -239,7 +239,7 @@ def _ohlc(group): def test_resample_how_callables(unit): # GH#7929 data = np.arange(5, dtype=np.int64) - ind = date_range(start="2014-01-01", periods=len(data), freq="d").as_unit(unit) + ind = date_range(start="2014-01-01", periods=len(data), freq="D").as_unit(unit) df = DataFrame({"A": data, "B": data}, index=ind) def fn(x, a=1): @@ -334,7 +334,7 @@ def test_resample_basic_from_daily(unit): s = Series(np.random.default_rng(2).random(len(dti)), dti) # to weekly - result = s.resample("w-sun").last() + result = s.resample("W-SUN").last() assert len(result) == 3 assert (result.index.dayofweek == [6, 6, 6]).all() @@ -463,7 +463,7 @@ def test_resample_upsample(unit): s = Series(np.random.default_rng(2).random(len(dti)), dti) # to minutely, by padding - result = s.resample("Min").ffill() + result = s.resample("min").ffill() assert len(result) == 12961 assert result.iloc[0] == s.iloc[0] assert result.iloc[-1] == s.iloc[-1] @@ -520,8 +520,8 @@ def test_upsample_with_limit(unit): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("freq", ["1D", "10h", "5Min", "10s"]) -@pytest.mark.parametrize("rule", ["YE", "3ME", "15D", "30h", "15Min", "30s"]) +@pytest.mark.parametrize("freq", ["1D", "10h", "5min", "10s"]) +@pytest.mark.parametrize("rule", ["YE", "3ME", "15D", "30h", "15min", "30s"]) def test_nearest_upsample_with_limit(tz_aware_fixture, freq, rule, unit): # GH 33939 rng = date_range("1/1/2000", periods=3, freq=freq, tz=tz_aware_fixture).as_unit( @@ -535,14 +535,14 @@ def test_nearest_upsample_with_limit(tz_aware_fixture, freq, rule, unit): def test_resample_ohlc(unit): - index = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="Min") + index = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="min") s = Series(range(len(index)), index=index) s.index.name = "index" s.index = s.index.as_unit(unit) grouper = Grouper(freq=Minute(5)) expect = s.groupby(grouper).agg(lambda x: x.iloc[-1]) - result = s.resample("5Min").ohlc() + result = s.resample("5min").ohlc() assert len(result) == len(expect) assert len(result.columns) == 4 @@ -1216,7 +1216,7 @@ def test_anchored_lowercase_buglet(unit): dates = date_range("4/16/2012 20:00", periods=50000, freq="s").as_unit(unit) ts = Series(np.random.default_rng(2).standard_normal(len(dates)), index=dates) # it works! - ts.resample("d").mean() + ts.resample("D").mean() def test_upsample_apply_functions(unit): @@ -1327,8 +1327,8 @@ def test_resample_consistency(unit): s10 = s.reindex(index=i10, method="bfill") s10_2 = s.reindex(index=i10, method="bfill", limit=2) rl = s.reindex_like(s10, method="bfill", limit=2) - r10_2 = s.resample("10Min").bfill(limit=2) - r10 = s.resample("10Min").bfill() + r10_2 = s.resample("10min").bfill(limit=2) + r10 = s.resample("10min").bfill() # s10_2, r10, r10_2, rl should all be equal tm.assert_series_equal(s10_2, r10) @@ -1556,9 +1556,9 @@ def test_groupby_with_dst_time_change(unit): ) df = DataFrame([1, 2], index=index) - result = df.groupby(Grouper(freq="1d")).last() + result = df.groupby(Grouper(freq="1D")).last() expected_index_values = date_range( - "2016-11-02", "2016-11-24", freq="d", tz="America/Chicago" + "2016-11-02", "2016-11-24", freq="D", tz="America/Chicago" ).as_unit(unit) index = DatetimeIndex(expected_index_values) @@ -1588,7 +1588,7 @@ def test_resample_dst_anchor(unit): def test_resample_dst_anchor2(unit): dti = date_range( - "2013-09-30", "2013-11-02", freq="30Min", tz="Europe/Paris" + "2013-09-30", "2013-11-02", freq="30min", tz="Europe/Paris" ).as_unit(unit) values = range(dti.size) df = DataFrame({"a": values, "b": values, "c": values}, index=dti, dtype="int64") @@ -1799,7 +1799,7 @@ def test_resample_datetime_values(unit): def test_resample_apply_with_additional_args(unit): # GH 14615 - index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="Min") + index = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") series = Series(range(len(index)), index=index) series.index.name = "index" @@ -1840,14 +1840,14 @@ def f(data, add_arg): @pytest.mark.parametrize( "n1, freq1, n2, freq2", [ - (30, "s", 0.5, "Min"), - (60, "s", 1, "Min"), + (30, "s", 0.5, "min"), + (60, "s", 1, "min"), (3600, "s", 1, "h"), - (60, "Min", 1, "h"), + (60, "min", 1, "h"), (21600, "s", 0.25, "D"), (86400, "s", 1, "D"), (43200, "s", 0.5, "D"), - (1440, "Min", 1, "D"), + (1440, "min", 1, "D"), (12, "h", 0.5, "D"), (24, "h", 1, "D"), ], @@ -2058,7 +2058,7 @@ def test_resample_M_Q_Y_A_deprecated(freq, freq_depr): depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " f"in a future version, please use '{freq[1:]}' instead." - s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) + s = Series(range(10), index=date_range("20130101", freq="D", periods=10)) expected = s.resample(freq).mean() with tm.assert_produces_warning(FutureWarning, match=depr_msg): result = s.resample(freq_depr).mean() @@ -2078,7 +2078,7 @@ def test_resample_BM_BQ_deprecated(freq, freq_depr): depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " f"in a future version, please use '{freq[1:]}' instead." - s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) + s = Series(range(10), index=date_range("20130101", freq="D", periods=10)) expected = s.resample(freq).mean() with tm.assert_produces_warning(FutureWarning, match=depr_msg): result = s.resample(freq_depr).mean() diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 610eeb6dcf32f..dc3020f6c2b77 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -165,12 +165,12 @@ def test_basic_downsample(self, simple_period_range_series): ("Y-DEC", ""), ("Q-MAR", ""), ("M", ""), - ("w-thu", ""), + ("W-THU", ""), ], ) def test_not_subperiod(self, simple_period_range_series, rule, expected_error_msg): # These are incompatible period rules for resampling - ts = simple_period_range_series("1/1/1990", "6/30/1995", freq="w-wed") + ts = simple_period_range_series("1/1/1990", "6/30/1995", freq="W-WED") msg = ( "Frequency cannot be resampled to " f"{expected_error_msg}, as they are not sub or super periods" @@ -901,8 +901,8 @@ def test_resample_with_only_nat(self): ("19910905 12:00", "19910909 12:00", "h", "17h", "10h"), ("19910905 12:00", "19910909 12:00", "h", "17h", "3h"), ("19910905", "19910913 06:00", "2h", "24h", "10h"), - ("19910905", "19910905 01:39", "Min", "5Min", "3Min"), - ("19910905", "19910905 03:18", "2Min", "5Min", "3Min"), + ("19910905", "19910905 01:39", "min", "5min", "3min"), + ("19910905", "19910905 03:18", "2min", "5min", "3min"), ], ) def test_resample_with_offset(self, start, end, start_freq, end_freq, offset): @@ -1055,7 +1055,7 @@ def test_asfreq_invalid_period_offset(self, offset, frame_or_series): ], ) def test_resample_frequency_ME_QE_YE_error_message(frame_or_series, freq, freq_depr): - # GH#9586 + # GH#9586, GH#56346 msg = f"for Period, please use '{freq[1:]}' instead of '{freq_depr[1:]}'" obj = frame_or_series(range(5), index=period_range("2020-01-01", periods=5)) diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index bf0543ffcc4bb..c8e93fd3cf6c3 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -18,7 +18,7 @@ @pytest.fixture def dti(): - return date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="Min") + return date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="min") @pytest.fixture diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index b312d708ade1e..993f93be74dc2 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -318,7 +318,7 @@ def f(x): def test_apply_columns_multilevel(): # GH 16231 cols = pd.MultiIndex.from_tuples([("A", "a", "", "one"), ("B", "b", "i", "two")]) - ind = date_range(start="2017-01-01", freq="15Min", periods=8) + ind = date_range(start="2017-01-01", freq="15min", periods=8) df = DataFrame(np.array([0] * 16).reshape(8, 2), index=ind, columns=cols) agg_dict = {col: (np.sum if col[3] == "one" else np.mean) for col in df.columns} result = df.resample("h").apply(lambda x: agg_dict[x.name](x)) diff --git a/pandas/tests/scalar/period/test_asfreq.py b/pandas/tests/scalar/period/test_asfreq.py index 73c4d8061c257..176079e652e63 100644 --- a/pandas/tests/scalar/period/test_asfreq.py +++ b/pandas/tests/scalar/period/test_asfreq.py @@ -11,6 +11,7 @@ import pandas._testing as tm bday_msg = "Period with BDay freq is deprecated" +depr_msg = "'{0}' is deprecated and will be removed in a future version" class TestFreqConversion: @@ -79,12 +80,13 @@ def test_conv_annual(self): ival_A_to_D_end = Period(freq="D", year=2007, month=12, day=31) ival_A_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_A_to_H_end = Period(freq="h", year=2007, month=12, day=31, hour=23) - ival_A_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_A_to_T_end = Period( - freq="Min", year=2007, month=12, day=31, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_A_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_A_to_T_end = Period( + freq="Min", year=2007, month=12, day=31, hour=23, minute=59 + ) ival_A_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -157,12 +159,13 @@ def test_conv_quarterly(self): ival_Q_to_D_end = Period(freq="D", year=2007, month=3, day=31) ival_Q_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_Q_to_H_end = Period(freq="h", year=2007, month=3, day=31, hour=23) - ival_Q_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_Q_to_T_end = Period( - freq="Min", year=2007, month=3, day=31, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_Q_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_Q_to_T_end = Period( + freq="Min", year=2007, month=3, day=31, hour=23, minute=59 + ) ival_Q_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -190,8 +193,9 @@ def test_conv_quarterly(self): assert ival_Q.asfreq("D", "E") == ival_Q_to_D_end assert ival_Q.asfreq("h", "s") == ival_Q_to_H_start assert ival_Q.asfreq("h", "E") == ival_Q_to_H_end - assert ival_Q.asfreq("Min", "s") == ival_Q_to_T_start - assert ival_Q.asfreq("Min", "E") == ival_Q_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_Q.asfreq("Min", "s") == ival_Q_to_T_start + assert ival_Q.asfreq("Min", "E") == ival_Q_to_T_end assert ival_Q.asfreq("s", "s") == ival_Q_to_S_start assert ival_Q.asfreq("s", "E") == ival_Q_to_S_end @@ -219,12 +223,13 @@ def test_conv_monthly(self): ival_M_to_D_end = Period(freq="D", year=2007, month=1, day=31) ival_M_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_M_to_H_end = Period(freq="h", year=2007, month=1, day=31, hour=23) - ival_M_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_M_to_T_end = Period( - freq="Min", year=2007, month=1, day=31, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_M_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_M_to_T_end = Period( + freq="Min", year=2007, month=1, day=31, hour=23, minute=59 + ) ival_M_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -246,8 +251,9 @@ def test_conv_monthly(self): assert ival_M.asfreq("D", "E") == ival_M_to_D_end assert ival_M.asfreq("h", "s") == ival_M_to_H_start assert ival_M.asfreq("h", "E") == ival_M_to_H_end - assert ival_M.asfreq("Min", "s") == ival_M_to_T_start - assert ival_M.asfreq("Min", "E") == ival_M_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_M.asfreq("Min", "s") == ival_M_to_T_start + assert ival_M.asfreq("Min", "E") == ival_M_to_T_end assert ival_M.asfreq("s", "s") == ival_M_to_S_start assert ival_M.asfreq("s", "E") == ival_M_to_S_end @@ -309,12 +315,13 @@ def test_conv_weekly(self): ival_W_to_D_end = Period(freq="D", year=2007, month=1, day=7) ival_W_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_W_to_H_end = Period(freq="h", year=2007, month=1, day=7, hour=23) - ival_W_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_W_to_T_end = Period( - freq="Min", year=2007, month=1, day=7, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_W_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_W_to_T_end = Period( + freq="Min", year=2007, month=1, day=7, hour=23, minute=59 + ) ival_W_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -355,8 +362,9 @@ def test_conv_weekly(self): assert ival_W.asfreq("h", "s") == ival_W_to_H_start assert ival_W.asfreq("h", "E") == ival_W_to_H_end - assert ival_W.asfreq("Min", "s") == ival_W_to_T_start - assert ival_W.asfreq("Min", "E") == ival_W_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_W.asfreq("Min", "s") == ival_W_to_T_start + assert ival_W.asfreq("Min", "E") == ival_W_to_T_end assert ival_W.asfreq("s", "s") == ival_W_to_S_start assert ival_W.asfreq("s", "E") == ival_W_to_S_end @@ -402,12 +410,13 @@ def test_conv_business(self): ival_B_to_D = Period(freq="D", year=2007, month=1, day=1) ival_B_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_B_to_H_end = Period(freq="h", year=2007, month=1, day=1, hour=23) - ival_B_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_B_to_T_end = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_B_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_B_to_T_end = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) ival_B_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -428,8 +437,9 @@ def test_conv_business(self): assert ival_B.asfreq("h", "s") == ival_B_to_H_start assert ival_B.asfreq("h", "E") == ival_B_to_H_end - assert ival_B.asfreq("Min", "s") == ival_B_to_T_start - assert ival_B.asfreq("Min", "E") == ival_B_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_B.asfreq("Min", "s") == ival_B_to_T_start + assert ival_B.asfreq("Min", "E") == ival_B_to_T_end assert ival_B.asfreq("s", "s") == ival_B_to_S_start assert ival_B.asfreq("s", "E") == ival_B_to_S_end @@ -468,12 +478,13 @@ def test_conv_daily(self): ival_D_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_D_to_H_end = Period(freq="h", year=2007, month=1, day=1, hour=23) - ival_D_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_D_to_T_end = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_D_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_D_to_T_end = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) ival_D_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -506,8 +517,9 @@ def test_conv_daily(self): assert ival_D.asfreq("h", "s") == ival_D_to_H_start assert ival_D.asfreq("h", "E") == ival_D_to_H_end - assert ival_D.asfreq("Min", "s") == ival_D_to_T_start - assert ival_D.asfreq("Min", "E") == ival_D_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_D.asfreq("Min", "s") == ival_D_to_T_start + assert ival_D.asfreq("Min", "E") == ival_D_to_T_end assert ival_D.asfreq("s", "s") == ival_D_to_S_start assert ival_D.asfreq("s", "E") == ival_D_to_S_end @@ -532,12 +544,13 @@ def test_conv_hourly(self): with tm.assert_produces_warning(FutureWarning, match=bday_msg): ival_H_to_B = Period(freq="B", year=2007, month=1, day=1) - ival_H_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_H_to_T_end = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_H_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_H_to_T_end = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=59 + ) ival_H_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -559,8 +572,9 @@ def test_conv_hourly(self): assert ival_H.asfreq("B") == ival_H_to_B assert ival_H_end_of_bus.asfreq("B") == ival_H_to_B - assert ival_H.asfreq("Min", "s") == ival_H_to_T_start - assert ival_H.asfreq("Min", "E") == ival_H_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_H.asfreq("Min", "s") == ival_H_to_T_start + assert ival_H.asfreq("Min", "E") == ival_H_to_T_end assert ival_H.asfreq("s", "s") == ival_H_to_S_start assert ival_H.asfreq("s", "E") == ival_H_to_S_end @@ -569,28 +583,29 @@ def test_conv_hourly(self): def test_conv_minutely(self): # frequency conversion tests: from Minutely Frequency" - ival_T = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) - ival_T_end_of_year = Period( - freq="Min", year=2007, month=12, day=31, hour=23, minute=59 - ) - ival_T_end_of_quarter = Period( - freq="Min", year=2007, month=3, day=31, hour=23, minute=59 - ) - ival_T_end_of_month = Period( - freq="Min", year=2007, month=1, day=31, hour=23, minute=59 - ) - ival_T_end_of_week = Period( - freq="Min", year=2007, month=1, day=7, hour=23, minute=59 - ) - ival_T_end_of_day = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) - ival_T_end_of_bus = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) - ival_T_end_of_hour = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_T = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) + ival_T_end_of_year = Period( + freq="Min", year=2007, month=12, day=31, hour=23, minute=59 + ) + ival_T_end_of_quarter = Period( + freq="Min", year=2007, month=3, day=31, hour=23, minute=59 + ) + ival_T_end_of_month = Period( + freq="Min", year=2007, month=1, day=31, hour=23, minute=59 + ) + ival_T_end_of_week = Period( + freq="Min", year=2007, month=1, day=7, hour=23, minute=59 + ) + ival_T_end_of_day = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) + ival_T_end_of_bus = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) + ival_T_end_of_hour = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=59 + ) ival_T_to_A = Period(freq="Y", year=2007) ival_T_to_Q = Period(freq="Q", year=2007, quarter=1) @@ -627,7 +642,8 @@ def test_conv_minutely(self): assert ival_T.asfreq("s", "s") == ival_T_to_S_start assert ival_T.asfreq("s", "E") == ival_T_to_S_end - assert ival_T.asfreq("Min") == ival_T + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_T.asfreq("Min") == ival_T def test_conv_secondly(self): # frequency conversion tests: from Secondly Frequency" @@ -666,7 +682,10 @@ def test_conv_secondly(self): with tm.assert_produces_warning(FutureWarning, match=bday_msg): ival_S_to_B = Period(freq="B", year=2007, month=1, day=1) ival_S_to_H = Period(freq="h", year=2007, month=1, day=1, hour=0) - ival_S_to_T = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_S_to_T = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) assert ival_S.asfreq("Y") == ival_S_to_A assert ival_S_end_of_year.asfreq("Y") == ival_S_to_A @@ -683,8 +702,9 @@ def test_conv_secondly(self): assert ival_S_end_of_bus.asfreq("B") == ival_S_to_B assert ival_S.asfreq("h") == ival_S_to_H assert ival_S_end_of_hour.asfreq("h") == ival_S_to_H - assert ival_S.asfreq("Min") == ival_S_to_T - assert ival_S_end_of_minute.asfreq("Min") == ival_S_to_T + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_S.asfreq("Min") == ival_S_to_T + assert ival_S_end_of_minute.asfreq("Min") == ival_S_to_T assert ival_S.asfreq("s") == ival_S diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 2c3a0816737fc..0ae6796e8682f 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -117,7 +117,9 @@ def test_construction(self): i2 = Period("3/1/2005", freq="D") assert i1 == i2 - i3 = Period(year=2005, month=3, day=1, freq="d") + msg = "'d' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + i3 = Period(year=2005, month=3, day=1, freq="d") assert i1 == i3 i1 = Period("2007-01-01 09:00:00.001") @@ -145,7 +147,7 @@ def test_construction(self): def test_tuple_freq_disallowed(self): # GH#34703 tuple freq disallowed with pytest.raises(TypeError, match="pass as a string instead"): - Period("1982", freq=("Min", 1)) + Period("1982", freq=("min", 1)) with pytest.raises(TypeError, match="pass as a string instead"): Period("2006-12-31", ("w", 1)) @@ -661,7 +663,7 @@ def test_to_timestamp(self): assert end_ts == p.to_timestamp("D", how=a) assert end_ts == p.to_timestamp("3D", how=a) - from_lst = ["Y", "Q", "M", "W", "B", "D", "h", "Min", "s"] + from_lst = ["Y", "Q", "M", "W", "B", "D", "h", "min", "s"] def _ex(p): if p.freq == "B": @@ -822,7 +824,7 @@ def test_quarterly_negative_ordinals(self): assert isinstance(p, Period) def test_freq_str(self): - i1 = Period("1982", freq="Min") + i1 = Period("1982", freq="min") assert i1.freq == offsets.Minute() assert i1.freqstr == "min" @@ -1067,7 +1069,7 @@ def test_properties_hourly(self): def test_properties_minutely(self): # Test properties on Periods with minutely frequency. - t_date = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) + t_date = Period(freq="min", year=2007, month=1, day=1, hour=0, minute=0) # assert t_date.quarter == 1 assert t_date.month == 1 @@ -1085,7 +1087,7 @@ def test_properties_minutely(self): def test_properties_secondly(self): # Test properties on Periods with secondly frequency. s_date = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="min", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) # assert s_date.year == 2007 @@ -1100,11 +1102,35 @@ def test_properties_secondly(self): assert s_date.days_in_month == 31 assert ( Period( - freq="Min", year=2012, month=2, day=1, hour=0, minute=0, second=0 + freq="min", year=2012, month=2, day=1, hour=0, minute=0, second=0 ).days_in_month == 29 ) + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2W", "2w"), + ("2M", "2m"), + ("2Q", "2q"), + ("2Y-SEP", "2y-sep"), + ("2h", "2H"), + ("2s", "2S"), + ("2us", "2US"), + ("2ns", "2NS"), + ], + ) + def test_period_upperlowercase_frequency_deprecated(self, freq, freq_depr): + # GH#56346 + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{freq[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + p1 = Period("2016-03-01 09:00", freq=freq_depr) + + p2 = Period("2016-03-01 09:00", freq=freq) + assert p1 == p2 + class TestPeriodComparisons: def test_sort_periods(self): diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index d4398f66e6f89..1d332cfa66cf5 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -461,13 +461,10 @@ def conv(v): assert Timedelta("1000") == np.timedelta64(1000, "ns") assert Timedelta("1000ns") == np.timedelta64(1000, "ns") - assert Timedelta("1000NS") == np.timedelta64(1000, "ns") assert Timedelta("10us") == np.timedelta64(10000, "ns") assert Timedelta("100us") == np.timedelta64(100000, "ns") assert Timedelta("1000us") == np.timedelta64(1000000, "ns") - assert Timedelta("1000Us") == np.timedelta64(1000000, "ns") - assert Timedelta("1000uS") == np.timedelta64(1000000, "ns") assert Timedelta("1ms") == np.timedelta64(1000000, "ns") assert Timedelta("10ms") == np.timedelta64(10000000, "ns") @@ -635,6 +632,25 @@ def test_resolution_deprecated(self): result = Timedelta.resolution assert result == Timedelta(nanoseconds=1) + @pytest.mark.parametrize( + "unit, unit_depr", + [ + ("2h", "2H"), + ("2us", "2Us"), + ("2us", "2US"), + ("2ns", "2nS"), + ("2ns", "2Ns"), + ], + ) + def test_timedelta_uppercase_units_deprecated(self, unit, unit_depr): + # GH#56346 + depr_msg = f"'{unit_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{unit[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + result = Timedelta(unit_depr) + assert result == Timedelta(unit) + @pytest.mark.parametrize( "value, expected", diff --git a/pandas/tests/scalar/timestamp/methods/test_round.py b/pandas/tests/scalar/timestamp/methods/test_round.py index 2fb0e1a8d3397..22051c3832afa 100644 --- a/pandas/tests/scalar/timestamp/methods/test_round.py +++ b/pandas/tests/scalar/timestamp/methods/test_round.py @@ -60,7 +60,7 @@ def test_round_tzaware(self): def test_round_30min(self): # round dt = Timestamp("20130104 12:32:00") - result = dt.round("30Min") + result = dt.round("30min") expected = Timestamp("20130104 12:30:00") assert result == expected diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 72eff4b6ee479..eb895fe73adb1 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -787,8 +787,8 @@ def test_get_offset(): pairs = [ ("B", BDay()), ("b", BDay()), - ("bme", BMonthEnd()), - ("Bme", BMonthEnd()), + ("BME", BMonthEnd()), + ("BME", BMonthEnd()), ("W-MON", Week(weekday=0)), ("W-TUE", Week(weekday=1)), ("W-WED", Week(weekday=2)), @@ -859,10 +859,10 @@ def test_rule_code(self): def test_freq_offsets(): off = BDay(1, offset=timedelta(0, 1800)) - assert off.freqstr == "B+30Min" + assert off.freqstr == "B+30min" off = BDay(1, offset=timedelta(0, -1800)) - assert off.freqstr == "B-30Min" + assert off.freqstr == "B-30min" class TestReprNames: diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index ad4e9e2bcf38a..9857fddad5cd2 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -128,7 +128,7 @@ def test_to_offset_leading_zero(freqstr, expected): assert result.n == expected -@pytest.mark.parametrize("freqstr,expected", [("+1d", 1), ("+2h30min", 150)]) +@pytest.mark.parametrize("freqstr,expected", [("+1D", 1), ("+2h30min", 150)]) def test_to_offset_leading_plus(freqstr, expected): result = to_offset(freqstr) assert result.n == expected @@ -192,7 +192,7 @@ def test_anchored_shortcuts(shortcut, expected): ], ) def test_to_offset_lowercase_frequency_deprecated(freq_depr): - # GH#54939 + # GH#54939, GH#56346 depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " f"future version, please use '{freq_depr.upper()[1:]}' instead." @@ -212,7 +212,7 @@ def test_to_offset_lowercase_frequency_deprecated(freq_depr): ], ) def test_to_offset_uppercase_frequency_deprecated(freq_depr): - # GH#54939 + # GH#54939, GH#56346 depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " f"future version, please use '{freq_depr.lower()[1:]}' instead." diff --git a/pandas/tests/window/test_groupby.py b/pandas/tests/window/test_groupby.py index 120470b09a92b..1ae6ba6c9fd4a 100644 --- a/pandas/tests/window/test_groupby.py +++ b/pandas/tests/window/test_groupby.py @@ -582,7 +582,7 @@ def test_groupby_rolling_string_index(self): groups = df.groupby("group") df["count_to_date"] = groups.cumcount() - rolling_groups = groups.rolling("10d", on="eventTime") + rolling_groups = groups.rolling("10D", on="eventTime") result = rolling_groups.apply(lambda df: df.shape[0]) expected = DataFrame( [ @@ -625,7 +625,7 @@ def test_groupby_rolling_count_closed_on(self, unit): ) result = ( df.groupby("group") - .rolling("3d", on="date", closed="left")["column1"] + .rolling("3D", on="date", closed="left")["column1"] .count() ) dti = DatetimeIndex(