Repository: pandas-dev/pandas

Issue:
DataFrame.groupby.fillna for axis=1, no filling happens
groupby.fillna not working along column axis.

The bug exists for 15.1 and 15.2
Works for 13.1

```
import pandas as pd
import numpy as np

print pd.__version__

test = pd.DataFrame(index=pd.MultiIndex.from_product([['value1','value2'],pd.date_range('2014-01-01','2014-01-06')]),
                    columns=pd.Index(['1','2'], name='id'))
test['1'] = [np.nan, 1, np.nan, np.nan, 11, np.nan, np.nan, 2, np.nan, np.nan, 22, np.nan]
test['2'] = [np.nan, 3, np.nan, np.nan, 33, np.nan, np.nan, 4, np.nan, np.nan, 44, np.nan]
testT = test.T

print '*' * 30
print test
print '*' * 30
print test.groupby(level=0, axis=0).fillna(method='ffill')
print '*' * 30
print testT
print '*' * 30
print testT.groupby(level=0, axis=1).fillna(method='ffill')
print '*' * 30
```



Discussion:

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -2252,7 +2252,7 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,
     #----------------------------------------------------------------------
     # Filling NA's
 
-    def fillna(self, value=None, method=None, axis=0, inplace=False,
+    def fillna(self, value=None, method=None, axis=None, inplace=False,
                limit=None, downcast=None):
         """
         Fill NA/NaN values using the specified method
@@ -2295,6 +2295,10 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
                             'you passed a "{0}"'.format(type(value).__name__))
         self._consolidate_inplace()
 
+        # set the default here, so functions examining the signaure
+        # can detect if something was set (e.g. in groupby) (GH9221)
+        if axis is None:
+            axis = 0
         axis = self._get_axis_number(axis)
         method = com._clean_fill_method(method)
 
@@ -2383,12 +2387,12 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
         else:
             return self._constructor(new_data).__finalize__(self)
 
-    def ffill(self, axis=0, inplace=False, limit=None, downcast=None):
+    def ffill(self, axis=None, inplace=False, limit=None, downcast=None):
         "Synonym for NDFrame.fillna(method='ffill')"
         return self.fillna(method='ffill', axis=axis, inplace=inplace,
                            limit=limit, downcast=downcast)
 
-    def bfill(self, axis=0, inplace=False, limit=None, downcast=None):
+    def bfill(self, axis=None, inplace=False, limit=None, downcast=None):
         "Synonym for NDFrame.fillna(method='bfill')"
         return self.fillna(method='bfill', axis=axis, inplace=inplace,
                            limit=limit, downcast=downcast)


Test patch:
diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py
--- a/pandas/tests/test_groupby.py
+++ b/pandas/tests/test_groupby.py
@@ -4322,6 +4322,21 @@ def test_filter_non_bool_raises(self):
         with tm.assertRaisesRegexp(TypeError, 'filter function returned a.*'):
             df.groupby('a').filter(lambda g: g.c.mean())
 
+    def test_fill_constistency(self):
+
+        # GH9221
+        # pass thru keyword arguments to the generated wrapper
+        # are set if the passed kw is None (only)
+        df = DataFrame(index=pd.MultiIndex.from_product([['value1','value2'],
+                                                         date_range('2014-01-01','2014-01-06')]),
+                       columns=Index(['1','2'], name='id'))
+        df['1'] = [np.nan, 1, np.nan, np.nan, 11, np.nan, np.nan, 2, np.nan, np.nan, 22, np.nan]
+        df['2'] = [np.nan, 3, np.nan, np.nan, 33, np.nan, np.nan, 4, np.nan, np.nan, 44, np.nan]
+
+        expected = df.groupby(level=0, axis=0).fillna(method='ffill')
+        result = df.T.groupby(level=0, axis=1).fillna(method='ffill').T
+        assert_frame_equal(result, expected)
+
     def test_index_label_overlaps_location(self):
         # checking we don't have any label/location confusion in the
         # the wake of GH5375