Skip to content

BUG: Fix for #37454: allow reversed axis when plotting with TimedeltaIndex #37469

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

Merged
merged 18 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9e8c5fe
add test to demonstrate converter issue #37454
theavey Oct 28, 2020
9677e5e
add fix for issue #37454
theavey Oct 28, 2020
78d7189
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Oct 28, 2020
78f8ae1
TST use monkeypatch instead of mock
theavey Oct 28, 2020
531f1da
DOC add to whatsnew
theavey Oct 28, 2020
43e8045
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Oct 29, 2020
79bf3b1
DOC update whatsnew entry for clarity and detail
theavey Oct 29, 2020
5f16612
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 2, 2020
7809661
TST: add higher-level test for reversed timedelta index plot
theavey Nov 2, 2020
0018735
DOC: move whatnew entry to newer version (missed cutoff)
theavey Nov 2, 2020
a4da1ff
TST: comment on test; fix style
theavey Nov 2, 2020
376d43e
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 2, 2020
5c9515b
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 4, 2020
df99713
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 6, 2020
20637c1
DOC: merged upstream, resolving overlapping edits
theavey Nov 10, 2020
cb90b7d
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 11, 2020
b06a99d
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 17, 2020
d8fb05f
Merge branch 'master' of https://github.com/pandas-dev/pandas
theavey Nov 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Bug fixes
- Bug in :meth:`GroupBy.fillna` that introduced a performance regression after 1.0.5 (:issue:`36757`)
- Bug in :meth:`DataFrame.info` was raising a ``KeyError`` when the DataFrame has integer column names (:issue:`37245`)
- Bug in :meth:`DataFrameGroupby.apply` would drop a :class:`CategoricalIndex` when grouped on (:issue:`35792`)
- Bug in :meth:`Series.plot` and :meth:`DataFrame.plot` was throwing :exc:`ValueError` with a :class:`Series` or :class:`DataFrame`
indexed by a :class:`TimedeltaIndex` with a fixed frequency when x-axis lower limit was greater than upper limit (:issue:`37454`)

.. ---------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def format_timedelta_ticks(x, pos, n_decimals: int) -> str:

def __call__(self, x, pos=0) -> str:
(vmin, vmax) = tuple(self.axis.get_view_interval())
n_decimals = int(np.ceil(np.log10(100 * 1e9 / (vmax - vmin))))
n_decimals = int(np.ceil(np.log10(100 * 1e9 / abs(vmax - vmin))))
if n_decimals > 9:
n_decimals = 9
return self.format_timedelta_ticks(x, pos, n_decimals)
10 changes: 10 additions & 0 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,13 @@ def test_format_timedelta_ticks(self, x, decimal, format_expected):
tdc = converter.TimeSeries_TimedeltaFormatter
result = tdc.format_timedelta_ticks(x, pos=None, n_decimals=decimal)
assert result == format_expected

@pytest.mark.parametrize("view_interval", [(1, 2), (2, 1)])
def test_call(self, view_interval, monkeypatch):
class mock_axis:
def get_view_interval(self):
return view_interval

tdc = converter.TimeSeries_TimedeltaFormatter()
monkeypatch.setattr(tdc, "axis", mock_axis())
tdc(0.0, 0)