Skip to content
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

DEPR: remove Index fastpath kwarg #29725

Merged
merged 9 commits into from
Nov 27, 2019
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
**Other removals**

- Removed the previously deprecated :meth:`Index.summary` (:issue:`18217`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this was what I had in mind for whatsnew placing.

- Removed the previously deprecated "fastpath" keyword from the :class:`Index` constructor (:issue:`23110`)
- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`)
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)
- Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`)
Expand Down
13 changes: 13 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,3 +854,16 @@ def float_frame():
[30 rows x 4 columns]
"""
return DataFrame(tm.getSeriesData())


@pytest.fixture(params=[pd.Index, pd.Series], ids=["index", "series"])
def index_or_series(request):
"""
Fixture to parametrize over Index and Series, made necessary by a mypy
bug, giving an error:

List item 0 has incompatible type "Type[Series]"; expected "Type[PandasObject]"

See GH#?????
"""
return request.param
19 changes: 1 addition & 18 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,7 @@ def _outer_indexer(self, left, right):
# Constructors

def __new__(
cls,
data=None,
dtype=None,
copy=False,
name=None,
fastpath=None,
tupleize_cols=True,
**kwargs,
cls, data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how we historically handle but unfortunate this accepts kwargs - I suppose if someone keeps supplying fastpath nothing will change. Not sure if we should explicitly raise now in that case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed test_deprecated_fastpath so instead of checking for a FutureWarning, it checks for a TypeError

) -> "Index":

from .range import RangeIndex
Expand All @@ -278,16 +271,6 @@ def __new__(
if name is None and hasattr(data, "name"):
name = data.name

if fastpath is not None:
warnings.warn(
"The 'fastpath' keyword is deprecated, and will be "
"removed in a future version.",
FutureWarning,
stacklevel=2,
)
if fastpath:
return cls._simple_new(data, name)

if isinstance(data, ABCPandasArray):
# ensure users don't accidentally put a PandasArray in an index.
data = data.to_numpy()
Expand Down
12 changes: 0 additions & 12 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import operator
from typing import Any
import warnings

import numpy as np

Expand Down Expand Up @@ -172,19 +171,8 @@ def __new__(
dtype=None,
copy=False,
name=None,
fastpath=None,
):

if fastpath is not None:
warnings.warn(
"The 'fastpath' keyword is deprecated, and will be "
"removed in a future version.",
FutureWarning,
stacklevel=2,
)
if fastpath:
return cls._simple_new(data, name=name, dtype=dtype)

dtype = CategoricalDtype._from_values_or_dtype(data, categories, ordered, dtype)

if name is None and hasattr(data, "name"):
Expand Down
13 changes: 1 addition & 12 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings

import numpy as np

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

_is_numeric_dtype = True

def __new__(cls, data=None, dtype=None, copy=False, name=None, fastpath=None):
def __new__(cls, data=None, dtype=None, copy=False, name=None):
cls._validate_dtype(dtype)
if fastpath is not None:
warnings.warn(
"The 'fastpath' keyword is deprecated, and will be "
"removed in a future version.",
FutureWarning,
stacklevel=2,
)
if fastpath:
return cls._simple_new(data, name=name)

# Coerce to ndarray if not already ndarray or Index
if not isinstance(data, (np.ndarray, Index)):
Expand Down
19 changes: 1 addition & 18 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,9 @@ class RangeIndex(Int64Index):
# Constructors

def __new__(
cls,
start=None,
stop=None,
step=None,
dtype=None,
copy=False,
name=None,
fastpath=None,
cls, start=None, stop=None, step=None, dtype=None, copy=False, name=None,
):

if fastpath is not None:
warnings.warn(
"The 'fastpath' keyword is deprecated, and will be "
"removed in a future version.",
FutureWarning,
stacklevel=2,
)
if fastpath:
return cls._simple_new(range(start, stop, step), name=name)

cls._validate_dtype(dtype)

# RangeIndex
Expand Down
56 changes: 16 additions & 40 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from decimal import Decimal
from itertools import combinations
import operator
from typing import Any, List

import numpy as np
import pytest
Expand All @@ -30,6 +31,19 @@ def adjust_negative_zero(zero, expected):
return expected


# TODO: remove this kludge once mypy stops giving false positives here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonjayhawkins any idea if this is something we can address?

# List comprehension has incompatible type List[PandasObject]; expected List[RangeIndex]
# See GH#?????
ser_or_index: List[Any] = [pd.Series, pd.Index]
lefts: List[Any] = [pd.RangeIndex(10, 40, 10)]
lefts.extend(
[
cls([10, 20, 30], dtype=dtype)
for dtype in ["i1", "i2", "i4", "i8", "u1", "u2", "u4", "u8", "f2", "f4", "f8"]
for cls in ser_or_index
]
)

# ------------------------------------------------------------------
# Comparisons

Expand Down Expand Up @@ -81,26 +95,7 @@ class TestNumericArraylikeArithmeticWithDatetimeLike:
# TODO: also check name retentention
@pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series])
@pytest.mark.parametrize(
"left",
[pd.RangeIndex(10, 40, 10)]
+ [
cls([10, 20, 30], dtype=dtype)
for dtype in [
"i1",
"i2",
"i4",
"i8",
"u1",
"u2",
"u4",
"u8",
"f2",
"f4",
"f8",
]
for cls in [pd.Series, pd.Index]
],
ids=lambda x: type(x).__name__ + str(x.dtype),
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype),
)
def test_mul_td64arr(self, left, box_cls):
# GH#22390
Expand All @@ -120,26 +115,7 @@ def test_mul_td64arr(self, left, box_cls):
# TODO: also check name retentention
@pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series])
@pytest.mark.parametrize(
"left",
[pd.RangeIndex(10, 40, 10)]
+ [
cls([10, 20, 30], dtype=dtype)
for dtype in [
"i1",
"i2",
"i4",
"i8",
"u1",
"u2",
"u4",
"u8",
"f2",
"f4",
"f8",
]
for cls in [pd.Series, pd.Index]
],
ids=lambda x: type(x).__name__ + str(x.dtype),
"left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype),
)
def test_div_td64arr(self, left, box_cls):
# GH#22390
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
return super()._from_sequence(scalars, dtype=dtype, copy=copy)


@pytest.mark.parametrize("box", [pd.Series, pd.Index])
def test_array_unboxes(box):
def test_array_unboxes(index_or_series):
box = index_or_series

data = box([decimal.Decimal("1"), decimal.Decimal("2")])
# make sure it works
with pytest.raises(TypeError):
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/dtypes/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas.core.dtypes.concat as _concat

from pandas import DatetimeIndex, Index, Period, PeriodIndex, Series, TimedeltaIndex
from pandas import DatetimeIndex, Period, PeriodIndex, Series, TimedeltaIndex


@pytest.mark.parametrize(
Expand Down Expand Up @@ -40,9 +40,8 @@
),
],
)
@pytest.mark.parametrize("klass", [Index, Series])
def test_get_dtype_kinds(klass, to_concat, expected):
to_concat_klass = [klass(c) for c in to_concat]
def test_get_dtype_kinds(index_or_series, to_concat, expected):
to_concat_klass = [index_or_series(c) for c in to_concat]
result = _concat.get_dtype_kinds(to_concat_klass)
assert result == set(expected)

Expand Down
32 changes: 9 additions & 23 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2762,32 +2762,18 @@ def test_index_subclass_constructor_wrong_kwargs(index_maker):


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

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

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

with tm.assert_produces_warning(FutureWarning):
idx = pd.Int64Index(
np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True
)

expected = pd.Index([1, 2, 3], name="test", dtype="int64")
tm.assert_index_equal(idx, expected)

with tm.assert_produces_warning(FutureWarning):
idx = pd.RangeIndex(0, 5, 2, name="test", fastpath=True)

expected = pd.RangeIndex(0, 5, 2, name="test")
tm.assert_index_equal(idx, expected)

with tm.assert_produces_warning(FutureWarning):
idx = pd.CategoricalIndex(["a", "b", "c"], name="test", fastpath=True)

expected = pd.CategoricalIndex(["a", "b", "c"], name="test")
tm.assert_index_equal(idx, expected)
with pytest.raises(TypeError, match=msg):
pd.CategoricalIndex(["a", "b", "c"], name="test", fastpath=True)


def test_shape_of_invalid_index():
Expand Down
Loading