Skip to content

BUG AttributeError: 'DataFrameGroupBy' object has no attribute '_obj_with_exclusions' #11640

Closed
@nbonnotte

Description

@nbonnotte

I guess it will be clearer with an example. First, let's prepare the dataframe:

In [2]: df = pd.DataFrame(columns=['a','b','c','d'], data=[[1,'b1','c1',3], [1,'b2','c2',4]])

In [3]: df = df.pivot_table(index='a', columns=['b','c'], values='d').reset_index()

In [4]: df
Out[28]: 
b  a b1 b2
c    c1 c2
0  1  3  4

Now, the exception raised:

In [5]: df.groupby('a').mean()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-a830c6135818> in <module>()
----> 1 df.groupby('a').mean()

/home/nicolas/Git/pandas/pandas/core/groupby.py in mean(self)
    764             self._set_selection_from_grouper()
    765             f = lambda x: x.mean(axis=self.axis)
--> 766             return self._python_agg_general(f)
    767 
    768     def median(self):

/home/nicolas/Git/pandas/pandas/core/groupby.py in _python_agg_general(self, func, *args, **kwargs)
   1245                 output[name] = self._try_cast(values[mask], result)
   1246 
-> 1247         return self._wrap_aggregated_output(output)
   1248 
   1249     def _wrap_applied_output(self, *args, **kwargs):

/home/nicolas/Git/pandas/pandas/core/groupby.py in _wrap_aggregated_output(self, output, names)
   3529     def _wrap_aggregated_output(self, output, names=None):
   3530         agg_axis = 0 if self.axis == 1 else 1
-> 3531         agg_labels = self._obj_with_exclusions._get_axis(agg_axis)
   3532 
   3533         output_keys = self._decide_output_index(output, agg_labels)

/home/nicolas/Git/pandas/pandas/core/groupby.py in __getattr__(self, attr)
    557 
    558         raise AttributeError("%r object has no attribute %r" %
--> 559                              (type(self).__name__, attr))
    560 
    561     def __getitem__(self, key):

AttributeError: 'DataFrameGroupBy' object has no attribute '_obj_with_exclusions'

Maybe I'm doing something wrong, and it's not a bug, but then the exception raised should definitely be more explicit than a reference to an internal attribute :-)

This attribute, by the way, is (only) referenced in one file and in issue #5264. It might be connected, but the discussion is a bit long and technical.

I'll try to have a look at what's going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions