Skip to content

REF: use _get_axis_number instead of if axis in [...]: #43048

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

Closed
3 tasks done
attack68 opened this issue Aug 15, 2021 · 38 comments
Closed
3 tasks done

REF: use _get_axis_number instead of if axis in [...]: #43048

attack68 opened this issue Aug 15, 2021 · 38 comments
Labels
Refactor Internal refactoring of code

Comments

@attack68
Copy link
Contributor

attack68 commented Aug 15, 2021

This PR regards searching the non-test codebase (i.e. don't find code examples in pandas/tests) for examples like the following:

Try to find and replace logic like:

if axis in [0, "index"]:
    ...
elif axis in [1, "columns"]:
    ...
else:
    ...

with the standard codebase method get_axis_number(axis). This is a DataFrame method so often you need use local DataFrame objects to call this method.

It may also be necessary to change axis args in internal methods to consistently accept the same input format compatible with this method, i.e. axis as an integer (0 or 1).

This is an open issue and contributions are welcome to solve individual files in the code. As an example see #43078 or other merged contributions below.

@attack68 attack68 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 15, 2021
@attack68 attack68 added Refactor Internal refactoring of code Styler conditional formatting using DataFrame.style and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 15, 2021
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Aug 16, 2021
@rhshadrach
Copy link
Member

I think this applies to all code, not just the style, is that right? Or would you like to keep this issue focused on just the styler?

@attack68
Copy link
Contributor Author

@rhshadrach I don't know. I know that it applies to much of the stuff I wrote in Styler that @jreback pointed out to me. If it applies more broadly can convert this issue into a master tracker and try to locate more examples..

@attack68 attack68 added good first issue and removed Styler conditional formatting using DataFrame.style labels Aug 17, 2021
@jreback
Copy link
Contributor

jreback commented Aug 17, 2021

yeah this was mainly for Styler, but its possible we do this elsewhere in the codebase so should clean those up (and ideally have a pre-commit rule but might be non-trivial)

@dhivyadharshin
Copy link

Can I work on this issues?

@rhshadrach
Copy link
Member

I noticed it in the tests recently, doing some quick searches I'm seeing a few instances in core as well.

@HemanjaliAdini
Copy link

hey, can i have this issue?
I'm quite new to this so I might need some guidance

@dhivyadharshin
Copy link

dhivyadharshin commented Aug 18, 2021 via email

@attack68
Copy link
Contributor Author

As has been commented here there are likely many places this pattern is present in the code and needs addressing.
The best PRs will be to work on a single file and correct all the offending occurrences within that file. There may be only one item to address or several.
After the PR is approved and merged, we will note it down here as having been addressed.
My example above shows how to do this for a file style.py.

In order to find bits to work on you will have to search for a pattern in the code axis in and then see if you can correct it as per my example.

@dhivyadharshin
Copy link

dhivyadharshin commented Aug 18, 2021 via email

@RohanTrix
Copy link
Contributor

take

@RohanTrix
Copy link
Contributor

@attack68 I have assigned myself to work on this issue, should I move forward with it?

@dhivyadharshin
Copy link

dhivyadharshin commented Aug 19, 2021 via email

@attack68
Copy link
Contributor Author

Anyone is welcome to work on this issue. This will not be solved by just one PR, there are likely many places and many files where the same work needs to be done. Therefore many people can work on this, simultaneously.

@alli1999
Copy link

Hello, could I help with this issue?
This would be my first ever contribution so I could use some guidance

@goyaldhara
Copy link

goyaldhara commented Aug 25, 2021

Fixed the issue : #43220

@ghost
Copy link

ghost commented Aug 26, 2021

Hey, i want to work towards resolving this issue. Please assign this to me

@ghost
Copy link

ghost commented Aug 26, 2021

take

@github-actions github-actions bot assigned ghost Aug 26, 2021
@soni-muskan1234
Copy link

Is this instance has to be replaced in test files also or only in generic and style files?

@ForthenchoPacino
Copy link

Ok, I'm pretty new to the whole scene, and directly replacing with get_axis_number was presenting with errors, so I tried importing the data frames directly, and that method did not give excess errors, so, I'm almost done

@SARANYA233
Copy link

I m first time to this contribution field, I need some guidance to work on this issue. can I?

@attack68
Copy link
Contributor Author

attack68 commented Aug 28, 2021

Please see the revised description of this issue.
You can find code patterns in the generic codebase.
Don't try and fix test files in pandas/tests.

@KiranHipparagi
Copy link

I am new to OpenSource Contributions . I want to work on this feature .
@attack68 Can I contribute to this issue ?

@KiranHipparagi
Copy link

take

@Tarunssd
Copy link

take

@tambibhavika2000
Copy link

take

@attack68
Copy link
Contributor Author

Did a quick search of the codebase and outside of all the test files this seems to have been addressed by all contributions now.

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

No branches or pull requests