Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
item_transactions_df = pd.DataFrame([value.dict() for value in item_transactions])
# item_transaction_df.dtypes
# quantity_after float64
# account_id object
# item_id object
# created_at datetime64[ns]
# quantity_before float64
# id object
# timestamp datetime64[ns]
# updated_at datetime64[ns]
# dtype: object
grouped_inventory_controls_df = item_transactions_df \
.sort_values(by=["timestamp"], ascending=True) \
.groupby(by=pd.Grouper(key="timestamp", freq='1D')) \
.first()
resampled_item_transactions_df = grouped_inventory_controls_df \
.resample(request.resample) \
.sum()
Issue Description
Displayed error message:
typeerror: datetime64 type does not support sum operations
However, in version pandas==1.5.3, that error doesn't show up.
Expected Behavior
Could do group by and resample normally.
Installed Versions
Comment From: jbrockmendel
In 1.5.3 you should have gotten a warning that silently dropping non-numeric columns in reductions was deprecated. you need to exclude the datetime64 column(s) before calling .sum
Comment From: muazhari
In 1.5.3 you should have gotten a warning that silently dropping non-numeric columns in reductions was deprecated. you need to exclude the datetime64 column(s) before calling .sum
I need to process the timestamp column with the datetime64 type. How do I do that if I drop the column? Are there any other methods to do .sum() with datetime64 type columns?
Comment From: jbrockmendel
when you do this in 1.5.3 you should see the column was getting dropped before. doing .sum() with datetime64 is gibberish
Comment From: muazhari
In 1.5.3 you should have gotten a warning that silently dropping non-numeric columns in reductions was deprecated. you need to exclude the datetime64 column(s) before calling .sum
Do you mean that I need to drop datetime64 type columns first before processing it?
Comment From: jbrockmendel
before calling .sum() at least, yes
Comment From: CabartPascal
Having the same issue, looking into this since hours. How do I drop all datetime columns automatically? I have a dataset with 3000 columns and mixed datatypes of all kinds, is there no simple way to do it?
Comment From: jbrockmendel
obj.select_dtypes(exclude=dtypes_to_exclude)
Comment From: phofl
You can also set numeric_only=True
. Closing since this behaves as expected