Skip to content

Commit

Permalink
REF: Created pandas.core.arrays
Browse files Browse the repository at this point in the history
Moved pandas.core.categorical to arrays.
  • Loading branch information
TomAugspurger committed Jan 16, 2018
1 parent 4ebdc50 commit 4b06ae4
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ from pandas.core.dtypes.common import (
is_bool_dtype, is_object_dtype,
is_datetime64_dtype,
pandas_dtype)
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
from pandas.core.dtypes.concat import union_categoricals
import pandas.io.common as com

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pandas.core.algorithms import factorize, unique, value_counts
from pandas.core.dtypes.missing import isna, isnull, notna, notnull
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
from pandas.core.groupby import Grouper
from pandas.io.formats.format import set_eng_float_format
from pandas.core.index import (Index, CategoricalIndex, Int64Index,
Expand Down
1 change: 1 addition & 0 deletions pandas/core/arrays/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .categorical import Categorical
File renamed without changes.
2 changes: 1 addition & 1 deletion pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def union_categoricals(to_union, sort_categories=False, ignore_order=False):
Categories (3, object): [b, c, a]
"""
from pandas import Index, Categorical, CategoricalIndex, Series
from pandas.core.categorical import _recode_for_categories
from pandas.core.arrays.categorical import _recode_for_categories

if len(to_union) == 0:
raise ValueError('No Categoricals to union')
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
create_block_manager_from_arrays,
create_block_manager_from_blocks)
from pandas.core.series import Series
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
import pandas.core.algorithms as algorithms
from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u,
OrderedDict, raise_with_traceback)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
DataError, SpecificationError)
from pandas.core.index import (Index, MultiIndex,
CategoricalIndex, _ensure_index)
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame, _shared_docs
from pandas.core.internals import BlockManager, make_block
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _create_from_codes(self, codes, categories=None, ordered=None,
CategoricalIndex
"""

from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
if categories is None:
categories = self.categories
if ordered is None:
Expand Down Expand Up @@ -162,7 +162,7 @@ def _create_categorical(self, data, categories=None, ordered=None,
if not isinstance(data, ABCCategorical):
if ordered is None and dtype is None:
ordered = False
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
data = Categorical(data, categories=categories, ordered=ordered,
dtype=dtype)
else:
Expand Down Expand Up @@ -462,7 +462,7 @@ def where(self, cond, other=None):
other = self._na_value
values = np.where(cond, self.values, other)

from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
cat = Categorical(values,
categories=self.categories,
ordered=self.ordered)
Expand Down Expand Up @@ -775,7 +775,7 @@ def _delegate_method(self, name, *args, **kwargs):
def _add_accessors(cls):
""" add in Categorical accessor methods """

from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
CategoricalIndex._add_delegate_accessors(
delegate=Categorical, accessors=["rename_categories",
"reorder_categories",
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ def from_arrays(cls, arrays, sortorder=None, names=None):
if len(arrays[i]) != len(arrays[i - 1]):
raise ValueError('all arrays must be same length')

from pandas.core.categorical import _factorize_from_iterables
from pandas.core.arrays.categorical import _factorize_from_iterables

labels, levels = _factorize_from_iterables(arrays)
if names is None:
Expand Down Expand Up @@ -1276,7 +1276,7 @@ def from_product(cls, iterables, sortorder=None, names=None):
MultiIndex.from_arrays : Convert list of arrays to MultiIndex
MultiIndex.from_tuples : Convert list of tuples to MultiIndex
"""
from pandas.core.categorical import _factorize_from_iterables
from pandas.core.arrays.categorical import _factorize_from_iterables
from pandas.core.reshape.util import cartesian_product

if not is_list_like(iterables):
Expand Down Expand Up @@ -1749,7 +1749,7 @@ def _get_labels_for_sorting(self):
for sorting, where we need to disambiguate that -1 is not
a valid valid
"""
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical

def cats(label):
return np.arange(np.array(label).max() + 1 if len(label) else 0,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

from pandas.core.index import Index, MultiIndex, _ensure_index
from pandas.core.indexing import maybe_convert_indices, length_of_indexer
from pandas.core.categorical import Categorical, _maybe_to_categorical
from pandas.core.arrays.categorical import Categorical, _maybe_to_categorical
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.io.formats.printing import pprint_thing

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pandas.core.index import (_get_objs_combined_axis,
_ensure_index, _get_consensus_names,
_all_indexes_same)
from pandas.core.categorical import (_factorize_from_iterable,
_factorize_from_iterables)
from pandas.core.arrays.categorical import (_factorize_from_iterable,
_factorize_from_iterables)
from pandas.core.internals import concatenate_block_managers
from pandas.core import common as com
from pandas.core.generic import NDFrame
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pandas.core.dtypes.common import is_list_like
from pandas import compat
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical

from pandas.core.dtypes.generic import ABCMultiIndex

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from pandas.core.sparse.array import SparseArray
from pandas._libs.sparse import IntIndex

from pandas.core.categorical import Categorical, _factorize_from_iterable
from pandas.core.arrays import Categorical
from pandas.core.arrays.categorical import _factorize_from_iterable
from pandas.core.sorting import (get_group_index, get_compressed_ids,
compress_group_index, decons_obs_group_ids)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from pandas.core.indexing import check_bool_indexer, maybe_convert_indices
from pandas.core import generic, base
from pandas.core.internals import SingleBlockManager
from pandas.core.categorical import Categorical, CategoricalAccessor
from pandas.core.arrays.categorical import Categorical, CategoricalAccessor
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def indexer_from_factorized(labels, shape, compress=True):


def lexsort_indexer(keys, orders=None, na_position='last'):
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical

labels = []
shape = []
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_ensure_index_from_sequences)
from pandas.core.series import Series
from pandas.core.frame import DataFrame
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
from pandas.core import algorithms
from pandas.core.common import AbstractMethodError
from pandas.io.date_converters import generic_parser
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from pandas.errors import PerformanceWarning
from pandas.core.common import _asarray_tuplesafe, _all_none
from pandas.core.algorithms import match, unique
from pandas.core.categorical import Categorical, _factorize_from_iterables
from pandas.core.arrays.categorical import (Categorical,
_factorize_from_iterables)
from pandas.core.internals import (BlockManager, make_block,
_block2d_to_blocknd,
_factor_indexer, _block_shape)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pandas.compat import (lrange, lmap, lzip, text_type, string_types, range,
zip, BytesIO)
from pandas.core.base import StringMixin
from pandas.core.categorical import Categorical
from pandas.core.arrays import Categorical
from pandas.core.dtypes.common import (is_categorical_dtype, _ensure_object,
is_datetime64_dtype)
from pandas.core.frame import DataFrame
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/categorical/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas.util.testing as tm
from pandas import Categorical, CategoricalIndex, Index, Series, DataFrame

from pandas.core.categorical import _recode_for_categories
from pandas.core.arrays.categorical import _recode_for_categories
from pandas.tests.categorical.common import TestCategorical


Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,7 @@ def test_cat_accessor(self):

def test_cat_accessor_api(self):
# GH 9322
from pandas.core.categorical import CategoricalAccessor

from pandas.core.arrays.categorical import CategoricalAccessor
assert Series.cat is CategoricalAccessor
s = Series(list('aabbcde')).astype('category')
assert isinstance(s.cat, CategoricalAccessor)
Expand Down

0 comments on commit 4b06ae4

Please sign in to comment.