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
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
@@ -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
2 changes: 1 addition & 1 deletion ci/deps/actions-311-downstream_compat.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ci/deps/actions-311.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ci/deps/actions-312.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ci/deps/actions-39-minimum_versions.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ci/deps/circle-310-arm64.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
@@ -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.
@@ -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`)
@@ -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`)

2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pandas/compat/_optional.py
Original file line number Diff line number Diff line change
@@ -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",
13 changes: 0 additions & 13 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
Union,
cast,
)
import warnings

import numpy as np

@@ -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,
@@ -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

17 changes: 0 additions & 17 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
@@ -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"]]
87 changes: 10 additions & 77 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
timedelta,
)
from typing import TYPE_CHECKING
import warnings

import numpy as np

@@ -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
@@ -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
@@ -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
----------
@@ -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()
6 changes: 1 addition & 5 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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
73 changes: 13 additions & 60 deletions pandas/tests/indexes/period/test_constructors.py
Original file line number Diff line number Diff line change
@@ -66,40 +66,10 @@ def test_from_ordinals(self):
Period(ordinal=-1000, freq="Y")
Period(ordinal=0, freq="Y")

msg = "The 'ordinal' keyword in PeriodIndex is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
idx1 = PeriodIndex(ordinal=[-1, 0, 1], freq="Y")
with tm.assert_produces_warning(FutureWarning, match=msg):
idx2 = PeriodIndex(ordinal=np.array([-1, 0, 1]), freq="Y")
idx1 = PeriodIndex.from_ordinals(ordinals=[-1, 0, 1], freq="Y")
idx2 = PeriodIndex.from_ordinals(ordinals=np.array([-1, 0, 1]), freq="Y")
tm.assert_index_equal(idx1, idx2)

alt1 = PeriodIndex.from_ordinals([-1, 0, 1], freq="Y")
tm.assert_index_equal(alt1, idx1)

alt2 = PeriodIndex.from_ordinals(np.array([-1, 0, 1]), freq="Y")
tm.assert_index_equal(alt2, idx2)

def test_keyword_mismatch(self):
# GH#55961 we should get exactly one of data/ordinals/**fields
per = Period("2016-01-01", "D")
depr_msg1 = "The 'ordinal' keyword in PeriodIndex is deprecated"
depr_msg2 = "Constructing PeriodIndex from fields is deprecated"

err_msg1 = "Cannot pass both data and ordinal"
with pytest.raises(ValueError, match=err_msg1):
with tm.assert_produces_warning(FutureWarning, match=depr_msg1):
PeriodIndex(data=[per], ordinal=[per.ordinal], freq=per.freq)

err_msg2 = "Cannot pass both data and fields"
with pytest.raises(ValueError, match=err_msg2):
with tm.assert_produces_warning(FutureWarning, match=depr_msg2):
PeriodIndex(data=[per], year=[per.year], freq=per.freq)

err_msg3 = "Cannot pass both ordinal and fields"
with pytest.raises(ValueError, match=err_msg3):
with tm.assert_produces_warning(FutureWarning, match=depr_msg2):
PeriodIndex(ordinal=[per.ordinal], year=[per.year], freq=per.freq)

def test_construction_base_constructor(self):
# GH 13664
arr = [Period("2011-01", freq="M"), NaT, Period("2011-03", freq="M")]
@@ -158,35 +128,28 @@ def test_constructor_field_arrays(self):
years = np.arange(1990, 2010).repeat(4)[2:-2]
quarters = np.tile(np.arange(1, 5), 20)[2:-2]

depr_msg = "Constructing PeriodIndex from fields is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
index = PeriodIndex(year=years, quarter=quarters, freq="Q-DEC")
index = PeriodIndex.from_fields(year=years, quarter=quarters, freq="Q-DEC")
expected = period_range("1990Q3", "2009Q2", freq="Q-DEC")
tm.assert_index_equal(index, expected)

with tm.assert_produces_warning(FutureWarning, match=depr_msg):
index2 = PeriodIndex(year=years, quarter=quarters, freq="2Q-DEC")
index2 = PeriodIndex.from_fields(year=years, quarter=quarters, freq="2Q-DEC")
tm.assert_numpy_array_equal(index.asi8, index2.asi8)

with tm.assert_produces_warning(FutureWarning, match=depr_msg):
index = PeriodIndex(year=years, quarter=quarters)
index = PeriodIndex.from_fields(year=years, quarter=quarters)
tm.assert_index_equal(index, expected)

years = [2007, 2007, 2007]
months = [1, 2]

msg = "Mismatched Period array lengths"
with pytest.raises(ValueError, match=msg):
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
PeriodIndex(year=years, month=months, freq="M")
PeriodIndex.from_fields(year=years, month=months, freq="M")
with pytest.raises(ValueError, match=msg):
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
PeriodIndex(year=years, month=months, freq="2M")
PeriodIndex.from_fields(year=years, month=months, freq="2M")

years = [2007, 2007, 2007]
months = [1, 2, 3]
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
idx = PeriodIndex(year=years, month=months, freq="M")
idx = PeriodIndex.from_fields(year=years, month=months, freq="M")
exp = period_range("2007-01", periods=3, freq="M")
tm.assert_index_equal(idx, exp)

@@ -210,25 +173,17 @@ def test_constructor_nano(self):
def test_constructor_arrays_negative_year(self):
years = np.arange(1960, 2000, dtype=np.int64).repeat(4)
quarters = np.tile(np.array([1, 2, 3, 4], dtype=np.int64), 40)

msg = "Constructing PeriodIndex from fields is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
pindex = PeriodIndex(year=years, quarter=quarters)
pindex = PeriodIndex.from_fields(year=years, quarter=quarters)

tm.assert_index_equal(pindex.year, Index(years))
tm.assert_index_equal(pindex.quarter, Index(quarters))

alt = PeriodIndex.from_fields(year=years, quarter=quarters)
tm.assert_index_equal(alt, pindex)

def test_constructor_invalid_quarters(self):
depr_msg = "Constructing PeriodIndex from fields is deprecated"
msg = "Quarter must be 1 <= q <= 4"
with pytest.raises(ValueError, match=msg):
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
PeriodIndex(
year=range(2000, 2004), quarter=list(range(4)), freq="Q-DEC"
)
PeriodIndex.from_fields(
year=range(2000, 2004), quarter=list(range(4)), freq="Q-DEC"
)

def test_period_range_fractional_period(self):
msg = "Non-integer 'periods' in pd.date_range, pd.timedelta_range"
@@ -434,9 +389,7 @@ def test_constructor_floats(self, floats):
def test_constructor_year_and_quarter(self):
year = Series([2001, 2002, 2003])
quarter = year - 2000
msg = "Constructing PeriodIndex from fields is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
idx = PeriodIndex(year=year, quarter=quarter)
idx = PeriodIndex.from_fields(year=year, quarter=quarter)
strs = [f"{t[0]:d}Q{t[1]:d}" for t in zip(quarter, year)]
lops = list(map(Period, strs))
p = PeriodIndex(lops)
5 changes: 2 additions & 3 deletions pandas/tests/indexes/test_old_base.py
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ def test_pickle_compat_construction(self, simple_index):
r"kind, None was passed",
r"__new__\(\) missing 1 required positional argument: 'data'",
r"__new__\(\) takes at least 2 arguments \(1 given\)",
r"'NoneType' object is not iterable",
]
)
with pytest.raises(TypeError, match=msg):
@@ -275,9 +276,7 @@ def test_ensure_copied_data(self, index):

if isinstance(index, PeriodIndex):
# .values an object array of Period, thus copied
depr_msg = "The 'ordinal' keyword in PeriodIndex is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
result = index_type(ordinal=index.asi8, copy=False, **init_kwargs)
result = index_type.from_ordinals(ordinals=index.asi8, **init_kwargs)
tm.assert_numpy_array_equal(index.asi8, result.asi8, check_same="same")
elif isinstance(index, IntervalIndex):
# checked in test_interval.py
6 changes: 1 addition & 5 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
@@ -164,11 +164,7 @@ def test_inspect_getmembers(self):
# GH38782
pytest.importorskip("jinja2")
ser = Series(dtype=object)
msg = "Series._data is deprecated"
with tm.assert_produces_warning(
DeprecationWarning, match=msg, check_stacklevel=False
):
inspect.getmembers(ser)
inspect.getmembers(ser)

def test_unknown_attribute(self):
# GH#9680
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ all = ['adbc-driver-postgresql>=0.8.0',
#'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',
'gcsfs>=2022.11.0',
'html5lib>=1.1',
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ pytz
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