Skip to content

BUG: Bug in propogating metadata on resample (GH5862) #5942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Bug Fixes
- Bug in assigning to chained series with a series via ix (:issue:`5928`)
- Bug in creating an empty DataFrame, copying, then assigning (:issue:`5932`)
- Bug in DataFrame.tail with empty frame (:issue:`5846`)
- Bug in propogating metadata on ``resample`` (:issue:`5862`)

pandas 0.13.0
-------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
axis=axis, kind=kind, loffset=loffset,
fill_method=fill_method, convention=convention,
limit=limit, base=base)
return sampler.resample(self)
return sampler.resample(self).__finalize__(self)

def first(self, offset):
"""
Expand Down
31 changes: 30 additions & 1 deletion pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def test_metadata_propagation(self):
except (AttributeError):
pass


# ---------------------------
# non-preserving (by default)
# ---------------------------
Expand Down Expand Up @@ -428,6 +427,19 @@ def test_metadata_propagation_indiv(self):
result = o.T
self.check_metadata(o,result)

# resample
ts = Series(np.random.rand(1000),
index=date_range('20130101',periods=1000,freq='s'),
name='foo')
result = ts.resample('1T')
self.check_metadata(ts,result)

result = ts.resample('1T',how='min')
self.check_metadata(ts,result)

result = ts.resample('1T',how=lambda x: x.sum())
self.check_metadata(ts,result)

def test_interpolate(self):
ts = Series(np.arange(len(self.ts), dtype=float), self.ts.index)

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

def test_metadata_propagation_indiv(self):

# groupby
df = DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.random.randn(8)})
result = df.groupby('A').sum()
self.check_metadata(df,result)

# resample
df = DataFrame(np.random.randn(1000,2), index=date_range('20130101',periods=1000,freq='s'))
result = df.resample('1T')
self.check_metadata(df,result)

class TestPanel(tm.TestCase, Generic):
_typ = Panel
_comparator = lambda self, x, y: assert_panel_equal(x, y)
Expand Down