Skip to content

Commit a8e367b

Browse files
committed
Merge pull request #4722 from jorisvandenbossche/slow-plotting
PERF: faster plotting of timeseries with PeriodIndex
2 parents 472b93a + ca9f1a4 commit a8e367b

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

doc/source/release.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pandas 0.13
4747
- ``get_dummies`` works with NaN (:issue:`4446`)
4848
- Added a test for ``read_clipboard()`` and ``to_clipboard()`` (:issue:`4282`)
4949
- Added bins argument to ``value_counts`` (:issue:`3945`), also sort and
50-
ascending, now available in Series method as well as top-level function.
50+
ascending, now available in Series method as well as top-level function.
5151
- Text parser now treats anything that reads like inf ("inf", "Inf", "-Inf",
5252
"iNf", etc.) to infinity. (:issue:`4220`, :issue:`4219`), affecting
5353
``read_table``, ``read_csv``, etc.
@@ -74,6 +74,8 @@ pandas 0.13
7474
- Better/cleaned up exceptions in core/common, io/excel and core/format
7575
(:issue:`4721`, :issue:`3954`), as well as cleaned up test cases in
7676
tests/test_frame, tests/test_multilevel (:issue:`4732`).
77+
- Performance improvement of timesesies plotting with PeriodIndex and added
78+
test to vbench (:issue:`4705` and :issue:`4722`)
7779

7880
**API Changes**
7981

pandas/tests/test_graphics.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_plot(self):
6060
_check_plot_works(self.ts.plot, style='.', logx=True)
6161
_check_plot_works(self.ts.plot, style='.', loglog=True)
6262
_check_plot_works(self.ts[:10].plot, kind='bar')
63+
_check_plot_works(self.iseries.plot)
6364
_check_plot_works(self.series[:5].plot, kind='bar')
6465
_check_plot_works(self.series[:5].plot, kind='line')
6566
_check_plot_works(self.series[:5].plot, kind='barh')

pandas/tseries/converter.py

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def convert(values, units, axis):
111111
if (isinstance(values, valid_types) or com.is_integer(values) or
112112
com.is_float(values)):
113113
return get_datevalue(values, axis.freq)
114+
if isinstance(values, PeriodIndex):
115+
return values.asfreq(axis.freq).values
114116
if isinstance(values, Index):
115117
return values.map(lambda x: get_datevalue(x, axis.freq))
116118
if isinstance(values, (list, tuple, np.ndarray)):

vb_suite/plotting.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from vbench.benchmark import Benchmark
2+
from datetime import datetime
3+
4+
common_setup = """from pandas_vb_common import *
5+
6+
try:
7+
from pandas import date_range
8+
except ImportError:
9+
def date_range(start=None, end=None, periods=None, freq=None):
10+
return DateRange(start, end, periods=periods, offset=freq)
11+
12+
"""
13+
14+
#-----------------------------------------------------------------------------
15+
# Timeseries plotting
16+
17+
setup = common_setup + """
18+
N = 2000
19+
M = 5
20+
df = DataFrame(np.random.randn(N,M), index=date_range('1/1/1975', periods=N))
21+
"""
22+
23+
plot_timeseries_period = Benchmark("df.plot()", setup=setup,
24+
name='plot_timeseries_period')
25+

vb_suite/suite.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'miscellaneous',
1818
'panel_ctor',
1919
'parser',
20+
'plotting',
2021
'reindex',
2122
'replace',
2223
'sparse',

0 commit comments

Comments
 (0)