Skip to content

Commit

Permalink
DEPR: Index.ravel returning an ndarray (pandas-dev#36900)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and Kevin D Smith committed Nov 2, 2020
1 parent f664547 commit c32dfaa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Deprecations
- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`)
- 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`)
- :meth:`Rolling.count` with ``min_periods=None`` will default to the size of the window in a future version (:issue:`31302`)
- :meth:`Index.ravel` returning a ``np.ndarray`` is deprecated, in the future this will return a view on the same index (:issue:`19956`)

.. ---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ def ravel(self, order="C"):
--------
numpy.ndarray.ravel
"""
warnings.warn(
"Index.ravel returning ndarray is deprecated; in a future version "
"this will return a view on self.",
FutureWarning,
stacklevel=2,
)
values = self._get_engine_target()
return values.ravel(order=order)

Expand Down
3 changes: 2 additions & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,8 @@ def is_dates_only(
values: Union[np.ndarray, DatetimeArray, Index, DatetimeIndex]
) -> bool:
# return a boolean if we are only dates (and don't have a timezone)
values = values.ravel()
if not isinstance(values, Index):
values = values.ravel()

values = DatetimeIndex(values)
if values.tz is not None:
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ def test_astype_preserves_name(self, index, dtype):
else:
assert result.name == index.name

def test_ravel_deprecation(self, index):
# GH#19956 ravel returning ndarray is deprecated
with tm.assert_produces_warning(FutureWarning):
index.ravel()


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

0 comments on commit c32dfaa

Please sign in to comment.