From 4c34345b3bbfe5be50b0b497e9c49a14c7d3f5cc Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 14 Oct 2021 11:46:23 +0200 Subject: [PATCH 1/2] Temporarily add back Index._get_attributes_dict for dask compat --- pandas/core/indexes/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f6bb8e7af3558..d86e951923944 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -731,6 +731,16 @@ 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 + """ + 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 From da9fcd3301acf031aa93d77dd115b1221ce0c036 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 14 Oct 2021 20:28:30 +0200 Subject: [PATCH 2/2] add warning --- pandas/core/indexes/base.py | 6 ++++++ pandas/tests/indexes/test_base.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d86e951923944..cc0521caaaf6c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -739,6 +739,12 @@ def _get_attributes_dict(self) -> dict[str_t, Any]: 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: 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}