-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Avoid circular import between core.series and plotting._xyz #16931
Conversation
This follows up on pandas-dev#16913 but cuts down on the scope of the PR.
This equality failing is my best guess for why tests are failing
@@ -334,7 +334,11 @@ def result(self): | |||
def _compute_plot_data(self): | |||
data = self.data | |||
|
|||
if isinstance(data, Series): | |||
from pandas import Series |
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.
what is this about?
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.
The first commit for this PR led to a bunch of TypeError
s on Travis that I can't reproduce locally. My best/only guess as to why is that the check isinstance(data, ABSeries)
(now at L341) is somehow evaluating differently than the original isinstance(data, Series)
(previously at L337).
So 337-339 is an attempt to check this guess. Regardless of whether the guess is correct, this check will be removed before long.
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.
New hypothesis: Series._set_subtyp
can sometimes set _subtyp
to time_series
, in which case it will not get recognized as ABCSeries
. It tentatively looks like the Travis errors are date-related cases.
@@ -1494,6 +1499,7 @@ def _args_adjust(self): | |||
|
|||
@classmethod | |||
def _plot(cls, ax, y, column_num=None, return_type='axes', **kwds): | |||
from pandas.core.series import remove_na |
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 would be happy to move remove_na
to pandas.core.dtypes.missing
, and rename to remove_na_arraylike
(will have to update a couple of references)
(pandas) bash-3.2$ grep -R remove_na pandas
pandas/core/series.py: result = remove_na(self)
pandas/core/series.py:def remove_na(series):
pandas/plotting/_core.py:from pandas.core.series import Series, remove_na
pandas/plotting/_core.py: y = remove_na(y)
pandas/plotting/_core.py: y = [remove_na(v) for v in y]
pandas/plotting/_core.py: y = remove_na(y)
pandas/plotting/_core.py: values = [remove_na(v) for v in values]
pandas/tests/test_panel.py:from pandas.core.series import remove_na
pandas/tests/test_panel.py: nona = remove_na(x)
pandas/tests/test_panel4d.py:from pandas.core.series import remove_na
pandas/tests/test_panel4d.py: nona = remove_na(x)
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.
this would allow the import to be at the top
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.
That'd be great.
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.
About to make a PR that makes this move and nothing else. We'll see if Travis still complains about that.
if isinstance(data, Series): | ||
from pandas import Series | ||
if isinstance(data, ABCSeries) != isinstance(data, Series): | ||
raise Exception('WTFError', 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.
We should make that error available only to developers when they rage-quit 😄
I can now reproduce at least some of these errors locally by adding Incidentally, |
@jbrockmendel : The |
let's close this one in light of your other PR's. |
The DataFrame part of this has been merged, but the Series version is still FUBAR. I'll describe some things I've tried in the hopes that someone smarter than me will find this interesting/annoying enough to take a look at. Everything here assumes we have delayed the import of The tracebacks go through If I move the import of Next try: define
OK! Now the tests pass (at least the ones from |
This follows up on #16913 but cuts down on the scope of the PR.
pandas.core.series
currently runsimport pandas.plotting._core as _gfx # noqa
about 8 lines from the bottom of the file.
pandas.plotting._core
runsfrom pandas.core.series import Series, remove_na
at the top of the file. Using very small words and talking very slowly, it was explained to me that this circular import works because
Series
andremove_na
are defined in theseries
namespace by the timeplotting._core
tries to import them.This PR gets rid of the module-level import from
core.series
and moves the import ofplotting._core
to the top ofcore.series
so as to avoid relying on hard-to-predict/debug behavior.Other changes that I'd like to make (like deleting the extraneous
ret = Series()
at plotting/_core.py:L2325) are ignored for now.git diff upstream/master --name-only -- '*.py' | flake8 --diff
(On Windows,git diff upstream/master -u -- "*.py" | flake8 --diff
might work as an alternative.)