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

CLN: trying isort-dev #32489

Closed

Conversation

ShaharNaveh
Copy link
Member

@ShaharNaveh ShaharNaveh commented Mar 6, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Trying isort 5.0.0 which is still under development.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm

@WillAyd WillAyd added the Clean label Mar 6, 2020
from pandas._libs.tslibs.conversion cimport convert_to_tsobject
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64
from pandas._libs.tslibs.timezones cimport get_timezone, tz_compare
Copy link
Member

Choose a reason for hiding this comment

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

putting tslibs imports before non-tslibs imports (within cython files) is intentional, can we update config to preserve this?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is an option to have groups in isort and then order them, so if we have two modules foo and bar, and we want bar first, we can do:

(in setup.cfg)

[isort]
known_foo = pandas.foo
known_bar = pandas.bar
sections = bar,foo

we can achieve the desired behavior but it will be applied across all files (py, pyx, pxi).


Edit:

I have opened an issue at isort asking that question.

ref: PyCQA/isort#1162

PyDateTime_IMPORT

import numpy as np

Copy link
Member

Choose a reason for hiding this comment

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

if there is a viable way to avoid this newline (and the one on 45), id like to maintain the pattern of keeping all the numpy imports together

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't achieve that unfortunately, my guess is that isort is separates import and cimport even if it's importing the same library/module

@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Mar 7, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins 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 @jbrockmendel comments

@jbrockmendel
Copy link
Member

-0.5 on the cython edits here. I'm fine with the non-cython edits.

Detecting unused imports in cython would be nice.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Hmm question on the Python imports now; I don't think worth changing

@@ -438,7 +438,7 @@ def __init__(
elif isinstance(data, dict):
mgr = init_dict(data, index, columns, dtype=dtype)
elif isinstance(data, ma.MaskedArray):
import numpy.ma.mrecords as mrecords
from numpy.ma import mrecords
Copy link
Member

Choose a reason for hiding this comment

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

Hmm actually now that I think about it is this an isort thing or something you are suggesting as a standard?

These aren't entirely equivalent and this change is more prone to circular imports. The former is actually suggest by Guido as the way to go so I don't think this is worth changing. (can't find link atm, but its somewhere in the Python docs)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in fact an isort thing (in the dev version), If you can find the link I think we should open an issue about this (to isort).

The first commit is the changes made by isort, the second commit was done manually to fix the pattern of:

from foo.bar import baz as baz

Copy link
Member

Choose a reason for hiding this comment

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

import numpy.ma doesnt import mrecords into the np.ma namespace. Is this pattern ever liable to trip us up with either form of import?

Copy link
Member

Choose a reason for hiding this comment

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

@MomIsBestFriend here is what I was describing:

https://docs.python.org/3/faq/programming.html#how-can-i-have-modules-that-mutually-import-each-other

Guido van Rossum recommends avoiding all uses of from import ..., and placing all code inside functions.

So while this is inside a function, I think still not worth changing to a usage that is discouraged by Guido himself

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you @WillAyd for sending the link!

I have opened an issue about this discussion at isort.


xref PyCQA/isort#1164

Choose a reason for hiding this comment

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

Regardless of the from x import y conversation, these usages are not needed since you are not renaming:

import numpy.na.mrecords is the same as import numpy.na.mrecords as mrecords (will probably help you at least workaround this decision by isort team).

@ShaharNaveh
Copy link
Member Author

Closing this as this meant to be a pilot, to see if we will have problems with isort 5.0.0, I will open a similar PR trying isort master, after they will do some changes.

@ShaharNaveh ShaharNaveh deleted the CLN-isort-dev-pilot branch March 24, 2020 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants