Skip to content

DataFrame.groupby fails with MultiIndex containing pd.NaT #9236

Closed
@stevenmanton

Description

@stevenmanton

It seems that the groupby operation fails when the row index is a MultiIndex containing NaT values. For example, the following code fails (v0.15.2) with TypeError: 'numpy.ndarray' object is not callable:

midx = pd.MultiIndex(levels=[[pd.NaT, pd.datetime(2012,1,2), 
                     pd.datetime(2012,1,3)], ['a', 'b']],
                     labels=[[0, 1, 1, 2], [0, 0, 1, 0]], names=['date', None])
df = pd.Series(pd.np.random.rand(4), index=midx)
df.groupby(level=1)

However, it seems as though np.nan values are handled properly:

midx = pd.MultiIndex(levels=[[pd.np.nan, 10, 20], ['a', 'b']],
                     labels=[[0, 1, 1, 2], [0, 0, 1, 0]], names=['date', None])
df = pd.Series(pd.np.random.rand(4), index=midx)
df.groupby(level=1)

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