Skip to content

PERF: faster plotting of timeseries with PeriodIndex #4722

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 2 commits into from
Sep 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pandas 0.13
- ``get_dummies`` works with NaN (:issue:`4446`)
- Added a test for ``read_clipboard()`` and ``to_clipboard()`` (:issue:`4282`)
- Added bins argument to ``value_counts`` (:issue:`3945`), also sort and
ascending, now available in Series method as well as top-level function.
ascending, now available in Series method as well as top-level function.
- Text parser now treats anything that reads like inf ("inf", "Inf", "-Inf",
"iNf", etc.) to infinity. (:issue:`4220`, :issue:`4219`), affecting
``read_table``, ``read_csv``, etc.
Expand All @@ -74,6 +74,8 @@ pandas 0.13
- Better/cleaned up exceptions in core/common, io/excel and core/format
(:issue:`4721`, :issue:`3954`), as well as cleaned up test cases in
tests/test_frame, tests/test_multilevel (:issue:`4732`).
- Performance improvement of timesesies plotting with PeriodIndex and added
test to vbench (:issue:`4705` and :issue:`4722`)

**API Changes**

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_plot(self):
_check_plot_works(self.ts.plot, style='.', logx=True)
_check_plot_works(self.ts.plot, style='.', loglog=True)
_check_plot_works(self.ts[:10].plot, kind='bar')
_check_plot_works(self.iseries.plot)
_check_plot_works(self.series[:5].plot, kind='bar')
_check_plot_works(self.series[:5].plot, kind='line')
_check_plot_works(self.series[:5].plot, kind='barh')
Expand Down
2 changes: 2 additions & 0 deletions pandas/tseries/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def convert(values, units, axis):
if (isinstance(values, valid_types) or com.is_integer(values) or
com.is_float(values)):
return get_datevalue(values, axis.freq)
if isinstance(values, PeriodIndex):
return values.asfreq(axis.freq).values
if isinstance(values, Index):
return values.map(lambda x: get_datevalue(x, axis.freq))
if isinstance(values, (list, tuple, np.ndarray)):
Expand Down
25 changes: 25 additions & 0 deletions vb_suite/plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from vbench.benchmark import Benchmark
from datetime import datetime

common_setup = """from pandas_vb_common import *

try:
from pandas import date_range
except ImportError:
def date_range(start=None, end=None, periods=None, freq=None):
return DateRange(start, end, periods=periods, offset=freq)

"""

#-----------------------------------------------------------------------------
# Timeseries plotting

setup = common_setup + """
N = 2000
M = 5
df = DataFrame(np.random.randn(N,M), index=date_range('1/1/1975', periods=N))
"""

plot_timeseries_period = Benchmark("df.plot()", setup=setup,
name='plot_timeseries_period')

1 change: 1 addition & 0 deletions vb_suite/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'miscellaneous',
'panel_ctor',
'parser',
'plotting',
'reindex',
'replace',
'sparse',
Expand Down