nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pandas-dev/pandas
Pull request #57467 (2024-02-17 01:16:24)

PERF: RangeIndex.append returns a RangeIndex when possible
Discovered in https://github.com/pandas-dev/pandas/pull/57441

datapythonista: This looks good, do you want to fix the conflict here @mroeschke 

Patch:
diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst
index 7802ef4798..157b87c93e 100644
--- a/doc/source/whatsnew/v3.0.0.rst
+++ b/doc/source/whatsnew/v3.0.0.rst
@@ -245,6 +245,7 @@ Removal of prior version deprecations/changes
 
 Performance improvements
 ~~~~~~~~~~~~~~~~~~~~~~~~
+- :meth:`RangeIndex.append` returns a :class:`RangeIndex` instead of a :class:`Index` when appending values that could continue the :class:`RangeIndex` (:issue:`57467`)
 - :meth:`Series.str.extract` returns a :class:`RangeIndex` columns instead of an :class:`Index` column when possible (:issue:`57542`)
 - Performance improvement in :class:`DataFrame` when ``data`` is a ``dict`` and ``columns`` is specified (:issue:`24368`)
 - Performance improvement in :meth:`DataFrame.join` for sorted but non-unique indexes (:issue:`56941`)
diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py
index 09d635b53c..0781a86e5d 100644
--- a/pandas/core/indexes/range.py
+++ b/pandas/core/indexes/range.py
@@ -989,7 +989,10 @@ class RangeIndex(Index):
         indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Index([0,1,2,4,5], dtype='int64')
         """
         if not all(isinstance(x, RangeIndex) for x in indexes):
-            return super()._concat(indexes, name)
+            result = super()._concat(indexes, name)
+            if result.dtype.kind == "i":
+                return self._shallow_copy(result._values)
+            return result
 
         elif len(indexes) == 1:
             return indexes[0]


Test patch:
diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py
index 898548d1cc..8c24ce5d69 100644
--- a/pandas/tests/indexes/ranges/test_range.py
+++ b/pandas/tests/indexes/ranges/test_range.py
@@ -608,6 +608,20 @@ class TestRangeIndex:
         tm.assert_index_equal(result, expected)
 
 
+def test_append_non_rangeindex_return_rangeindex():
+    ri = RangeIndex(1)
+    result = ri.append(Index([1]))
+    expected = RangeIndex(2)
+    tm.assert_index_equal(result, expected, exact=True)
+
+
+def test_append_non_rangeindex_return_index():
+    ri = RangeIndex(1)
+    result = ri.append(Index([1, 3, 4]))
+    expected = Index([0, 1, 3, 4])
+    tm.assert_index_equal(result, expected, exact=True)
+
+
 def test_reindex_returns_rangeindex():
     ri = RangeIndex(2, name="foo")
     result, result_indexer = ri.reindex([1, 2, 3])
Repository: pandas-dev/pandas
Pull request #57515 (2024-02-19 23:36:40)

Backport PR #57488 on branch 2.2.x (REGR: query raising for all NaT in object column)
Backport PR #57488: REGR: query raising for all NaT in object column


Patch:
diff --git a/doc/source/whatsnew/v2.2.1.rst b/doc/source/whatsnew/v2.2.1.rst
index e1da0af59b..6c6a37b2b2 100644
--- a/doc/source/whatsnew/v2.2.1.rst
+++ b/doc/source/whatsnew/v2.2.1.rst
@@ -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`)
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
index 62dd0c3bf0..0ec1717328 100644
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -657,7 +657,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
 
         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)


Test patch:
diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py
index a498296e09..2c807c7258 100644
--- a/pandas/tests/frame/test_query_eval.py
+++ b/pandas/tests/frame/test_query_eval.py
@@ -1415,3 +1415,11 @@ class TestDataFrameQueryBacktickQuoting:
             }
         )
         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)
Repository: pandas-dev/pandas
Pull request #57892 (2024-03-18 17:36:30)

CI: xfail Pyarrow slicing test
https://github.com/apache/arrow/issues/40642

mroeschke: Since the pyarrow nightly build is green, going to merge

Patch:
diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py
index 1c08df80df..caa00b205a 100644
--- a/pandas/compat/__init__.py
+++ b/pandas/compat/__init__.py
@@ -31,6 +31,7 @@ from pandas.compat.pyarrow import (
     pa_version_under13p0,
     pa_version_under14p0,
     pa_version_under14p1,
+    pa_version_under16p0,
 )
 
 if TYPE_CHECKING:
@@ -187,6 +188,7 @@ __all__ = [
     "pa_version_under13p0",
     "pa_version_under14p0",
     "pa_version_under14p1",
+    "pa_version_under16p0",
     "IS64",
     "ISMUSL",
     "PY310",
diff --git a/pandas/compat/pyarrow.py b/pandas/compat/pyarrow.py
index 5c9e885f8e..5a96e5a4cc 100644
--- a/pandas/compat/pyarrow.py
+++ b/pandas/compat/pyarrow.py
@@ -15,6 +15,7 @@ try:
     pa_version_under14p0 = _palv < Version("14.0.0")
     pa_version_under14p1 = _palv < Version("14.0.1")
     pa_version_under15p0 = _palv < Version("15.0.0")
+    pa_version_under16p0 = _palv < Version("16.0.0")
 except ImportError:
     pa_version_under10p1 = True
     pa_version_under11p0 = True
@@ -23,3 +24,4 @@ except ImportError:
     pa_version_under14p0 = True
     pa_version_under14p1 = True
     pa_version_under15p0 = True
+    pa_version_under16p0 = True


Test patch:
diff --git a/pandas/tests/indexes/object/test_indexing.py b/pandas/tests/indexes/object/test_indexing.py
index 039836da75..34cc8eab4d 100644
--- a/pandas/tests/indexes/object/test_indexing.py
+++ b/pandas/tests/indexes/object/test_indexing.py
@@ -7,6 +7,7 @@ from pandas._libs.missing import (
     NA,
     is_matching_na,
 )
+from pandas.compat import pa_version_under16p0
 import pandas.util._test_decorators as td
 
 import pandas as pd
@@ -201,7 +202,16 @@ class TestSliceLocs:
             (pd.IndexSlice["m":"m":-1], ""),  # type: ignore[misc]
         ],
     )
-    def test_slice_locs_negative_step(self, in_slice, expected, dtype):
+    def test_slice_locs_negative_step(self, in_slice, expected, dtype, request):
+        if (
+            not pa_version_under16p0
+            and dtype == "string[pyarrow_numpy]"
+            and in_slice == slice("a", "a", -1)
+        ):
+            request.applymarker(
+                pytest.mark.xfail(reason="https://github.com/apache/arrow/issues/40642")
+            )
+
         index = Index(list("bcdxy"), dtype=dtype)
 
         s_start, s_stop = index.slice_locs(in_slice.start, in_slice.stop, in_slice.step)
Repository: pandas-dev/pandas
Pull request #57893 (2024-03-18 18:09:35)

TST: add pytest-localserver to dev deps
Needed for the httpserver fixture that we use.


Patch:
diff --git a/environment.yml b/environment.yml
index 3528f12c66..e7bf2556d2 100644
--- a/environment.yml
+++ b/environment.yml
@@ -17,6 +17,7 @@ dependencies:
   - pytest-cov
   - pytest-xdist>=2.2.0
   - pytest-qt>=4.2.0
+  - pytest-localserver
   - pyqt>=5.15.9
   - coverage
 
diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py
index 1c08df80df..caa00b205a 100644
--- a/pandas/compat/__init__.py
+++ b/pandas/compat/__init__.py
@@ -31,6 +31,7 @@ from pandas.compat.pyarrow import (
     pa_version_under13p0,
     pa_version_under14p0,
     pa_version_under14p1,
+    pa_version_under16p0,
 )
 
 if TYPE_CHECKING:
@@ -187,6 +188,7 @@ __all__ = [
     "pa_version_under13p0",
     "pa_version_under14p0",
     "pa_version_under14p1",
+    "pa_version_under16p0",
     "IS64",
     "ISMUSL",
     "PY310",
diff --git a/pandas/compat/pyarrow.py b/pandas/compat/pyarrow.py
index 5c9e885f8e..5a96e5a4cc 100644
--- a/pandas/compat/pyarrow.py
+++ b/pandas/compat/pyarrow.py
@@ -15,6 +15,7 @@ try:
     pa_version_under14p0 = _palv < Version("14.0.0")
     pa_version_under14p1 = _palv < Version("14.0.1")
     pa_version_under15p0 = _palv < Version("15.0.0")
+    pa_version_under16p0 = _palv < Version("16.0.0")
 except ImportError:
     pa_version_under10p1 = True
     pa_version_under11p0 = True
@@ -23,3 +24,4 @@ except ImportError:
     pa_version_under14p0 = True
     pa_version_under14p1 = True
     pa_version_under15p0 = True
+    pa_version_under16p0 = True
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 40c7403cb8..0cc064d266 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -10,6 +10,7 @@ pytest>=7.3.2
 pytest-cov
 pytest-xdist>=2.2.0
 pytest-qt>=4.2.0
+pytest-localserver
 PyQt5>=5.15.9
 coverage
 python-dateutil


Test patch:
diff --git a/pandas/tests/indexes/object/test_indexing.py b/pandas/tests/indexes/object/test_indexing.py
index 039836da75..34cc8eab4d 100644
--- a/pandas/tests/indexes/object/test_indexing.py
+++ b/pandas/tests/indexes/object/test_indexing.py
@@ -7,6 +7,7 @@ from pandas._libs.missing import (
     NA,
     is_matching_na,
 )
+from pandas.compat import pa_version_under16p0
 import pandas.util._test_decorators as td
 
 import pandas as pd
@@ -201,7 +202,16 @@ class TestSliceLocs:
             (pd.IndexSlice["m":"m":-1], ""),  # type: ignore[misc]
         ],
     )
-    def test_slice_locs_negative_step(self, in_slice, expected, dtype):
+    def test_slice_locs_negative_step(self, in_slice, expected, dtype, request):
+        if (
+            not pa_version_under16p0
+            and dtype == "string[pyarrow_numpy]"
+            and in_slice == slice("a", "a", -1)
+        ):
+            request.applymarker(
+                pytest.mark.xfail(reason="https://github.com/apache/arrow/issues/40642")
+            )
+
         index = Index(list("bcdxy"), dtype=dtype)
 
         s_start, s_stop = index.slice_locs(in_slice.start, in_slice.stop, in_slice.step)
Repository: pandas-dev/pandas
Pull request #57898 (2024-03-18 18:46:36)

Backport PR #57892 on branch 2.2.x (CI: xfail Pyarrow slicing test)
Backport PR #57892: CI: xfail Pyarrow slicing test


Patch:
diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py
index 738442fab8..eb890c8b8c 100644
--- a/pandas/compat/__init__.py
+++ b/pandas/compat/__init__.py
@@ -30,6 +30,7 @@ from pandas.compat.pyarrow import (
     pa_version_under13p0,
     pa_version_under14p0,
     pa_version_under14p1,
+    pa_version_under16p0,
 )
 
 if TYPE_CHECKING:
@@ -186,6 +187,7 @@ __all__ = [
     "pa_version_under13p0",
     "pa_version_under14p0",
     "pa_version_under14p1",
+    "pa_version_under16p0",
     "IS64",
     "ISMUSL",
     "PY310",
diff --git a/pandas/compat/pyarrow.py b/pandas/compat/pyarrow.py
index beb4814914..a2dfa69bbf 100644
--- a/pandas/compat/pyarrow.py
+++ b/pandas/compat/pyarrow.py
@@ -15,6 +15,7 @@ try:
     pa_version_under14p0 = _palv < Version("14.0.0")
     pa_version_under14p1 = _palv < Version("14.0.1")
     pa_version_under15p0 = _palv < Version("15.0.0")
+    pa_version_under16p0 = _palv < Version("16.0.0")
 except ImportError:
     pa_version_under10p1 = True
     pa_version_under11p0 = True
@@ -23,3 +24,4 @@ except ImportError:
     pa_version_under14p0 = True
     pa_version_under14p1 = True
     pa_version_under15p0 = True
+    pa_version_under16p0 = True


Test patch:
diff --git a/pandas/tests/indexes/object/test_indexing.py b/pandas/tests/indexes/object/test_indexing.py
index ebf9dac715..443cacf94d 100644
--- a/pandas/tests/indexes/object/test_indexing.py
+++ b/pandas/tests/indexes/object/test_indexing.py
@@ -7,6 +7,7 @@ from pandas._libs.missing import (
     NA,
     is_matching_na,
 )
+from pandas.compat import pa_version_under16p0
 import pandas.util._test_decorators as td
 
 import pandas as pd
@@ -200,7 +201,16 @@ class TestSliceLocs:
             (pd.IndexSlice["m":"m":-1], ""),  # type: ignore[misc]
         ],
     )
-    def test_slice_locs_negative_step(self, in_slice, expected, dtype):
+    def test_slice_locs_negative_step(self, in_slice, expected, dtype, request):
+        if (
+            not pa_version_under16p0
+            and dtype == "string[pyarrow_numpy]"
+            and in_slice == slice("a", "a", -1)
+        ):
+            request.applymarker(
+                pytest.mark.xfail(reason="https://github.com/apache/arrow/issues/40642")
+            )
+
         index = Index(list("bcdxy"), dtype=dtype)
 
         s_start, s_stop = index.slice_locs(in_slice.start, in_slice.stop, in_slice.step)