Skip to content

DEPR: Index.ravel behavior #32641

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

Closed
Closed
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
12 changes: 11 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,17 @@ def ravel(self, order="C"):
--------
numpy.ndarray.ravel
"""
return self._ndarray_values.ravel(order=order)
values = self._values
if isinstance(values, np.ndarray):
return values.ravel(order=order)

warnings.warn(
f"The behavior of Index.ravel for {self.dtype} is deprecated; "
"in a future version it will return the underlying ExtensionArray",
FutureWarning,
stacklevel=2,
)
return values._ndarray_values.ravel(order=order)

def view(self, cls=None):

Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/indexes/categorical/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,8 @@ def test_reindex_base(self):
def test_map_str(self):
# See test_map.py
pass

def test_ravel_deprecated(self):
idx = self.create_index()
with tm.assert_produces_warning(FutureWarning):
idx.ravel()
5 changes: 5 additions & 0 deletions pandas/tests/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ def test_map_dictlike(self, mapper):
expected = pd.Index([np.nan] * len(index))
result = index.map(mapper([], []))
tm.assert_index_equal(result, expected)

def test_ravel_deprecated(self):
idx = self.create_index()
with tm.assert_produces_warning(FutureWarning):
idx.ravel()
5 changes: 5 additions & 0 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,11 @@ def test_is_all_dates(self):
year_2017_index = pd.IntervalIndex([year_2017])
assert not year_2017_index.is_all_dates

def test_ravel_deprecated(self):
idx = self.create_index()
with tm.assert_produces_warning(FutureWarning):
idx.ravel()


def test_dir():
# GH#27571 dir(interval_index) should not raise
Expand Down