Skip to content

Commit 5a2adf3

Browse files
jbrockmendelproost
authored andcommitted
DEPR: remove Index fastpath kwarg (pandas-dev#29725)
1 parent 432d78d commit 5a2adf3

File tree

14 files changed

+115
-182
lines changed

14 files changed

+115
-182
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
403403

404404
- Floordiv of integer-dtyped array by :class:`Timedelta` now raises ``TypeError`` (:issue:`21036`)
405405
- Removed the previously deprecated :meth:`Index.summary` (:issue:`18217`)
406+
- Removed the previously deprecated "fastpath" keyword from the :class:`Index` constructor (:issue:`23110`)
406407
- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`)
407408
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)
408409
- Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`)

pandas/conftest.py

+13
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,16 @@ def float_frame():
868868
[30 rows x 4 columns]
869869
"""
870870
return DataFrame(tm.getSeriesData())
871+
872+
873+
@pytest.fixture(params=[pd.Index, pd.Series], ids=["index", "series"])
874+
def index_or_series(request):
875+
"""
876+
Fixture to parametrize over Index and Series, made necessary by a mypy
877+
bug, giving an error:
878+
879+
List item 0 has incompatible type "Type[Series]"; expected "Type[PandasObject]"
880+
881+
See GH#?????
882+
"""
883+
return request.param

pandas/core/indexes/base.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,7 @@ def _outer_indexer(self, left, right):
265265
# Constructors
266266

267267
def __new__(
268-
cls,
269-
data=None,
270-
dtype=None,
271-
copy=False,
272-
name=None,
273-
fastpath=None,
274-
tupleize_cols=True,
275-
**kwargs,
268+
cls, data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs,
276269
) -> "Index":
277270

278271
from .range import RangeIndex
@@ -284,16 +277,6 @@ def __new__(
284277
if name is None and hasattr(data, "name"):
285278
name = data.name
286279

287-
if fastpath is not None:
288-
warnings.warn(
289-
"The 'fastpath' keyword is deprecated, and will be "
290-
"removed in a future version.",
291-
FutureWarning,
292-
stacklevel=2,
293-
)
294-
if fastpath:
295-
return cls._simple_new(data, name)
296-
297280
if isinstance(data, ABCPandasArray):
298281
# ensure users don't accidentally put a PandasArray in an index.
299282
data = data.to_numpy()

pandas/core/indexes/category.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import operator
22
from typing import Any
3-
import warnings
43

54
import numpy as np
65

@@ -172,19 +171,8 @@ def __new__(
172171
dtype=None,
173172
copy=False,
174173
name=None,
175-
fastpath=None,
176174
):
177175

178-
if fastpath is not None:
179-
warnings.warn(
180-
"The 'fastpath' keyword is deprecated, and will be "
181-
"removed in a future version.",
182-
FutureWarning,
183-
stacklevel=2,
184-
)
185-
if fastpath:
186-
return cls._simple_new(data, name=name, dtype=dtype)
187-
188176
dtype = CategoricalDtype._from_values_or_dtype(data, categories, ordered, dtype)
189177

190178
if name is None and hasattr(data, "name"):

pandas/core/indexes/numeric.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
import numpy as np
42

53
from pandas._libs import index as libindex
@@ -47,17 +45,8 @@ class NumericIndex(Index):
4745

4846
_is_numeric_dtype = True
4947

50-
def __new__(cls, data=None, dtype=None, copy=False, name=None, fastpath=None):
48+
def __new__(cls, data=None, dtype=None, copy=False, name=None):
5149
cls._validate_dtype(dtype)
52-
if fastpath is not None:
53-
warnings.warn(
54-
"The 'fastpath' keyword is deprecated, and will be "
55-
"removed in a future version.",
56-
FutureWarning,
57-
stacklevel=2,
58-
)
59-
if fastpath:
60-
return cls._simple_new(data, name=name)
6150

6251
# Coerce to ndarray if not already ndarray or Index
6352
if not isinstance(data, (np.ndarray, Index)):

pandas/core/indexes/range.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,9 @@ class RangeIndex(Int64Index):
8181
# Constructors
8282

8383
def __new__(
84-
cls,
85-
start=None,
86-
stop=None,
87-
step=None,
88-
dtype=None,
89-
copy=False,
90-
name=None,
91-
fastpath=None,
84+
cls, start=None, stop=None, step=None, dtype=None, copy=False, name=None,
9285
):
9386

94-
if fastpath is not None:
95-
warnings.warn(
96-
"The 'fastpath' keyword is deprecated, and will be "
97-
"removed in a future version.",
98-
FutureWarning,
99-
stacklevel=2,
100-
)
101-
if fastpath:
102-
return cls._simple_new(range(start, stop, step), name=name)
103-
10487
cls._validate_dtype(dtype)
10588

10689
# RangeIndex

pandas/tests/arithmetic/test_numeric.py

+16-40
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from decimal import Decimal
66
from itertools import combinations
77
import operator
8+
from typing import Any, List
89

910
import numpy as np
1011
import pytest
@@ -30,6 +31,19 @@ def adjust_negative_zero(zero, expected):
3031
return expected
3132

3233

34+
# TODO: remove this kludge once mypy stops giving false positives here
35+
# List comprehension has incompatible type List[PandasObject]; expected List[RangeIndex]
36+
# See GH#?????
37+
ser_or_index: List[Any] = [pd.Series, pd.Index]
38+
lefts: List[Any] = [pd.RangeIndex(10, 40, 10)]
39+
lefts.extend(
40+
[
41+
cls([10, 20, 30], dtype=dtype)
42+
for dtype in ["i1", "i2", "i4", "i8", "u1", "u2", "u4", "u8", "f2", "f4", "f8"]
43+
for cls in ser_or_index
44+
]
45+
)
46+
3347
# ------------------------------------------------------------------
3448
# Comparisons
3549

@@ -81,26 +95,7 @@ class TestNumericArraylikeArithmeticWithDatetimeLike:
8195
# TODO: also check name retentention
8296
@pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series])
8397
@pytest.mark.parametrize(
84-
"left",
85-
[pd.RangeIndex(10, 40, 10)]
86-
+ [
87-
cls([10, 20, 30], dtype=dtype)
88-
for dtype in [
89-
"i1",
90-
"i2",
91-
"i4",
92-
"i8",
93-
"u1",
94-
"u2",
95-
"u4",
96-
"u8",
97-
"f2",
98-
"f4",
99-
"f8",
100-
]
101-
for cls in [pd.Series, pd.Index]
102-
],
103-
ids=lambda x: type(x).__name__ + str(x.dtype),
98+
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype),
10499
)
105100
def test_mul_td64arr(self, left, box_cls):
106101
# GH#22390
@@ -120,26 +115,7 @@ def test_mul_td64arr(self, left, box_cls):
120115
# TODO: also check name retentention
121116
@pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series])
122117
@pytest.mark.parametrize(
123-
"left",
124-
[pd.RangeIndex(10, 40, 10)]
125-
+ [
126-
cls([10, 20, 30], dtype=dtype)
127-
for dtype in [
128-
"i1",
129-
"i2",
130-
"i4",
131-
"i8",
132-
"u1",
133-
"u2",
134-
"u4",
135-
"u8",
136-
"f2",
137-
"f4",
138-
"f8",
139-
]
140-
for cls in [pd.Series, pd.Index]
141-
],
142-
ids=lambda x: type(x).__name__ + str(x.dtype),
118+
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype),
143119
)
144120
def test_div_td64arr(self, left, box_cls):
145121
# GH#22390

pandas/tests/arrays/test_array.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
272272
return super()._from_sequence(scalars, dtype=dtype, copy=copy)
273273

274274

275-
@pytest.mark.parametrize("box", [pd.Series, pd.Index])
276-
def test_array_unboxes(box):
275+
def test_array_unboxes(index_or_series):
276+
box = index_or_series
277+
277278
data = box([decimal.Decimal("1"), decimal.Decimal("2")])
278279
# make sure it works
279280
with pytest.raises(TypeError):

pandas/tests/dtypes/test_concat.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pandas.core.dtypes.concat as _concat
44

5-
from pandas import DatetimeIndex, Index, Period, PeriodIndex, Series, TimedeltaIndex
5+
from pandas import DatetimeIndex, Period, PeriodIndex, Series, TimedeltaIndex
66

77

88
@pytest.mark.parametrize(
@@ -40,9 +40,8 @@
4040
),
4141
],
4242
)
43-
@pytest.mark.parametrize("klass", [Index, Series])
44-
def test_get_dtype_kinds(klass, to_concat, expected):
45-
to_concat_klass = [klass(c) for c in to_concat]
43+
def test_get_dtype_kinds(index_or_series, to_concat, expected):
44+
to_concat_klass = [index_or_series(c) for c in to_concat]
4645
result = _concat.get_dtype_kinds(to_concat_klass)
4746
assert result == set(expected)
4847

pandas/tests/indexes/test_base.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -2786,32 +2786,18 @@ def test_index_subclass_constructor_wrong_kwargs(index_maker):
27862786

27872787

27882788
def test_deprecated_fastpath():
2789+
msg = "[Uu]nexpected keyword argument"
2790+
with pytest.raises(TypeError, match=msg):
2791+
pd.Index(np.array(["a", "b"], dtype=object), name="test", fastpath=True)
27892792

2790-
with tm.assert_produces_warning(FutureWarning):
2791-
idx = pd.Index(np.array(["a", "b"], dtype=object), name="test", fastpath=True)
2793+
with pytest.raises(TypeError, match=msg):
2794+
pd.Int64Index(np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True)
27922795

2793-
expected = pd.Index(["a", "b"], name="test")
2794-
tm.assert_index_equal(idx, expected)
2796+
with pytest.raises(TypeError, match=msg):
2797+
pd.RangeIndex(0, 5, 2, name="test", fastpath=True)
27952798

2796-
with tm.assert_produces_warning(FutureWarning):
2797-
idx = pd.Int64Index(
2798-
np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True
2799-
)
2800-
2801-
expected = pd.Index([1, 2, 3], name="test", dtype="int64")
2802-
tm.assert_index_equal(idx, expected)
2803-
2804-
with tm.assert_produces_warning(FutureWarning):
2805-
idx = pd.RangeIndex(0, 5, 2, name="test", fastpath=True)
2806-
2807-
expected = pd.RangeIndex(0, 5, 2, name="test")
2808-
tm.assert_index_equal(idx, expected)
2809-
2810-
with tm.assert_produces_warning(FutureWarning):
2811-
idx = pd.CategoricalIndex(["a", "b", "c"], name="test", fastpath=True)
2812-
2813-
expected = pd.CategoricalIndex(["a", "b", "c"], name="test")
2814-
tm.assert_index_equal(idx, expected)
2799+
with pytest.raises(TypeError, match=msg):
2800+
pd.CategoricalIndex(["a", "b", "c"], name="test", fastpath=True)
28152801

28162802

28172803
def test_shape_of_invalid_index():

0 commit comments

Comments
 (0)