Skip to content

Commit d8079e4

Browse files
author
Tristan Marechaux
committed
DEPR: Series.ravel
1 parent 910f159 commit d8079e4

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

doc/source/whatsnew/v2.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Deprecations
235235
- Deprecated :func:`is_interval_dtype`, check ``isinstance(dtype, pd.IntervalDtype)`` instead (:issue:`52607`)
236236
- Deprecated :meth:`DataFrame.applymap`. Use the new :meth:`DataFrame.map` method instead (:issue:`52353`)
237237
- Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`)
238+
- Deprecated :meth:`Series.ravel` (:issue:`52511`)
238239
- Deprecated ``freq`` parameter in :class:`PeriodArray` constructor, pass ``dtype`` instead (:issue:`52462`)
239240
- 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`)
240241
- 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`)
@@ -247,7 +248,6 @@ Deprecations
247248
- Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`)
248249
- Deprecated unused "closed" and "normalize" keywords in the :class:`DatetimeIndex` constructor (:issue:`52628`)
249250
- Deprecated unused "closed" keyword in the :class:`TimedeltaIndex` constructor (:issue:`52628`)
250-
-
251251

252252
.. ---------------------------------------------------------------------------
253253
.. _whatsnew_210.performance:

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def trans(x):
351351
return trans(result).astype(dtype)
352352

353353
# do a test on the first element, if it fails then we are done
354-
r = result.ravel()
354+
r = np.ravel(result)
355355
arr = np.array([r[0]])
356356

357357
if isna(arr).any():

pandas/core/series.py

+7
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,13 @@ def ravel(self, order: str = "C") -> ArrayLike:
771771
--------
772772
numpy.ndarray.ravel : Return a flattened array.
773773
"""
774+
warnings.warn(
775+
# GH#52511
776+
f"'{type(self).__name__}.ravel' is deprecated and will be removed in a "
777+
f"future version.",
778+
FutureWarning,
779+
stacklevel=find_stack_level(),
780+
)
774781
arr = self._values.ravel(order=order)
775782
if isinstance(arr, np.ndarray) and using_copy_on_write():
776783
arr.flags.writeable = False

pandas/tests/series/test_api.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def test_ndarray_compat_like_func(self):
142142
def test_ndarray_compat_ravel(self):
143143
# ravel
144144
s = Series(np.random.randn(10))
145-
tm.assert_almost_equal(s.ravel(order="F"), s.values.ravel(order="F"))
145+
msg = "'Series.ravel' is deprecated"
146+
with tm.assert_produces_warning(FutureWarning, match=msg):
147+
tm.assert_almost_equal(s.ravel(order="F"), s.values.ravel(order="F"))
146148

147149
def test_empty_method(self):
148150
s_empty = Series(dtype=object)

0 commit comments

Comments
 (0)