Skip to content

Commit 290315e

Browse files
committed
move pandas.api.lib.infer_dtype -> pandas.api.types
move union_categoricals to pandas.api.types make feather single test fix odd tz hashing issue remove circular import pandas.core.common warning message
1 parent ba32641 commit 290315e

File tree

13 files changed

+58
-31
lines changed

13 files changed

+58
-31
lines changed

doc/source/categorical.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ will be the union of the categories being combined.
673673

674674
.. ipython:: python
675675
676-
from pandas.types.concat import union_categoricals
676+
from pandas.api.types import union_categoricals
677677
a = pd.Categorical(["b", "c"])
678678
b = pd.Categorical(["a", "b"])
679679
union_categoricals([a, b])

doc/source/whatsnew/v0.20.0.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ Other Enhancements
489489

490490

491491
- ``TimedeltaIndex`` now has a custom datetick formatter specifically designed for nanosecond level precision (:issue:`8711`)
492-
- ``pd.types.concat.union_categoricals`` gained the ``ignore_ordered`` argument to allow ignoring the ordered attribute of unioned categoricals (:issue:`13410`). See the :ref:`categorical union docs <categorical.union>` for more information.
492+
- ``pd.api.types.union_categoricals`` gained the ``ignore_ordered`` argument to allow ignoring the ordered attribute of unioned categoricals (:issue:`13410`). See the :ref:`categorical union docs <categorical.union>` for more information.
493493
- ``DataFrame.to_latex()`` and ``DataFrame.to_string()`` now allow optional header aliases. (:issue:`15536`)
494494
- Re-enable the ``parse_dates`` keyword of ``pd.read_excel()`` to parse string columns as dates (:issue:`14326`)
495495
- Added ``.empty`` property to subclasses of ``Index``. (:issue:`15270`)
@@ -1057,6 +1057,8 @@ If indicated, a deprecation warning will be issued if you reference that module.
10571057
"pandas._hash", "pandas.tools.libhash", ""
10581058
"pandas._window", "pandas.core.libwindow", ""
10591059

1060+
- The function :func:`~pandas.api.type.union_categoricals` is now importable from ``pandas.api.types``, formerly from ``pandas.types.concat`` (:issue:`15998`)
1061+
10601062
.. _whatsnew_0200.api_breaking.sort_index:
10611063

10621064
DataFrame.sort_index changes

pandas/api/types/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" public toolkit API """
22

33
from pandas.core.typed.api import * # noqa
4+
from pandas.core.typed.concat import union_categoricals # noqa
45
del np # noqa

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from pandas.compat.numpy import _np_version_under1p10
2929
from pandas.core.typed.missing import isnull
3030

31-
import pandas.core.common as com
31+
from pandas.core import common as com
3232
from pandas.compat import string_types
3333
from pandas._libs import algos, lib, hashtable as htable
3434
from pandas._libs.tslib import iNaT

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def wrapper(*args, **kwargs):
6060
warnings.warn("pandas.core.common.{t} is deprecated. "
6161
"These are not longer public API functions, "
6262
"but can be imported from "
63-
"pandas.core.typed.common.{t} instead".format(t=t),
63+
"pandas.api.types.{t} instead".format(t=t),
6464
DeprecationWarning, stacklevel=3)
6565
return getattr(common, t)(*args, **kwargs)
6666
return wrapper

pandas/core/series.py

-2
Original file line numberDiff line numberDiff line change
@@ -2869,8 +2869,6 @@ def _sanitize_index(data, index, copy=False):
28692869
data = data.asobject
28702870
elif isinstance(data, DatetimeIndex):
28712871
data = data._to_embed(keep_tz=True)
2872-
if copy:
2873-
data = data.copy()
28742872
elif isinstance(data, np.ndarray):
28752873

28762874
# coerce datetimelike types

pandas/core/typed/concat.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
import numpy as np
66
import pandas._libs.tslib as tslib
77
from pandas import compat
8-
from pandas.core.algorithms import take_1d
9-
from .common import (is_categorical_dtype,
10-
is_sparse,
11-
is_datetimetz,
12-
is_datetime64_dtype,
13-
is_timedelta64_dtype,
14-
is_period_dtype,
15-
is_object_dtype,
16-
is_bool_dtype,
17-
is_dtype_equal,
18-
_NS_DTYPE,
19-
_TD_DTYPE)
8+
from pandas.core.typed.common import (
9+
is_categorical_dtype,
10+
is_sparse,
11+
is_datetimetz,
12+
is_datetime64_dtype,
13+
is_timedelta64_dtype,
14+
is_period_dtype,
15+
is_object_dtype,
16+
is_bool_dtype,
17+
is_dtype_equal,
18+
_NS_DTYPE,
19+
_TD_DTYPE)
2020
from pandas.core.typed.generic import (
2121
ABCDatetimeIndex, ABCTimedeltaIndex,
2222
ABCPeriodIndex)
@@ -277,6 +277,8 @@ def _maybe_unwrap(x):
277277
if sort_categories and not categories.is_monotonic_increasing:
278278
categories = categories.sort_values()
279279
indexer = categories.get_indexer(first.categories)
280+
281+
from pandas.core.algorithms import take_1d
280282
new_codes = take_1d(indexer, new_codes, fill_value=-1)
281283
elif ignore_order or all(not c.ordered for c in to_union):
282284
# different categories - union and recode
@@ -289,6 +291,8 @@ def _maybe_unwrap(x):
289291
for c in to_union:
290292
if len(c.categories) > 0:
291293
indexer = categories.get_indexer(c.categories)
294+
295+
from pandas.core.algorithms import take_1d
292296
new_codes.append(take_1d(indexer, c.codes, fill_value=-1))
293297
else:
294298
# must be all NaN

pandas/core/typed/dtypes.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,15 @@ def __new__(cls, unit=None, tz=None):
209209
raise ValueError("DatetimeTZDtype constructor must have a tz "
210210
"supplied")
211211

212+
# hash with the actual tz if we can
213+
# some cannot be hashed, so stringfy
214+
try:
215+
key = (unit, tz)
216+
hash(key)
217+
except TypeError:
218+
key = (unit, str(tz))
219+
212220
# set/retrieve from cache
213-
key = (unit, str(tz))
214221
try:
215222
return cls._cache[key]
216223
except KeyError:

pandas/tests/api/test_lib.py

-10
This file was deleted.

pandas/tests/api/test_types.py

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

3+
from warnings import catch_warnings
34
import numpy as np
45

6+
import pandas
57
from pandas.core import common as com
68
from pandas.api import types
79
from pandas.util import testing as tm
@@ -28,7 +30,7 @@ class TestTypes(Base, tm.TestCase):
2830
'is_dict_like', 'is_iterator', 'is_file_like',
2931
'is_list_like', 'is_hashable',
3032
'is_named_tuple', 'is_sequence',
31-
'pandas_dtype']
33+
'pandas_dtype', 'union_categoricals']
3234

3335
def test_types(self):
3436

@@ -82,3 +84,10 @@ def test_removed_from_core_common(self):
8284
for t in ['is_null_datelike_scalar',
8385
'ensure_float']:
8486
self.assertRaises(AttributeError, lambda: getattr(com, t))
87+
88+
89+
def test_moved_infer_dtype():
90+
91+
with catch_warnings(record=True):
92+
e = pandas.lib.infer_dtype('foo')
93+
assert e is not None

pandas/tests/indexes/datetimes/test_construction.py

+15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,36 @@
1212

1313
class TestDatetimeIndex(tm.TestCase):
1414

15+
def test_construction_caching(self):
16+
17+
df = pd.DataFrame({'dt': pd.date_range('20130101', periods=3),
18+
'dttz': pd.date_range('20130101', periods=3,
19+
tz='US/Eastern'),
20+
'dt_with_null': [pd.Timestamp('20130101'), pd.NaT,
21+
pd.Timestamp('20130103')],
22+
'dtns': pd.date_range('20130101', periods=3,
23+
freq='ns')})
24+
assert df.dttz.dtype.tz.zone == 'US/Eastern'
25+
1526
def test_construction_with_alt(self):
1627

1728
i = pd.date_range('20130101', periods=5, freq='H', tz='US/Eastern')
1829
i2 = DatetimeIndex(i, dtype=i.dtype)
1930
self.assert_index_equal(i, i2)
31+
assert i.tz.zone == 'US/Eastern'
2032

2133
i2 = DatetimeIndex(i.tz_localize(None).asi8, tz=i.dtype.tz)
2234
self.assert_index_equal(i, i2)
35+
assert i.tz.zone == 'US/Eastern'
2336

2437
i2 = DatetimeIndex(i.tz_localize(None).asi8, dtype=i.dtype)
2538
self.assert_index_equal(i, i2)
39+
assert i.tz.zone == 'US/Eastern'
2640

2741
i2 = DatetimeIndex(
2842
i.tz_localize(None).asi8, dtype=i.dtype, tz=i.dtype.tz)
2943
self.assert_index_equal(i, i2)
44+
assert i.tz.zone == 'US/Eastern'
3045

3146
# localize into the provided tz
3247
i2 = DatetimeIndex(i.tz_localize(None).asi8, tz='UTC')

pandas/tests/io/test_feather.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas.util.testing import assert_frame_equal, ensure_clean
1212

1313

14+
@pytest.mark.single
1415
class TestFeather(object):
1516

1617
def check_error_on_write(self, df, exc):
@@ -52,6 +53,7 @@ def test_basic(self):
5253
'dtns': pd.date_range('20130101', periods=3,
5354
freq='ns')})
5455

56+
assert df.dttz.dtype.tz.zone == 'US/Eastern'
5557
self.check_round_trip(df)
5658

5759
def test_strided_data_issues(self):

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ def pxd(name):
636636
packages=['pandas',
637637
'pandas.api',
638638
'pandas.api.types',
639-
'pandas.api.lib',
640639
'pandas.compat',
641640
'pandas.compat.numpy',
642641
'pandas.core',

0 commit comments

Comments
 (0)