Skip to content

Commit 28973fa

Browse files
jbrockmendeltopper-123
authored andcommitted
DEPR: allowing unknowns in take (pandas-dev#52981)
* DEPR: allowing unknowns in take * GH ref
1 parent dd163f7 commit 28973fa

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Deprecations
253253
- Deprecated :meth:`DataFrame.applymap`. Use the new :meth:`DataFrame.map` method instead (:issue:`52353`)
254254
- Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`)
255255
- Deprecated ``freq`` parameter in :class:`PeriodArray` constructor, pass ``dtype`` instead (:issue:`52462`)
256+
- Deprecated allowing non-standard inputs in :func:`take`, pass either a ``numpy.ndarray``, :class:`ExtensionArray`, :class:`Index`, or :class:`Series` (:issue:`52981`)
256257
- Deprecated behavior of :class:`DataFrame` reductions ``sum``, ``prod``, ``std``, ``var``, ``sem`` with ``axis=None``, in a future version this will operate over both axes returning a scalar instead of behaving like ``axis=0``; note this also affects numpy functions e.g. ``np.sum(df)`` (:issue:`21597`)
257258
- Deprecated behavior of :func:`concat` when :class:`DataFrame` has columns that are all-NA, in a future version these will not be discarded when determining the resulting dtype (:issue:`40893`)
258259
- Deprecated behavior of :meth:`Series.dt.to_pydatetime`, in a future version this will return a :class:`Series` containing python ``datetime`` objects instead of an ``ndarray`` of datetimes; this matches the behavior of other :meth:`Series.dt` properties (:issue:`20306`)

pandas/core/algorithms.py

+15
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,11 @@ def take(
11751175
arr : array-like or scalar value
11761176
Non array-likes (sequences/scalars without a dtype) are coerced
11771177
to an ndarray.
1178+
1179+
.. deprecated:: 2.1.0
1180+
Passing an argument other than a numpy.ndarray, ExtensionArray,
1181+
Index, or Series is deprecated.
1182+
11781183
indices : sequence of int or one-dimensional np.ndarray of int
11791184
Indices to be taken.
11801185
axis : int, default 0
@@ -1240,6 +1245,16 @@ def take(
12401245
... fill_value=-10)
12411246
array([ 10, 10, -10])
12421247
"""
1248+
if not isinstance(arr, (np.ndarray, ABCExtensionArray, ABCIndex, ABCSeries)):
1249+
# GH#52981
1250+
warnings.warn(
1251+
"pd.api.extensions.take accepting non-standard inputs is deprecated "
1252+
"and will raise in a future version. Pass either a numpy.ndarray, "
1253+
"ExtensionArray, Index, or Series instead.",
1254+
FutureWarning,
1255+
stacklevel=find_stack_level(),
1256+
)
1257+
12431258
if not is_array_like(arr):
12441259
arr = np.asarray(arr)
12451260

pandas/tests/test_take.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ def test_take_na_empty(self):
301301

302302
def test_take_coerces_list(self):
303303
arr = [1, 2, 3]
304-
result = algos.take(arr, [0, 0])
304+
msg = "take accepting non-standard inputs is deprecated"
305+
with tm.assert_produces_warning(FutureWarning, match=msg):
306+
result = algos.take(arr, [0, 0])
305307
expected = np.array([1, 1])
306308
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)