Skip to content

Commit 62a31d9

Browse files
author
Kei
committed
Merge branch 'main' into fix/group_by_agg_pyarrow_bool_numpy_same_type
2 parents d510052 + b8a4691 commit 62a31d9

File tree

23 files changed

+86
-156
lines changed

23 files changed

+86
-156
lines changed

asv_bench/benchmarks/categoricals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setup(self):
2424
self.codes = np.tile(range(len(self.categories)), N)
2525

2626
self.datetimes = pd.Series(
27-
pd.date_range("1995-01-01 00:00:00", periods=N / 10, freq="s")
27+
pd.date_range("1995-01-01 00:00:00", periods=N // 10, freq="s")
2828
)
2929
self.datetimes_with_nat = self.datetimes.copy()
3030
self.datetimes_with_nat.iloc[-1] = pd.NaT

asv_bench/benchmarks/timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setup(self, index_type):
2929
"dst": date_range(
3030
start="10/29/2000 1:00:00", end="10/29/2000 1:59:59", freq="s"
3131
),
32-
"repeated": date_range(start="2000", periods=N / 10, freq="s").repeat(10),
32+
"repeated": date_range(start="2000", periods=N // 10, freq="s").repeat(10),
3333
"tz_aware": date_range(start="2000", periods=N, freq="s", tz="US/Eastern"),
3434
"tz_local": date_range(
3535
start="2000", periods=N, freq="s", tz=dateutil.tz.tzlocal()

doc/redirects.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ reference/api/pandas.Series.transpose,pandas.Series.T
14221422
reference/api/pandas.Index.transpose,pandas.Index.T
14231423
reference/api/pandas.Index.notnull,pandas.Index.notna
14241424
reference/api/pandas.Index.tolist,pandas.Index.to_list
1425-
reference/api/pandas.arrays.PandasArray,pandas.arrays.NumpyExtensionArray
14261425
reference/api/pandas.core.groupby.DataFrameGroupBy.backfill,pandas.core.groupby.DataFrameGroupBy.bfill
14271426
reference/api/pandas.core.groupby.GroupBy.backfill,pandas.core.groupby.DataFrameGroupBy.bfill
14281427
reference/api/pandas.core.resample.Resampler.backfill,pandas.core.resample.Resampler.bfill

doc/source/whatsnew/v3.0.0.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,25 @@ Removal of prior version deprecations/changes
208208
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
209209
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
210210
- Disallow calling :meth:`Series.replace` or :meth:`DataFrame.replace` without a ``value`` and with non-dict-like ``to_replace`` (:issue:`33302`)
211+
- Disallow constructing a :class:`arrays.SparseArray` with scalar data (:issue:`53039`)
211212
- Disallow non-standard (``np.ndarray``, :class:`Index`, :class:`ExtensionArray`, or :class:`Series`) to :func:`isin`, :func:`unique`, :func:`factorize` (:issue:`52986`)
212213
- Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`)
213214
- Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`)
214215
- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`)
216+
- Removed 'fastpath' keyword in :class:`Categorical` constructor (:issue:`20110`)
217+
- Removed alias :class:`arrays.PandasArray` for :class:`arrays.NumpyExtensionArray` (:issue:`53694`)
215218
- Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`)
216219
- Removed extension test classes ``BaseNoReduceTests``, ``BaseNumericReduceTests``, ``BaseBooleanReduceTests`` (:issue:`54663`)
217220
- Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`)
221+
- Require :meth:`SparseDtype.fill_value` to be a valid value for the :meth:`SparseDtype.subtype` (:issue:`53043`)
218222
- Stopped performing dtype inference with in :meth:`Index.insert` with object-dtype index; this often affects the index/columns that result when setting new entries into an empty :class:`Series` or :class:`DataFrame` (:issue:`51363`)
219223
- Removed the "closed" and "unit" keywords in :meth:`TimedeltaIndex.__new__` (:issue:`52628`, :issue:`55499`)
220224
- All arguments in :meth:`Index.sort_values` are now keyword only (:issue:`56493`)
221225
- All arguments in :meth:`Series.to_dict` are now keyword only (:issue:`56493`)
222226
- Changed the default value of ``observed`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to ``True`` (:issue:`51811`)
223227
- Enforce deprecation in :func:`testing.assert_series_equal` and :func:`testing.assert_frame_equal` with object dtype and mismatched null-like values, which are now considered not-equal (:issue:`18463`)
224-
- Enforced deprecation ``all`` and ``any`` reductions with ``datetime64`` and :class:`DatetimeTZDtype` dtypes (:issue:`58029`)
228+
- Enforced deprecation ``all`` and ``any`` reductions with ``datetime64``, :class:`DatetimeTZDtype`, and :class:`PeriodDtype` dtypes (:issue:`58029`)
229+
- Enforced deprecation disallowing ``float`` "periods" in :func:`date_range`, :func:`period_range`, :func:`timedelta_range`, :func:`interval_range`, (:issue:`56036`)
225230
- Enforced deprecation disallowing parsing datetimes with mixed time zones unless user passes ``utc=True`` to :func:`to_datetime` (:issue:`57275`)
226231
- Enforced deprecation in :meth:`Series.value_counts` and :meth:`Index.value_counts` with object dtype performing dtype inference on the ``.index`` of the result (:issue:`56161`)
227232
- Enforced deprecation of :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` allowing the ``name`` argument to be a non-tuple when grouping by a list of length 1 (:issue:`54155`)
@@ -448,6 +453,7 @@ Other
448453
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
449454
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
450455
- Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`)
456+
- Bug in :meth:`Index.sort_values` when passing a key function that turns values into tuples, e.g. ``key=natsort.natsort_key``, would raise ``TypeError`` (:issue:`56081`)
451457
- Bug in Dataframe Interchange Protocol implementation was returning incorrect results for data buffers' associated dtype, for string and datetime columns (:issue:`54781`)
452458

453459
.. ***DO NOT USE THIS SECTION***

pandas/arrays/__init__.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,3 @@
3535
"StringArray",
3636
"TimedeltaArray",
3737
]
38-
39-
40-
def __getattr__(name: str) -> type[NumpyExtensionArray]:
41-
if name == "PandasArray":
42-
# GH#53694
43-
import warnings
44-
45-
from pandas.util._exceptions import find_stack_level
46-
47-
warnings.warn(
48-
"PandasArray has been renamed NumpyExtensionArray. Use that "
49-
"instead. This alias will be removed in a future version.",
50-
FutureWarning,
51-
stacklevel=find_stack_level(),
52-
)
53-
return NumpyExtensionArray
54-
raise AttributeError(f"module 'pandas.arrays' has no attribute '{name}'")

pandas/core/arrays/categorical.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,6 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject, ObjectStringArrayMi
276276
provided).
277277
dtype : CategoricalDtype
278278
An instance of ``CategoricalDtype`` to use for this categorical.
279-
fastpath : bool
280-
The 'fastpath' keyword in Categorical is deprecated and will be
281-
removed in a future version. Use Categorical.from_codes instead.
282279
copy : bool, default True
283280
Whether to copy if the codes are unchanged.
284281
@@ -391,33 +388,15 @@ def __init__(
391388
categories=None,
392389
ordered=None,
393390
dtype: Dtype | None = None,
394-
fastpath: bool | lib.NoDefault = lib.no_default,
395391
copy: bool = True,
396392
) -> None:
397-
if fastpath is not lib.no_default:
398-
# GH#20110
399-
warnings.warn(
400-
"The 'fastpath' keyword in Categorical is deprecated and will "
401-
"be removed in a future version. Use Categorical.from_codes instead",
402-
DeprecationWarning,
403-
stacklevel=find_stack_level(),
404-
)
405-
else:
406-
fastpath = False
407-
408393
dtype = CategoricalDtype._from_values_or_dtype(
409394
values, categories, ordered, dtype
410395
)
411396
# At this point, dtype is always a CategoricalDtype, but
412397
# we may have dtype.categories be None, and we need to
413398
# infer categories in a factorization step further below
414399

415-
if fastpath:
416-
codes = coerce_indexer_dtype(values, dtype.categories)
417-
dtype = CategoricalDtype(ordered=False).update_dtype(dtype)
418-
super().__init__(codes, dtype)
419-
return
420-
421400
if not is_list_like(values):
422401
# GH#38433
423402
raise TypeError("Categorical input must be list-like")

pandas/core/arrays/datetimelike.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,20 +1661,24 @@ def _groupby_op(
16611661
dtype = self.dtype
16621662
if dtype.kind == "M":
16631663
# Adding/multiplying datetimes is not valid
1664-
if how in ["any", "all", "sum", "prod", "cumsum", "cumprod", "var", "skew"]:
1664+
if how in ["sum", "prod", "cumsum", "cumprod", "var", "skew"]:
16651665
raise TypeError(f"datetime64 type does not support operation '{how}'")
1666+
if how in ["any", "all"]:
1667+
# GH#34479
1668+
raise TypeError(
1669+
f"'{how}' with datetime64 dtypes is no longer supported. "
1670+
f"Use (obj != pd.Timestamp(0)).{how}() instead."
1671+
)
16661672

16671673
elif isinstance(dtype, PeriodDtype):
16681674
# Adding/multiplying Periods is not valid
16691675
if how in ["sum", "prod", "cumsum", "cumprod", "var", "skew"]:
16701676
raise TypeError(f"Period type does not support {how} operations")
16711677
if how in ["any", "all"]:
16721678
# GH#34479
1673-
warnings.warn(
1674-
f"'{how}' with PeriodDtype is deprecated and will raise in a "
1675-
f"future version. Use (obj != pd.Period(0, freq)).{how}() instead.",
1676-
FutureWarning,
1677-
stacklevel=find_stack_level(),
1679+
raise TypeError(
1680+
f"'{how}' with PeriodDtype is no longer supported. "
1681+
f"Use (obj != pd.Period(0, freq)).{how}() instead."
16781682
)
16791683
else:
16801684
# timedeltas we can add but not multiply
@@ -2424,17 +2428,17 @@ def validate_periods(periods: None) -> None: ...
24242428

24252429

24262430
@overload
2427-
def validate_periods(periods: int | float) -> int: ...
2431+
def validate_periods(periods: int) -> int: ...
24282432

24292433

2430-
def validate_periods(periods: int | float | None) -> int | None:
2434+
def validate_periods(periods: int | None) -> int | None:
24312435
"""
24322436
If a `periods` argument is passed to the Datetime/Timedelta Array/Index
24332437
constructor, cast it to an integer.
24342438
24352439
Parameters
24362440
----------
2437-
periods : None, float, int
2441+
periods : None, int
24382442
24392443
Returns
24402444
-------
@@ -2443,22 +2447,13 @@ def validate_periods(periods: int | float | None) -> int | None:
24432447
Raises
24442448
------
24452449
TypeError
2446-
if periods is None, float, or int
2450+
if periods is not None or int
24472451
"""
2448-
if periods is not None:
2449-
if lib.is_float(periods):
2450-
warnings.warn(
2451-
# GH#56036
2452-
"Non-integer 'periods' in pd.date_range, pd.timedelta_range, "
2453-
"pd.period_range, and pd.interval_range are deprecated and "
2454-
"will raise in a future version.",
2455-
FutureWarning,
2456-
stacklevel=find_stack_level(),
2457-
)
2458-
periods = int(periods)
2459-
elif not lib.is_integer(periods):
2460-
raise TypeError(f"periods must be a number, got {periods}")
2461-
return periods
2452+
if periods is not None and not lib.is_integer(periods):
2453+
raise TypeError(f"periods must be an integer, got {periods}")
2454+
# error: Incompatible return value type (got "int | integer[Any] | None",
2455+
# expected "int | None")
2456+
return periods # type: ignore[return-value]
24622457

24632458

24642459
def _validate_inferred_freq(

pandas/core/arrays/sparse/array.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
from pandas.core.dtypes.astype import astype_array
4242
from pandas.core.dtypes.cast import (
43-
construct_1d_arraylike_from_scalar,
4443
find_common_type,
4544
maybe_box_datetimelike,
4645
)
@@ -399,19 +398,10 @@ def __init__(
399398
dtype = dtype.subtype
400399

401400
if is_scalar(data):
402-
warnings.warn(
403-
f"Constructing {type(self).__name__} with scalar data is deprecated "
404-
"and will raise in a future version. Pass a sequence instead.",
405-
FutureWarning,
406-
stacklevel=find_stack_level(),
401+
raise TypeError(
402+
f"Cannot construct {type(self).__name__} from scalar data. "
403+
"Pass a sequence instead."
407404
)
408-
if sparse_index is None:
409-
npoints = 1
410-
else:
411-
npoints = sparse_index.length
412-
413-
data = construct_1d_arraylike_from_scalar(data, npoints, dtype=None)
414-
dtype = data.dtype
415405

416406
if dtype is not None:
417407
dtype = pandas_dtype(dtype)

pandas/core/dtypes/dtypes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,24 +1762,18 @@ def _check_fill_value(self) -> None:
17621762
val = self._fill_value
17631763
if isna(val):
17641764
if not is_valid_na_for_dtype(val, self.subtype):
1765-
warnings.warn(
1766-
"Allowing arbitrary scalar fill_value in SparseDtype is "
1767-
"deprecated. In a future version, the fill_value must be "
1768-
"a valid value for the SparseDtype.subtype.",
1769-
FutureWarning,
1770-
stacklevel=find_stack_level(),
1765+
raise ValueError(
1766+
# GH#53043
1767+
"fill_value must be a valid value for the SparseDtype.subtype"
17711768
)
17721769
else:
17731770
dummy = np.empty(0, dtype=self.subtype)
17741771
dummy = ensure_wrapped_if_datetimelike(dummy)
17751772

17761773
if not can_hold_element(dummy, val):
1777-
warnings.warn(
1778-
"Allowing arbitrary scalar fill_value in SparseDtype is "
1779-
"deprecated. In a future version, the fill_value must be "
1780-
"a valid value for the SparseDtype.subtype.",
1781-
FutureWarning,
1782-
stacklevel=find_stack_level(),
1774+
raise ValueError(
1775+
# GH#53043
1776+
"fill_value must be a valid value for the SparseDtype.subtype"
17831777
)
17841778

17851779
@property

pandas/core/sorting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def ensure_key_mapped(
577577
if isinstance(
578578
values, Index
579579
): # convert to a new Index subclass, not necessarily the same
580-
result = Index(result)
580+
result = Index(result, tupleize_cols=False)
581581
else:
582582
# try to revert to original type otherwise
583583
type_of_values = type(values)

0 commit comments

Comments
 (0)