Skip to content

Commit 5753816

Browse files
committed
BUG: Series.interpolate bug with method='values' and datetime64[ns], close #1646
1 parent f5fb709 commit 5753816

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pandas 0.8.1
9696
- Fix use of string alias timestamps with tz-aware time series (#1647)
9797
- Fix Series.max/min and Series.describe on len-0 series (#1650)
9898
- Handle None values in dict passed to concat (#1649)
99+
- Fix Series.interpolate with method='values' and DatetimeIndex (#1646)
99100

100101
pandas 0.8.0
101102
============

pandas/core/series.py

+4
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,10 @@ def interpolate(self, method='linear'):
25202520
inds = np.array([d.toordinal() for d in self.index])
25212521
elif method == 'values':
25222522
inds = self.index.values
2523+
# hack for DatetimeIndex, #1646
2524+
if issubclass(inds.dtype.type, np.datetime64):
2525+
inds = inds.view(np.int64)
2526+
25232527
if inds.dtype == np.object_:
25242528
inds = lib.maybe_convert_objects(inds)
25252529
else:

pandas/io/tests/test_yahoo.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas.io.data as pd
99
import nose
1010
from pandas.util.testing import network
11+
import urllib2
1112

1213
class TestYahoo(unittest.TestCase):
1314

@@ -18,13 +19,23 @@ def test_yahoo(self):
1819
# yahoo
1920
start = datetime(2010,1,1)
2021
end = datetime(2012,1,24)
21-
self.assertEquals(
22-
pd.DataReader("F", 'yahoo', start, end)['Close'][-1],
23-
12.82)
2422

25-
self.assertRaises(
26-
Exception,
27-
lambda: pd.DataReader("NON EXISTENT TICKER", 'yahoo', start, end))
23+
try:
24+
self.assertEquals(
25+
pd.DataReader("F", 'yahoo', start, end)['Close'][-1],
26+
12.82)
27+
28+
self.assertRaises(
29+
Exception,
30+
lambda: pd.DataReader("NON EXISTENT TICKER", 'yahoo',
31+
start, end))
32+
except urllib2.URLError:
33+
try:
34+
urllib2.urlopen('http://www.google.com')
35+
except urllib2.URLError:
36+
raise nose.SkipTest
37+
else:
38+
raise
2839

2940
if __name__ == '__main__':
3041
import nose

pandas/tseries/tests/test_timeseries.py

+9
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,15 @@ def test_constructor_int64_nocopy(self):
10261026
arr[50:100] = -1
10271027
self.assert_((index.asi8[50:100] != -1).all())
10281028

1029+
def test_series_interpolate_method_values(self):
1030+
# #1646
1031+
ts = _simple_ts('1/1/2000', '1/20/2000')
1032+
ts[::2] = np.nan
1033+
1034+
result = ts.interpolate(method='values')
1035+
exp = ts.interpolate()
1036+
assert_series_equal(result, exp)
1037+
10291038
def _simple_ts(start, end, freq='D'):
10301039
rng = date_range(start, end, freq=freq)
10311040
return Series(np.random.randn(len(rng)), index=rng)

0 commit comments

Comments
 (0)