Skip to content

Commit 8526264

Browse files
committed
ENH: add option to use Series.values to interpolate, close #1206
1 parent 2c1de1a commit 8526264

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

RELEASE.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ pandas 0.8.0
5555
DataFrame (#929, #1241)
5656
- Add 'kde' plot kind for Series/DataFrame.plot (#1059)
5757
- More flexible multiple function aggregation with GroupBy
58-
- Add pct_chagne function
58+
- Add pct_change function to Series/DataFrame
59+
- Add option to interpolate by Index values in Series.interpolate (#1206)
5960

6061
**Improvements to existing features**
6162

pandas/core/series.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2527,10 +2527,11 @@ def interpolate(self, method='linear'):
25272527
25282528
Parameters
25292529
----------
2530-
method : {'linear', 'time'}
2530+
method : {'linear', 'time', 'values'}
25312531
Interpolation method.
2532-
Time interpolation works on daily and higher resolution
2532+
'time' interpolation works on daily and higher resolution
25332533
data to interpolate given length of interval
2534+
'values' using the actual index numeric values
25342535
25352536
Returns
25362537
-------
@@ -2541,6 +2542,10 @@ def interpolate(self, method='linear'):
25412542
raise Exception('time-weighted interpolation only works'
25422543
'on TimeSeries')
25432544
inds = np.array([d.toordinal() for d in self.index])
2545+
elif method == 'values':
2546+
inds = self.index.values
2547+
if inds.dtype == np.object_:
2548+
inds = lib.maybe_convert_objects(inds)
25442549
else:
25452550
inds = np.arange(len(self))
25462551

pandas/tests/test_series.py

+15
Original file line numberDiff line numberDiff line change
@@ -2685,6 +2685,21 @@ def test_interpolate(self):
26852685
# try time interpolation on a non-TimeSeries
26862686
self.assertRaises(Exception, self.series.interpolate, method='time')
26872687

2688+
def test_interpolate_index_values(self):
2689+
s = Series(np.nan, index=np.sort(np.random.rand(30)))
2690+
s[::3] = np.random.randn(10)
2691+
2692+
vals = s.index.values.astype(float)
2693+
2694+
result = s.interpolate(method='values')
2695+
2696+
expected = s.copy()
2697+
bad = isnull(expected.values)
2698+
good = -bad
2699+
expected[bad] = np.interp(vals[bad], vals[good], s.values[good])
2700+
2701+
assert_series_equal(result, expected)
2702+
26882703
def test_weekday(self):
26892704
# Just run the function
26902705
weekdays = self.ts.weekday

pandas/tseries/tests/test_offsets.py

-1
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,6 @@ def test_alias_equality(self):
13191319
for k, v in _offset_map.iteritems():
13201320
if v is None:
13211321
continue
1322-
foo
13231322
self.assertEqual(k, v.copy())
13241323

13251324
def test_rule_code(self):

pandas/tseries/tests/test_timezones.py

-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ def test_tz_convert(self):
282282
expected = DataFrame({'a': 1}, rng.tz_convert('UTC'))
283283
self.assert_(result.index.tz.zone == 'UTC')
284284
assert_frame_equal(result, expected)
285-
foo
286285

287286
df = df.T
288287
result = df.tz_convert('utc', axis=1)

0 commit comments

Comments
 (0)