-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Plotting Timedelta on y-axis #16953 #17430
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
Conversation
@s-weigand : Don't forget a |
Codecov Report
@@ Coverage Diff @@
## master #17430 +/- ##
==========================================
- Coverage 91.15% 91.14% -0.02%
==========================================
Files 163 163
Lines 49581 49582 +1
==========================================
- Hits 45198 45191 -7
- Misses 4383 4391 +8
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17430 +/- ##
==========================================
- Coverage 91.15% 91.14% -0.02%
==========================================
Files 163 163
Lines 49581 49582 +1
==========================================
- Hits 45198 45191 -7
- Misses 4383 4391 +8
Continue to review full report at Codecov.
|
Hello @s-weigand! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 05, 2017 at 17:38 Hours UTC |
pandas/plotting/_core.py
Outdated
@@ -342,7 +342,9 @@ def _compute_plot_data(self): | |||
label = 'None' | |||
data = data.to_frame(name=label) | |||
|
|||
numeric_data = data._convert(datetime=True)._get_numeric_data() | |||
# GH16953 | |||
data = data._convert(datetime=True, timedelta=True) |
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 don't think we need the _convert
at all here. this is for object types that need to be coerced. almost all routines in pandas already assume this.
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 _convert is needed for a test, where a Series
with numeric values and dtype object
is used (tests.plotting.test_series.test_valid_object_plot
).
If _convert isn't used, that test will fail in circleci
.
To prevent the test from failing, _convert can either be used only on Series
with dtype==object
and after the to_frame
(line 344), or on data
in general after the Series
specific part (line 346 as is now).
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -400,7 +400,7 @@ I/O | |||
Plotting | |||
^^^^^^^^ | |||
- Bug in plotting methods using ``secondary_y`` and ``fontsize`` not setting secondary axis font size (:issue:`12565`) | |||
|
|||
- Bug when plotting Timedelta and Datetime on y-axis (:issue:`16953`) |
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.
say timedelta
and datetime
dtypes (and use double back-ticks).
pandas/tests/plotting/test_frame.py
Outdated
"timedelta": [pd.Timedelta(10, unit="s"), | ||
pd.Timedelta(10, unit="m"), | ||
pd.Timedelta(10, unit="h")], | ||
"datetime": [pd.to_datetime("2017-08-01 00:00:00"), |
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 add a datetime with a tz as well
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.
sure ^^
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 some other types, e.g. Period might fail, if you can add them in another test with xfail would be fine (Categoricals might work as they area converted to ndarrays)
pandas/tests/plotting/test_frame.py
Outdated
with pytest.raises(TypeError): | ||
testdata.plot(y="text") | ||
|
||
@pytest.mark.xfail |
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 need to have a reason='not support for period, categorical, datetime_mixed_tz')
here
numeric_data = data._convert(datetime=True)._get_numeric_data() | ||
# GH16953, _convert is needed as fallback, for ``Series`` | ||
# with ``dtype == object`` | ||
data = data._convert(datetime=True, timedelta=True) |
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.
did you take out the _convert
and see, on what input does it fail?
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.
Yap i did, circleci fails at tests.plotting.test_series.test_valid_object_plot
, since the Series
is of dtype == object
(s = Series(lrange(10), dtype=object)
, also see comment on your last requested changes).
Also i think doing a general data._convert
is more sturdy, than just calling in if the Series
is of type object (which would be the minimal change for the test to pass).
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.
ok I guess leave it in is ok. In general we don't automatically coerce object types (even if they are numbers) in other functions / places; we happen to do it in plotting for compat I think. Can you open a new issue for this to discuss (deprecating this).
lgtm. @TomAugspurger |
Thanks @s-weigand! |
@s-weigand What is matplotlib issue number? Thanks for this fix. |
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
git diff upstream/master -u -- "*.py" | flake8 --diff
This fixes the issue with a TypeError being raised if the y-data were of type Timedelta or Datetime.
The plot of Timedelta doesn't look pretty since it is converted to ns representation, but matplotlib has already an open issue for that.
PS: Greetings to the people from the EuroSciPy 2017 sprints ^^