-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Add isort config #23096
Add isort config #23096
Conversation
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.
in general looks good, added some comments
ci/code_checks.sh
Outdated
@@ -13,10 +13,11 @@ | |||
# $ ./ci/code_checks.sh lint # run linting only | |||
# $ ./ci/code_checks.sh patterns # check for patterns that should not exist | |||
# $ ./ci/code_checks.sh doctests # run doctests | |||
# $ ./ci/code_checks.sh imports # run isort on imports |
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'd add it as a subtask of lint
instead.
combine_as_imports=True | ||
skip= | ||
pandas/lib.py, | ||
pandas/tslib.py, |
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 isort automatically reorganizes the code. Not sure if that's your plan for later, but I think we want to run that instead of skipping everything.
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.
Thanks - Yes it does i could run isort -rc pandas
to sort the entire codebase but I will go for a more incremental approach suggested by @TomAugspurger here
setup.cfg
Outdated
[isort] | ||
known_first_party=pandas | ||
known_third_party=numpy,python-dateutil,pytz | ||
force_sort_within_sections=true |
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'm not sure if we want this (I guess this sorts modules alphabetically in each of the 3 sections, right?)
@@ -14,6 +14,7 @@ dependencies: | |||
- geopandas | |||
- html5lib | |||
- ipython | |||
- isort |
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 we'll also have to add this in the yaml dependencies for conda.
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.
Thanks have done added to environment-dev.yaml
Hello @alimcmaster1! Thanks for updating the PR.
|
pls rebase. let's lmit this first push to what you have done. don't add more files here. this will need many small PR's to avoid rebase issues generally. |
Lint failure: https://travis-ci.org/pandas-dev/pandas/jobs/442319848#L2919
Did CI fail without it? What did the output look like? I think things were pretty quiet over in #23048, so just to confirm are any maintainers against doing this (@jorisvandenbossche @WillAyd @jschendel @gfyoung @mroeschke, ...)? |
@TomAugspurger - thanks for taking a look - below is an example CI failing for files with incorrectly formatted imports: https://travis-ci.org/pandas-dev/pandas/jobs/440557769#L2830 Sample output: Doctests top-level reshaping functions DONE |
Codecov Report
@@ Coverage Diff @@
## master #23096 +/- ##
==========================================
+ Coverage 92.19% 92.19% +<.01%
==========================================
Files 169 169
Lines 50956 50957 +1
==========================================
+ Hits 46977 46978 +1
Misses 3979 3979
Continue to review full report at Codecov.
|
I am on board in general, but will isort raise an error if imports are inlined in functions and not at the top of the file? I've seen them used here and there in the code base (maybe for a good reason). Example: pandas/pandas/core/tools/datetimes.py Line 98 in 913f71f
|
It only lints imports at the top of a file. I think it even stops linting if you do an import in a try/except.
…________________________________
From: Matthew Roeschke <notifications@github.com>
Sent: Tuesday, October 16, 2018 7:03:54 PM
To: pandas-dev/pandas
Cc: Tom Augspurger; Mention
Subject: Re: [pandas-dev/pandas] Add isort config (#23096)
I am on board in general, but will isort raise an error if imports are inlined in functions and not at the top of the file? I've seen them used here and there in the code base (maybe for a good reason).
Example:
https://github.com/pandas-dev/pandas/blob/913f71f74709e4d4814e50f21768b97ce2c6ef8d/pandas/core/tools/datetimes.py#L98
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#23096 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABQHIoFArQpmOwHo-9nMV6IV_zUx_1y0ks5ulnPqgaJpZM4XYfbd>.
|
this looks fine. can you rebase, and ping on green. |
@jreback green aside from the windows 3.6 failure. We should probably merge this before any others. |
FYI, people may want to check out pre-commit for having these checks run on each commit. I haven't tried isort on a repo as large as pandas though. |
Thanks @TomAugspurger . We could also use this, so any issues with imports will be highlighted when developers hopefully run |
@alimcmaster1 yeah why don't you merge master on this and ping when passes travis |
thanks @alimcmaster1 |
certainly take followups to remove the non-checked files, but do in smaller batches (doesn't have to be tiny), but not > 20 files |
Thanks @jreback for sorting, apologies for lack of response from myself, unfortunately I cant push to public repo's on my work machine.. I will follow up with PRs for small batches of files. Let me know if there is anything I should be doing to document what's going on here :) |
@alimcmaster1 if that makes sense, you can get the list of files to update, divide it in chunks, and create an issue for each chunk explaining well what needs to be done. This way you don't need to do all them yourself. |
Thanks @datapythonista - I've started doing a few PRs myself and created an issue so others can hopefully help #23334. |
@alimcmaster1 something else: would you like to add a small section to the contributing guideline explaining |
Hey @jorisvandenbossche - sure I can do this, was thinking this might be handy! Thanks |
@jorisvandenbossche thoughts on something like this #23364 ? |
git diff upstream/master -u -- "*.py" | flake8 --diff
Confirming that CI fails when Imports are incorrectly formatted. See here:
https://travis-ci.org/pandas-dev/pandas/jobs/440557769
Sample output:
Doctests top-level reshaping functions DONE
Check import format using isort
ERROR: /home/travis/build/pandas-dev/pandas/pandas/core/series.py Imports are incorrectly sorted.
ERROR: /home/travis/build/pandas-dev/pandas/pandas/core/indexes/range.py Imports are incorrectly sorted.
ERROR: /home/travis/build/pandas-dev/pandas/pandas/io/packers.py Imports are incorrectly sorted.
ERROR: /home/travis/build/pandas-dev/pandas/pandas/io/pytables.py Imports are incorrectly sorted.
Check import format using isort DONE
The command "ci/code_checks.sh" exited with 1.