-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
df.head()[['Country','GDP']]
Country GDP
0 Abkhazia NaN
1 Afghanistan 1.946902e+10
2 Albania 1.186387e+10
3 Algeria 1.590490e+11
4 American Samoa NaN
un = ['Afghanistan',
'Albania',
'Algeria',
'Andorra',
'Angola',
'Antigua and Barbuda', ... # etc. to Zimbabwe
]
df.query(f"Country in {un}")
#
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 df.query(f'` in {un}')
File ~/anaconda3/envs/py13/lib/python3.13/site-packages/pandas/core/frame.py:4834, in DataFrame.query(self, expr, inplace, **kwargs)
4832 kwargs["level"] = kwargs.pop("level", 0) + 1
4833 kwargs["target"] = None
-> 4834 res = self.eval(expr, **kwargs)
4836 try:
4837 result = self.loc[res]
File ~/anaconda3/envs/py13/lib/python3.13/site-packages/pandas/core/frame.py:4954, in DataFrame.eval(self, expr, inplace, **kwargs)
4952 kwargs["level"] = kwargs.pop("level", 0) + 1
4953 index_resolvers = self._get_index_resolvers()
-> 4954 column_resolvers = self._get_cleaned_column_resolvers()
4955 resolvers = column_resolvers, index_resolvers
4956 if "target" not in kwargs:
File ~/anaconda3/envs/py13/lib/python3.13/site-packages/pandas/core/generic.py:663, in NDFrame._get_cleaned_column_resolvers(self)
659 if isinstance(self, ABCSeries):
660 return {clean_column_name(self.name): self}
662 return {
--> 663 clean_column_name(k): Series(
664 v, copy=False, index=self.index, name=k, dtype=self.dtypes[k]
665 ).__finalize__(self)
666 for k, v in zip(self.columns, self._iter_column_arrays())
667 if not isinstance(k, int)
668 }
File ~/anaconda3/envs/py13/lib/python3.13/site-packages/pandas/core/series.py:496, in Series.__init__(self, data, index, dtype, name, copy, fastpath)
493 index = ensure_index(index)
495 if dtype is not None:
--> 496 dtype = self._validate_dtype(dtype)
498 if data is None:
499 index = index if index is not None else default_index(0)
File ~/anaconda3/envs/py13/lib/python3.13/site-packages/pandas/core/generic.py:519, in NDFrame._validate_dtype(cls, dtype)
517 """validate the passed dtype"""
518 if dtype is not None:
--> 519 dtype = pandas_dtype(dtype)
521 # a compound dtype
522 if dtype.kind == "V":
File ~/anaconda3/envs/py13/lib/python3.13/site-packages/pandas/core/dtypes/common.py:1684, in pandas_dtype(dtype)
1682 return npdtype
1683 elif npdtype.kind == "O":
-> 1684 raise TypeError(f"dtype '{dtype}' not understood")
1686 return npdtype
TypeError: dtype ' object
object
object
object
object
object
object
object
object
dtype: object' not understoodIssue Description
Use Pandas query to filter a pandas dataframe column of strings based on if they are present in a list of strings fails.
Expected Behavior
Returns a dataframe with only the rows where the values in a column are present in a list.
Installed Versions
INSTALLED VERSIONS
commit : 9c8bc3e
python : 3.13.9
python-bits : 64
OS : Linux
OS-release : 6.12.48+deb13-amd64
Version : #1 SMP PREEMPT_DYNAMIC Debian 6.12.48-1 (2025-09-20)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.3.3
numpy : 2.3.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.2
Cython : None
sphinx : None
IPython : 9.5.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.14.2
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.10.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.7
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.16.3
sqlalchemy : 2.0.44
tables : None
tabulate : None
xarray : None
xlrd : 2.0.2
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None