STY: proposed isort settings [ci skip] [skip ci] [ciskip] [skipci]
State: closed

(not sure which tag(s) skip the CI)

I propose we change the isort settings to arrange within-pandas imports by dependency structure.  i.e. 

- `pandas._libs`, `pandas.compat`, `pandas.util._*`, `pandas.errors` are for the most part not dependent on pandas.core, so get their own section(s)
- `pandas.core.dtypes` for the most part does not depend on the rest of `pandas.core`, so it goes next
- then the rest of `pandas.core`
- then pandas non-core: `pandas.io`, `pandas.plotting`, `pandas.tseries`

Within blocks I propose we stick to alphabetical ordering.  e.g. right now in `core.series` we have import `pandas.core.indexes.base as ibase` 35 lines away from all the other `pandas.core.indexes` imports.  These should be adjacent.

The main thing I'd still like to fix/improve is that in this PR isort is failing to put `from pandas import compat` with the other `pandas.compat` imports.

Putting the trailing parentheses on the same line as the imports instead of a separate line is less important, but I prefer it because it makes it cleaner when I wrap lines in sublimetext.  Happy to revert that if it is a sticking point.

Labels:
name: Code Style
description: Code style, linting, code_checks

Comments:
Hello @jbrockmendel! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/series.py`](https://github.com/jbrockmendel/pandas/blob/ec71fc689b4ae99f57e0c29888964df1390bc8ba/pandas/core/series.py) !


this is going to massively change the in-progress isort cleanups no?
> this is going to massively change the in-progress isort cleanups no?

Yes.  If there is an agreement that this format is better (it is), then better to implement it before more isort work is done.

Also a bunch of modules already use approx this pattern, e.g. core.internals, datetimelike arrays
ok does this break anything i the current build?
>ok does this break anything i the current build?

Yes, a bunch of files.  If this format is agreed upon, I can either add those back to the ignore list in setup.cfg or go through and fix them all in one swoop now.
either ok
updated, now passes `isort -rc pandas`
is the -rc needed? if so can u update auto check and instructions 
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=h1) Report
> Merging [#23366](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/96d321c70e55c619ad6eab40a84e3fa166982a4c?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/23366/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #23366   +/-   ##
=======================================
  Coverage   92.18%   92.18%           
=======================================
  Files         161      161           
  Lines       51160    51160           
=======================================
  Hits        47161    47161           
  Misses       3999     3999
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <100%> (ø)` | :arrow_up: |
| #single | `42.24% <97.93%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/sas/sasreader.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNyZWFkZXIucHk=) | `86.2% <ø> (ø)` | :arrow_up: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `95.45% <ø> (ø)` | :arrow_up: |
| [pandas/io/packers.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhY2tlcnMucHk=) | `88.08% <100%> (+0.03%)` | :arrow_up: |
| [pandas/io/parquet.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnF1ZXQucHk=) | `73.72% <100%> (ø)` | :arrow_up: |
| [pandas/tseries/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvYXBpLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `96.79% <100%> (ø)` | :arrow_up: |
| [pandas/core/groupby/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9ncm91cGJ5LnB5) | `96.48% <100%> (ø)` | :arrow_up: |
| [pandas/core/groupby/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9iYXNlLnB5) | `91.83% <100%> (ø)` | :arrow_up: |
| [pandas/core/groupby/grouper.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9ncm91cGVyLnB5) | `98.16% <100%> (ø)` | :arrow_up: |
| [pandas/io/clipboards.py](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2NsaXBib2FyZHMucHk=) | `100% <100%> (ø)` | :arrow_up: |
| ... and [10 more](https://codecov.io/gh/pandas-dev/pandas/pull/23366/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=footer). Last update [96d321c...51834f0](https://codecov.io/gh/pandas-dev/pandas/pull/23366?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @jbrockmendel let's hope this works :>
I like this alot - thanks @jbrockmendel ! I did actually try this myself since you requested it back in #23048 . But isort seemed to produce non-deterministic sort for me. But I think i wasn't sorting within sections like you added `force_sort_within_sections=True` 
One disadvantage is that it will be harder to know how to correctly do the imports manually, so I think we need to explain the logic in the guidelines (@alimcmaster1 if you can do that in https://github.com/pandas-dev/pandas/pull/23364, that would be great)
Sure happy to @jorisvandenbossche , but I hope most people  will use isort to sort imports opposed to doing so manually 
Yes, but still, if I just need to add an import to an already correctly sorted file, I think it is nice to know how to do this correctly instead of each time to have to run isort after making a small change (although you could maybe configure your editor to do so, or with a git commit hook)