Skip to content

Commit 2272364

Browse files
authored
DEPR: Index.ravel returning an ndarray (#36900)
1 parent f8e0ecb commit 2272364

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Deprecations
268268
- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`)
269269
- Deprecated automatic alignment on comparison operations between :class:`DataFrame` and :class:`Series`, do ``frame, ser = frame.align(ser, axis=1, copy=False)`` before e.g. ``frame == ser`` (:issue:`28759`)
270270
- :meth:`Rolling.count` with ``min_periods=None`` will default to the size of the window in a future version (:issue:`31302`)
271+
- :meth:`Index.ravel` returning a ``np.ndarray`` is deprecated, in the future this will return a view on the same index (:issue:`19956`)
271272

272273
.. ---------------------------------------------------------------------------
273274

pandas/core/indexes/base.py

+6
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ def ravel(self, order="C"):
659659
--------
660660
numpy.ndarray.ravel
661661
"""
662+
warnings.warn(
663+
"Index.ravel returning ndarray is deprecated; in a future version "
664+
"this will return a view on self.",
665+
FutureWarning,
666+
stacklevel=2,
667+
)
662668
values = self._get_engine_target()
663669
return values.ravel(order=order)
664670

pandas/io/formats/format.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,8 @@ def is_dates_only(
16771677
values: Union[np.ndarray, DatetimeArray, Index, DatetimeIndex]
16781678
) -> bool:
16791679
# return a boolean if we are only dates (and don't have a timezone)
1680-
values = values.ravel()
1680+
if not isinstance(values, Index):
1681+
values = values.ravel()
16811682

16821683
values = DatetimeIndex(values)
16831684
if values.tz is not None:

pandas/tests/indexes/test_common.py

+5
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ def test_astype_preserves_name(self, index, dtype):
399399
else:
400400
assert result.name == index.name
401401

402+
def test_ravel_deprecation(self, index):
403+
# GH#19956 ravel returning ndarray is deprecated
404+
with tm.assert_produces_warning(FutureWarning):
405+
index.ravel()
406+
402407

403408
@pytest.mark.parametrize("na_position", [None, "middle"])
404409
def test_sort_values_invalid_na_position(index_with_missing, na_position):

0 commit comments

Comments
 (0)