Skip to content

Commit

Permalink
BUG: work around ndarray.round not preserving subclasses, GH #314
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Nov 3, 2011
1 parent f009f97 commit 44ecd0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,17 @@ def _ndarray_statistic(self, funcname, dtype=None, skipna=True):

return retVal

def round(self, decimals=0, out=None):
"""
"""
result = self.values.round(decimals, out=out)
if out is None:
result = Series(result, index=self.index, name=self.name)

return result
round.__doc__ = np.ndarray.round.__doc__

def quantile(self, q=0.5):
"""
Return value at the given quantile, a la scoreatpercentile in
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@ def _check_accum_op(self, name):

self.assert_(np.array_equal(result, expected))

def test_round(self):
# numpy.round doesn't preserve metadata, probably a numpy bug,
# re: GH #314
result = np.round(self.ts, 2)
expected = Series(np.round(self.ts.values, 2), index=self.ts.index)
assert_series_equal(result, expected)
self.assertEqual(result.name, self.ts.name)

def test_prod_numpy16_bug(self):
s = Series([1., 1., 1.] , index=range(3))
result = s.prod()
Expand Down

0 comments on commit 44ecd0f

Please sign in to comment.