Skip to content

Commit e64328e

Browse files
committed
Merge pull request #9222 from jreback/grouper
BUG: Bug in using grouper functions that need passed thru arguments (GH9221)
2 parents e2b014c + a868cba commit e64328e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

doc/source/whatsnew/v0.16.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Bug Fixes
142142

143143

144144

145-
145+
- Bug in using grouper functions that need passed thru arguments (e.g. axis), when using wrapped function (e.g. ``fillna``), (:issue:`9221`)
146146

147147
- DataFrame now properly supports simultaneous ``copy`` and ``dtype`` arguments in constructor (:issue:`9099`)
148148
- Bug in read_csv when using skiprows on a file with CR line endings with the c engine. (:issue:`9079`)

pandas/core/generic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,
22522252
#----------------------------------------------------------------------
22532253
# Filling NA's
22542254

2255-
def fillna(self, value=None, method=None, axis=0, inplace=False,
2255+
def fillna(self, value=None, method=None, axis=None, inplace=False,
22562256
limit=None, downcast=None):
22572257
"""
22582258
Fill NA/NaN values using the specified method
@@ -2295,6 +2295,10 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
22952295
'you passed a "{0}"'.format(type(value).__name__))
22962296
self._consolidate_inplace()
22972297

2298+
# set the default here, so functions examining the signaure
2299+
# can detect if something was set (e.g. in groupby) (GH9221)
2300+
if axis is None:
2301+
axis = 0
22982302
axis = self._get_axis_number(axis)
22992303
method = com._clean_fill_method(method)
23002304

@@ -2383,12 +2387,12 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
23832387
else:
23842388
return self._constructor(new_data).__finalize__(self)
23852389

2386-
def ffill(self, axis=0, inplace=False, limit=None, downcast=None):
2390+
def ffill(self, axis=None, inplace=False, limit=None, downcast=None):
23872391
"Synonym for NDFrame.fillna(method='ffill')"
23882392
return self.fillna(method='ffill', axis=axis, inplace=inplace,
23892393
limit=limit, downcast=downcast)
23902394

2391-
def bfill(self, axis=0, inplace=False, limit=None, downcast=None):
2395+
def bfill(self, axis=None, inplace=False, limit=None, downcast=None):
23922396
"Synonym for NDFrame.fillna(method='bfill')"
23932397
return self.fillna(method='bfill', axis=axis, inplace=inplace,
23942398
limit=limit, downcast=downcast)

pandas/tests/test_groupby.py

+15
Original file line numberDiff line numberDiff line change
@@ -4322,6 +4322,21 @@ def test_filter_non_bool_raises(self):
43224322
with tm.assertRaisesRegexp(TypeError, 'filter function returned a.*'):
43234323
df.groupby('a').filter(lambda g: g.c.mean())
43244324

4325+
def test_fill_constistency(self):
4326+
4327+
# GH9221
4328+
# pass thru keyword arguments to the generated wrapper
4329+
# are set if the passed kw is None (only)
4330+
df = DataFrame(index=pd.MultiIndex.from_product([['value1','value2'],
4331+
date_range('2014-01-01','2014-01-06')]),
4332+
columns=Index(['1','2'], name='id'))
4333+
df['1'] = [np.nan, 1, np.nan, np.nan, 11, np.nan, np.nan, 2, np.nan, np.nan, 22, np.nan]
4334+
df['2'] = [np.nan, 3, np.nan, np.nan, 33, np.nan, np.nan, 4, np.nan, np.nan, 44, np.nan]
4335+
4336+
expected = df.groupby(level=0, axis=0).fillna(method='ffill')
4337+
result = df.T.groupby(level=0, axis=1).fillna(method='ffill').T
4338+
assert_frame_equal(result, expected)
4339+
43254340
def test_index_label_overlaps_location(self):
43264341
# checking we don't have any label/location confusion in the
43274342
# the wake of GH5375

0 commit comments

Comments
 (0)