-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
STYLE use absolute imports #39561
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
STYLE use absolute imports #39561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,26 +41,26 @@ class TestMyDtype(BaseDtypeTests): | |
``assert_series_equal`` on your base test class. | ||
|
||
""" | ||
from .casting import BaseCastingTests # noqa | ||
from .constructors import BaseConstructorsTests # noqa | ||
from .dtype import BaseDtypeTests # noqa | ||
from .getitem import BaseGetitemTests # noqa | ||
from .groupby import BaseGroupbyTests # noqa | ||
from .interface import BaseInterfaceTests # noqa | ||
from .io import BaseParsingTests # noqa | ||
from .methods import BaseMethodsTests # noqa | ||
from .missing import BaseMissingTests # noqa | ||
from .ops import ( # noqa | ||
from pandas.tests.extension.base.casting import BaseCastingTests # noqa | ||
from pandas.tests.extension.base.constructors import BaseConstructorsTests # noqa | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I am -1 on general linting check for this. For example, this specific example where I am commenting on, I find the relative imports actually more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Joris on this (more generally, i like relative imports for same-directory as it clarified dependency structure) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no strong opinion here, I was just following the (existing) pandas style guide - should the style guide be changed so an exception is made for same-level imports? Or this can be reverted if you wish, it was a really good learning exercise anyway. My personal preference would be to have some kind of rule agreed on, but again, not a strong opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we had easily automatic check able for relative imports that would be ok for a limited purpose we cannot expreess 'more readable' in this way and have it enforced this is why i am currently -1 on relative imports and why we cannot use them in the code base There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The part of the style guide about general relative imports, of course fully agreed that we never want implicit relative imports. But personally I think we should reconsider explicit ones, yes.
+1, I also find this helpful. I think it should certainly be doable to have a check that relative imports are never outside the local directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
there are a bunch of places where we have dependency structure rules (imperfectly enforced, so maybe better thought of as aspirations) of the form "this file doesnt depend on anything else in pandas except other files in this directory or things explicitly higher up in the dependency structure": pandas._config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for explaining, I hadn't appreciated that - I'll look into this and see how to adapt imports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@jbrockmendel just to make sure I've understood, are you suggesting that every file inside
, would you want that to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, I would essentially never use Note that isort has a LOCALFOLDER section, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so you'd always use a relative import when importing from the same directory (even outside of the folders you listed above), and use absolute elsewhere? If so, this seems easily enforceable, I can make a PR later this week |
||
from pandas.tests.extension.base.dtype import BaseDtypeTests # noqa | ||
from pandas.tests.extension.base.getitem import BaseGetitemTests # noqa | ||
from pandas.tests.extension.base.groupby import BaseGroupbyTests # noqa | ||
from pandas.tests.extension.base.interface import BaseInterfaceTests # noqa | ||
from pandas.tests.extension.base.io import BaseParsingTests # noqa | ||
from pandas.tests.extension.base.methods import BaseMethodsTests # noqa | ||
from pandas.tests.extension.base.missing import BaseMissingTests # noqa | ||
from pandas.tests.extension.base.ops import ( # noqa | ||
BaseArithmeticOpsTests, | ||
BaseComparisonOpsTests, | ||
BaseOpsUtil, | ||
BaseUnaryOpsTests, | ||
) | ||
from .printing import BasePrintingTests # noqa | ||
from .reduce import ( # noqa | ||
from pandas.tests.extension.base.printing import BasePrintingTests # noqa | ||
from pandas.tests.extension.base.reduce import ( # noqa | ||
BaseBooleanReduceTests, | ||
BaseNoReduceTests, | ||
BaseNumericReduceTests, | ||
) | ||
from .reshaping import BaseReshapingTests # noqa | ||
from .setitem import BaseSetitemTests # noqa | ||
from pandas.tests.extension.base.reshaping import BaseReshapingTests # noqa | ||
from pandas.tests.extension.base.setitem import BaseSetitemTests # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
from .array import DecimalArray, DecimalDtype, make_data, to_decimal | ||
from pandas.tests.extension.decimal.array import ( | ||
DecimalArray, | ||
DecimalDtype, | ||
make_data, | ||
to_decimal, | ||
) | ||
|
||
__all__ = ["DecimalArray", "DecimalDtype", "to_decimal", "make_data"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .array import JSONArray, JSONDtype, make_data | ||
from pandas.tests.extension.json.array import JSONArray, JSONDtype, make_data | ||
|
||
__all__ = ["JSONArray", "JSONDtype", "make_data"] |
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.
is this added automatically by versioneer?
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.
yes, thanks for spotting this - I've updated
versioneer.py
to use an absolute import