From 9c66ab9dfebabd4cd849aade484f00d600e9d75f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 17 Oct 2022 13:51:43 -0700 Subject: [PATCH 1/4] Remove unused rand_bools --- pandas/_testing/__init__.py | 2 -- pandas/_testing/_random.py | 5 ----- 2 files changed, 7 deletions(-) diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index da4db1fcc9e04..b2b7771becbfe 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -60,7 +60,6 @@ write_to_compressed, ) from pandas._testing._random import ( - randbool, rands, rands_array, ) @@ -1116,7 +1115,6 @@ def shares_memory(left, right) -> bool: "NULL_OBJECTS", "OBJECT_DTYPES", "raise_assert_detail", - "randbool", "rands", "reset_display_options", "RNGContext", diff --git a/pandas/_testing/_random.py b/pandas/_testing/_random.py index 218816308f95d..52e5d5f58b01f 100644 --- a/pandas/_testing/_random.py +++ b/pandas/_testing/_random.py @@ -4,11 +4,6 @@ from pandas._typing import NpDtype - -def randbool(size=(), p: float = 0.5): - return np.random.rand(*size) <= p - - RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1)) RANDU_CHARS = np.array( list("".join(map(chr, range(1488, 1488 + 26))) + string.digits), From d694fcbe8be8b634ce1321748f6b35d390e906a3 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:23:07 -0800 Subject: [PATCH 2/4] Remove references to append --- doc/source/user_guide/merging.rst | 3 +-- pandas/conftest.py | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/source/user_guide/merging.rst b/doc/source/user_guide/merging.rst index bbca5773afdfe..ce4b3d1e8c7f3 100644 --- a/doc/source/user_guide/merging.rst +++ b/doc/source/user_guide/merging.rst @@ -151,8 +151,7 @@ It's not a stretch to see how this can be very useful. More detail on this functionality below. .. note:: - It is worth noting that :func:`~pandas.concat` (and therefore - :func:`~pandas.append`) makes a full copy of the data, and that constantly + It is worth noting that :func:`~pandas.concat` makes a full copy of the data, and that constantly reusing this function can create a significant performance hit. If you need to use the operation over several datasets, use a list comprehension. diff --git a/pandas/conftest.py b/pandas/conftest.py index 308f63a4ebe5c..0b19ff12a6cd2 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -150,9 +150,6 @@ def pytest_collection_modifyitems(items, config) -> None: # Warnings from doctests that can be ignored; place reason in comment above. # Each entry specifies (path, message) - see the ignore_doctest_warning function ignored_doctest_warnings = [ - # Deprecations where the docstring will emit a warning - ("DataFrame.append", "The frame.append method is deprecated"), - ("Series.append", "The series.append method is deprecated"), # Docstring divides by zero to show behavior difference ("missing.mask_zero_div_zero", "divide by zero encountered"), # Docstring demonstrates the call raises a warning From 6ff40b1947e6b0ce3c2b8985e28158cc6b9df5aa Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:32:48 -0800 Subject: [PATCH 3/4] Reuse existing fixtures --- pandas/tests/frame/methods/test_drop_duplicates.py | 1 - pandas/tests/series/methods/test_duplicated.py | 1 - pandas/tests/window/test_rolling.py | 1 - 3 files changed, 3 deletions(-) diff --git a/pandas/tests/frame/methods/test_drop_duplicates.py b/pandas/tests/frame/methods/test_drop_duplicates.py index 988d8e3b6f13f..df12139258a6d 100644 --- a/pandas/tests/frame/methods/test_drop_duplicates.py +++ b/pandas/tests/frame/methods/test_drop_duplicates.py @@ -441,7 +441,6 @@ def test_drop_duplicates_null_in_object_column(nulls_fixture): tm.assert_frame_equal(result, df) -@pytest.mark.parametrize("keep", ["first", "last", False]) def test_drop_duplicates_series_vs_dataframe(keep): # GH#14192 df = DataFrame( diff --git a/pandas/tests/series/methods/test_duplicated.py b/pandas/tests/series/methods/test_duplicated.py index 29a523a4468f6..e177b5275d855 100644 --- a/pandas/tests/series/methods/test_duplicated.py +++ b/pandas/tests/series/methods/test_duplicated.py @@ -69,7 +69,6 @@ def test_duplicated_mask(keep, vals): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("keep", ["last", "first", False]) def test_duplicated_mask_no_duplicated_na(keep): # GH#48150 ser = Series([1, 2, NA], dtype="Int64") diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index e4d96e270fa66..474d87ee5639a 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -170,7 +170,6 @@ def test_numpy_compat(method): getattr(r, method)(dtype=np.float64) -@pytest.mark.parametrize("closed", ["right", "left", "both", "neither"]) def test_closed_fixed(closed, arithmetic_win_operators): # GH 34315 func_name = arithmetic_win_operators From 274b7adbb10ea4cca416ff7c1d88ccd7d035310a Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:22:50 -0800 Subject: [PATCH 4/4] Replace another top level fixture --- pandas/tests/dtypes/cast/test_promote.py | 95 +++++++----------------- 1 file changed, 28 insertions(+), 67 deletions(-) diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index c54e99f2c2225..4f13858b0c131 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -27,43 +27,6 @@ import pandas as pd -@pytest.fixture( - params=[ - bool, - "uint8", - "int32", - "uint64", - "float32", - "float64", - "complex64", - "complex128", - "M8[ns]", - "m8[ns]", - str, - bytes, - object, - ] -) -def any_numpy_dtype_reduced(request): - """ - Parameterized fixture for numpy dtypes, reduced from any_numpy_dtype. - - * bool - * 'int32' - * 'uint64' - * 'float32' - * 'float64' - * 'complex64' - * 'complex128' - * 'M8[ns]' - * 'M8[ns]' - * str - * bytes - * object - """ - return request.param - - def _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar=None): """ Auxiliary function to unify testing of scalar/array promotion. @@ -307,9 +270,9 @@ def test_maybe_promote_float_with_float(dtype, fill_value, expected_dtype): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_bool_with_any(any_numpy_dtype_reduced): +def test_maybe_promote_bool_with_any(any_numpy_dtype): dtype = np.dtype(bool) - fill_dtype = np.dtype(any_numpy_dtype_reduced) + fill_dtype = np.dtype(any_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -321,8 +284,8 @@ def test_maybe_promote_bool_with_any(any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_any_with_bool(any_numpy_dtype_reduced): - dtype = np.dtype(any_numpy_dtype_reduced) +def test_maybe_promote_any_with_bool(any_numpy_dtype): + dtype = np.dtype(any_numpy_dtype) fill_value = True # filling anything but bool with bool casts to object @@ -333,9 +296,9 @@ def test_maybe_promote_any_with_bool(any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype_reduced): +def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype): dtype = np.dtype(bytes_dtype) - fill_dtype = np.dtype(any_numpy_dtype_reduced) + fill_dtype = np.dtype(any_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -347,8 +310,8 @@ def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced): - dtype = np.dtype(any_numpy_dtype_reduced) +def test_maybe_promote_any_with_bytes(any_numpy_dtype): + dtype = np.dtype(any_numpy_dtype) # create array of given dtype fill_value = b"abc" @@ -361,9 +324,9 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_datetime64_with_any(datetime64_dtype, any_numpy_dtype_reduced): +def test_maybe_promote_datetime64_with_any(datetime64_dtype, any_numpy_dtype): dtype = np.dtype(datetime64_dtype) - fill_dtype = np.dtype(any_numpy_dtype_reduced) + fill_dtype = np.dtype(any_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -390,8 +353,8 @@ def test_maybe_promote_datetime64_with_any(datetime64_dtype, any_numpy_dtype_red ], ids=["pd.Timestamp", "np.datetime64", "datetime.datetime", "datetime.date"], ) -def test_maybe_promote_any_with_datetime64(any_numpy_dtype_reduced, fill_value): - dtype = np.dtype(any_numpy_dtype_reduced) +def test_maybe_promote_any_with_datetime64(any_numpy_dtype, fill_value): + dtype = np.dtype(any_numpy_dtype) # filling datetime with anything but datetime casts to object if is_datetime64_dtype(dtype): @@ -421,9 +384,9 @@ def test_maybe_promote_any_with_datetime64(any_numpy_dtype_reduced, fill_value): ids=["pd.Timestamp", "np.datetime64", "datetime.datetime", "datetime.date"], ) def test_maybe_promote_any_numpy_dtype_with_datetimetz( - any_numpy_dtype_reduced, tz_aware_fixture, fill_value + any_numpy_dtype, tz_aware_fixture, fill_value ): - dtype = np.dtype(any_numpy_dtype_reduced) + dtype = np.dtype(any_numpy_dtype) fill_dtype = DatetimeTZDtype(tz=tz_aware_fixture) fill_value = pd.Series([fill_value], dtype=fill_dtype)[0] @@ -435,9 +398,9 @@ def test_maybe_promote_any_numpy_dtype_with_datetimetz( _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_timedelta64_with_any(timedelta64_dtype, any_numpy_dtype_reduced): +def test_maybe_promote_timedelta64_with_any(timedelta64_dtype, any_numpy_dtype): dtype = np.dtype(timedelta64_dtype) - fill_dtype = np.dtype(any_numpy_dtype_reduced) + fill_dtype = np.dtype(any_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -459,10 +422,8 @@ def test_maybe_promote_timedelta64_with_any(timedelta64_dtype, any_numpy_dtype_r [pd.Timedelta(days=1), np.timedelta64(24, "h"), datetime.timedelta(1)], ids=["pd.Timedelta", "np.timedelta64", "datetime.timedelta"], ) -def test_maybe_promote_any_with_timedelta64( - any_numpy_dtype_reduced, fill_value, request -): - dtype = np.dtype(any_numpy_dtype_reduced) +def test_maybe_promote_any_with_timedelta64(any_numpy_dtype, fill_value, request): + dtype = np.dtype(any_numpy_dtype) # filling anything but timedelta with timedelta casts to object if is_timedelta64_dtype(dtype): @@ -489,9 +450,9 @@ def test_maybe_promote_any_with_timedelta64( _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_string_with_any(string_dtype, any_numpy_dtype_reduced): +def test_maybe_promote_string_with_any(string_dtype, any_numpy_dtype): dtype = np.dtype(string_dtype) - fill_dtype = np.dtype(any_numpy_dtype_reduced) + fill_dtype = np.dtype(any_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -503,8 +464,8 @@ def test_maybe_promote_string_with_any(string_dtype, any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_any_with_string(any_numpy_dtype_reduced): - dtype = np.dtype(any_numpy_dtype_reduced) +def test_maybe_promote_any_with_string(any_numpy_dtype): + dtype = np.dtype(any_numpy_dtype) # create array of given dtype fill_value = "abc" @@ -516,9 +477,9 @@ def test_maybe_promote_any_with_string(any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_object_with_any(object_dtype, any_numpy_dtype_reduced): +def test_maybe_promote_object_with_any(object_dtype, any_numpy_dtype): dtype = np.dtype(object_dtype) - fill_dtype = np.dtype(any_numpy_dtype_reduced) + fill_dtype = np.dtype(any_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -530,8 +491,8 @@ def test_maybe_promote_object_with_any(object_dtype, any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_any_with_object(any_numpy_dtype_reduced): - dtype = np.dtype(any_numpy_dtype_reduced) +def test_maybe_promote_any_with_object(any_numpy_dtype): + dtype = np.dtype(any_numpy_dtype) # create array of object dtype from a scalar value (i.e. passing # dtypes.common.is_scalar), which can however not be cast to int/float etc. @@ -544,9 +505,9 @@ def test_maybe_promote_any_with_object(any_numpy_dtype_reduced): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_any_numpy_dtype_with_na(any_numpy_dtype_reduced, nulls_fixture): +def test_maybe_promote_any_numpy_dtype_with_na(any_numpy_dtype, nulls_fixture): fill_value = nulls_fixture - dtype = np.dtype(any_numpy_dtype_reduced) + dtype = np.dtype(any_numpy_dtype) if isinstance(fill_value, Decimal): # Subject to change, but ATM (When Decimal(NAN) is being added to nulls_fixture)