Skip to content

Commit 4c5f4ca

Browse files
authored
Fix pandas-dev#60494: query doesn't work on DataFrame integer column names (pandas-dev#61207)
* Fix pandas-dev#60494: query doesn't work on DataFrame integer column names * fix: removed line that ignores an integer column name from _get_cleaned_column_resolvers Also removed the changes from the previous commit, which converted integer column names to strings
1 parent 83979d6 commit 4c5f4ca

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ Other
835835
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
836836
- Bug in :meth:`DataFrame.query` where using duplicate column names led to a ``TypeError``. (:issue:`59950`)
837837
- Bug in :meth:`DataFrame.query` which raised an exception or produced incorrect results when expressions contained backtick-quoted column names containing the hash character ``#``, backticks, or characters that fall outside the ASCII range (U+0001..U+007F). (:issue:`59285`) (:issue:`49633`)
838+
- Bug in :meth:`DataFrame.query` which raised an exception when querying integer column names using backticks. (:issue:`60494`)
838839
- Bug in :meth:`DataFrame.shift` where passing a ``freq`` on a DataFrame with no columns did not shift the index correctly. (:issue:`60102`)
839840
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
840841
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)

pandas/core/generic.py

-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ def _get_cleaned_column_resolvers(self) -> dict[Hashable, Series]:
612612
v, copy=False, index=self.index, name=k, dtype=dtype
613613
).__finalize__(self)
614614
for k, v, dtype in zip(self.columns, self._iter_column_arrays(), dtypes)
615-
if not isinstance(k, int)
616615
}
617616

618617
@final

pandas/tests/frame/test_query_eval.py

+5
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,11 @@ def test_start_with_spaces(self, df):
13451345
expect = df[" A"] + df[" "]
13461346
tm.assert_series_equal(res, expect)
13471347

1348+
def test_ints(self, df):
1349+
res = df.query("`1` == 7")
1350+
expect = df[df[1] == 7]
1351+
tm.assert_frame_equal(res, expect)
1352+
13481353
def test_lots_of_operators_string(self, df):
13491354
res = df.query("` &^ :!€$?(} > <++*'' ` > 4")
13501355
expect = df[df[" &^ :!€$?(} > <++*'' "] > 4]

0 commit comments

Comments
 (0)