Skip to content

Commit b7a22a4

Browse files
phoflmroeschke
authored andcommitted
DEP: Disallow abbreviations for orient in to_dict (pandas-dev#49289)
* DEP: Disallow abbreviations for orient in to_dict * Update pandas/tests/frame/methods/test_to_dict.py Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 973a3d6 commit b7a22a4

File tree

3 files changed

+3
-36
lines changed

3 files changed

+3
-36
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Removal of prior version deprecations/changes
215215
- Removed :meth:`Series.slice_shift` and :meth:`DataFrame.slice_shift` (:issue:`37601`)
216216
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
217217
- Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`)
218+
- Disallow passing abbreviations for ``orient`` in :meth:`DataFrame.to_dict` (:issue:`32516`)
218219
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
219220
- Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`)
220221
- Removed the ``pandas.datetime`` submodule (:issue:`30489`)

pandas/core/frame.py

-33
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,6 @@ def to_dict(
18551855
[{column -> value}, ... , {column -> value}]
18561856
- 'index' : dict like {index -> {column -> value}}
18571857
1858-
Abbreviations are allowed. `s` indicates `series` and `sp`
1859-
indicates `split`.
1860-
18611858
.. versionadded:: 1.4.0
18621859
'tight' as an allowed value for the ``orient`` argument
18631860
@@ -1948,36 +1945,6 @@ def to_dict(
19481945
# variable has type "Literal['dict', 'list', 'series', 'split', 'tight',
19491946
# 'records', 'index']")
19501947
orient = orient.lower() # type: ignore[assignment]
1951-
# GH32515
1952-
if orient.startswith(("d", "l", "s", "r", "i")) and orient not in {
1953-
"dict",
1954-
"list",
1955-
"series",
1956-
"split",
1957-
"records",
1958-
"index",
1959-
}:
1960-
warnings.warn(
1961-
"Using short name for 'orient' is deprecated. Only the "
1962-
"options: ('dict', list, 'series', 'split', 'records', 'index') "
1963-
"will be used in a future version. Use one of the above "
1964-
"to silence this warning.",
1965-
FutureWarning,
1966-
stacklevel=find_stack_level(),
1967-
)
1968-
1969-
if orient.startswith("d"):
1970-
orient = "dict"
1971-
elif orient.startswith("l"):
1972-
orient = "list"
1973-
elif orient.startswith("sp"):
1974-
orient = "split"
1975-
elif orient.startswith("s"):
1976-
orient = "series"
1977-
elif orient.startswith("r"):
1978-
orient = "records"
1979-
elif orient.startswith("i"):
1980-
orient = "index"
19811948

19821949
if not index and orient not in ["split", "tight"]:
19831950
raise ValueError(

pandas/tests/frame/methods/test_to_dict.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ def test_to_dict_invalid_orient(self):
8080
df.to_dict(orient="xinvalid")
8181

8282
@pytest.mark.parametrize("orient", ["d", "l", "r", "sp", "s", "i"])
83-
def test_to_dict_short_orient_warns(self, orient):
83+
def test_to_dict_short_orient_raises(self, orient):
8484
# GH#32515
8585
df = DataFrame({"A": [0, 1]})
86-
msg = "Using short name for 'orient' is deprecated"
87-
with tm.assert_produces_warning(FutureWarning, match=msg):
86+
with pytest.raises(ValueError, match="not understood"):
8887
df.to_dict(orient=orient)
8988

9089
@pytest.mark.parametrize("mapping", [dict, defaultdict(list), OrderedDict])

0 commit comments

Comments
 (0)