Skip to content

BUG: Aggregating over an integer on an empty DataFrame causes datetime64 types to convert to float64 #7649

Closed
@chrisaycock

Description

@chrisaycock

Possibly related to issue #7574:

Suppose I have a DataFrame:

In [61]: df
Out[61]:
          ref                  localtime  size
0    45361866 2014-06-25 14:11:11.753597   100
1    45361866 2014-06-25 14:11:11.753769   100
2    45361866 2014-06-25 14:11:11.754350   200
3    45361866 2014-06-25 14:11:11.756413   200
4    45361866 2014-06-25 14:18:59.442972   200
..        ...                        ...   ...
29  204286294 2014-06-25 19:43:27.770083   100
30  204286294 2014-06-25 19:43:27.771266  7036
31  216308339 2014-06-25 19:57:32.468547   100
32  216308339 2014-06-25 19:57:37.534973   200
33  216308339 2014-06-25 19:57:37.535035   300

[34 rows x 3 columns]

If I aggregate over an integer, the resulting types are as expected:

In [62]: df.groupby('ref').first().reset_index().dtypes
Out[62]:
ref                   int64
localtime    datetime64[ns]
size                  int64
dtype: object

However, if I aggregate on an empty DataFrame, then my timestamp's type is converted from datetime64 to float64:

In [63]: df.query('size>10000').groupby('ref').first().reset_index().dtypes
Out[63]:
index          int64
localtime    float64
size         float64
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions