Skip to content

Commit e5fbdc8

Browse files
committed
give nicer deprecation / message on infer_dtype moving
1 parent ab4525b commit e5fbdc8

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

pandas/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262

6363
json = _DeprecatedModule(deprmod='pandas.json', deprmodto='pandas.io.json.libjson')
6464
parser = _DeprecatedModule(deprmod='pandas.parser', deprmodto='pandas.io.libparsers')
65-
lib = _DeprecatedModule(deprmod='pandas.lib', deprmodto='pandas._libs.lib')
65+
lib = _DeprecatedModule(deprmod='pandas.lib', deprmodto='pandas._libs.lib',
66+
moved={'infer_dtype': 'pandas.api.lib.infer_dtype'})
6667
tslib = _DeprecatedModule(deprmod='pandas.tslib', deprmodto='pandas._libs.tslib')
6768

6869
# use the closest tagged version if possible

pandas/tests/api/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class TestLib(tm.TestCase):
187187

188188
def test_deprecation_access_func(self):
189189
with catch_warnings(record=True):
190-
pd.lib.infer_dtype
190+
pd.lib.infer_dtype('foo')
191191

192192

193193
class TestTSLib(tm.TestCase):

pandas/tests/api/test_lib.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
import pytest
3+
from warnings import catch_warnings
44
import pandas # noqa
55

66

7-
@pytest.mark.parametrize('f', ['infer_dtype'])
8-
def test_importable(f):
9-
from pandas.api import lib
10-
e = getattr(lib, f)
11-
assert e is not None
7+
def test_moved_infer_dtype():
8+
with catch_warnings(record=True):
9+
e = pandas.lib.infer_dtype('foo')
10+
assert e is not None

pandas/util/depr_module.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ class _DeprecatedModule(object):
1818
be used when needed.
1919
removals : objects or methods in module that will no longer be
2020
accessible once module is removed.
21+
moved : dict, optional
22+
dictionary of function name -> new location for moved
23+
objects
2124
"""
2225

23-
def __init__(self, deprmod, deprmodto=None, removals=None):
26+
def __init__(self, deprmod, deprmodto=None, removals=None,
27+
moved=None):
2428
self.deprmod = deprmod
2529
self.deprmodto = deprmodto
2630
self.removals = removals
2731
if self.removals is not None:
2832
self.removals = frozenset(self.removals)
33+
self.moved = moved
2934

3035
# For introspection purposes.
3136
self.self_dir = frozenset(dir(self.__class__))
@@ -60,6 +65,14 @@ def __getattr__(self, name):
6065
"{deprmod}.{name} is deprecated and will be removed in "
6166
"a future version.".format(deprmod=self.deprmod, name=name),
6267
FutureWarning, stacklevel=2)
68+
elif self.moved is not None and name in self.moved:
69+
warnings.warn(
70+
"{deprmod} is deprecated and will be removed in "
71+
"a future version.\nYou can access {name} in {moved}".format(
72+
deprmod=self.deprmod,
73+
name=name,
74+
moved=self.moved[name]),
75+
FutureWarning, stacklevel=2)
6376
else:
6477
deprmodto = self.deprmodto
6578
if deprmodto is None:

0 commit comments

Comments
 (0)