Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR offsets: rename 'M' to 'ME' #52064

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
d21c195
Frequency: raise warnings when using ‘M’ frequency
natmokval Mar 18, 2023
6522436
Frequency: raise warnings when using ‘M’ frequency II
natmokval Mar 18, 2023
8e2b974
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Mar 30, 2023
184debf
remove is_period and change str representation for freq in Period [sk…
natmokval Mar 30, 2023
e1d82cb
remove is_period and fix some tests [skip ci]
natmokval Mar 30, 2023
55c4d76
fix some tests
natmokval Mar 31, 2023
24756bc
fix some tests II
natmokval Apr 1, 2023
989db20
fix tests in pandas/tests/indexes/period/ [skip ci]
natmokval Apr 4, 2023
253b823
fix tests in pandas/tests/indexes/period/ and correct timedeltas.pyx
natmokval Apr 5, 2023
bfb59ae
fix tests in pandas/tests/indexes/period/ and correct timedeltas.pyx
natmokval Apr 5, 2023
266c480
update frequencies.py, resample.py, and fix some tests
natmokval Apr 6, 2023
c204645
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Apr 6, 2023
dfbc1ed
modify pandas/tseries/frequencies.py
natmokval Apr 6, 2023
06c1473
fix tests
natmokval Apr 7, 2023
4c9b621
fix tests II
natmokval Apr 8, 2023
a9bd9db
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Apr 8, 2023
b64e15d
fix tests III
natmokval Apr 8, 2023
0744e9a
rename 'M' to 'ME' in docs
natmokval Apr 9, 2023
c640779
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Apr 9, 2023
305d035
rename 'M' to 'ME' in docs II
natmokval Apr 9, 2023
31f4cef
rename 'M' to 'ME' in docs III
natmokval Apr 11, 2023
70cd19d
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Apr 11, 2023
5d9cad5
rename 'M' to 'ME' in docs IV
natmokval Apr 11, 2023
f695a80
rename 'M' to 'ME' in docs V
natmokval Apr 20, 2023
0dfeece
rename 'M' to 'ME' in docs VI
natmokval Apr 20, 2023
87b36ab
add is_period to to_offset I
natmokval May 5, 2023
5c68420
add is_period to to_offset and merge main
natmokval May 6, 2023
69e8ade
add is_period to to_offset II
natmokval May 9, 2023
18be333
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval May 15, 2023
fe8a199
correct the definition of period_array(…) and fix 19 tests
natmokval May 15, 2023
c763b5e
add is_period to _parse_dtype_strict() and fix tests
natmokval May 16, 2023
a0cdb11
add constant OFFSET_TO_PERIOD_FREQSTR to period.pyx and fix tests
natmokval May 17, 2023
92792ec
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval May 17, 2023
ba1220e
correct definitions of extract_ordinals() and _round(), fix tests
natmokval May 18, 2023
dcea43b
add replacement ME to M in _require_matching_freq, _parsed_string_to_…
natmokval May 21, 2023
7ad194a
resolve conflict in test_replace.py
natmokval May 21, 2023
baceaf2
add the constant PERIOD_TO_OFFSET_FREQSTR to period.pyx, correct defi…
natmokval May 22, 2023
d589c68
fix tests
natmokval May 22, 2023
16db0b7
add the conversion ME to M to _from_datetime64, period_index, raise_o…
natmokval May 23, 2023
4defaf9
fix some tests with resample
natmokval May 24, 2023
cc7b069
correct definitions of to_period, freqstr and get_period_alias, fix t…
natmokval May 26, 2023
33e0ac1
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval May 26, 2023
a1701e4
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval May 26, 2023
e6b62d9
correct pre-commit failures
natmokval May 26, 2023
e1f0d65
add key from Grouper to the constructor of TimeGrouper and fix tests
natmokval May 27, 2023
db3124e
add to asfreq() from resampler the conversion ME to M, fix tests
natmokval May 27, 2023
37e4baa
fix tests for for PeriodIndex and base tests for resample
natmokval May 29, 2023
a101781
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval May 29, 2023
6c195e9
correct the constructor of TimeGrouper and fix tests for resample and…
natmokval May 30, 2023
5a5916d
correct the definition of use_dynamic_x() and fix tests for plotting
natmokval May 31, 2023
adff5ae
correct the definition of the method use_dynamic_x, fix tests
natmokval Jun 1, 2023
8af8a36
correct the definition of the asfreq for PeriodArray, _get_period_ali…
natmokval Jun 4, 2023
0ab5c1e
resolve conflicts
natmokval Jun 5, 2023
9bbb970
correct documentation, fix tests
natmokval Jun 5, 2023
6544053
correct docs: rename ME to M for periods
natmokval Jun 7, 2023
b032018
resolve conflicts
natmokval Jun 7, 2023
7233fab
add pytest.mark.xfail to test_to_timestamp_quarterly_bug
natmokval Jun 8, 2023
055a14f
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jun 8, 2023
b8a6827
correct mypy error attr-defined
natmokval Jun 10, 2023
4023a54
correct the definition of variables which convert M/ME to ME/M in dty…
natmokval Jun 13, 2023
562d92a
created the c version for dicts which convert M/ME to ME/M and fix my…
natmokval Jun 14, 2023
9106ee9
fix doc build error in 09_timeseries.rst and mypy error
natmokval Jun 14, 2023
da2a32f
correct the constructor of Period, fix mypy errors
natmokval Jun 15, 2023
9e7374c
replace in _attrname_to_abbrevs ME with M and correct the constructor…
natmokval Jun 15, 2023
e352f82
add conversion ME/M to Period constructor, add conversion M/ME to may…
natmokval Jun 15, 2023
fd3174a
correct dict “time rules”, correct the definition of _parsed_string_t…
natmokval Jun 16, 2023
524621a
remove the argument is_period from _parse_dtype_strict
natmokval Jun 18, 2023
021d980
add to is_subperiod, is_superperiod and _is_monthly both M and ME, co…
natmokval Jun 19, 2023
35e0146
add dict ME to M to the definition of freqstr, constructor of Period …
natmokval Jun 19, 2023
db84369
refactor freqstr, extract_ordinals, and _require_matching_freq for P…
natmokval Jun 20, 2023
563c775
refactor _resolution_obj in dtypes.pyx and freqstr in /indexes/dateti…
natmokval Jun 21, 2023
c870d1b
define a new function freq_to_period_freqstr in dtypes to convert ME …
natmokval Jun 21, 2023
4c299cf
refactor use_dynamic_x for plotting and to_period in arrays/datetimes.py
natmokval Jun 21, 2023
55865c9
refactor def _check_plot_works in plotting and test_to_period in clas…
natmokval Jun 21, 2023
a404fa2
resolve conflict
natmokval Jun 21, 2023
b0bd2d8
refactor name method of PeriodDtype, refactor __arrow_array__ and a…
natmokval Jun 22, 2023
b947e6a
resolve conflict in pandas/tests/resample/test_base.py
natmokval Jun 22, 2023
3ab6833
in PeriodArray refactor _from_datetime64 and remove redundant if in …
natmokval Jun 23, 2023
cfb60a3
correct def _resolution_obj in DatetimeLikeArrayMixin, refactor def f…
natmokval Jun 23, 2023
223540c
correct def _resolution_obj in DatetimeLikeArrayMixin and def to_offs…
natmokval Jun 25, 2023
0060761
add tests for 'UserWarning'
natmokval Jun 26, 2023
239090b
refactor methods to_period in DatetimeArray, _from_datetime64 in Peri…
natmokval Jun 26, 2023
6a816ef
add freq_to_offset_freqstr to convert M to ME, refactor _resolution_o…
natmokval Jun 27, 2023
8cbe679
resolve conflict
natmokval Jun 27, 2023
b1e0ad7
fix pre-commit failures
natmokval Jun 27, 2023
454b685
correct the definition of to_period in DatetimeArray, refactor _chec…
natmokval Jun 27, 2023
fa8e15d
correct definitions of _resolution_obj in dtypes.pyx and in DatetimeL…
natmokval Jun 27, 2023
34b5957
correct def asfreq in PeriodArray, remove unused function freq_to_off…
natmokval Jun 28, 2023
3a8dcc1
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jun 28, 2023
02c83f3
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jun 28, 2023
120355d
roll back in test_fillna_period dtype Period[M] with capital P
natmokval Jun 28, 2023
16e9376
refactor the function raise_on_incompatible
natmokval Jun 28, 2023
a1fd73c
fix mypy error in pandas/core/arrays/period.py
natmokval Jun 29, 2023
c1beb9f
resolve conflicts and fix tests in plotting
natmokval Jun 29, 2023
5052630
fix ruff error in pandas/tests/arrays/period/test_constructors.py
natmokval Jun 29, 2023
ccfc4bd
remove ME from definitions of is_monthly, is_subperiod, correct _mayb…
natmokval Jul 3, 2023
cff4eeb
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jul 4, 2023
8c3fc98
fix test_dti_to_period_2monthish
natmokval Jul 4, 2023
b89980e
update whatsnew/v2.1.0.rst
natmokval Jul 11, 2023
c1d9c79
resolve conflicts
natmokval Jul 11, 2023
6ed4730
add an example for old/new behavior in whatsnew/v2.1.0.rst
natmokval Jul 12, 2023
22fe7e3
corrected typo
natmokval Jul 12, 2023
29c4b72
replace name of section Deprecations with Other Deprecations
natmokval Jul 12, 2023
4d4342b
remove ME form is_superperiod, refactored tests
natmokval Jul 13, 2023
e3dcaf6
correct a test
natmokval Jul 13, 2023
616f681
move some tests to a new place
natmokval Jul 18, 2023
b6a9a8e
correct def asfreq for resampling, refactor asfreq for Period, fix tests
natmokval Jul 18, 2023
856f09b
correct tests
natmokval Jul 18, 2023
cbac3be
correct def _shift_with_freq and fix test for shift
natmokval Jul 19, 2023
383799d
correct docs for asfreq in PeriodArray
natmokval Jul 19, 2023
6432301
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jul 19, 2023
9d3f15c
correct def _shift_with_freq
natmokval Jul 20, 2023
4f8c861
add ‘me’ to _dont_uppercase, correct _require_matching_freq, fix tests
natmokval Jul 21, 2023
4fade37
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jul 24, 2023
0286cf6
minor corrections
natmokval Jul 24, 2023
e32e8cb
resolve conflicts
natmokval Jul 25, 2023
6ee4554
resolve conflict in whatsnew/v2.1.0.rst
natmokval Jul 28, 2023
549d95b
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Jul 31, 2023
01abf51
resolve conflicts
natmokval Aug 3, 2023
8fb1a4c
resolve conflicts
natmokval Aug 21, 2023
23b567a
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Aug 21, 2023
3a91cba
correct whatsnew
natmokval Aug 22, 2023
ebbcbf5
resolve conflict in v2.2.0.rst
natmokval Aug 22, 2023
882fefa
correct an example in user_guide/reshaping.rst
natmokval Aug 23, 2023
0bd8b1a
resolve conflicts'
natmokval Aug 30, 2023
05d68c8
Merge branch 'main' into 9586-inconsistent-labeling-sub-daily-super-d…
natmokval Aug 30, 2023
d4e15e1
fix tests for plotting
natmokval Aug 30, 2023
ecee6de
correct tests for plotting
natmokval Aug 31, 2023
141fbdc
resolve conflicts
natmokval Sep 19, 2023
8979eb5
remove from OFFSET_TO_PERIOD_FREQSTR deprecated freqstr, fix tests
natmokval Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Aggregate the current hourly time series values to the monthly maximum value in

.. ipython:: python

monthly_max = no_2.resample("M").max()
monthly_max = no_2.resample("ME").max()
monthly_max

A very powerful method on time series data with a datetime index, is the
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ To create year and month cross tabulation:

df = pd.DataFrame(
{"value": np.random.randn(36)},
index=pd.date_range("2011-01-01", freq="M", periods=36),
index=pd.date_range("2011-01-01", freq="ME", periods=36),
)

pd.pivot_table(
Expand Down
6 changes: 3 additions & 3 deletions doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ Groupby a specific column with the desired frequency. This is like resampling.

.. ipython:: python

df.groupby([pd.Grouper(freq="1M", key="Date"), "Buyer"])[["Quantity"]].sum()
df.groupby([pd.Grouper(freq="1ME", key="Date"), "Buyer"])[["Quantity"]].sum()

When ``freq`` is specified, the object returned by ``pd.Grouper`` will be an
instance of ``pandas.api.typing.TimeGrouper``. You have an ambiguous specification
Expand All @@ -1413,9 +1413,9 @@ in that you have a named index and a column that could be potential groupers.

df = df.set_index("Date")
df["Date"] = df.index + pd.offsets.MonthEnd(2)
df.groupby([pd.Grouper(freq="6M", key="Date"), "Buyer"])[["Quantity"]].sum()
df.groupby([pd.Grouper(freq="6ME", key="Date"), "Buyer"])[["Quantity"]].sum()

df.groupby([pd.Grouper(freq="6M", level="Date"), "Buyer"])[["Quantity"]].sum()
df.groupby([pd.Grouper(freq="6ME", level="Date"), "Buyer"])[["Quantity"]].sum()


Taking the first rows of each group
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Also, you can use :class:`Grouper` for ``index`` and ``columns`` keywords. For d

.. ipython:: python

pd.pivot_table(df, values="D", index=pd.Grouper(freq="M", key="F"), columns="C")
pd.pivot_table(df, values="D", index=pd.Grouper(freq="ME", key="F"), columns="C")

.. _reshaping.pivot.margins:

Expand Down
18 changes: 9 additions & 9 deletions doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ data however will be stored as ``object`` data.

pd.Series(pd.period_range("1/1/2011", freq="M", periods=3))
pd.Series([pd.DateOffset(1), pd.DateOffset(2)])
pd.Series(pd.date_range("1/1/2011", freq="M", periods=3))
pd.Series(pd.date_range("1/1/2011", freq="ME", periods=3))

Lastly, pandas represents null date times, time deltas, and time spans as ``NaT`` which
is useful for representing missing or null date like values and behaves similar
Expand Down Expand Up @@ -450,7 +450,7 @@ variety of :ref:`frequency aliases <timeseries.offset_aliases>`:

.. ipython:: python

pd.date_range(start, periods=1000, freq="M")
pd.date_range(start, periods=1000, freq="ME")

pd.bdate_range(start, periods=250, freq="BQS")

Expand Down Expand Up @@ -882,7 +882,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ
:class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week"
:class:`~pandas.tseries.offsets.WeekOfMonth`, ``'WOM'``, "the x-th day of the y-th week of each month"
:class:`~pandas.tseries.offsets.LastWeekOfMonth`, ``'LWOM'``, "the x-th day of the last week of each month"
:class:`~pandas.tseries.offsets.MonthEnd`, ``'M'``, "calendar month end"
:class:`~pandas.tseries.offsets.MonthEnd`, ``'ME'``, "calendar month end"
:class:`~pandas.tseries.offsets.MonthBegin`, ``'MS'``, "calendar month begin"
:class:`~pandas.tseries.offsets.BMonthEnd` or :class:`~pandas.tseries.offsets.BusinessMonthEnd`, ``'BM'``, "business month end"
:class:`~pandas.tseries.offsets.BMonthBegin` or :class:`~pandas.tseries.offsets.BusinessMonthBegin`, ``'BMS'``, "business month begin"
Expand Down Expand Up @@ -1246,7 +1246,7 @@ frequencies. We will refer to these aliases as *offset aliases*.
"C", "custom business day frequency"
"D", "calendar day frequency"
"W", "weekly frequency"
"M", "month end frequency"
"ME", "month end frequency"
"SM", "semi-month end frequency (15th and end of month)"
"BM", "business month end frequency"
"CBM", "custom business month end frequency"
Expand Down Expand Up @@ -1690,7 +1690,7 @@ the end of the interval.
.. warning::

The default values for ``label`` and ``closed`` is '**left**' for all
frequency offsets except for 'M', 'A', 'Q', 'BM', 'BA', 'BQ', and 'W'
frequency offsets except for 'ME', 'A', 'Q', 'BM', 'BA', 'BQ', and 'W'
which all have a default of 'right'.

This might unintendedly lead to looking ahead, where the value for a later
Expand Down Expand Up @@ -1856,15 +1856,15 @@ to resample based on datetimelike column in the frame, it can passed to the
),
)
df
df.resample("M", on="date")[["a"]].sum()
df.resample("ME", on="date")[["a"]].sum()

Similarly, if you instead want to resample by a datetimelike
level of ``MultiIndex``, its name or location can be passed to the
``level`` keyword.

.. ipython:: python

df.resample("M", level="d")[["a"]].sum()
df.resample("ME", level="d")[["a"]].sum()

.. _timeseries.iterating-label:

Expand Down Expand Up @@ -2137,7 +2137,7 @@ The ``period`` dtype can be used in ``.astype(...)``. It allows one to change th
pi.astype("datetime64[ns]")

# convert to PeriodIndex
dti = pd.date_range("2011-01-01", freq="M", periods=3)
dti = pd.date_range("2011-01-01", freq="ME", periods=3)
dti
dti.astype("period[M]")

Expand Down Expand Up @@ -2256,7 +2256,7 @@ and vice-versa using ``to_timestamp``:

.. ipython:: python

rng = pd.date_range("1/1/2012", periods=5, freq="M")
rng = pd.date_range("1/1/2012", periods=5, freq="ME")

ts = pd.Series(np.random.randn(len(rng)), index=rng)

Expand Down
18 changes: 14 additions & 4 deletions doc/source/whatsnew/v0.14.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,20 @@ Enhancements
datetime.datetime(2013, 9, 5, 10, 0)]})
df

df.pivot_table(values='Quantity',
index=pd.Grouper(freq='M', key='Date'),
columns=pd.Grouper(freq='M', key='PayDay'),
aggfunc="sum")
.. code-block:: ipython

In [75]: df.pivot_table(values='Quantity',
....: index=pd.Grouper(freq='M', key='Date'),
....: columns=pd.Grouper(freq='M', key='PayDay'),
....: aggfunc="sum")
Out[75]:
PayDay 2013-09-30 2013-10-31 2013-11-30
Date
2013-09-30 NaN 3.0 NaN
2013-10-31 6.0 NaN 1.0
2013-11-30 NaN 9.0 NaN

[3 rows x 3 columns]

- Arrays of strings can be wrapped to a specified width (``str.wrap``) (:issue:`6999`)
- Add :meth:`~Series.nsmallest` and :meth:`Series.nlargest` methods to Series, See :ref:`the docs <basics.nsorted>` (:issue:`3960`)
Expand Down
19 changes: 17 additions & 2 deletions doc/source/whatsnew/v0.18.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,24 @@ Previously

New API

.. ipython:: python
.. code-block:: ipython

s.resample('M').ffill()
In [91]: s.resample('M').ffill()
Out[91]:
2010-03-31 0
2010-04-30 0
2010-05-31 0
2010-06-30 1
2010-07-31 1
2010-08-31 1
2010-09-30 2
2010-10-31 2
2010-11-30 2
2010-12-31 3
2011-01-31 3
2011-02-28 3
2011-03-31 4
Freq: M, Length: 13, dtype: int64

.. note::

Expand Down
22 changes: 20 additions & 2 deletions doc/source/whatsnew/v0.19.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,26 @@ Other enhancements
),
)
df
df.resample("M", on="date")[["a"]].sum()
df.resample("M", level="d")[["a"]].sum()

.. code-block:: ipython

In [74]: df.resample("M", on="date")[["a"]].sum()
Out[74]:
a
date
2015-01-31 6
2015-02-28 4

[2 rows x 1 columns]

In [75]: df.resample("M", level="d")[["a"]].sum()
Out[75]:
a
d
2015-01-31 6
2015-02-28 4

[2 rows x 1 columns]

- The ``.get_credentials()`` method of ``GbqConnector`` can now first try to fetch `the application default credentials <https://developers.google.com/identity/protocols/application-default-credentials>`__. See the docs for more details (:issue:`13577`).
- The ``.tz_localize()`` method of ``DatetimeIndex`` and ``Timestamp`` has gained the ``errors`` keyword, so you can potentially coerce nonexistent timestamps to ``NaT``. The default behavior remains to raising a ``NonExistentTimeError`` (:issue:`13057`)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Below is a possibly non-exhaustive list of changes:

.. ipython:: python

idx = pd.date_range(start='1/1/2018', periods=3, freq='M')
idx = pd.date_range(start='1/1/2018', periods=3, freq='ME')
idx.array.year
idx.year

Expand Down
25 changes: 25 additions & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ Other API changes

Deprecations
~~~~~~~~~~~~

Deprecate alias ``M`` in favour of ``ME`` for offsets
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The alias ``M`` is deprecated in favour of ``ME`` for offsets, please use ``ME`` for "month end" instead of ``M`` (:issue:`9586`)
Comment on lines +181 to +184
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably reword this again before the final release when other offsets are included, so I think this is ok for now


For example:

*Previous behavior*:

.. code-block:: ipython

In [7]: pd.date_range('2020-01-01', periods=3, freq='M')
Out [7]:
DatetimeIndex(['2020-01-31', '2020-02-29', '2020-03-31'],
dtype='datetime64[ns]', freq='M')

*Future behavior*:

.. ipython:: python

pd.date_range('2020-01-01', periods=3, freq='ME')

Other Deprecations
^^^^^^^^^^^^^^^^^^
- Changed :meth:`Timedelta.resolution_string` to return ``min``, ``s``, ``ms``, ``us``, and ``ns`` instead of ``T``, ``S``, ``L``, ``U``, and ``N``, for compatibility with respective deprecations in frequency aliases (:issue:`52536`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_clipboard`. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_csv` except ``path_or_buf``. (:issue:`54229`)
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslibs/dtypes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ cpdef int64_t periods_per_second(NPY_DATETIMEUNIT reso) except? -1
cpdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso)
cpdef bint is_supported_unit(NPY_DATETIMEUNIT reso)

cpdef freq_to_period_freqstr(freq_n, freq_name)
cdef dict c_OFFSET_TO_PERIOD_FREQSTR
cdef dict c_DEPR_ABBREVS
cdef dict attrname_to_abbrevs
cdef dict npy_unit_to_attrname
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslibs/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from pandas._libs.tslibs.timedeltas import UnitChoices
# are imported in tests.
_attrname_to_abbrevs: dict[str, str]
_period_code_map: dict[str, int]
OFFSET_TO_PERIOD_FREQSTR: dict[str, str]
DEPR_ABBREVS: dict[str, UnitChoices]

def periods_per_day(reso: int) -> int: ...
Expand All @@ -14,6 +15,7 @@ def is_supported_unit(reso: int) -> bool: ...
def npy_unit_to_abbrev(reso: int) -> str: ...
def get_supported_reso(reso: int) -> int: ...
def abbrev_to_npy_unit(abbrev: str) -> int: ...
def freq_to_period_freqstr(freq_n: int, freq_name: str) -> str: ...

class PeriodDtypeBase:
_dtype_code: int # PeriodDtypeCode
Expand Down
40 changes: 39 additions & 1 deletion pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ from pandas._libs.tslibs.np_datetime cimport (

import_pandas_datetime()


cdef class PeriodDtypeBase:
"""
Similar to an actual dtype, this contains all of the information
Expand Down Expand Up @@ -186,6 +185,45 @@ _attrname_to_abbrevs = {
cdef dict attrname_to_abbrevs = _attrname_to_abbrevs
cdef dict _abbrev_to_attrnames = {v: k for k, v in attrname_to_abbrevs.items()}

OFFSET_TO_PERIOD_FREQSTR: dict = {
"WEEKDAY": "D",
"EOM": "M",
"BM": "M",
"BQS": "Q",
"QS": "Q",
"BQ": "Q",
"BA": "A",
"AS": "A",
"BAS": "A",
"MS": "M",
"D": "D",
"B": "B",
"min": "min",
"s": "s",
"ms": "ms",
"us": "us",
"ns": "ns",
"H": "H",
"Q": "Q",
"A": "A",
"W": "W",
"ME": "M",
"Y": "A",
"BY": "A",
"YS": "A",
"BYS": "A",
}
cdef dict c_OFFSET_TO_PERIOD_FREQSTR = OFFSET_TO_PERIOD_FREQSTR

cpdef freq_to_period_freqstr(freq_n, freq_name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be viable to get away from this entirely and use PeriodDtype(Base)._freqstr?

if freq_n == 1:
freqstr = f"""{c_OFFSET_TO_PERIOD_FREQSTR.get(
freq_name, freq_name)}"""
else:
freqstr = f"""{freq_n}{c_OFFSET_TO_PERIOD_FREQSTR.get(
freq_name, freq_name)}"""
return freqstr

# Map deprecated resolution abbreviations to correct resolution abbreviations
DEPR_ABBREVS: dict[str, str]= {
"T": "min",
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from numpy cimport int64_t


cpdef to_offset(object obj)
cpdef to_offset(object obj, bint is_period=*)
cdef bint is_offset_object(object obj)
cdef bint is_tick_object(object obj)

Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ class SingleConstructorOffset(BaseOffset):
def __reduce__(self): ...

@overload
def to_offset(freq: None) -> None: ...
def to_offset(freq: None, is_period: bool = ...) -> None: ...
@overload
def to_offset(freq: _BaseOffsetT) -> _BaseOffsetT: ...
def to_offset(freq: _BaseOffsetT, is_period: bool = ...) -> _BaseOffsetT: ...
@overload
def to_offset(freq: timedelta | str) -> BaseOffset: ...
def to_offset(freq: timedelta | str, is_period: bool = ...) -> BaseOffset: ...

class Tick(SingleConstructorOffset):
_creso: int
Expand Down
Loading