Skip to content

CLN: ._data, PeriodIndex arguments #57385

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

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ci/deps/actions-310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311-downstream_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-312.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-39-minimum_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
- beautifulsoup4=4.11.2
- blosc=1.21.3
- bottleneck=1.3.6
- fastparquet=2022.12.0
- fastparquet=2023.04.0
- fsspec=2022.11.0
- html5lib=1.1
- hypothesis=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/circle-310-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Dependency Minimum Version pip extra Notes
PyTables 3.8.0 hdf5 HDF5-based reading / writing
blosc 1.21.3 hdf5 Compression for HDF5; only available on ``conda``
zlib hdf5 Compression for HDF5
fastparquet 2022.12.0 - Parquet reading / writing (pyarrow is default)
fastparquet 2023.04.0 - Parquet reading / writing (pyarrow is default)
pyarrow 10.0.1 parquet, feather Parquet, ORC, and feather reading / writing
pyreadstat 1.2.0 spss SPSS files (.sav) reading
odfpy 1.4.1 excel Open document format (.odf, .ods, .odt) reading / writing
Expand Down
5 changes: 4 additions & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Optional libraries below the lowest tested version may still work, but are not c
+-----------------+---------------------+
| Package | New Minimum Version |
+=================+=====================+
| | |
| fastparquet | 2023.04.0 |
+-----------------+---------------------+

See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more.
Expand Down Expand Up @@ -118,6 +118,7 @@ Removal of prior version deprecations/changes
- Removed ``Series.ravel`` (:issue:`56053`)
- Removed ``Series.view`` (:issue:`56054`)
- Removed ``StataReader.close`` (:issue:`49228`)
- Removed ``_data`` from :class:`DataFrame`, :class:`Series`, :class:`.arrays.ArrowExtensionArray` (:issue:`52003`)
- Removed ``axis`` argument from :meth:`DataFrame.groupby`, :meth:`Series.groupby`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.resample`, and :meth:`Series.resample` (:issue:`51203`)
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
- Removed ``convert_dtype`` from :meth:`Series.apply` (:issue:`52257`)
Expand All @@ -126,12 +127,14 @@ Removal of prior version deprecations/changes
- Removed ``pandas.value_counts``, use :meth:`Series.value_counts` instead (:issue:`53493`)
- Removed ``read_gbq`` and ``DataFrame.to_gbq``. Use ``pandas_gbq.read_gbq`` and ``pandas_gbq.to_gbq`` instead https://pandas-gbq.readthedocs.io/en/latest/api.html (:issue:`55525`)
- Removed ``use_nullable_dtypes`` from :func:`read_parquet` (:issue:`51853`)
- Removed ``year``, ``month``, ``quarter``, ``day``, ``hour``, ``minute``, and ``second`` keywords in the :class:`PeriodIndex` constructor, use :meth:`PeriodIndex.from_fields` instead (:issue:`55960`)
- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`)
- Removed deprecated behavior of :meth:`Series.agg` using :meth:`Series.apply` (:issue:`53325`)
- Removed support for ``errors="ignore"`` in :func:`to_datetime`, :func:`to_timedelta` and :func:`to_numeric` (:issue:`55734`)
- Removed the ``ArrayManager`` (:issue:`55043`)
- Removed the ``fastpath`` argument from the :class:`Series` constructor (:issue:`55466`)
- Removed the ``is_boolean``, ``is_integer``, ``is_floating``, ``holds_integer``, ``is_numeric``, ``is_categorical``, ``is_object``, and ``is_interval`` attributes of :class:`Index` (:issue:`50042`)
- Removed the ``ordinal`` keyword in :class:`PeriodIndex`, use :meth:`PeriodIndex.from_ordinals` instead (:issue:`55960`)
- Removed unused arguments ``*args`` and ``**kwargs`` in :class:`Resampler` methods (:issue:`50977`)
- Unrecognized timezones when parsing strings to datetimes now raises a ``ValueError`` (:issue:`51477`)

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc
- bottleneck>=1.3.6
- fastparquet>=2022.12.0
- fastparquet>=2023.04.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"blosc": "1.21.3",
"bottleneck": "1.3.6",
"dataframe-api-compat": "0.1.7",
"fastparquet": "2022.12.0",
"fastparquet": "2023.04.0",
"fsspec": "2022.11.0",
"html5lib": "1.1",
"hypothesis": "6.46.1",
Expand Down
13 changes: 0 additions & 13 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Union,
cast,
)
import warnings

import numpy as np

Expand All @@ -21,7 +20,6 @@
pa_version_under10p1,
pa_version_under13p0,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_bool_dtype,
Expand Down Expand Up @@ -272,17 +270,6 @@ def astype(self, dtype, copy: bool = True):

return super().astype(dtype, copy=copy)

@property
def _data(self):
# dask accesses ._data directlys
warnings.warn(
f"{type(self).__name__}._data is a deprecated and will be removed "
"in a future version, use ._pa_array instead",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._pa_array

# ------------------------------------------------------------------------
# String methods interface

Expand Down
17 changes: 0 additions & 17 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,6 @@ def _constructor(self) -> Callable[..., Self]:
"""
raise AbstractMethodError(self)

# ----------------------------------------------------------------------
# Internals

@final
@property
def _data(self):
# GH#33054 retained because some downstream packages uses this,
# e.g. fastparquet
# GH#33333
warnings.warn(
f"{type(self).__name__}._data is deprecated and will be removed in "
"a future version. Use public APIs instead.",
DeprecationWarning,
stacklevel=find_stack_level(),
)
return self._mgr

# ----------------------------------------------------------------------
# Axis
_AXIS_ORDERS: list[Literal["index", "columns"]]
Expand Down
87 changes: 10 additions & 77 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
timedelta,
)
from typing import TYPE_CHECKING
import warnings

import numpy as np

Expand All @@ -22,7 +21,6 @@
cache_readonly,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import is_integer
from pandas.core.dtypes.dtypes import PeriodDtype
Expand Down Expand Up @@ -94,11 +92,6 @@ class PeriodIndex(DatetimeIndexOpsMixin):
----------
data : array-like (1d int np.ndarray or PeriodArray), optional
Optional period-like data to construct index with.
ordinal : array-like of int, optional
The period offsets from the proleptic Gregorian epoch.

.. deprecated:: 2.2.0
Use PeriodIndex.from_ordinals instead.
freq : str or period object, optional
One of pandas period strings or corresponding objects.
dtype : str or PeriodDtype, default None
Expand All @@ -107,11 +100,6 @@ class PeriodIndex(DatetimeIndexOpsMixin):
Make a copy of input ndarray.
name : str, default None
Name of the resulting PeriodIndex.
**fields : optional
Date fields such as year, month, etc.

.. deprecated:: 2.2.0
Use PeriodIndex.from_fields instead.

Attributes
----------
Expand Down Expand Up @@ -219,84 +207,29 @@ def second(self) -> Index:
def __new__(
cls,
data=None,
ordinal=None,
freq=None,
dtype: Dtype | None = None,
copy: bool = False,
name: Hashable | None = None,
**fields,
) -> Self:
valid_field_set = {
"year",
"month",
"day",
"quarter",
"hour",
"minute",
"second",
}

refs = None
if not copy and isinstance(data, (Index, ABCSeries)):
refs = data._references

if not set(fields).issubset(valid_field_set):
argument = next(iter(set(fields) - valid_field_set))
raise TypeError(f"__new__() got an unexpected keyword argument {argument}")
elif len(fields):
# GH#55960
warnings.warn(
"Constructing PeriodIndex from fields is deprecated. Use "
"PeriodIndex.from_fields instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

if ordinal is not None:
# GH#55960
warnings.warn(
"The 'ordinal' keyword in PeriodIndex is deprecated and will "
"be removed in a future version. Use PeriodIndex.from_ordinals "
"instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

name = maybe_extract_name(name, data, cls)

if data is None and ordinal is None:
# range-based.
if not fields:
# test_pickle_compat_construction
cls._raise_scalar_data_error(None)
data = cls.from_fields(**fields, freq=freq)._data
copy = False
freq = validate_dtype_freq(dtype, freq)

elif fields:
if data is not None:
raise ValueError("Cannot pass both data and fields")
raise ValueError("Cannot pass both ordinal and fields")
# PeriodIndex allow PeriodIndex(period_index, freq=different)
# Let's not encourage that kind of behavior in PeriodArray.

else:
freq = validate_dtype_freq(dtype, freq)

# PeriodIndex allow PeriodIndex(period_index, freq=different)
# Let's not encourage that kind of behavior in PeriodArray.

if freq and isinstance(data, cls) and data.freq != freq:
# TODO: We can do some of these with no-copy / coercion?
# e.g. D -> 2D seems to be OK
data = data.asfreq(freq)

if data is None and ordinal is not None:
ordinal = np.asarray(ordinal, dtype=np.int64)
dtype = PeriodDtype(freq)
data = PeriodArray(ordinal, dtype=dtype)
elif data is not None and ordinal is not None:
raise ValueError("Cannot pass both data and ordinal")
else:
# don't pass copy here, since we copy later.
data = period_array(data=data, freq=freq)
if freq and isinstance(data, cls) and data.freq != freq:
# TODO: We can do some of these with no-copy / coercion?
# e.g. D -> 2D seems to be OK
data = data.asfreq(freq)

# don't pass copy here, since we copy later.
data = period_array(data=data, freq=freq)

if copy:
data = data.copy()
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,4 @@ def test_inspect_getmembers(self):
# GH38740
pytest.importorskip("jinja2")
df = DataFrame()
msg = "DataFrame._data is deprecated"
with tm.assert_produces_warning(
DeprecationWarning, match=msg, check_stacklevel=False
):
inspect.getmembers(df)
inspect.getmembers(df)
7 changes: 0 additions & 7 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,6 @@ def test_copy_and_deepcopy(self, frame_or_series, shape, func):
assert obj_copy is not obj
tm.assert_equal(obj_copy, obj)

def test_data_deprecated(self, frame_or_series):
obj = frame_or_series()
msg = "(Series|DataFrame)._data is deprecated"
with tm.assert_produces_warning(DeprecationWarning, match=msg):
mgr = obj._data
assert mgr is obj._mgr


class TestNDFrame:
# tests that don't fit elsewhere
Expand Down
Loading