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

INSTALLED VERSIONS ------------------ commit : 478d340667831908b5b4bf09a2787a11a14560c9 python : 3.9.13.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22621 machine : AMD64 processor : Intel64 Family 6 Model 183 Stepping 1, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252 pandas : 2.0.0 numpy : 1.21.5 pytz : 2022.1 dateutil : 2.8.2 setuptools : 63.4.1 pip : 22.2.2 Cython : 0.29.32 pytest : 7.3.0 hypothesis : None sphinx : 5.0.2 blosc : None feather : None xlsxwriter : 3.0.3 lxml.etree : 4.9.1 html5lib : None pymysql : None psycopg2 : 2.9.6 jinja2 : 2.11.3 IPython : 7.31.1 pandas_datareader: None bs4 : 4.11.1 bottleneck : 1.3.5 brotli : fastparquet : None fsspec : 2022.7.1 gcsfs : None matplotlib : 3.5.2 numba : 0.55.1 numexpr : 2.8.3 odfpy : None openpyxl : 3.0.10 pandas_gbq : None pyarrow : 10.0.1 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.8.1 snappy : sqlalchemy : 1.4.41 tables : 3.6.1 tabulate : 0.8.10 xarray : 0.20.1 xlrd : 2.0.1 zstandard : None tzdata : 2022.7 qtpy : 2.2.0 pyqt5 : None

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