-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: fixes #12405 by eliding values index by NaT in MPLPlot._get_xticks #14540
Conversation
Will add a test in test_datetimelike.py but it will probably just repeat the sorting and eliding that occurs in the |
Codecov Report
@@ Coverage Diff @@
## master #14540 +/- ##
==========================================
+ Coverage 90.41% 90.41% +<.01%
==========================================
Files 161 161
Lines 50997 50999 +2
==========================================
+ Hits 46107 46109 +2
Misses 4890 4890
Continue to review full report at Codecov.
|
i would add some edge cases |
@jreback , I think all NaTs should be a failure: Otherwise, all cases are the same since |
incidentally, re @jorisvandenbossche's comment in the orignal bug report, matplotlib complains if you try to plot with |
plt.clf() | ||
ax = plt.gca() | ||
|
||
s = (tm.makeTimeSeries() |
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 is overly complicated, can you simplify the creation?
.pipe(inject_nat_into_index_col) | ||
.set_index('index', drop=True)) | ||
s.plot(ax=ax) | ||
xdata = ax.get_lines()[0].get_xdata() |
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.
add a _check_plot_works
call
pls add a release note, 0.19.1 bug fixes is fine. |
7963fea
to
72f9d88
Compare
The way matplotlib deals with missing values (for numerical data) is to leave a gap in the line. So matplotlib can actually deal with nan values. So therefore, we could also opt for this behaviour, rather than just removing those NaN values from the data before plotting. |
@jorisvandenbossche , we sort the index before we plot the data. Where would we insert the |
doc/source/whatsnew/v0.19.1.txt
Outdated
@@ -39,6 +39,7 @@ Bug Fixes | |||
- Bug in ``pd.read_csv`` for Python 2.x in which Unicode quote characters were no longer being respected (:issue:`14477`) | |||
- Bug in localizing an ambiguous timezone when a boolean is passed (:issue:`14402`) | |||
- Bug in ``TimedeltaIndex`` addition with a Datetime-like object where addition overflow in the negative direction was not being caught (:issue:`14068`, :issue:`14453`) | |||
- Bug in ``plot`` where ``NaT`` in ``DatetimeIndex`` results in ``Timestamp.min`` (:issue: `12405`) |
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.
can you move to 0.20.0
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.
moved
@tsdlovell can you rebase / update |
status of this? |
72f9d88
to
1048255
Compare
@tsdlovell ping! |
@tsdlovell can you rebase? |
@jreback , I had some issues rebase'ing onto master. I ended up just applying the changes manually to the current head and creating a new branch: fix-gh12405-2. Can I just push that to the original fork branch for this PR or will that mess something up? |
yes i think u can just force push it and will work |
@TomAugspurger how does this look? |
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -1643,6 +1643,7 @@ Plotting | |||
- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`) | |||
- Bug in the date and time converters pandas registers with matplotlib not handling multiple dimensions (:issue:`16026`) | |||
- Bug in ``pd.scatter_matrix()`` could accept either ``color`` or ``c``, but not both (:issue:`14855`) | |||
- Bug in ``plot`` where ``NaT`` in ``DatetimeIndex`` results in ``Timestamp.min`` (:issue: `12405`) |
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.
can you move to 0.20.2
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.
Just a few changes @tsdlovell and can you move the release note to 0.20.2? Thanks!
@@ -815,6 +815,23 @@ def test_mixed_freq_shared_ax(self): | |||
# self.assertEqual(ax1.lines[0].get_xydata()[0, 0], | |||
# ax2.lines[0].get_xydata()[0, 0]) | |||
|
|||
def test_nat_handling(self): | |||
|
|||
import matplotlib.pyplot as plt # noqa |
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.
You can remove this import and use self.plt
, which comes from the base class
|
||
import matplotlib.pyplot as plt # noqa | ||
|
||
fig = plt.gcf() |
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 necessary for the test to work? Our base class should take care of closing all the figures, so there shouldn't be any hanging around from a previous test.
s.plot(ax=ax) | ||
xdata = ax.get_lines()[0].get_xdata() | ||
# plot x data is bounded by index values | ||
self.assertLessEqual(s.index.min(), Series(xdata).min()) |
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 just switched over to pytest, so this can be assert s.index.min() <= Series(xdata).min()
. Same thing with the next line.
# plot x data is bounded by index values | ||
self.assertLessEqual(s.index.min(), Series(xdata).min()) | ||
self.assertLessEqual(Series(xdata).max(), s.index.max()) | ||
_check_plot_works(s.plot) |
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 think you can remove this line. It's just calling s.plot()
again.
…._get_xticks TST: add test for fix of pandas-dev#12405 DOC: update whatsnew/v0.20.0.txt
@TomAugspurger , let me know if there's something I still need to do. |
Thanks! |
…._get_xticks (pandas-dev#14540) TST: add test for fix of pandas-dev#12405 DOC: update whatsnew/v0.20.2.txt
…._get_xticks (pandas-dev#14540) TST: add test for fix of pandas-dev#12405 DOC: update whatsnew/v0.20.2.txt
git diff upstream/master | flake8 --diff
Proposed solution: elide rows where x value would be
NaT
in MPLPlot._get_xticks (which seems like a minor misnomer: its getting x values, not what will ultimately be ticks).Reordering occurs in MPLPlot._get_xticks and it has a block that is conditional on
use_index
andis_datetype
, so seems like a reasonable place to elide the values. Mutation ofself.data
already occurs there (reordering) and a read through suggests nothing has saved info related toself.data
's shape before this point.