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

Add isort config #23096

Merged
merged 7 commits into from
Oct 17, 2018
Merged

Add isort config #23096

merged 7 commits into from
Oct 17, 2018

Conversation

alimcmaster1
Copy link
Member

@alimcmaster1 alimcmaster1 commented Oct 11, 2018

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.

Copy link
Member

@datapythonista datapythonista left a 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

@@ -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
Copy link
Member

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,
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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

@datapythonista datapythonista added CI Continuous Integration Code Style Code style, linting, code_checks labels Oct 12, 2018
@pep8speaks
Copy link

Hello @alimcmaster1! Thanks for updating the PR.

@jreback
Copy link
Contributor

jreback commented Oct 14, 2018

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.

@TomAugspurger
Copy link
Contributor

Lint failure: https://travis-ci.org/pandas-dev/pandas/jobs/442319848#L2919

Confirming that CI fails when Imports are incorrectly formatted.

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, ...)?

@alimcmaster1 alimcmaster1 changed the title WIP: Add isort config Add isort config Oct 16, 2018
@alimcmaster1
Copy link
Member Author

alimcmaster1 commented Oct 16, 2018

@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
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.

@codecov
Copy link

codecov bot commented Oct 16, 2018

Codecov Report

Merging #23096 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23096      +/-   ##
==========================================
+ Coverage   92.19%   92.19%   +<.01%     
==========================================
  Files         169      169              
  Lines       50956    50957       +1     
==========================================
+ Hits        46977    46978       +1     
  Misses       3979     3979
Flag Coverage Δ
#multiple 90.61% <100%> (ø) ⬆️
#single 42.29% <100%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/core/series.py 93.86% <100%> (ø) ⬆️
pandas/io/packers.py 88.01% <100%> (-0.04%) ⬇️
pandas/io/pytables.py 92.44% <100%> (-0.01%) ⬇️
pandas/tseries/api.py 100% <100%> (ø) ⬆️
pandas/core/indexes/range.py 95.73% <100%> (ø) ⬆️
pandas/core/reshape/merge.py 93.89% <0%> (-0.05%) ⬇️
pandas/core/indexes/base.py 96.54% <0%> (-0.01%) ⬇️
pandas/core/indexes/numeric.py 97.41% <0%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e8d29e7...3b5f524. Read the comment docs.

@mroeschke
Copy link
Member

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:

from pandas import Series, DatetimeIndex, Index

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 17, 2018 via email

@jreback jreback added this to the 0.24.0 milestone Oct 17, 2018
@jreback
Copy link
Contributor

jreback commented Oct 17, 2018

this looks fine. can you rebase, and ping on green.

@TomAugspurger
Copy link
Contributor

@jreback green aside from the windows 3.6 failure. We should probably merge this before any others.

@TomAugspurger
Copy link
Contributor

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.

@alimcmaster1
Copy link
Member Author

Thanks @TomAugspurger . We could also use this, so any issues with imports will be highlighted when developers hopefully run git diff upstream/master -u -- "*.py" | flake8 --diff before committing. I can rebase this eve if required. ( this branch is 2 commits behind master )

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 17, 2018

Maybe merge mater to be safe.

Or you could spot check #23190 and #23193 to see if they touch files that are now being linted.

@jreback
Copy link
Contributor

jreback commented Oct 17, 2018

@alimcmaster1 yeah why don't you merge master on this and ping when passes travis

@jreback jreback merged commit 9285820 into pandas-dev:master Oct 17, 2018
@jreback
Copy link
Contributor

jreback commented Oct 17, 2018

thanks @alimcmaster1

@jreback
Copy link
Contributor

jreback commented Oct 17, 2018

certainly take followups to remove the non-checked files, but do in smaller batches (doesn't have to be tiny), but not > 20 files

@alimcmaster1
Copy link
Member Author

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 :)

@datapythonista
Copy link
Member

@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.

@alimcmaster1
Copy link
Member Author

Thanks @datapythonista - I've started doing a few PRs myself and created an issue so others can hopefully help #23334.

@jorisvandenbossche
Copy link
Member

@alimcmaster1 something else: would you like to add a small section to the contributing guideline explaining isort and its use? So we have something to point to if contributors on a PR get a red CI with "Imports are incorrectly sorted." (which sort order is expected? how to let isort do this automatically for you? ..)

@alimcmaster1
Copy link
Member Author

Hey @jorisvandenbossche - sure I can do this, was thinking this might be handy! Thanks

@alimcmaster1 alimcmaster1 mentioned this pull request Oct 26, 2018
2 tasks
@alimcmaster1
Copy link
Member Author

@jorisvandenbossche thoughts on something like this #23364 ?

tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
@alimcmaster1 alimcmaster1 deleted the isort branch December 25, 2019 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use isort for standardizing import formatting
7 participants