Skip to content

DEPR: remove Index fastpath kwarg #29725

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 9 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ 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`)
- :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`)
Expand Down
32 changes: 1 addition & 31 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 Expand Up @@ -1132,19 +1115,6 @@ def _summary(self, name=None):
name = type(self).__name__
return f"{name}: {len(self)} entries{index_summary}"

def summary(self, name=None):
"""
Return a summarized representation.

.. deprecated:: 0.23.0
"""
warnings.warn(
"'summary' is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=2,
)
return self._summary(name)

# --------------------------------------------------------------------
# Conversion Methods

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
39 changes: 9 additions & 30 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,13 +1385,6 @@ def test_summary_bug(self):
assert "~:{range}:0" in result
assert "{other}%s" in result

# GH18217
def test_summary_deprecated(self):
ind = Index(["{other}%s", "~:{range}:0"], name="A")

with tm.assert_produces_warning(FutureWarning):
ind.summary()

def test_format(self, indices):
self._check_method_works(Index.format, indices)

Expand Down Expand Up @@ -2769,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)

expected = pd.Index(["a", "b"], name="test")
tm.assert_index_equal(idx, expected)

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 pytest.raises(TypeError, match=msg):
pd.Int64Index(np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True)

with tm.assert_produces_warning(FutureWarning):
idx = pd.CategoricalIndex(["a", "b", "c"], name="test", fastpath=True)
with pytest.raises(TypeError, match=msg):
pd.RangeIndex(0, 5, 2, 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