Skip to content

Commit

Permalink
Backport PR pandas-dev#57488: REGR: query raising for all NaT in obje…
Browse files Browse the repository at this point in the history
…ct column
  • Loading branch information
phofl authored and meeseeksmachine committed Feb 19, 2024
1 parent 6766c92 commit 805f01d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Fixed regressions
- Fixed regression in :meth:`DataFrame.loc` which was unnecessarily throwing "incompatible dtype warning" when expanding with partial row indexer and multiple columns (see `PDEP6 <https://pandas.pydata.org/pdeps/0006-ban-upcasting.html>`_) (:issue:`56503`)
- Fixed regression in :meth:`DataFrame.map` with ``na_action="ignore"`` not being respected for NumPy nullable and :class:`ArrowDtypes` (:issue:`57316`)
- Fixed regression in :meth:`DataFrame.merge` raising ``ValueError`` for certain types of 3rd-party extension arrays (:issue:`57316`)
- Fixed regression in :meth:`DataFrame.query` with all ``NaT`` column with object dtype (:issue:`57068`)
- Fixed regression in :meth:`DataFrame.shift` raising ``AssertionError`` for ``axis=1`` and empty :class:`DataFrame` (:issue:`57301`)
- Fixed regression in :meth:`DataFrame.sort_index` not producing a stable sort for a index with duplicates (:issue:`57151`)
- Fixed regression in :meth:`DataFrame.to_dict` with ``orient='list'`` and datetime or timedelta types returning integers (:issue:`54824`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def _get_cleaned_column_resolvers(self) -> dict[Hashable, Series]:

return {
clean_column_name(k): Series(
v, copy=False, index=self.index, name=k
v, copy=False, index=self.index, name=k, dtype=self.dtypes[k]
).__finalize__(self)
for k, v in zip(self.columns, self._iter_column_arrays())
if not isinstance(k, int)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,3 +1415,11 @@ def test_query_ea_equality_comparison(self, dtype, engine):
}
)
tm.assert_frame_equal(result, expected)

def test_all_nat_in_object(self):
# GH#57068
now = pd.Timestamp.now("UTC") # noqa: F841
df = DataFrame({"a": pd.to_datetime([None, None], utc=True)}, dtype=object)
result = df.query("a > @now")
expected = DataFrame({"a": []}, dtype=object)
tm.assert_frame_equal(result, expected)

0 comments on commit 805f01d

Please sign in to comment.