Skip to content
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

REF: _AXIS_TO_AXIS_NUMBER to simplify axis access #33637

Merged
merged 5 commits into from Apr 21, 2020

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Apr 18, 2020

This adds a dict called _AXIS_TO_AXIS_NUMBER to NDFrame/DataFrame where the keys are the allowed parameter values for the axis parameter in various ndframe methods and the dict values are the related axis number. This makes getting to the correct axis more straight forward, see for example the new _get_axis_number, and makes adding type hints to the axis parameter easier.

""".. deprecated:: 1.1.0"""
super()._AXIS_NAMES
return {0: "index", 1: "columns"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither _AXIS_NUMBERS and _AXIS_NAMES are needed anymore. Just in case they are used downstream I've deprecated them instead of just removing them.

@topper-123 topper-123 force-pushed the cln_get_axis branch 2 times, most recently from 162b954 to ab8ed31 Compare April 18, 2020 20:21
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 on adding anything here

@topper-123
Copy link
Contributor Author

This is not adding things, it's moving things around and simplifying.

A nice side effect will that we can now see the allowed values for axis in as the keys in the new attribute, where previosly it had to be done in THREE(!) locations (_AXIS_NAMES, _AXIS_NUMBERS and _AXIS_ALIASES), which is relatively insane, when you think about it...

@topper-123 topper-123 force-pushed the cln_get_axis branch 2 times, most recently from 39ba455 to db44239 Compare April 18, 2020 22:16
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

def _AXIS_NUMBERS(self) -> Dict[str, int]:
""".. deprecated:: 1.1.0"""
warnings.warn(
"_AXIS_NUMBERS has been deprecated. Call ._get_axis_number instead",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably not point to another private method? (maybe just say it is deprecated, without alternative, unless we want to expose something more publicly somewhere, or document this private method as "public" for developer use)

@topper-123 topper-123 force-pushed the cln_get_axis branch 3 times, most recently from dd76ae0 to 014b95f Compare April 20, 2020 16:37
@topper-123
Copy link
Contributor Author

topper-123 commented Apr 20, 2020

I've found out that this PR requires a change to the recipe on setting aliases in cookbook.rst.

I quite dislike encouraging setting aliases in the official pandas docs. If anyone actually uses that pattern in real code, is would be just confusing without being helpful IMO. But I've just changed it to the new style, for now, but would prefer to delete the section on aliases if there's no objections.

@jreback jreback added the Refactor Internal refactoring of code label Apr 20, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. ex my doc-comment above.

@@ -1336,21 +1336,27 @@ Values can be set to NaT using np.nan, similar to datetime
Aliasing axis names
-------------------

.. versionchanged:: 1.1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should just remove this section entirely. it isn't really tested / nor well supported.

@topper-123
Copy link
Contributor Author

ex my doc-comment above.

Could you expand, I don't understand this comment (and maybe the first comment too).

@jreback jreback added this to the 1.1 milestone Apr 20, 2020
@jorisvandenbossche
Copy link
Member

I think Jeff just mean to say to remove the cookbook example, alltogether, as you did (and indeed, that is not something to put in our docs I think)

@topper-123
Copy link
Contributor Author

Ok.

@jreback jreback merged commit 27beffc into pandas-dev:master Apr 21, 2020
@jreback
Copy link
Contributor

jreback commented Apr 21, 2020

thanks @topper-123 very nice

@jreback
Copy link
Contributor

jreback commented Apr 21, 2020

can you add the deprecations to issue for removal: #30228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants