|
19 | 19 | from pandas.core.dtypes.common import _NS_DTYPE
|
20 | 20 | from pandas.core.dtypes.inference import _iterable_not_string
|
21 | 21 | from pandas.core.dtypes.missing import isna, isnull, notnull # noqa
|
22 |
| -from pandas.api import types |
23 | 22 | from pandas.core.dtypes import common
|
24 | 23 | from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
|
25 | 24 |
|
26 | 25 | # compat
|
27 | 26 | from pandas.errors import ( # noqa
|
28 | 27 | PerformanceWarning, UnsupportedFunctionCall, UnsortedIndexError)
|
29 | 28 |
|
30 |
| -# back-compat of public API |
31 |
| -# deprecate these functions |
32 |
| -m = sys.modules['pandas.core.common'] |
33 |
| -for t in [t for t in dir(types) if not t.startswith('_')]: |
34 |
| - |
35 |
| - def outer(t=t): |
36 |
| - |
37 |
| - def wrapper(*args, **kwargs): |
38 |
| - warnings.warn("pandas.core.common.{t} is deprecated. " |
39 |
| - "import from the public API: " |
40 |
| - "pandas.api.types.{t} instead".format(t=t), |
41 |
| - DeprecationWarning, stacklevel=3) |
42 |
| - return getattr(types, t)(*args, **kwargs) |
43 |
| - return wrapper |
44 |
| - |
45 |
| - setattr(m, t, outer(t)) |
46 |
| - |
47 |
| -# back-compat for non-public functions |
48 |
| -# deprecate these functions |
49 |
| -for t in ['is_datetime_arraylike', |
50 |
| - 'is_datetime_or_timedelta_dtype', |
51 |
| - 'is_datetimelike', |
52 |
| - 'is_datetimelike_v_numeric', |
53 |
| - 'is_datetimelike_v_object', |
54 |
| - 'is_datetimetz', |
55 |
| - 'is_int_or_datetime_dtype', |
56 |
| - 'is_period_arraylike', |
57 |
| - 'is_string_like', |
58 |
| - 'is_string_like_dtype']: |
59 |
| - |
60 |
| - def outer(t=t): |
61 |
| - |
62 |
| - def wrapper(*args, **kwargs): |
63 |
| - warnings.warn("pandas.core.common.{t} is deprecated. " |
64 |
| - "These are not longer public API functions, " |
65 |
| - "but can be imported from " |
66 |
| - "pandas.api.types.{t} instead".format(t=t), |
67 |
| - DeprecationWarning, stacklevel=3) |
68 |
| - return getattr(common, t)(*args, **kwargs) |
69 |
| - return wrapper |
70 |
| - |
71 |
| - setattr(m, t, outer(t)) |
| 29 | + |
| 30 | +def _add_deprecated(): |
| 31 | + # back-compat of public API |
| 32 | + # deprecate these functions |
| 33 | + # This is called at the end of pandas.__init__, after all the imports |
| 34 | + # have already been resolved, to avoid any circular imports. |
| 35 | + from pandas.api import types |
| 36 | + |
| 37 | + m = sys.modules['pandas.core.common'] |
| 38 | + for t in [t for t in dir(types) if not t.startswith('_')]: |
| 39 | + |
| 40 | + def outer(t=t): |
| 41 | + |
| 42 | + def wrapper(*args, **kwargs): |
| 43 | + warnings.warn("pandas.core.common.{t} is deprecated. " |
| 44 | + "import from the public API: " |
| 45 | + "pandas.api.types.{t} instead".format(t=t), |
| 46 | + DeprecationWarning, stacklevel=3) |
| 47 | + return getattr(types, t)(*args, **kwargs) |
| 48 | + return wrapper |
| 49 | + |
| 50 | + setattr(m, t, outer(t)) |
| 51 | + |
| 52 | + # back-compat for non-public functions |
| 53 | + # deprecate these functions |
| 54 | + for t in ['is_datetime_arraylike', |
| 55 | + 'is_datetime_or_timedelta_dtype', |
| 56 | + 'is_datetimelike', |
| 57 | + 'is_datetimelike_v_numeric', |
| 58 | + 'is_datetimelike_v_object', |
| 59 | + 'is_datetimetz', |
| 60 | + 'is_int_or_datetime_dtype', |
| 61 | + 'is_period_arraylike', |
| 62 | + 'is_string_like', |
| 63 | + 'is_string_like_dtype']: |
| 64 | + |
| 65 | + def outer(t=t): |
| 66 | + |
| 67 | + def wrapper(*args, **kwargs): |
| 68 | + warnings.warn("pandas.core.common.{t} is deprecated. " |
| 69 | + "These are not longer public API functions, " |
| 70 | + "but can be imported from " |
| 71 | + "pandas.api.types.{t} instead".format(t=t), |
| 72 | + DeprecationWarning, stacklevel=3) |
| 73 | + return getattr(common, t)(*args, **kwargs) |
| 74 | + return wrapper |
| 75 | + |
| 76 | + setattr(m, t, outer(t)) |
72 | 77 |
|
73 | 78 |
|
74 | 79 | # deprecate array_equivalent
|
@@ -646,6 +651,7 @@ def _random_state(state=None):
|
646 | 651 | -------
|
647 | 652 | np.random.RandomState
|
648 | 653 | """
|
| 654 | + from pandas.api import types |
649 | 655 |
|
650 | 656 | if types.is_integer(state):
|
651 | 657 | return np.random.RandomState(state)
|
|
0 commit comments