From 6161f99ab5f570173b33e7767f8da7a85065e55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 15 Jul 2022 11:47:55 -0400 Subject: [PATCH 1/4] DEPR: deprecate pandas.tests --- doc/source/whatsnew/v1.5.0.rst | 1 + pandas/tests/__init__.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 9651269963803..955e496be6592 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -771,6 +771,7 @@ Other Deprecations - Clarified warning from :func:`to_datetime` when delimited dates can't be parsed in accordance to specified ``dayfirst`` argument (:issue:`46210`) - Deprecated :class:`Series` and :class:`Resampler` reducers (e.g. ``min``, ``max``, ``sum``, ``mean``) raising a ``NotImplementedError`` when the dtype is non-numric and ``numeric_only=True`` is provided; this will raise a ``TypeError`` in a future version (:issue:`47500`) - Deprecated :meth:`Series.rank` returning an empty result when the dtype is non-numeric and ``numeric_only=True`` is provided; this will raise a ``TypeError`` in a future version (:issue:`47500`) +- Deprecated the module ``pandas.tests``. It will be private in the future and renamed to to ``pandas._tests`` (:issue:`46651`) .. --------------------------------------------------------------------------- .. _whatsnew_150.performance: diff --git a/pandas/tests/__init__.py b/pandas/tests/__init__.py index e69de29bb2d1d..f835c2d3624b4 100644 --- a/pandas/tests/__init__.py +++ b/pandas/tests/__init__.py @@ -0,0 +1,6 @@ +from warnings import warn + +warn( + "pandas.tests is considered to be private and will be renamed to pandas._tests in the future.", + DeprecationWarning, +) From 63b88ac481ce0c156f4aff752adfda19c4edd5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 15 Jul 2022 11:55:38 -0400 Subject: [PATCH 2/4] line length --- pandas/tests/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/__init__.py b/pandas/tests/__init__.py index f835c2d3624b4..b69eb2abea07c 100644 --- a/pandas/tests/__init__.py +++ b/pandas/tests/__init__.py @@ -1,6 +1,7 @@ from warnings import warn warn( - "pandas.tests is considered to be private and will be renamed to pandas._tests in the future.", + "pandas.tests is considered to be private and will be renamed " + "to pandas._tests in the future.", DeprecationWarning, ) From 8494a86a1401ed9baf817f04a2172974b1d2e943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 15 Jul 2022 15:55:21 -0400 Subject: [PATCH 3/4] testcase, not yet working --- pandas/tests/test_common.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index d31f617b9be15..0669cc4d38da9 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -1,6 +1,8 @@ import collections from functools import partial import string +import subprocess +import sys import numpy as np import pytest @@ -229,3 +231,16 @@ def test_temp_setattr(with_exception): raise ValueError("Inside exception raised") raise ValueError("Outside exception raised") assert ser.name == "first" + + +def test_private_tests(): + # GH 47738 + output = subprocess.check_output( + [sys.executable, "-W", "default", "-c", '"from pandas import tests"'], + stderr=subprocess.STDOUT, + ) + msg = ( + "DeprecationWarning: pandas.tests is considered to be private and " + "will be renamed to pandas._tests in the future." + ) + assert msg in output.decode() From 40b27b479879e7d4f57132fcf048d145b363a13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 16 Jul 2022 14:27:02 -0400 Subject: [PATCH 4/4] trigger and catch warning before calling pytest --- pandas/util/_tester.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/util/_tester.py b/pandas/util/_tester.py index 1b018a6a1ba34..af2c1830c32fb 100644 --- a/pandas/util/_tester.py +++ b/pandas/util/_tester.py @@ -5,6 +5,7 @@ import os import sys +import warnings from pandas.compat._optional import import_optional_dependency @@ -22,6 +23,11 @@ def test(extra_args: list[str] | None = None): extra_args : list[str], default None Extra marks to run the tests. """ + # prevent pytest from containing the pandas/tests deprecation + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + from pandas import tests + pytest = import_optional_dependency("pytest") import_optional_dependency("hypothesis") cmd = ["--skip-slow", "--skip-network", "--skip-db"]