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: pandas.util.testing #30620

Merged
Merged
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/categoricals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

import pandas as pd
import pandas.util.testing as tm
import pandas._testing as tm

try:
from pandas.api.types import union_categoricals
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/ctors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DatetimeIndex, Index, MultiIndex, Series, Timestamp
import pandas.util.testing as tm
import pandas._testing as tm


def no_change(arr):
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/frame_ctor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, MultiIndex, Series, Timestamp, date_range
import pandas.util.testing as tm
import pandas._testing as tm

try:
from pandas.tseries.offsets import Nano, Hour
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

from pandas import DataFrame, MultiIndex, NaT, Series, date_range, isnull, period_range
import pandas.util.testing as tm
import pandas._testing as tm


class GetNumericData:
Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/gil.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

from pandas import DataFrame, Series, date_range, factorize, read_csv
import pandas._testing as tm
from pandas.core.algorithms import take_1d
import pandas.util.testing as tm

try:
from pandas import (
Expand All @@ -24,7 +24,7 @@
except ImportError:
from pandas import algos
try:
from pandas.util.testing import test_parallel
from pandas._testing import test_parallel

have_real_test_parallel = True
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
date_range,
period_range,
)
import pandas.util.testing as tm
import pandas._testing as tm

method_blacklist = {
"object": {
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/index_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Series,
date_range,
)
import pandas.util.testing as tm
import pandas._testing as tm


class SetOperations:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
option_context,
period_range,
)
import pandas.util.testing as tm
import pandas._testing as tm


class NumericSeriesIndexing:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/inference.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, Series, to_numeric
import pandas.util.testing as tm
import pandas._testing as tm

from .pandas_vb_common import lib, numeric_dtypes

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from pandas import Categorical, DataFrame, date_range, read_csv, to_datetime
import pandas.util.testing as tm
import pandas._testing as tm

from ..pandas_vb_common import BaseIO

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from odf.text import P

from pandas import DataFrame, ExcelWriter, date_range, read_excel
import pandas.util.testing as tm
import pandas._testing as tm


def _generate_dataframe():
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/hdf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, HDFStore, date_range, read_hdf
import pandas.util.testing as tm
import pandas._testing as tm

from ..pandas_vb_common import BaseIO

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, concat, date_range, read_json, timedelta_range
import pandas.util.testing as tm
import pandas._testing as tm

from ..pandas_vb_common import BaseIO

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/pickle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, date_range, read_pickle
import pandas.util.testing as tm
import pandas._testing as tm

from ..pandas_vb_common import BaseIO

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sqlalchemy import create_engine

from pandas import DataFrame, date_range, read_sql_query, read_sql_table
import pandas.util.testing as tm
import pandas._testing as tm


class SQL:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/stata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, date_range, read_stata
import pandas.util.testing as tm
import pandas._testing as tm

from ..pandas_vb_common import BaseIO

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/join_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from pandas import DataFrame, MultiIndex, Series, concat, date_range, merge, merge_asof
import pandas.util.testing as tm
import pandas._testing as tm

try:
from pandas import merge_ordered
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/multiindex_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from pandas import DataFrame, MultiIndex, RangeIndex, date_range
import pandas.util.testing as tm
import pandas._testing as tm


class GetLoc:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/reindex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas import DataFrame, Index, MultiIndex, Series, date_range, period_range
import pandas.util.testing as tm
import pandas._testing as tm

from .pandas_vb_common import lib

Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from pandas import NaT, Series, date_range
import pandas.util.testing as tm
import pandas._testing as tm


class SeriesConstructor:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from pandas import DataFrame, Series
import pandas.util.testing as tm
import pandas._testing as tm


class Methods:
Expand Down
4 changes: 2 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
RET=$(($RET + $?)) ; echo $MSG "DONE"

# Checks for test suite
# Check for imports from pandas.util.testing instead of `import pandas.util.testing as tm`
invgrep -R --include="*.py*" -E "from pandas.util.testing import" pandas/tests
# Check for imports from pandas._testing instead of `import pandas._testing as tm`
invgrep -R --include="*.py*" -E "from pandas._testing import" pandas/tests
RET=$(($RET + $?)) ; echo $MSG "DONE"
invgrep -R --include="*.py*" -E "from pandas.util import testing as tm" pandas/tests
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down
4 changes: 2 additions & 2 deletions doc/source/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ inspiration. If your test requires working with files or
network connectivity, there is more information on the `testing page
<https://github.com/pandas-dev/pandas/wiki/Testing>`_ of the wiki.

The ``pandas.util.testing`` module has many special ``assert`` functions that
The ``pandas._testing`` module has many special ``assert`` functions that
make it easier to make statements about whether Series or DataFrame objects are
equivalent. The easiest way to verify that your code is correct is to
explicitly construct the result you expect, then compare the actual result to
Expand Down Expand Up @@ -1143,7 +1143,7 @@ If your change involves checking that a warning is actually emitted, use

.. code-block:: python

import pandas.util.testing as tm
import pandas._testing as tm


df = pd.DataFrame()
Expand Down
12 changes: 12 additions & 0 deletions doc/source/reference/general_utility_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Working with options
set_option
option_context

.. _api.general.testing:

Testing functions
-----------------
.. autosummary::
Expand All @@ -26,6 +28,16 @@ Testing functions
testing.assert_frame_equal
testing.assert_series_equal
testing.assert_index_equal
testing.assert_equal
testing.assert_almost_equal
testing.assert_categorical_equal
Copy link
Member

Choose a reason for hiding this comment

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

Is it needed to make all those asserts public?
Eg, what's the pandas-specific value for external projects of using pandas' assert_equal or assert_almost_equal ?
Also all the EA specific ones could probably be limited to a single general array assert?

Copy link
Member

Choose a reason for hiding this comment

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

Thoughts about this? (can also make an issue for it)

testing.assert_datetime_array_equal
testing.assert_extension_array_equal
testing.assert_interval_array_equal
testing.assert_numpy_array_equal
testing.assert_period_array_equal
testing.assert_sp_array_equal
testing.assert_timedelta_array_equal

Exceptions and warnings
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ rows will skip the intervening rows.

.. ipython:: python

from pandas.util.testing import makeCustomDataframe as mkdf
from pandas._testing import makeCustomDataframe as mkdf
df = mkdf(5, 3, r_idx_nlevels=2, c_idx_nlevels=4)
df.to_csv('mi.csv')
print(open('mi.csv').read())
Expand Down
4 changes: 2 additions & 2 deletions doc/source/user_guide/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Reshaping by pivoting DataFrame objects
.. ipython:: python
:suppress:

import pandas.util.testing as tm
import pandas._testing as tm
tm.N = 3

def unpivot(frame):
Expand All @@ -38,7 +38,7 @@ For the curious here is how the above ``DataFrame`` was created:

.. code-block:: python

import pandas.util.testing as tm
import pandas._testing as tm

tm.N = 3

Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/scale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Assuming you want or need the expressiveness and power of pandas, let's carry on
.. ipython:: python
:suppress:

from pandas.util.testing import _make_timeseries
from pandas._testing import _make_timeseries

# Make a random in-memory dataset
ts = _make_timeseries(freq="30S", seed=0)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.12.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ I/O enhancements

.. ipython:: python

from pandas.util.testing import makeCustomDataframe as mkdf
from pandas._testing import makeCustomDataframe as mkdf
df = mkdf(5, 3, r_idx_nlevels=2, c_idx_nlevels=4)
df.to_csv('mi.csv')
print(open('mi.csv').read())
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.13.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Enhancements

.. code-block:: ipython

In [28]: import pandas.util.testing as tm
In [28]: import pandas._testing as tm

In [29]: panel = tm.makePanel(5)

Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.18.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ Bug Fixes

- Removed ``millisecond`` property of ``DatetimeIndex``. This would always raise a ``ValueError`` (:issue:`12019`).
- Bug in ``Series`` constructor with read-only data (:issue:`11502`)
- Removed ``pandas.util.testing.choice()``. Should use ``np.random.choice()``, instead. (:issue:`12386`)
- Removed ``pandas._testing.choice()``. Should use ``np.random.choice()``, instead. (:issue:`12386`)
- Bug in ``.loc`` setitem indexer preventing the use of a TZ-aware DatetimeIndex (:issue:`12050`)
- Bug in ``.style`` indexes and MultiIndexes not appearing (:issue:`11655`)
- Bug in ``to_msgpack`` and ``from_msgpack`` which did not correctly serialize or deserialize ``NaT`` (:issue:`12307`).
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ provides a :meth:`~Panel.to_xarray` method to automate this conversion (:issue:`

.. code-block:: ipython

In [133]: import pandas.util.testing as tm
In [133]: import pandas._testing as tm

In [134]: p = tm.makePanel()

Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ Other API changes
- :class:`pandas.HDFStore`'s string representation is now faster and less detailed. For the previous behavior, use ``pandas.HDFStore.info()``. (:issue:`16503`).
- Compression defaults in HDF stores now follow pytables standards. Default is no compression and if ``complib`` is missing and ``complevel`` > 0 ``zlib`` is used (:issue:`15943`)
- ``Index.get_indexer_non_unique()`` now returns a ndarray indexer rather than an ``Index``; this is consistent with ``Index.get_indexer()`` (:issue:`16819`)
- Removed the ``@slow`` decorator from ``pandas.util.testing``, which caused issues for some downstream packages' test suites. Use ``@pytest.mark.slow`` instead, which achieves the same thing (:issue:`16850`)
- Removed the ``@slow`` decorator from ``pandas._testing``, which caused issues for some downstream packages' test suites. Use ``@pytest.mark.slow`` instead, which achieves the same thing (:issue:`16850`)
- Moved definition of ``MergeError`` to the ``pandas.errors`` module.
- The signature of :func:`Series.set_axis` and :func:`DataFrame.set_axis` has been changed from ``set_axis(axis, labels)`` to ``set_axis(labels, axis=0)``, for consistency with the rest of the API. The old signature is deprecated and will show a ``FutureWarning`` (:issue:`14636`)
- :func:`Series.argmin` and :func:`Series.argmax` will now raise a ``TypeError`` when used with ``object`` dtypes, instead of a ``ValueError`` (:issue:`13595`)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ provides a :meth:`~Panel.to_xarray` method to automate this conversion (:issue:`

.. code-block:: ipython

In [75]: import pandas.util.testing as tm
In [75]: import pandas._testing as tm

In [76]: p = tm.makePanel()

Expand Down
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ Deprecations
it is recommended to use ``json_normalize`` as :func:`pandas.json_normalize` instead (:issue:`27586`).
- :meth:`DataFrame.to_stata`, :meth:`DataFrame.to_feather`, and :meth:`DataFrame.to_parquet` argument "fname" is deprecated, use "path" instead (:issue:`23574`)
- The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`)
- The ``pandas.util.testing`` module has been deprecated. Use the public API in ``pandas.testing`` documented at :ref:`api.general.testing` (:issue:`16232`).

**Selecting Columns from a Grouped DataFrame**

Expand Down Expand Up @@ -703,7 +704,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Ability to read pickles containing :class:`Categorical` instances created with pre-0.16 version of pandas has been removed (:issue:`27538`)
- Removed :func:`pandas.tseries.plotting.tsplot` (:issue:`18627`)
- Removed the previously deprecated keywords "reduce" and "broadcast" from :meth:`DataFrame.apply` (:issue:`18577`)
- Removed the previously deprecated ``assert_raises_regex`` function in ``pandas.util.testing`` (:issue:`29174`)
- Removed the previously deprecated ``assert_raises_regex`` function in ``pandas._testing`` (:issue:`29174`)
- Removed the previously deprecated ``FrozenNDArray`` class in ``pandas.core.indexes.frozen`` (:issue:`29335`)
- Removed the previously deprecated keyword "nthreads" from :func:`read_feather`, use "use_threads" instead (:issue:`23053`)
- Removed :meth:`Index.is_lexsorted_for_tuple` (:issue:`29305`)
Expand Down
Loading