8000 API: expose pandas.errors by jreback · Pull Request #15541 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

API: expose pandas.errors #15541

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

Closed
wants to merge 12 commits into from
Prev Previous commit
give nicer deprecation / message on infer_dtype moving
  • Loading branch information
jreback committed Apr 3, 2017
commit e5fbdc8e00e220eed797d4fb05bcb02b356d2f45
3 changes: 2 additions & 1 deletion pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@

json = _DeprecatedModule(deprmod='pandas.json', deprmodto='pandas.io.json.libjson')
parser = _DeprecatedModule(deprmod='pandas.parser', deprmodto='pandas.io.libparsers')
lib = _DeprecatedModule(deprmod='pandas.lib', deprmodto='pandas._libs.lib')
lib = _DeprecatedModule(deprmod='pandas.lib', deprmodto='pandas._libs.lib',
moved={'infer_dtype': 'pandas.api.lib.infer_dtype'})
tslib = _DeprecatedModule(deprmod='pandas.tslib', deprmodto='pandas._libs.tslib')

# use the closest tagged version if possible
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class TestLib(tm.TestCase):

def test_deprecation_access_func(self):
with catch_warnings(record=True):
pd.lib.infer_dtype
pd.lib.infer_dtype('foo')


class TestTSLib(tm.TestCase):
Expand Down
11 changes: 5 additions & 6 deletions pandas/tests/api/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-

import pytest
from warnings import catch_warnings
import pandas # noqa


@pytest.mark.parametrize('f', ['infer_dtype'])
def test_importable(f):
from pandas.api import lib
e = getattr(lib, f)
assert e is not None
def test_moved_infer_dtype():
with catch_warnings(record=True):
e = pandas.lib.infer_dtype('foo')
assert e is not None
15 changes: 14 additions & 1 deletion pandas/util/depr_module.py
Original file line number Diff line number Diff line change
Expand Up 8000 @@ -18,14 +18,19 @@ class _DeprecatedModule(object):
be used when needed.
removals : objects or methods in module that will no longer be
accessible once module is removed.
moved : dict, optional
dictionary of function name -> new location for moved
objects
"""

def __init__(self, deprmod, deprmodto=None, removals=None):
def __init__(self, deprmod, deprmodto=None, removals=None,
moved=None):
self.deprmod = deprmod
self.deprmodto = deprmodto
self.removals = removals
if self.removals is not None:
self.removals = frozenset(self.removals)
self.moved = moved

# For introspection purposes.
self.self_dir = frozenset(dir(self.__class__))
Expand Down Expand Up @@ -60,6 +65,14 @@ def __getattr__(self, name):
"{deprmod}.{name} is deprecated and will be removed in "
"a future version.".format(deprmod=self.deprmod, name=name),
FutureWarning, stacklevel=2)
elif self.moved is not None and name in self.moved:
warnings.warn(
"{deprmod} is deprecated and will be removed in "
"a future version.\nYou can access {name} in {moved}".format(
deprmod=self.deprmod,
name=name,
moved=self.moved[name]),
FutureWarning, stacklevel=2)
else:
deprmodto = self.deprmodto
if deprmodto is None:
Expand Down
0