Skip to content

BUG: resample/groupby with NaT in the grouper #7227

Closed
@jreback

Description

@jreback

related to this: #6992

These are broken

In [70]: df.set_index('A').resample('M',how='count')
ValueError: month must be in 1..12

In [73]: df.groupby(pd.Grouper(freq='MS',key='A')).count()
ValueError: month must be in 1..12

Separately, this should not also return the A column

In [74]: df.dropna(how='any',subset=['A']).groupby(pd.Grouper(key='A',freq='M')).count()
Out[74]: 
            A  B
A               
2014-10-31  3  3
2014-11-30  2  2
2014-12-31  1  1
In [57]: data
Out[57]: 
0   2014-10-01
1   2014-10-01
2   2014-10-31
3   2014-11-15
4   2014-11-30
5          NaT
6   2014-12-01
dtype: datetime64[ns]

In [58]: df = DataFrame(dict(A = data, B = np.arange(len(data))))

This is a work-around

In [59]: df.dropna(how='any',subset=['A']).set_index('A').resample('M',how='count')
Out[59]: 
            B
A            
2014-10-31  3
2014-11-30  2
2014-12-31  1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugGroupbyMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateResampleresample method

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions