Repository: pandas-dev/pandas
Pull request #57897 (2024-03-18 18:41:17)

TST: Reduce some test data sizes


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/pandas/core/series.py b/pandas/core/series.py
index 699ff413ef..8a7c153120 100644
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -452,7 +452,7 @@ class Series(base.IndexOpsMixin, NDFrame):  # type: ignore[misc]
                 data = data.reindex(index)
                 copy = False
                 data = data._mgr
-        elif is_dict_like(data):
+        elif isinstance(data, Mapping):
             data, index = self._init_dict(data, index, dtype)
             dtype = None
             copy = False
@@ -519,7 +519,7 @@ class Series(base.IndexOpsMixin, NDFrame):  # type: ignore[misc]
                 )
 
     def _init_dict(
-        self, data, index: Index | None = None, dtype: DtypeObj | None = None
+        self, data: Mapping, index: Index | None = None, dtype: DtypeObj | None = None
     ):
         """
         Derive the "_mgr" and "index" attributes of a new Series from a
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/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py
index 8e73fbf152..4d2d83d25e 100644
--- a/pandas/tests/frame/methods/test_cov_corr.py
+++ b/pandas/tests/frame/methods/test_cov_corr.py
@@ -355,8 +355,8 @@ class TestDataFrameCorrWith:
         tm.assert_series_equal(result, expected)
 
     def test_corrwith_matches_corrcoef(self):
-        df1 = DataFrame(np.arange(10000), columns=["a"])
-        df2 = DataFrame(np.arange(10000) ** 2, columns=["a"])
+        df1 = DataFrame(np.arange(100), columns=["a"])
+        df2 = DataFrame(np.arange(100) ** 2, columns=["a"])
         c1 = df1.corrwith(df2)["a"]
         c2 = np.corrcoef(df1["a"], df2["a"])[0][1]
 
diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py
index e91ca64bb8..46f6367fbb 100644
--- a/pandas/tests/groupby/transform/test_transform.py
+++ b/pandas/tests/groupby/transform/test_transform.py
@@ -87,8 +87,8 @@ def test_transform():
 def test_transform_fast():
     df = DataFrame(
         {
-            "id": np.arange(100000) / 3,
-            "val": np.random.default_rng(2).standard_normal(100000),
+            "id": np.arange(10) / 3,
+            "val": np.random.default_rng(2).standard_normal(10),
         }
     )
 
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)
diff --git a/pandas/tests/indexing/test_chaining_and_caching.py b/pandas/tests/indexing/test_chaining_and_caching.py
index cfadf34823..2a2772d1b3 100644
--- a/pandas/tests/indexing/test_chaining_and_caching.py
+++ b/pandas/tests/indexing/test_chaining_and_caching.py
@@ -17,15 +17,6 @@ import pandas._testing as tm
 msg = "A value is trying to be set on a copy of a slice from a DataFrame"
 
 
-def random_text(nobs=100):
-    # Construct a DataFrame where each row is a random slice from 'letters'
-    idxs = np.random.default_rng(2).integers(len(ascii_letters), size=(nobs, 2))
-    idxs.sort(axis=1)
-    strings = [ascii_letters[x[0] : x[1]] for x in idxs]
-
-    return DataFrame(strings, columns=["letters"])
-
-
 class TestCaching:
     def test_slice_consolidate_invalidate_item_cache(self):
         # this is chained assignment, but will 'work'
@@ -233,7 +224,11 @@ class TestChaining:
 
     @pytest.mark.arm_slow
     def test_detect_chained_assignment_str(self):
-        df = random_text(100000)
+        idxs = np.random.default_rng(2).integers(len(ascii_letters), size=(100, 2))
+        idxs.sort(axis=1)
+        strings = [ascii_letters[x[0] : x[1]] for x in idxs]
+
+        df = DataFrame(strings, columns=["letters"])
         indexer = df.letters.apply(lambda x: len(x) > 10)
         df.loc[indexer, "letters"] = df.loc[indexer, "letters"].apply(str.lower)
 
diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py
index ce7bb74240..8e05a8e6fc 100644
--- a/pandas/tests/io/json/test_ujson.py
+++ b/pandas/tests/io/json/test_ujson.py
@@ -1036,11 +1036,7 @@ class TestPandasJSONTests:
         )
 
     def test_encode_big_set(self):
-        s = set()
-
-        for x in range(100000):
-            s.add(x)
-
+        s = set(range(100000))
         # Make sure no Exception is raised.
         ujson.ujson_dumps(s)
 
diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py
index 0ee5ee4ec1..fecd24c9a4 100644
--- a/pandas/tests/resample/test_datetime_index.py
+++ b/pandas/tests/resample/test_datetime_index.py
@@ -1464,12 +1464,12 @@ def test_resample_nunique_with_date_gap(func, unit):
     tm.assert_series_equal(result, expected)
 
 
-@pytest.mark.parametrize("n", [10000, 100000])
-@pytest.mark.parametrize("k", [10, 100, 1000])
-def test_resample_group_info(n, k, unit):
+def test_resample_group_info(unit):
     # GH10914
 
     # use a fixed seed to always have the same uniques
+    n = 100
+    k = 10
     prng = np.random.default_rng(2)
 
     dr = date_range(start="2015-08-27", periods=n // 10, freq="min").as_unit(unit)