From bb65d127f37f84bd3f4aad60e5dd455d500d254a Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 14 Apr 2017 21:50:01 +0200 Subject: [PATCH 1/2] API: expose public testing functions in pandas.testing (GH9895) --- doc/source/api.rst | 10 ++++++++++ pandas/__init__.py | 1 + pandas/testing.py | 8 ++++++++ pandas/tests/api/test_api.py | 13 ++++++++++++- pandas/util/testing.py | 2 +- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 pandas/testing.py diff --git a/doc/source/api.rst b/doc/source/api.rst index 6d1765ce65714..d0f548cc3d0b1 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -1886,3 +1886,13 @@ Working with options get_option set_option option_context + +Testing functions +~~~~~~~~~~~~~~~~~ + +.. autosummary:: + :toctree: generated/ + + testing.assert_frame_equal + testing.assert_series_equal + testing.assert_index_equal diff --git a/pandas/__init__.py b/pandas/__init__.py index 529750cd97076..74af33831d79a 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -56,6 +56,7 @@ from pandas.util.print_versions import show_versions from pandas.io.api import * from pandas.util._tester import test +import pandas.testing # extension module deprecations from pandas.util.depr_module import _DeprecatedModule diff --git a/pandas/testing.py b/pandas/testing.py new file mode 100644 index 0000000000000..3baf99957cb33 --- /dev/null +++ b/pandas/testing.py @@ -0,0 +1,8 @@ +# flake8: noqa + +""" +Public testing utility functions. +""" + +from pandas.util.testing import ( + assert_frame_equal, assert_series_equal, assert_index_equal) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index a15d7cf26cbea..dca0563655ce5 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -33,7 +33,7 @@ class TestPDApi(Base, tm.TestCase): lib = ['api', 'compat', 'computation', 'core', 'indexes', 'formats', 'errors', 'pandas', 'test', 'tools', 'tseries', 'sparse', - 'types', 'util', 'options', 'io'] + 'types', 'util', 'options', 'io', 'testing'] # these are already deprecated; awaiting removal deprecated_modules = ['stats', 'datetools', 'parser', @@ -127,6 +127,17 @@ def test_api(self): self.check(api, self.allowed) +class TestTesting(Base): + + funcs = ['assert_frame_equal', 'assert_series_equal', + 'assert_index_equal'] + + def test_testing(self): + + from pandas import testing + self.check(testing, self.funcs) + + class TestDatetoolsDeprecation(tm.TestCase): def test_deprecation_access_func(self): diff --git a/pandas/util/testing.py b/pandas/util/testing.py index c73cca56f975a..31c5ad414ee26 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -859,7 +859,7 @@ def assert_index_equal(left, right, exact='equiv', check_names=True, right : Index exact : bool / string {'equiv'}, default False Whether to check the Index class, dtype and inferred_type - are identical. If 'equiv', then RangeIndex can be substitued for + are identical. If 'equiv', then RangeIndex can be substituted for Int64Index as well check_names : bool, default True Whether to check the names attribute. From 89900b25a49163eb013c67ddd6fc8511bd4cd503 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 15 Apr 2017 15:59:11 +0200 Subject: [PATCH 2/2] add whatsnew --- doc/source/whatsnew/v0.20.0.txt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 133757b131312..364d874721435 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -146,8 +146,8 @@ Commonly called 'unix epoch' or POSIX time. This was the previous default, so th .. _whatsnew_0200.enhancements.errors: -pandas errors -^^^^^^^^^^^^^ +``pandas.errors`` +^^^^^^^^^^^^^^^^^ We are adding a standard public module for all pandas exceptions & warnings ``pandas.errors``. (:issue:`14800`). Previously these exceptions & warnings could be imported from ``pandas.core.common`` or ``pandas.io.common``. These exceptions and warnings @@ -166,6 +166,21 @@ The following are now part of this API: 'UnsortedIndexError', 'UnsupportedFunctionCall'] + +.. _whatsnew_0200.enhancements.testing: + +``pandas.testing`` +^^^^^^^^^^^^^^^^^^ + +We are adding a standard module that exposes the public testing functions in ``pandas.testing``(:issue:`9895`). Those functions can be used when writing tests for functionality using pandas objects. + +The following testing functions are now part of this API: + +- :func:`testing.assert_frame_equal` +- :func:`testing.assert_series_equal` +- :func:`testing.assert_index_equal` + + .. _whatsnew_0200.enhancements.groupby_access: Groupby Enhancements