Skip to content

Commit

Permalink
BUG: method='time' interpolation incorrect for intraday data close #1698
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Aug 12, 2012
1 parent 745a496 commit fdcc106
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pandas 0.8.2
- Don't lose tzinfo in DatetimeIndex when shifting by different offset (#1683)
- Hack to support storing data with a zero-length axis in HDFStore (#1707)
- Fix DatetimeIndex tz-aware range generation issue (#1674)
- Fix method='time' interpolation with intraday data (#1698)

pandas 0.8.1
============
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2537,8 +2537,10 @@ def interpolate(self, method='linear'):
if not isinstance(self, TimeSeries):
raise Exception('time-weighted interpolation only works'
'on TimeSeries')
inds = np.array([d.toordinal() for d in self.index])
elif method == 'values':
method = 'values'
# inds = np.array([d.toordinal() for d in self.index])

if method == 'values':
inds = self.index.values
# hack for DatetimeIndex, #1646
if issubclass(inds.dtype.type, np.datetime64):
Expand Down
16 changes: 16 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,22 @@ def test_frame_datetime64_handling_groupby(self):
result = df.groupby('a').first()
self.assertEqual(result['date'][3].year, 2012)

def test_series_interpolate_intraday(self):
# #1698
import pandas as pd
index = pd.date_range('1/1/2012', periods=4, freq='12D')
ts = pd.Series([0, 12, 24, 36], index)
new_index = index.append(index + pd.DateOffset(days=1)).order()

exp = ts.reindex(new_index).interpolate(method='time')

index = pd.date_range('1/1/2012', periods=4, freq='12H')
ts = pd.Series([0, 12, 24, 36], index)
new_index = index.append(index + pd.DateOffset(hours=1)).order()
result = ts.reindex(new_index).interpolate(method='time')

self.assert_(np.array_equal(result.values, exp.values))

def _simple_ts(start, end, freq='D'):
rng = date_range(start, end, freq=freq)
return Series(np.random.randn(len(rng)), index=rng)
Expand Down

0 comments on commit fdcc106

Please sign in to comment.