Skip to content

CLN: Testing and unused #49754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 17, 2022
3 changes: 1 addition & 2 deletions doc/source/user_guide/merging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 0 additions & 2 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
write_to_compressed,
)
from pandas._testing._random import (
randbool,
rands,
rands_array,
)
Expand Down Expand Up @@ -1121,7 +1120,6 @@ def shares_memory(left, right) -> bool:
"NULL_OBJECTS",
"OBJECT_DTYPES",
"raise_assert_detail",
"randbool",
"rands",
"reset_display_options",
"RNGContext",
Expand Down
5 changes: 0 additions & 5 deletions pandas/_testing/_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 0 additions & 3 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,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
Expand Down
95 changes: 28 additions & 67 deletions pandas/tests/dtypes/cast/test_promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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"
Expand All @@ -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]
Expand All @@ -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):
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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):
Expand All @@ -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):
Comment on lines -492 to +453
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the idea here just that any_numpy_dtype is a superset of any_numpy_dtype_reduced, and that one might as well test over the larger set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, exactly

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]
Expand All @@ -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"
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/frame/methods/test_drop_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause this is the same as the fixture? 🤔 might be an idea for an automated test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup same as this one

pandas/pandas/conftest.py

Lines 304 to 310 in cca262d

@pytest.fixture(params=["first", "last", False])
def keep(request):
"""
Valid values for the 'keep' parameter used in
.duplicated or .drop_duplicates
"""
return request.param

Yeah it would be great to have a check to answer "Does a @pytest.mark.parametrize return the same params as an existing fixture"

# GH#14192
df = DataFrame(
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/series/methods/test_duplicated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down