-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Deprecate Aliases as orient Argument in DataFrame.to_dict #32516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate Aliases as orient Argument in DataFrame.to_dict #32516
Conversation
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -352,6 +352,7 @@ Other | |||
instead of ``TypeError: Can only append a Series if ignore_index=True or if the Series has a name`` (:issue:`30871`) | |||
- Set operations on an object-dtype :class:`Index` now always return object-dtype results (:issue:`31401`) | |||
- Bug in :meth:`AbstractHolidayCalendar.holidays` when no rules were defined (:issue:`31415`) | |||
- Using an `orient` argument not listed inside :meth:`DataFrame.to_dict` will raise a ``ValueError`` (:issue:`32515`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MomIsBestFriend I cannot see why the doc CI are failing with this added line. Not sure if this what's new info had to be added in some other place or I am not supposed to add this myself 🤔 Any ideas?
(btw, just checked and it works fine on my local machine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elmonsomiat I am not sure why the docs are failing, maybe try to merge master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like there are too many lines in this section (I tried adding my comment on another section within the same file and it works). Adding this new line breaks it. Not sure if it's OK to leave it as it is, without chaning the whatsnew file!
On board with the change but I think should wait until 2.0 since this could break things (though yes undocumented) |
Should deprecate for 1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. ex @WillAyd comment that we should deprecate it, I believe that we should at least give a Deprecation warning. so I was thinking some thing with the style of:
orient = orient.lower()
if orient in {'i', 's', 'sp', ... }:
warnings.warn("Using short name for 'orient' is deprecated...", DeprecationWarning, stacklevel=2)
if orient == "i":
orient = "index"
elif orient == "l":
orient = "list"
...
And then below the rest of your code.
I see that in c598b32 you reverted some code, with pytest.raises(Exception):
foo() You can read more about how To sum it up, you catch DeprecationWarning by: with pytest.deprecated_call():
foo() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the comments in #32516 (comment), this looks very good (IMO)
@MomIsBestFriend Thanks for the patient review! 👏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only comment I have, otherwise this is LGTM.
@@ -64,14 +64,24 @@ def test_to_dict_index_not_unique_with_index_orient(self): | |||
with pytest.raises(ValueError, match=msg): | |||
df.to_dict(orient="index") | |||
|
|||
def test_to_dict_invalid_orient(self): | |||
@pytest.mark.parametrize("orient", ["xinvalid"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that parameteration is redundant, can you remove it and have this test as it was before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice! lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -174,7 +174,7 @@ Deprecations | |||
- Lookups on a :class:`Series` with a single-item list containing a slice (e.g. ``ser[[slice(0, 4)]]``) are deprecated, will raise in a future version. Either convert the list to tuple, or pass the slice directly instead (:issue:`31333`) | |||
- :meth:`DataFrame.mean` and :meth:`DataFrame.median` with ``numeric_only=None`` will include datetime64 and datetime64tz columns in a future version (:issue:`29941`) | |||
- Setting values with ``.loc`` using a positional slice is deprecated and will raise in a future version. Use ``.loc`` with labels or ``.iloc`` with positions instead (:issue:`31840`) | |||
- | |||
- :meth:`DataFrame.to_dict` will not accept short names for ``orient`` in future versions (:issue:`32515`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has deprecated accepting short names
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks @elmonsomiat - very impressive first contribution |
Just reading through some PRs to understand the contribution process better. I see this sentence in the documentation "Abbreviations are allowed. s indicates series and sp indicates split." Is a corresponding doc change needed for this? https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_dict.html |
@@ -1401,11 +1401,45 @@ def to_dict(self, orient="dict", into=dict): | |||
) | |||
# GH16122 | |||
into_c = com.standardize_mapping(into) | |||
if orient.lower().startswith("d"): | |||
|
|||
orient = orient.lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 1328 above might also need a change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think so - are you interested in submitting a PR to update the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be removed in a future PR. Check below, there is a FutureWarning
that says this will not be accepted anymore, then we can remove this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, so to confirm, in the future any code like
df.to_dict(orient='s')
will stop working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it should
Oh, yes, this sentence should be removed. This is not the case for |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff