Skip to content

Commit 4d0068e

Browse files
authored
CLN: Remove pandas.value_counts, Index.format, is_interval, is_period (#57296)
1 parent 203a661 commit 4d0068e

28 files changed

+17
-690
lines changed

asv_bench/benchmarks/strftime.py

-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ def time_frame_period_formatting_default(self, nobs, freq):
7979
def time_frame_period_formatting_default_explicit(self, nobs, freq):
8080
self.data["p"].dt.strftime(date_format=self.default_fmt)
8181

82-
def time_frame_period_formatting_index_default(self, nobs, freq):
83-
self.data.index.format()
84-
85-
def time_frame_period_formatting_index_default_explicit(self, nobs, freq):
86-
self.data.index.format(self.default_fmt)
87-
8882
def time_frame_period_formatting_custom(self, nobs, freq):
8983
self.data["p"].dt.strftime(date_format="%Y-%m-%d --- %H:%M:%S")
9084

doc/redirects.csv

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ generated/pandas.api.types.is_int64_dtype,../reference/api/pandas.api.types.is_i
118118
generated/pandas.api.types.is_integer_dtype,../reference/api/pandas.api.types.is_integer_dtype
119119
generated/pandas.api.types.is_integer,../reference/api/pandas.api.types.is_integer
120120
generated/pandas.api.types.is_interval_dtype,../reference/api/pandas.api.types.is_interval_dtype
121-
generated/pandas.api.types.is_interval,../reference/api/pandas.api.types.is_interval
122121
generated/pandas.api.types.is_iterator,../reference/api/pandas.api.types.is_iterator
123122
generated/pandas.api.types.is_list_like,../reference/api/pandas.api.types.is_list_like
124123
generated/pandas.api.types.is_named_tuple,../reference/api/pandas.api.types.is_named_tuple

doc/source/reference/arrays.rst

-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ Scalar introspection
700700
api.types.is_float
701701
api.types.is_hashable
702702
api.types.is_integer
703-
api.types.is_interval
704703
api.types.is_number
705704
api.types.is_re
706705
api.types.is_re_compilable

doc/source/whatsnew/v3.0.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ Removal of prior version deprecations/changes
108108
- Removed ``DataFrame.first`` and ``DataFrame.last`` (:issue:`53710`)
109109
- Removed ``DataFrameGroupBy.grouper`` and ``SeriesGroupBy.grouper`` (:issue:`56521`)
110110
- Removed ``DataFrameGroupby.fillna`` and ``SeriesGroupBy.fillna``` (:issue:`55719`)
111+
- Removed ``Index.format``, use :meth:`Index.astype` with ``str`` or :meth:`Index.map` with a ``formatter`` function instead (:issue:`55439`)
111112
- Removed ``Series.__int__`` and ``Series.__float__``. Call ``int(Series.iloc[0])`` or ``float(Series.iloc[0])`` instead. (:issue:`51131`)
112113
- Removed ``Series.ravel`` (:issue:`56053`)
113114
- Removed ``Series.view`` (:issue:`56054`)
114115
- 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`)
115116
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
117+
- Removed ``pandas.api.types.is_interval`` and ``pandas.api.types.is_period``, use ``isinstance(obj, pd.Interval)`` and ``isinstance(obj, pd.Period)`` instead (:issue:`55264`)
116118
- Removed ``pandas.io.sql.execute`` (:issue:`50185`)
119+
- Removed ``pandas.value_counts``, use :meth:`Series.value_counts` instead (:issue:`53493`)
117120
- 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`)
118121
- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`)
119122
- Removed the ``ArrayManager`` (:issue:`55043`)

pandas/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
Grouper,
102102
factorize,
103103
unique,
104-
value_counts,
105104
NamedAgg,
106105
array,
107106
Categorical,
@@ -378,6 +377,5 @@
378377
"to_timedelta",
379378
"tseries",
380379
"unique",
381-
"value_counts",
382380
"wide_to_long",
383381
]

pandas/_libs/lib.pyi

-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ from typing import (
1414

1515
import numpy as np
1616

17-
from pandas._libs.interval import Interval
18-
from pandas._libs.tslibs import Period
1917
from pandas._typing import (
2018
ArrayLike,
2119
DtypeObj,
@@ -44,8 +42,6 @@ def is_iterator(obj: object) -> bool: ...
4442
def is_scalar(val: object) -> bool: ...
4543
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ...
4644
def is_pyarrow_array(obj: object) -> bool: ...
47-
def is_period(val: object) -> TypeGuard[Period]: ...
48-
def is_interval(obj: object) -> TypeGuard[Interval]: ...
4945
def is_decimal(obj: object) -> TypeGuard[Decimal]: ...
5046
def is_complex(obj: object) -> TypeGuard[complex]: ...
5147
def is_bool(obj: object) -> TypeGuard[bool | np.bool_]: ...

pandas/_libs/lib.pyx

-37
Original file line numberDiff line numberDiff line change
@@ -1164,43 +1164,6 @@ cpdef bint is_decimal(object obj):
11641164
return isinstance(obj, Decimal)
11651165

11661166

1167-
cpdef bint is_interval(object obj):
1168-
import warnings
1169-
1170-
from pandas.util._exceptions import find_stack_level
1171-
1172-
warnings.warn(
1173-
# GH#55264
1174-
"is_interval is deprecated and will be removed in a future version. "
1175-
"Use isinstance(obj, pd.Interval) instead.",
1176-
FutureWarning,
1177-
stacklevel=find_stack_level(),
1178-
)
1179-
return getattr(obj, "_typ", "_typ") == "interval"
1180-
1181-
1182-
def is_period(val: object) -> bool:
1183-
"""
1184-
Return True if given object is Period.
1185-
1186-
Returns
1187-
-------
1188-
bool
1189-
"""
1190-
import warnings
1191-
1192-
from pandas.util._exceptions import find_stack_level
1193-
1194-
warnings.warn(
1195-
# GH#55264
1196-
"is_period is deprecated and will be removed in a future version. "
1197-
"Use isinstance(obj, pd.Period) instead.",
1198-
FutureWarning,
1199-
stacklevel=find_stack_level(),
1200-
)
1201-
return is_period_object(val)
1202-
1203-
12041167
def is_list_like(obj: object, allow_sets: bool = True) -> bool:
12051168
"""
12061169
Check if the object is list-like.

pandas/core/algorithms.py

-47
Original file line numberDiff line numberDiff line change
@@ -818,53 +818,6 @@ def factorize(
818818
return codes, uniques
819819

820820

821-
def value_counts(
822-
values,
823-
sort: bool = True,
824-
ascending: bool = False,
825-
normalize: bool = False,
826-
bins=None,
827-
dropna: bool = True,
828-
) -> Series:
829-
"""
830-
Compute a histogram of the counts of non-null values.
831-
832-
Parameters
833-
----------
834-
values : ndarray (1-d)
835-
sort : bool, default True
836-
Sort by values
837-
ascending : bool, default False
838-
Sort in ascending order
839-
normalize: bool, default False
840-
If True then compute a relative histogram
841-
bins : integer, optional
842-
Rather than count values, group them into half-open bins,
843-
convenience for pd.cut, only works with numeric data
844-
dropna : bool, default True
845-
Don't include counts of NaN
846-
847-
Returns
848-
-------
849-
Series
850-
"""
851-
warnings.warn(
852-
# GH#53493
853-
"pandas.value_counts is deprecated and will be removed in a "
854-
"future version. Use pd.Series(obj).value_counts() instead.",
855-
FutureWarning,
856-
stacklevel=find_stack_level(),
857-
)
858-
return value_counts_internal(
859-
values,
860-
sort=sort,
861-
ascending=ascending,
862-
normalize=normalize,
863-
bins=bins,
864-
dropna=dropna,
865-
)
866-
867-
868821
def value_counts_internal(
869822
values,
870823
sort: bool = True,

pandas/core/api.py

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from pandas.core.algorithms import (
2424
factorize,
2525
unique,
26-
value_counts,
2726
)
2827
from pandas.core.arrays import Categorical
2928
from pandas.core.arrays.boolean import BooleanDtype
@@ -136,5 +135,4 @@
136135
"UInt64Dtype",
137136
"UInt8Dtype",
138137
"unique",
139-
"value_counts",
140138
]

pandas/core/dtypes/api.py

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
is_int64_dtype,
2121
is_integer,
2222
is_integer_dtype,
23-
is_interval,
2423
is_interval_dtype,
2524
is_iterator,
2625
is_list_like,
@@ -63,7 +62,6 @@
6362
"is_int64_dtype",
6463
"is_integer",
6564
"is_integer_dtype",
66-
"is_interval",
6765
"is_interval_dtype",
6866
"is_iterator",
6967
"is_list_like",

pandas/core/dtypes/common.py

-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
is_float,
4343
is_hashable,
4444
is_integer,
45-
is_interval,
4645
is_iterator,
4746
is_list_like,
4847
is_named_tuple,
@@ -1710,7 +1709,6 @@ def is_all_strings(value: ArrayLike) -> bool:
17101709
"is_float_dtype",
17111710
"is_int64_dtype",
17121711
"is_integer_dtype",
1713-
"is_interval",
17141712
"is_interval_dtype",
17151713
"is_iterator",
17161714
"is_named_tuple",

pandas/core/dtypes/inference.py

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
is_decimal = lib.is_decimal
3131

32-
is_interval = lib.is_interval
33-
3432
is_list_like = lib.is_list_like
3533

3634
is_iterator = lib.is_iterator

pandas/core/indexes/base.py

-30
Original file line numberDiff line numberDiff line change
@@ -1394,36 +1394,6 @@ def _mpl_repr(self) -> np.ndarray:
13941394
return cast(np.ndarray, self.values)
13951395
return self.astype(object, copy=False)._values
13961396

1397-
def format(
1398-
self,
1399-
name: bool = False,
1400-
formatter: Callable | None = None,
1401-
na_rep: str_t = "NaN",
1402-
) -> list[str_t]:
1403-
"""
1404-
Render a string representation of the Index.
1405-
"""
1406-
warnings.warn(
1407-
# GH#55413
1408-
f"{type(self).__name__}.format is deprecated and will be removed "
1409-
"in a future version. Convert using index.astype(str) or "
1410-
"index.map(formatter) instead.",
1411-
FutureWarning,
1412-
stacklevel=find_stack_level(),
1413-
)
1414-
header = []
1415-
if name:
1416-
header.append(
1417-
pprint_thing(self.name, escape_chars=("\t", "\r", "\n"))
1418-
if self.name is not None
1419-
else ""
1420-
)
1421-
1422-
if formatter is not None:
1423-
return header + list(self.map(formatter))
1424-
1425-
return self._format_with_header(header=header, na_rep=na_rep)
1426-
14271397
_default_na_rep = "NaN"
14281398

14291399
@final

pandas/core/indexes/datetimelike.py

-36
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
from typing import (
1111
TYPE_CHECKING,
1212
Any,
13-
Callable,
1413
cast,
1514
final,
1615
)
17-
import warnings
1816

1917
import numpy as np
2018

@@ -43,7 +41,6 @@
4341
cache_readonly,
4442
doc,
4543
)
46-
from pandas.util._exceptions import find_stack_level
4744

4845
from pandas.core.dtypes.common import (
4946
is_integer,
@@ -192,39 +189,6 @@ def _convert_tolerance(self, tolerance, target):
192189
# Rendering Methods
193190
_default_na_rep = "NaT"
194191

195-
def format(
196-
self,
197-
name: bool = False,
198-
formatter: Callable | None = None,
199-
na_rep: str = "NaT",
200-
date_format: str | None = None,
201-
) -> list[str]:
202-
"""
203-
Render a string representation of the Index.
204-
"""
205-
warnings.warn(
206-
# GH#55413
207-
f"{type(self).__name__}.format is deprecated and will be removed "
208-
"in a future version. Convert using index.astype(str) or "
209-
"index.map(formatter) instead.",
210-
FutureWarning,
211-
stacklevel=find_stack_level(),
212-
)
213-
header = []
214-
if name:
215-
header.append(
216-
ibase.pprint_thing(self.name, escape_chars=("\t", "\r", "\n"))
217-
if self.name is not None
218-
else ""
219-
)
220-
221-
if formatter is not None:
222-
return header + list(self.map(formatter))
223-
224-
return self._format_with_header(
225-
header=header, na_rep=na_rep, date_format=date_format
226-
)
227-
228192
def _format_with_header(
229193
self, *, header: list[str], na_rep: str, date_format: str | None = None
230194
) -> list[str]:

0 commit comments

Comments
 (0)