Skip to content

Commit

Permalink
BUG: raise exception in DataFrame.fillna when axis=1 and pass dict/Se…
Browse files Browse the repository at this point in the history
…ries. close #1485
  • Loading branch information
wesm committed Jun 19, 2012
1 parent 7bc6455 commit 7b484e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,11 @@ def fillna(self, value=None, method='pad', axis=0, inplace=False,
if len(self.columns) == 0:
return self
if isinstance(value, (dict, Series)):
if axis == 1:
raise NotImplementedError('Currently only can fill '
'with dict/Series column '
'by column')

result = self if inplace else self.copy()
for k, v in value.iteritems():
if k not in result:
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import cPickle as pickle
import operator
import os
import sys
import unittest

import nose

from numpy import random, nan
from numpy.random import randn, randint
from numpy.random import randn
import numpy as np
import numpy.ma as ma

Expand Down Expand Up @@ -3868,6 +3867,9 @@ def test_fillna_dict_series(self):
expected = df.fillna(df.max().to_dict())
assert_frame_equal(result, expected)

# disable this for now
self.assertRaises(Exception, df.fillna, df.max(1), axis=1)

def test_fillna_columns(self):
df = DataFrame(np.random.randn(10, 10))
df.values[:, ::2] = np.nan
Expand Down

0 comments on commit 7b484e0

Please sign in to comment.