Skip to content
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

DEPR: Remove check_less_precise in asserters #49461

Merged
merged 5 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Removal of prior version deprecations/changes
- Removed deprecated :meth:`.Styler.where` (:issue:`49397`)
- Removed deprecated :meth:`.Styler.render` (:issue:`49397`)
- Removed deprecated argument ``null_color`` in :meth:`.Styler.highlight_null` (:issue:`49397`)
- Removed deprecated argument ``check_less_precise`` in :meth:`.testing.assert_frame_equal`, :meth:`.testing.assert_extension_array_equal`, :meth:`.testing.assert_series_equal`, :meth:`.testing.assert_index_equal` (:issue:`30562`)
- Removed deprecated ``null_counts`` argument in :meth:`DataFrame.info`. Use ``show_counts`` instead (:issue:`37999`)
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
Expand Down
159 changes: 0 additions & 159 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
Literal,
cast,
)
import warnings

import numpy as np

from pandas._libs.lib import (
NoDefault,
no_default,
)
from pandas._libs.missing import is_matching_na
from pandas._libs.sparse import SparseIndex
import pandas._libs.testing as _testing
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_bool,
Expand Down Expand Up @@ -64,7 +58,6 @@ def assert_almost_equal(
left,
right,
check_dtype: bool | Literal["equiv"] = "equiv",
check_less_precise: bool | int | NoDefault = no_default,
rtol: float = 1.0e-5,
atol: float = 1.0e-8,
**kwargs,
Expand All @@ -83,20 +76,6 @@ def assert_almost_equal(
Check dtype if both a and b are the same type. If 'equiv' is passed in,
then `RangeIndex` and `Int64Index` are also considered equivalent
when doing type checking.
check_less_precise : bool or int, default False
Specify comparison precision. 5 digits (False) or 3 digits (True)
after decimal points are compared. If int, then specify the number
of digits to compare.

When comparing two numbers, if the first number has magnitude less
than 1e-5, we compare the two numbers directly and check whether
they are equivalent within the specified precision. Otherwise, we
compare the **ratio** of the second number to the first number and
check whether it is equivalent to 1 within the specified precision.

.. deprecated:: 1.1.0
Use `rtol` and `atol` instead to define relative/absolute
tolerance, respectively. Similar to :func:`math.isclose`.
rtol : float, default 1e-5
Relative tolerance.

Expand All @@ -106,16 +85,6 @@ def assert_almost_equal(

.. versionadded:: 1.1.0
"""
if check_less_precise is not no_default:
warnings.warn(
"The 'check_less_precise' keyword in testing.assert_*_equal "
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

if isinstance(left, Index):
assert_index_equal(
left,
Expand Down Expand Up @@ -171,46 +140,6 @@ def assert_almost_equal(
)


def _get_tol_from_less_precise(check_less_precise: bool | int) -> float:
"""
Return the tolerance equivalent to the deprecated `check_less_precise`
parameter.

Parameters
----------
check_less_precise : bool or int

Returns
-------
float
Tolerance to be used as relative/absolute tolerance.

Examples
--------
>>> # Using check_less_precise as a bool:
>>> _get_tol_from_less_precise(False)
5e-06
>>> _get_tol_from_less_precise(True)
0.0005
>>> # Using check_less_precise as an int representing the decimal
>>> # tolerance intended:
>>> _get_tol_from_less_precise(2)
0.005
>>> _get_tol_from_less_precise(8)
5e-09
"""
if isinstance(check_less_precise, bool):
if check_less_precise:
# 3-digit tolerance
return 0.5e-3
else:
# 5-digit tolerance
return 0.5e-5
else:
# Equivalent to setting checking_less_precise=<decimals>
return 0.5 * 10**-check_less_precise


def _check_isinstance(left, right, cls):
"""
Helper method for our assert_* methods that ensures that
Expand Down Expand Up @@ -250,7 +179,6 @@ def assert_index_equal(
right: Index,
exact: bool | str = "equiv",
check_names: bool = True,
check_less_precise: bool | int | NoDefault = no_default,
check_exact: bool = True,
check_categorical: bool = True,
check_order: bool = True,
Expand All @@ -271,14 +199,6 @@ def assert_index_equal(
Int64Index as well.
check_names : bool, default True
Whether to check the names attribute.
check_less_precise : bool or int, default False
Specify comparison precision. Only used when check_exact is False.
5 digits (False) or 3 digits (True) after decimal points are compared.
If int, then specify the digits to compare.

.. deprecated:: 1.1.0
Use `rtol` and `atol` instead to define relative/absolute
tolerance, respectively. Similar to :func:`math.isclose`.
check_exact : bool, default True
Whether to compare number exactly.
check_categorical : bool, default True
Expand Down Expand Up @@ -333,16 +253,6 @@ def _get_ilevel_values(index, level):
filled = take_nd(unique._values, level_codes, fill_value=unique._na_value)
return unique._shallow_copy(filled, name=index.names[level])

if check_less_precise is not no_default:
warnings.warn(
"The 'check_less_precise' keyword in testing.assert_*_equal "
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

# instance validation
_check_isinstance(left, right, Index)

Expand Down Expand Up @@ -775,7 +685,6 @@ def assert_extension_array_equal(
right,
check_dtype: bool | Literal["equiv"] = True,
index_values=None,
check_less_precise=no_default,
check_exact: bool = False,
rtol: float = 1.0e-5,
atol: float = 1.0e-8,
Expand All @@ -791,14 +700,6 @@ def assert_extension_array_equal(
Whether to check if the ExtensionArray dtypes are identical.
index_values : numpy.ndarray, default None
Optional index (shared by both left and right), used in output.
check_less_precise : bool or int, default False
Specify comparison precision. Only used when check_exact is False.
5 digits (False) or 3 digits (True) after decimal points are compared.
If int, then specify the digits to compare.

.. deprecated:: 1.1.0
Use `rtol` and `atol` instead to define relative/absolute
tolerance, respectively. Similar to :func:`math.isclose`.
check_exact : bool, default False
Whether to compare number exactly.
rtol : float, default 1e-5
Expand All @@ -823,16 +724,6 @@ def assert_extension_array_equal(
>>> b, c = a.array, a.array
>>> tm.assert_extension_array_equal(b, c)
"""
if check_less_precise is not no_default:
warnings.warn(
"The 'check_less_precise' keyword in testing.assert_*_equal "
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

assert isinstance(left, ExtensionArray), "left is not an ExtensionArray"
assert isinstance(right, ExtensionArray), "right is not an ExtensionArray"
if check_dtype:
Expand Down Expand Up @@ -881,7 +772,6 @@ def assert_series_equal(
check_dtype: bool | Literal["equiv"] = True,
check_index_type: bool | Literal["equiv"] = "equiv",
check_series_type: bool = True,
check_less_precise: bool | int | NoDefault = no_default,
check_names: bool = True,
check_exact: bool = False,
check_datetimelike_compat: bool = False,
Expand Down Expand Up @@ -910,20 +800,6 @@ def assert_series_equal(
are identical.
check_series_type : bool, default True
Whether to check the Series class is identical.
check_less_precise : bool or int, default False
Specify comparison precision. Only used when check_exact is False.
5 digits (False) or 3 digits (True) after decimal points are compared.
If int, then specify the digits to compare.

When comparing two numbers, if the first number has magnitude less
than 1e-5, we compare the two numbers directly and check whether
they are equivalent within the specified precision. Otherwise, we
compare the **ratio** of the second number to the first number and
check whether it is equivalent to 1 within the specified precision.

.. deprecated:: 1.1.0
Use `rtol` and `atol` instead to define relative/absolute
tolerance, respectively. Similar to :func:`math.isclose`.
check_names : bool, default True
Whether to check the Series and Index names attribute.
check_exact : bool, default False
Expand Down Expand Up @@ -978,16 +854,6 @@ def assert_series_equal(
if not check_index and check_like:
raise ValueError("check_like must be False if check_index is False")

if check_less_precise is not no_default:
warnings.warn(
"The 'check_less_precise' keyword in testing.assert_*_equal "
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

# instance validation
_check_isinstance(left, right, Series)

Expand Down Expand Up @@ -1150,7 +1016,6 @@ def assert_frame_equal(
check_index_type: bool | Literal["equiv"] = "equiv",
check_column_type: bool | Literal["equiv"] = "equiv",
check_frame_type: bool = True,
check_less_precise=no_default,
check_names: bool = True,
by_blocks: bool = False,
check_exact: bool = False,
Expand Down Expand Up @@ -1188,20 +1053,6 @@ def assert_frame_equal(
:func:`assert_index_equal`.
check_frame_type : bool, default True
Whether to check the DataFrame class is identical.
check_less_precise : bool or int, default False
Specify comparison precision. Only used when check_exact is False.
5 digits (False) or 3 digits (True) after decimal points are compared.
If int, then specify the digits to compare.

When comparing two numbers, if the first number has magnitude less
than 1e-5, we compare the two numbers directly and check whether
they are equivalent within the specified precision. Otherwise, we
compare the **ratio** of the second number to the first number and
check whether it is equivalent to 1 within the specified precision.

.. deprecated:: 1.1.0
Use `rtol` and `atol` instead to define relative/absolute
tolerance, respectively. Similar to :func:`math.isclose`.
check_names : bool, default True
Whether to check that the `names` attribute for both the `index`
and `column` attributes of the DataFrame is identical.
Expand Down Expand Up @@ -1271,16 +1122,6 @@ def assert_frame_equal(
"""
__tracebackhide__ = True

if check_less_precise is not no_default:
warnings.warn(
"The 'check_less_precise' keyword in testing.assert_*_equal "
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

# instance validation
_check_isinstance(left, right, DataFrame)

Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ def sem(x):
check_dates=True,
)

# GH#32571 check_less_precise is needed on apparently-random
# py37-npdev builds and OSX-PY36-min_version builds
Copy link
Member

Choose a reason for hiding this comment

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

could update the comment to refer to rtol?

# GH#32571: rol needed for flaky CI builds
# mixed types (with upcasting happening)
assert_stat_op_calc(
"sum",
Expand Down
12 changes: 1 addition & 11 deletions pandas/tests/util/test_assert_almost_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ def _assert_not_almost_equal_both(a, b, **kwargs):
_assert_not_almost_equal(b, a, **kwargs)


@pytest.mark.parametrize(
"a,b,check_less_precise",
[(1.1, 1.1, False), (1.1, 1.100001, True), (1.1, 1.1001, 2)],
)
def test_assert_almost_equal_deprecated(a, b, check_less_precise):
# GH#30562
with tm.assert_produces_warning(FutureWarning):
_assert_almost_equal_both(a, b, check_less_precise=check_less_precise)


@pytest.mark.parametrize(
"a,b",
[
Expand Down Expand Up @@ -122,7 +112,7 @@ def test_assert_not_almost_equal_numbers(a, b):
],
)
def test_assert_almost_equal_numbers_atol(a, b):
# Equivalent to the deprecated check_less_precise=True
# Equivalent to the deprecated check_less_precise=True, enforced in 2.0
_assert_almost_equal_both(a, b, rtol=0.5e-3, atol=0.5e-3)


Expand Down