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

ENH: NDFrame.axis_ops #52461

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
00c20d2
ENH: NDFrame.axis_ops
jbrockmendel Apr 5, 2023
c74d222
mypy fixup
jbrockmendel Apr 5, 2023
23f4f99
pyright fixup
jbrockmendel Apr 5, 2023
5454576
Merge branch 'main' into ref-axis_ops
jbrockmendel Apr 13, 2023
87d260b
Merge branch 'main' into ref-axis_ops
jbrockmendel Apr 13, 2023
fc8ffb6
Merge branch 'main' into ref-axis_ops
jbrockmendel Apr 18, 2023
993d351
underscores
jbrockmendel Apr 18, 2023
403ba35
Merge branch 'main' into ref-axis_ops
jbrockmendel Apr 29, 2023
ddd4523
Merge branch 'main' into ref-axis_ops
jbrockmendel May 8, 2023
709b976
DEPR: deprecate the non-axis_ops methods
jbrockmendel May 8, 2023
9e335a3
GH ref
jbrockmendel May 9, 2023
33850ce
Merge branch 'main' into ref-axis_ops
jbrockmendel May 12, 2023
47ef2ef
Merge branch 'main' into ref-axis_ops
jbrockmendel May 24, 2023
3ea3b76
update doc
jbrockmendel May 24, 2023
2d490ee
update docs
jbrockmendel May 24, 2023
ceaaa6f
Merge branch 'main' into ref-axis_ops
jbrockmendel May 24, 2023
19bc15a
update docs
jbrockmendel May 24, 2023
36102a0
Merge branch 'main' into ref-axis_ops
jbrockmendel May 25, 2023
8dd8af7
update docs
jbrockmendel May 25, 2023
b4e8a06
okwarning
jbrockmendel May 25, 2023
0cbee17
Merge branch 'main' into ref-axis_ops
jbrockmendel May 26, 2023
2d63e9d
doc fixup
jbrockmendel May 26, 2023
b39105c
Merge branch 'main' into ref-axis_ops
jbrockmendel May 27, 2023
39f15ec
allow doctest deprecation warnings
jbrockmendel May 27, 2023
70d1dcc
Merge branch 'main' into ref-axis_ops
jbrockmendel Jun 7, 2023
7f1c23e
Merge branch 'main' into ref-axis_ops
jbrockmendel Jul 3, 2023
42b5578
use code block
jbrockmendel Jul 3, 2023
74f49f4
Merge branch 'main' into ref-axis_ops
jbrockmendel Jul 12, 2023
d6f2c4f
Merge branch 'main' into ref-axis_ops
jbrockmendel Jul 18, 2023
7dd08c7
Fix test, update doc
jbrockmendel Jul 19, 2023
44b69df
pre-commit fixup
jbrockmendel Jul 19, 2023
1127199
Merge branch 'main' into ref-axis_ops
jbrockmendel Jul 27, 2023
034acd4
Merge branch 'main' into ref-axis_ops
jbrockmendel Oct 19, 2023
09ebb89
Merge branch 'main' into ref-axis_ops
jbrockmendel Oct 24, 2023
c5c9bdf
troubleshoot docs
jbrockmendel Oct 25, 2023
1b28fa1
Merge branch 'main' into ref-axis_ops
jbrockmendel Oct 25, 2023
39804cf
mypy fixup
jbrockmendel Oct 25, 2023
a39bef2
Merge branch 'main' into ref-axis_ops
jbrockmendel Oct 25, 2023
de0a8b8
pyright fixup
jbrockmendel Oct 25, 2023
843cbb4
update doctests
jbrockmendel Oct 25, 2023
b41cbaa
Merge branch 'main' into ref-axis_ops
jbrockmendel Oct 29, 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
8 changes: 4 additions & 4 deletions doc/source/user_guide/10min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,14 @@ financial applications. See the :ref:`Time Series section <timeseries>`.
rng = pd.date_range("3/6/2012 00:00", periods=5, freq="D")
ts = pd.Series(np.random.randn(len(rng)), rng)
ts
ts_utc = ts.tz_localize("UTC")
ts_utc = ts.axis_ops.tz_localize("UTC")
ts_utc

:meth:`Series.tz_convert` converts a timezones aware time series to another time zone:

.. ipython:: python

ts_utc.tz_convert("US/Eastern")
ts_utc.axis_ops.tz_convert("US/Eastern")

Converting between time span representations:

Expand All @@ -643,9 +643,9 @@ Converting between time span representations:
rng = pd.date_range("1/1/2012", periods=5, freq="M")
ts = pd.Series(np.random.randn(len(rng)), index=rng)
ts
ps = ts.to_period()
ps = ts.axis_ops.to_period()
ps
ps.to_timestamp()
ps.axis_ops.to_timestamp()

Converting between period and timestamp enables some convenient arithmetic
functions to be used. In the following example, we convert a quarterly
Expand Down
12 changes: 6 additions & 6 deletions doc/source/user_guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -501,27 +501,27 @@ values across a level. For instance:
df2_aligned


Swapping levels with ``swaplevel``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Swapping levels with ``axis_ops.swap_level``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The :meth:`~MultiIndex.swaplevel` method can switch the order of two levels:

.. ipython:: python

df[:5]
df[:5].swaplevel(0, 1, axis=0)
df[:5].axis_ops.swap_level(0, 1, axis=0)

.. _advanced.reorderlevels:

Reordering levels with ``reorder_levels``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reordering levels with ``axis_ops.reorder_levels``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The :meth:`~MultiIndex.reorder_levels` method generalizes the ``swaplevel``
method, allowing you to permute the hierarchical index levels in one step:

.. ipython:: python

df[:5].reorder_levels([1, 0], axis=0)
df[:5].axis_ops.reorder_levels([1, 0], axis=0)

.. _advanced.index_names:

Expand Down
16 changes: 8 additions & 8 deletions doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ We are stopping on the included end-point as it is part of the index:
dft2
dft2.loc["2013-01-05"]
idx = pd.IndexSlice
dft2 = dft2.swaplevel(0, 1).sort_index()
dft2 = dft2.axis_ops.swap_level(0, 1).sort_index()
dft2.loc[idx[:, "2013-01-05"], :]

Slicing with string indexing also honors UTC offset.
Expand Down Expand Up @@ -2218,8 +2218,8 @@ frequencies ``Q-JAN`` through ``Q-DEC``.
Converting between representations
----------------------------------

Timestamped data can be converted to PeriodIndex-ed data using ``to_period``
and vice-versa using ``to_timestamp``:
Timestamped data can be converted to PeriodIndex-ed data using ``axis_ops.to_period``
and vice-versa using ``axis_ops.to_timestamp``:

.. ipython:: python

Expand All @@ -2229,18 +2229,18 @@ and vice-versa using ``to_timestamp``:

ts

ps = ts.to_period()
ps = ts.axis_ops.to_period()

ps

ps.to_timestamp()
ps.axis_ops.to_timestamp()

Remember that 's' and 'e' can be used to return the timestamps at the start or
end of the period:

.. ipython:: python

ps.to_timestamp("D", how="s")
ps.axis_ops.to_timestamp("D", how="s")

Converting between period and timestamp enables some convenient arithmetic
functions to be used. In the following example, we convert a quarterly
Expand Down Expand Up @@ -2460,8 +2460,8 @@ Operations between :class:`Series` in different time zones will yield UTC
.. ipython:: python

ts_utc = pd.Series(range(3), pd.date_range("20130101", periods=3, tz="UTC"))
eastern = ts_utc.tz_convert("US/Eastern")
berlin = ts_utc.tz_convert("Europe/Berlin")
eastern = ts_utc.axis_ops.tz_convert("US/Eastern")
berlin = ts_utc.axis_ops.tz_convert("Europe/Berlin")
result = eastern + berlin
result
result.index
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Partial string indexing now matches on ``DateTimeIndex`` when part of a ``MultiI
On other levels

.. ipython:: python
:okwarning:
Copy link
Member

Choose a reason for hiding this comment

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

Could you just change this to use axis_ops.swaplevel?

Copy link
Member Author

Choose a reason for hiding this comment

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

i dont think we'd want to change this in the old doc

Copy link
Member

Choose a reason for hiding this comment

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

Okay could we use code block instead?


idx = pd.IndexSlice
dft2 = dft2.swaplevel(0, 1).sort_index()
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Other enhancements
- :meth:`arrays.SparseArray.map` now supports ``na_action`` (:issue:`52096`).
- Add :meth:`diff()` and :meth:`round()` for :class:`Index` (:issue:`19708`)
- Add dtype of categories to ``repr`` information of :class:`CategoricalDtype` (:issue:`52179`)
- Added :meth:`Series.axis_ops` and :meth:`DataFrame.axis_ops` accessor for methods that operate on the object axes but not the data (:issue:`52461`)
- Added to the escape mode "latex-math" preserving without escaping all characters between "\(" and "\)" in formatter (:issue:`51903`)
- Adding ``engine_kwargs`` parameter to :meth:`DataFrame.read_excel` (:issue:`52214`)
- Classes that are useful for type-hinting have been added to the public API in the new submodule ``pandas.api.typing`` (:issue:`48577`)
Expand Down Expand Up @@ -264,6 +265,7 @@ Deprecations
- Deprecated unused "closed" and "normalize" keywords in the :class:`DatetimeIndex` constructor (:issue:`52628`)
- Deprecated unused "closed" keyword in the :class:`TimedeltaIndex` constructor (:issue:`52628`)
- Deprecated logical operation between two non boolean :class:`Series` with different indexes always coercing the result to bool dtype. In a future version, this will maintain the return type of the inputs. (:issue:`52500`, :issue:`52538`)
- Deprecated :meth:`Series.tz_localize`, :meth:`Series.tz_convert`, :meth:`Series.to_timestamp`, :meth:`Series.to_period`, :meth:`Series.swaplevel`, :meth:`Series.reorder_level` and their :class:`DataFrame` counterparts, use ``obj.axis_ops.to_period``, ``obj.axis_ops.swap_level``, etc instead (:issue:`52461`)
- Deprecated allowing ``downcast`` keyword other than ``None``, ``False``, "infer", or a dict with these as values in :meth:`Series.fillna`, :meth:`DataFrame.fillna` (:issue:`40988`)
- Deprecated allowing arbitrary ``fill_value`` in :class:`SparseDtype`, in a future version the ``fill_value`` will need to be compatible with the ``dtype.subtype``, either a scalar that can be held by that subtype or ``NaN`` for integer or bool subtypes (:issue:`23124`)
- Deprecated behavior of :func:`assert_series_equal` and :func:`assert_frame_equal` considering NA-like values (e.g. ``NaN`` vs ``None`` as equivalent) (:issue:`52081`)
Expand Down
5 changes: 5 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def pytest_collection_modifyitems(items, config) -> None:
"(Series|DataFrame).bool is now deprecated and will be removed "
"in future version of pandas",
),
("DataFrame.to_timestamp", "DataFrame.to_timestamp is deprecated"),
("Series.swaplevel", "Series.swaplevel is deprecated"),
("Series.to_timestamp", "Series.to_timestamp is deprecated"),
("Series.to_period", "Series.to_period is deprecated"),
("Series.reorder_levels", "Series.reorder_levels is deprecated"),
]

for item in items:
Expand Down
Loading