diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f6bb8e7af3558..cc0521caaaf6c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -731,6 +731,22 @@ def _format_duplicate_message(self) -> DataFrame: # -------------------------------------------------------------------- # Index Internals Methods + @final + def _get_attributes_dict(self) -> dict[str_t, Any]: + """ + Return an attributes dict for my class. + + Temporarily added back for compatibility issue in dask, see + https://github.com/pandas-dev/pandas/pull/43895 + """ + warnings.warn( + "The Index._get_attributes_dict method is deprecated, and will be " + "removed in a future version", + DeprecationWarning, + stacklevel=2, + ) + return {k: getattr(self, k, None) for k in self._attributes} + def _shallow_copy(self: _IndexT, values, name: Hashable = no_default) -> _IndexT: """ Create a new Index with the same class as the caller, don't copy the diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 4b7a377570fd5..cbcb00a4230cc 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1788,3 +1788,11 @@ def test_drop_duplicates_pos_args_deprecation(): result = idx.drop_duplicates("last") expected = Index([2, 3, 1]) tm.assert_index_equal(expected, result) + + +def test_get_attributes_dict_deprecated(): + # https://github.com/pandas-dev/pandas/pull/44028 + idx = Index([1, 2, 3, 1]) + with tm.assert_produces_warning(DeprecationWarning): + attrs = idx._get_attributes_dict() + assert attrs == {"name": None}