From 4052bdf6e33808a121f377585fb9afab0d7605f0 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 25 Oct 2022 00:05:54 +0200 Subject: [PATCH 1/2] DEP: Disallow abbreviations for orient in to_dict --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/frame.py | 33 ---------------------- pandas/tests/frame/methods/test_to_dict.py | 3 +- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 060de8ff8ef09..845812572d872 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -214,6 +214,7 @@ Removal of prior version deprecations/changes - Removed :meth:`Series.slice_shift` and :meth:`DataFrame.slice_shift` (:issue:`37601`) - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) - Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`) +- Disallow passing abbreviations for ``orient`` in :meth:`DataFrame.to_dict` (:issue:`32516`) - Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`) - Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`) - Removed the ``pandas.datetime`` submodule (:issue:`30489`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cc2bca1bcece6..3b4b5a04fcf2b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1855,9 +1855,6 @@ def to_dict( [{column -> value}, ... , {column -> value}] - 'index' : dict like {index -> {column -> value}} - Abbreviations are allowed. `s` indicates `series` and `sp` - indicates `split`. - .. versionadded:: 1.4.0 'tight' as an allowed value for the ``orient`` argument @@ -1948,36 +1945,6 @@ def to_dict( # variable has type "Literal['dict', 'list', 'series', 'split', 'tight', # 'records', 'index']") orient = orient.lower() # type: ignore[assignment] - # GH32515 - if orient.startswith(("d", "l", "s", "r", "i")) and orient not in { - "dict", - "list", - "series", - "split", - "records", - "index", - }: - warnings.warn( - "Using short name for 'orient' is deprecated. Only the " - "options: ('dict', list, 'series', 'split', 'records', 'index') " - "will be used in a future version. Use one of the above " - "to silence this warning.", - FutureWarning, - stacklevel=find_stack_level(), - ) - - if orient.startswith("d"): - orient = "dict" - elif orient.startswith("l"): - orient = "list" - elif orient.startswith("sp"): - orient = "split" - elif orient.startswith("s"): - orient = "series" - elif orient.startswith("r"): - orient = "records" - elif orient.startswith("i"): - orient = "index" if not index and orient not in ["split", "tight"]: raise ValueError( diff --git a/pandas/tests/frame/methods/test_to_dict.py b/pandas/tests/frame/methods/test_to_dict.py index 613f7147a4a7d..2a13d51fcad83 100644 --- a/pandas/tests/frame/methods/test_to_dict.py +++ b/pandas/tests/frame/methods/test_to_dict.py @@ -83,8 +83,7 @@ def test_to_dict_invalid_orient(self): def test_to_dict_short_orient_warns(self, orient): # GH#32515 df = DataFrame({"A": [0, 1]}) - msg = "Using short name for 'orient' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): + with pytest.raises(ValueError, match="not understood"): df.to_dict(orient=orient) @pytest.mark.parametrize("mapping", [dict, defaultdict(list), OrderedDict]) From fabbdf6c51ac6242b9c428d37ae16f16644d96b0 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:34:45 -0700 Subject: [PATCH 2/2] Update pandas/tests/frame/methods/test_to_dict.py --- pandas/tests/frame/methods/test_to_dict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_to_dict.py b/pandas/tests/frame/methods/test_to_dict.py index 2a13d51fcad83..521f6ead2e69e 100644 --- a/pandas/tests/frame/methods/test_to_dict.py +++ b/pandas/tests/frame/methods/test_to_dict.py @@ -80,7 +80,7 @@ def test_to_dict_invalid_orient(self): df.to_dict(orient="xinvalid") @pytest.mark.parametrize("orient", ["d", "l", "r", "sp", "s", "i"]) - def test_to_dict_short_orient_warns(self, orient): + def test_to_dict_short_orient_raises(self, orient): # GH#32515 df = DataFrame({"A": [0, 1]}) with pytest.raises(ValueError, match="not understood"):