Skip to content

Commit d97f49d

Browse files
committed
BUG: Bug in propogating metadata on resample (GH5862)
1 parent 1a0eb84 commit d97f49d

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Bug Fixes
9595
- Bug in assigning to chained series with a series via ix (:issue:`5928`)
9696
- Bug in creating an empty DataFrame, copying, then assigning (:issue:`5932`)
9797
- Bug in DataFrame.tail with empty frame (:issue:`5846`)
98+
- Bug in propogating metadata on ``resample`` (:issue:`5862`)
9899

99100
pandas 0.13.0
100101
-------------

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
25622562
axis=axis, kind=kind, loffset=loffset,
25632563
fill_method=fill_method, convention=convention,
25642564
limit=limit, base=base)
2565-
return sampler.resample(self)
2565+
return sampler.resample(self).__finalize__(self)
25662566

25672567
def first(self, offset):
25682568
"""

pandas/tests/test_generic.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def test_metadata_propagation(self):
285285
except (AttributeError):
286286
pass
287287

288-
289288
# ---------------------------
290289
# non-preserving (by default)
291290
# ---------------------------
@@ -428,6 +427,19 @@ def test_metadata_propagation_indiv(self):
428427
result = o.T
429428
self.check_metadata(o,result)
430429

430+
# resample
431+
ts = Series(np.random.rand(1000),
432+
index=date_range('20130101',periods=1000,freq='s'),
433+
name='foo')
434+
result = ts.resample('1T')
435+
self.check_metadata(ts,result)
436+
437+
result = ts.resample('1T',how='min')
438+
self.check_metadata(ts,result)
439+
440+
result = ts.resample('1T',how=lambda x: x.sum())
441+
self.check_metadata(ts,result)
442+
431443
def test_interpolate(self):
432444
ts = Series(np.arange(len(self.ts), dtype=float), self.ts.index)
433445

@@ -768,6 +780,23 @@ def test_spline(self):
768780
expected = Series([1, 2, 3, 4, 5, 6, 7])
769781
assert_series_equal(result, expected)
770782

783+
def test_metadata_propagation_indiv(self):
784+
785+
# groupby
786+
df = DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
787+
'foo', 'bar', 'foo', 'foo'],
788+
'B': ['one', 'one', 'two', 'three',
789+
'two', 'two', 'one', 'three'],
790+
'C': np.random.randn(8),
791+
'D': np.random.randn(8)})
792+
result = df.groupby('A').sum()
793+
self.check_metadata(df,result)
794+
795+
# resample
796+
df = DataFrame(np.random.randn(1000,2), index=date_range('20130101',periods=1000,freq='s'))
797+
result = df.resample('1T')
798+
self.check_metadata(df,result)
799+
771800
class TestPanel(tm.TestCase, Generic):
772801
_typ = Panel
773802
_comparator = lambda self, x, y: assert_panel_equal(x, y)

0 commit comments

Comments
 (0)