Skip to content

Commit 4527839

Browse files
mroeschkemliu08
authored andcommitted
CLN: Testing and unused (pandas-dev#49754)
* Remove unused rand_bools * Remove references to append * Reuse existing fixtures * Replace another top level fixture
1 parent db42e61 commit 4527839

File tree

8 files changed

+29
-82
lines changed

8 files changed

+29
-82
lines changed

doc/source/user_guide/merging.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ It's not a stretch to see how this can be very useful. More detail on this
151151
functionality below.
152152

153153
.. note::
154-
It is worth noting that :func:`~pandas.concat` (and therefore
155-
:func:`~pandas.append`) makes a full copy of the data, and that constantly
154+
It is worth noting that :func:`~pandas.concat` makes a full copy of the data, and that constantly
156155
reusing this function can create a significant performance hit. If you need
157156
to use the operation over several datasets, use a list comprehension.
158157

pandas/_testing/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
write_to_compressed,
6262
)
6363
from pandas._testing._random import (
64-
randbool,
6564
rands,
6665
rands_array,
6766
)
@@ -1121,7 +1120,6 @@ def shares_memory(left, right) -> bool:
11211120
"NULL_OBJECTS",
11221121
"OBJECT_DTYPES",
11231122
"raise_assert_detail",
1124-
"randbool",
11251123
"rands",
11261124
"reset_display_options",
11271125
"RNGContext",

pandas/_testing/_random.py

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
from pandas._typing import NpDtype
66

7-
8-
def randbool(size=(), p: float = 0.5):
9-
return np.random.rand(*size) <= p
10-
11-
127
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
138
RANDU_CHARS = np.array(
149
list("".join(map(chr, range(1488, 1488 + 26))) + string.digits),

pandas/conftest.py

-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ def pytest_collection_modifyitems(items, config) -> None:
151151
# Warnings from doctests that can be ignored; place reason in comment above.
152152
# Each entry specifies (path, message) - see the ignore_doctest_warning function
153153
ignored_doctest_warnings = [
154-
# Deprecations where the docstring will emit a warning
155-
("DataFrame.append", "The frame.append method is deprecated"),
156-
("Series.append", "The series.append method is deprecated"),
157154
# Docstring divides by zero to show behavior difference
158155
("missing.mask_zero_div_zero", "divide by zero encountered"),
159156
# Docstring demonstrates the call raises a warning

pandas/tests/dtypes/cast/test_promote.py

+28-67
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,6 @@
2727
import pandas as pd
2828

2929

30-
@pytest.fixture(
31-
params=[
32-
bool,
33-
"uint8",
34-
"int32",
35-
"uint64",
36-
"float32",
37-
"float64",
38-
"complex64",
39-
"complex128",
40-
"M8[ns]",
41-
"m8[ns]",
42-
str,
43-
bytes,
44-
object,
45-
]
46-
)
47-
def any_numpy_dtype_reduced(request):
48-
"""
49-
Parameterized fixture for numpy dtypes, reduced from any_numpy_dtype.
50-
51-
* bool
52-
* 'int32'
53-
* 'uint64'
54-
* 'float32'
55-
* 'float64'
56-
* 'complex64'
57-
* 'complex128'
58-
* 'M8[ns]'
59-
* 'M8[ns]'
60-
* str
61-
* bytes
62-
* object
63-
"""
64-
return request.param
65-
66-
6730
def _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar=None):
6831
"""
6932
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):
307270
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
308271

309272

310-
def test_maybe_promote_bool_with_any(any_numpy_dtype_reduced):
273+
def test_maybe_promote_bool_with_any(any_numpy_dtype):
311274
dtype = np.dtype(bool)
312-
fill_dtype = np.dtype(any_numpy_dtype_reduced)
275+
fill_dtype = np.dtype(any_numpy_dtype)
313276

314277
# create array of given dtype; casts "1" to correct dtype
315278
fill_value = np.array([1], dtype=fill_dtype)[0]
@@ -321,8 +284,8 @@ def test_maybe_promote_bool_with_any(any_numpy_dtype_reduced):
321284
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
322285

323286

324-
def test_maybe_promote_any_with_bool(any_numpy_dtype_reduced):
325-
dtype = np.dtype(any_numpy_dtype_reduced)
287+
def test_maybe_promote_any_with_bool(any_numpy_dtype):
288+
dtype = np.dtype(any_numpy_dtype)
326289
fill_value = True
327290

328291
# filling anything but bool with bool casts to object
@@ -333,9 +296,9 @@ def test_maybe_promote_any_with_bool(any_numpy_dtype_reduced):
333296
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
334297

335298

336-
def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype_reduced):
299+
def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype):
337300
dtype = np.dtype(bytes_dtype)
338-
fill_dtype = np.dtype(any_numpy_dtype_reduced)
301+
fill_dtype = np.dtype(any_numpy_dtype)
339302

340303
# create array of given dtype; casts "1" to correct dtype
341304
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):
347310
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
348311

349312

350-
def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced):
351-
dtype = np.dtype(any_numpy_dtype_reduced)
313+
def test_maybe_promote_any_with_bytes(any_numpy_dtype):
314+
dtype = np.dtype(any_numpy_dtype)
352315

353316
# create array of given dtype
354317
fill_value = b"abc"
@@ -361,9 +324,9 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced):
361324
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
362325

363326

364-
def test_maybe_promote_datetime64_with_any(datetime64_dtype, any_numpy_dtype_reduced):
327+
def test_maybe_promote_datetime64_with_any(datetime64_dtype, any_numpy_dtype):
365328
dtype = np.dtype(datetime64_dtype)
366-
fill_dtype = np.dtype(any_numpy_dtype_reduced)
329+
fill_dtype = np.dtype(any_numpy_dtype)
367330

368331
# create array of given dtype; casts "1" to correct dtype
369332
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
390353
],
391354
ids=["pd.Timestamp", "np.datetime64", "datetime.datetime", "datetime.date"],
392355
)
393-
def test_maybe_promote_any_with_datetime64(any_numpy_dtype_reduced, fill_value):
394-
dtype = np.dtype(any_numpy_dtype_reduced)
356+
def test_maybe_promote_any_with_datetime64(any_numpy_dtype, fill_value):
357+
dtype = np.dtype(any_numpy_dtype)
395358

396359
# filling datetime with anything but datetime casts to object
397360
if is_datetime64_dtype(dtype):
@@ -421,9 +384,9 @@ def test_maybe_promote_any_with_datetime64(any_numpy_dtype_reduced, fill_value):
421384
ids=["pd.Timestamp", "np.datetime64", "datetime.datetime", "datetime.date"],
422385
)
423386
def test_maybe_promote_any_numpy_dtype_with_datetimetz(
424-
any_numpy_dtype_reduced, tz_aware_fixture, fill_value
387+
any_numpy_dtype, tz_aware_fixture, fill_value
425388
):
426-
dtype = np.dtype(any_numpy_dtype_reduced)
389+
dtype = np.dtype(any_numpy_dtype)
427390
fill_dtype = DatetimeTZDtype(tz=tz_aware_fixture)
428391

429392
fill_value = pd.Series([fill_value], dtype=fill_dtype)[0]
@@ -435,9 +398,9 @@ def test_maybe_promote_any_numpy_dtype_with_datetimetz(
435398
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
436399

437400

438-
def test_maybe_promote_timedelta64_with_any(timedelta64_dtype, any_numpy_dtype_reduced):
401+
def test_maybe_promote_timedelta64_with_any(timedelta64_dtype, any_numpy_dtype):
439402
dtype = np.dtype(timedelta64_dtype)
440-
fill_dtype = np.dtype(any_numpy_dtype_reduced)
403+
fill_dtype = np.dtype(any_numpy_dtype)
441404

442405
# create array of given dtype; casts "1" to correct dtype
443406
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
459422
[pd.Timedelta(days=1), np.timedelta64(24, "h"), datetime.timedelta(1)],
460423
ids=["pd.Timedelta", "np.timedelta64", "datetime.timedelta"],
461424
)
462-
def test_maybe_promote_any_with_timedelta64(
463-
any_numpy_dtype_reduced, fill_value, request
464-
):
465-
dtype = np.dtype(any_numpy_dtype_reduced)
425+
def test_maybe_promote_any_with_timedelta64(any_numpy_dtype, fill_value, request):
426+
dtype = np.dtype(any_numpy_dtype)
466427

467428
# filling anything but timedelta with timedelta casts to object
468429
if is_timedelta64_dtype(dtype):
@@ -489,9 +450,9 @@ def test_maybe_promote_any_with_timedelta64(
489450
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
490451

491452

492-
def test_maybe_promote_string_with_any(string_dtype, any_numpy_dtype_reduced):
453+
def test_maybe_promote_string_with_any(string_dtype, any_numpy_dtype):
493454
dtype = np.dtype(string_dtype)
494-
fill_dtype = np.dtype(any_numpy_dtype_reduced)
455+
fill_dtype = np.dtype(any_numpy_dtype)
495456

496457
# create array of given dtype; casts "1" to correct dtype
497458
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):
503464
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
504465

505466

506-
def test_maybe_promote_any_with_string(any_numpy_dtype_reduced):
507-
dtype = np.dtype(any_numpy_dtype_reduced)
467+
def test_maybe_promote_any_with_string(any_numpy_dtype):
468+
dtype = np.dtype(any_numpy_dtype)
508469

509470
# create array of given dtype
510471
fill_value = "abc"
@@ -516,9 +477,9 @@ def test_maybe_promote_any_with_string(any_numpy_dtype_reduced):
516477
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
517478

518479

519-
def test_maybe_promote_object_with_any(object_dtype, any_numpy_dtype_reduced):
480+
def test_maybe_promote_object_with_any(object_dtype, any_numpy_dtype):
520481
dtype = np.dtype(object_dtype)
521-
fill_dtype = np.dtype(any_numpy_dtype_reduced)
482+
fill_dtype = np.dtype(any_numpy_dtype)
522483

523484
# create array of given dtype; casts "1" to correct dtype
524485
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):
530491
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
531492

532493

533-
def test_maybe_promote_any_with_object(any_numpy_dtype_reduced):
534-
dtype = np.dtype(any_numpy_dtype_reduced)
494+
def test_maybe_promote_any_with_object(any_numpy_dtype):
495+
dtype = np.dtype(any_numpy_dtype)
535496

536497
# create array of object dtype from a scalar value (i.e. passing
537498
# 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):
544505
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
545506

546507

547-
def test_maybe_promote_any_numpy_dtype_with_na(any_numpy_dtype_reduced, nulls_fixture):
508+
def test_maybe_promote_any_numpy_dtype_with_na(any_numpy_dtype, nulls_fixture):
548509
fill_value = nulls_fixture
549-
dtype = np.dtype(any_numpy_dtype_reduced)
510+
dtype = np.dtype(any_numpy_dtype)
550511

551512
if isinstance(fill_value, Decimal):
552513
# Subject to change, but ATM (When Decimal(NAN) is being added to nulls_fixture)

pandas/tests/frame/methods/test_drop_duplicates.py

-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ def test_drop_duplicates_null_in_object_column(nulls_fixture):
441441
tm.assert_frame_equal(result, df)
442442

443443

444-
@pytest.mark.parametrize("keep", ["first", "last", False])
445444
def test_drop_duplicates_series_vs_dataframe(keep):
446445
# GH#14192
447446
df = DataFrame(

pandas/tests/series/methods/test_duplicated.py

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def test_duplicated_mask(keep, vals):
6969
tm.assert_series_equal(result, expected)
7070

7171

72-
@pytest.mark.parametrize("keep", ["last", "first", False])
7372
def test_duplicated_mask_no_duplicated_na(keep):
7473
# GH#48150
7574
ser = Series([1, 2, NA], dtype="Int64")

pandas/tests/window/test_rolling.py

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def test_numpy_compat(method):
170170
getattr(r, method)(dtype=np.float64)
171171

172172

173-
@pytest.mark.parametrize("closed", ["right", "left", "both", "neither"])
174173
def test_closed_fixed(closed, arithmetic_win_operators):
175174
# GH 34315
176175
func_name = arithmetic_win_operators

0 commit comments

Comments
 (0)