Skip to content
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

BUG: median() not correctly handling non-float null values (fixes #10… #10072

Merged
merged 1 commit into from
May 7, 2015
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/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,4 @@ Bug Fixes
- Google BigQuery connector now imports dependencies on a per-method basis.(:issue:`9713`)
- Updated BigQuery connector to no longer use deprecated ``oauth2client.tools.run()`` (:issue:`8327`)
- Bug in subclassed ``DataFrame``. It may not return the correct class, when slicing or subsetting it. (:issue:`9632`)
- BUG in median() where non-float null values are not handled correctly (:issue:`10040`)
1 change: 1 addition & 0 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def get_median(x):

if values.dtype != np.float64:
values = values.astype('f8')
values[mask] = np.nan

if axis is None:
values = values.ravel()
Expand Down
10 changes: 9 additions & 1 deletion pandas/tseries/tests/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def test_timedelta_ops(self):
self.assertEqual(result, expected)

result = td.median()
expected = to_timedelta('00:00:08')
expected = to_timedelta('00:00:09')
self.assertEqual(result, expected)

result = td.to_frame().median()
Expand All @@ -641,6 +641,14 @@ def test_timedelta_ops(self):
for op in ['skew','kurt','sem','var','prod']:
self.assertRaises(TypeError, lambda : getattr(td,op)())

# GH 10040
# make sure NaT is properly handled by median()
s = Series([Timestamp('2015-02-03'), Timestamp('2015-02-07')])
self.assertEqual(s.diff().median(), timedelta(days=4))

s = Series([Timestamp('2015-02-03'), Timestamp('2015-02-07'), Timestamp('2015-02-15')])
self.assertEqual(s.diff().median(), timedelta(days=6))

def test_timedelta_ops_scalar(self):
# GH 6808
base = pd.to_datetime('20130101 09:01:12.123456')
Expand Down