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

from datetime import datetime
import pandas as pd
from pandas import Timestamp

df = pd.DataFrame(
        {'Betrag': {0: '-30,60', 1: '-45,00', 2: '-582,00'},
        'Buchungsart': {0: 'Überweisung', 1: 'Überweisung', 2: 'Überweisung'},
        'Dokumentdatum': {0: Timestamp('2024-01-25 00:00:00'),
                          1: Timestamp('2024-01-01 00:00:00'),
                          2: Timestamp('2024-01-08 00:00:00')},
        'Fälligkeitsdatum': {0: Timestamp('2024-01-25 00:00:00'),
                             1: Timestamp('2024-01-31 00:00:00'),
                             2: Timestamp('2024-02-01 00:00:00')},
        'Genauigkeit Betrag': {0: 'fix', 1: 'fix', 2: 'fix'},
        'Genauigkeit Datum': {0: 'fix', 1: 'fix', 2: 'fix'},
        'Kategorie': {0: 'Kategorie1',
                      1: 'Kategorie2',
                      2: 'Kategorie3'},
        'Kontrahent': {0: 'Kontrahent1', 1: 'Kontrahent2', 2: 'Kontrahent3'},
        'Kontrahent BIC': {0: '', 1: '', 2: ''},
        'Kontrahent IBAN': {0: 'XX000000000000000001',
                            1: 'XX000000000000000002',
                            2: 'XX000000000000000003'},
        'Kostenträger': {0: 'Ort',
                         1: 'Person',
                         2: 'Gegenstand'},
        'Mandatsreferenz': {0: '', 1: '', 2: ''},
        'Produkt': {0: 'Produkt1',
                    1: 'Produkt2',
                    2: 'Produkt3'},
        'Zahlungsreferenz/SEPA Creditor Id': {0: '3276842762347',
                                              1: '327684276234712',
                                              2: '32768427'},
        'erledigt': {0: '', 1: '', 2: ''},
        'gesendet am': {0: Timestamp('2024-01-14 00:00:00'), 1: None, 2: None},
        'laufende Summe': {0: '1.659,09', 1: '1.614,09', 2: '1.032,09'}}
        )

aktuelles_Jahr = datetime.today().year
aktueller_Monat = datetime.today().month

df_nicht_erfasst = df.query("Fälligkeitsdatum.dt.year == @aktuelles_Jahr and "
                    "Fälligkeitsdatum.dt.month == @aktueller_Monat and "
                    "Buchungsart == 'Überweisung' and "
                    "`gesendet am` == ''")

Issue Description

After updating to pandas 2.2, when I run a program with the last line above, there is now the following warning displayed:

FutureWarning: The behavior of 'isin' with dtype=datetime64[ns] and castable values (e.g. strings) is deprecated. In a future version, these will not be considered matching by isin. Explicitly cast to the appropriate dtype before calling isin instead.

However, the line referenced in the warning does not contain any isin function.

Also, I am unclear what I am now supposed to do to remedy this warning.

Expected Behavior

Clarification about why this is about isinand pointer to explanation + example about how to change the code

Installed Versions

/Users/guy/Library/Python/3.11/lib/python/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.11.7.final.0 python-bits : 64 OS : Darwin OS-release : 17.7.0 Version : Darwin Kernel Version 17.7.0: Fri Oct 30 13:34:27 PDT 2020; root:xnu-4570.71.82.8~1/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : de_AT.UTF-8 LANG : de_AT.UTF-8 LOCALE : de_AT.UTF-8 pandas : 2.2.0 numpy : 1.26.3 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 69.0.3 pip : 23.3.2 Cython : 3.0.8 pytest : 7.4.4 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : 3.1.9 lxml.etree : 5.1.0 html5lib : 1.1 pymysql : 1.4.6 psycopg2 : None jinja2 : 3.1.3 IPython : 8.20.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 13.0.0.dev0+gb7d2f7ffc.d20231220 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.11.4 sqlalchemy : 2.0.25 tables : None tabulate : 0.9.0 xarray : None xlrd : 2.0.1 zstandard : 0.22.0 tzdata : 2023.4 qtpy : 2.4.1 pyqt5 : None

Comment From: phofl

Can you please provide a reproducer? The DataFrame is missing

Comment From: workflowsguy

@phofl, thank you. I have updated the code example.

Comment From: lithomas1

Thanks for the reproducer - I can reproduce on my laptop.

Tentatively milestoning for 2.2.1.

Comment From: lopof

The problem is "'gesendet am' == ''". Where you want to filter on "None" values, which are stored as NaT.

Could be fixed with

df_nicht_erfasst = df.query("Fälligkeitsdatum.dt.year == @aktuelles_Jahr and "
                    "Fälligkeitsdatum.dt.month == @aktueller_Monat and "
                    "Buchungsart == 'Überweisung' and "
                    "`gesendet am` == 'NaT'")

or

df_nicht_erfasst = df.query("Fälligkeitsdatum.dt.year == @aktuelles_Jahr and "
                    "Fälligkeitsdatum.dt.month == @aktueller_Monat and "
                    "Buchungsart == 'Überweisung' and "
                    "`gesendet am` != `gesendet am`")

Comment From: workflowsguy

@lopof, Thank you for looking into this.

Your first solution still gives the warning, while the second one does not.

As I have gained a little bit better understanding of the workings of pandas, I have changed the last line of the query statement to

"`gesendet am`.isnull()")

as, I think, this most clearly reflects the intention, namely filtering for scheduled transactions with a missing "sent on" date (and this also does not trigger the FutureWarning).

Comment From: lopof

@workflowsguy ah even better solution, nice. Didn't see that

Comment From: jbrockmendel

No warning on main. Can patch for 2.3.3 or close.