Permalink
Browse files

ENH: add option to use Series.values to interpolate, close #1206

  • Loading branch information...
1 parent 2c1de1a commit 8526264255791e4eb22f5dc03e60d1e4d019f4ae @wesm committed May 29, 2012
View
@@ -55,7 +55,8 @@ pandas 0.8.0
DataFrame (#929, #1241)
- Add 'kde' plot kind for Series/DataFrame.plot (#1059)
- More flexible multiple function aggregation with GroupBy
- - Add pct_chagne function
+ - Add pct_change function to Series/DataFrame
+ - Add option to interpolate by Index values in Series.interpolate (#1206)
**Improvements to existing features**
View
@@ -2527,10 +2527,11 @@ def interpolate(self, method='linear'):
Parameters
----------
- method : {'linear', 'time'}
+ method : {'linear', 'time', 'values'}
Interpolation method.
- Time interpolation works on daily and higher resolution
+ 'time' interpolation works on daily and higher resolution
data to interpolate given length of interval
+ 'values' using the actual index numeric values
Returns
-------
@@ -2541,6 +2542,10 @@ def interpolate(self, method='linear'):
raise Exception('time-weighted interpolation only works'
'on TimeSeries')
inds = np.array([d.toordinal() for d in self.index])
+ elif method == 'values':
+ inds = self.index.values
+ if inds.dtype == np.object_:
+ inds = lib.maybe_convert_objects(inds)
else:
inds = np.arange(len(self))
@@ -2685,6 +2685,21 @@ def test_interpolate(self):
# try time interpolation on a non-TimeSeries
self.assertRaises(Exception, self.series.interpolate, method='time')
+ def test_interpolate_index_values(self):
+ s = Series(np.nan, index=np.sort(np.random.rand(30)))
+ s[::3] = np.random.randn(10)
+
+ vals = s.index.values.astype(float)
+
+ result = s.interpolate(method='values')
+
+ expected = s.copy()
+ bad = isnull(expected.values)
+ good = -bad
+ expected[bad] = np.interp(vals[bad], vals[good], s.values[good])
+
+ assert_series_equal(result, expected)
+
def test_weekday(self):
# Just run the function
weekdays = self.ts.weekday
@@ -1319,7 +1319,6 @@ def test_alias_equality(self):
for k, v in _offset_map.iteritems():
if v is None:
continue
- foo
self.assertEqual(k, v.copy())
def test_rule_code(self):
@@ -282,7 +282,6 @@ def test_tz_convert(self):
expected = DataFrame({'a': 1}, rng.tz_convert('UTC'))
self.assert_(result.index.tz.zone == 'UTC')
assert_frame_equal(result, expected)
- foo
df = df.T
result = df.tz_convert('utc', axis=1)

0 comments on commit 8526264

Please sign in to comment.