Skip to content

cleanup inconsistently used imports #19292

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

Merged
merged 4 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
is_list_like, is_sequence,
is_scalar,
is_dict_like)
from pandas.core.common import is_null_slice, _maybe_box_datetimelike

from pandas.core.algorithms import factorize, take_1d, unique1d
from pandas.core.accessor import PandasDelegate
Expand Down Expand Up @@ -468,7 +467,7 @@ def tolist(self):
(for Timestamp/Timedelta/Interval/Period)
"""
if is_datetimelike(self.categories):
return [_maybe_box_datetimelike(x) for x in self]
return [com._maybe_box_datetimelike(x) for x in self]
return np.array(self).tolist()

@property
Expand Down Expand Up @@ -1686,7 +1685,7 @@ def _slice(self, slicer):
# only allow 1 dimensional slicing, but can
# in a 2-d case be passd (slice(None),....)
if isinstance(slicer, tuple) and len(slicer) == 2:
if not is_null_slice(slicer[0]):
if not com.is_null_slice(slicer[0]):
raise AssertionError("invalid slicing for a 1-ndim "
"categorical")
slicer = slicer[1]
Expand Down Expand Up @@ -1847,7 +1846,7 @@ def __setitem__(self, key, value):
# only allow 1 dimensional slicing, but can
# in a 2-d case be passd (slice(None),....)
if len(key) == 2:
if not is_null_slice(key[0]):
if not com.is_null_slice(key[0]):
raise AssertionError("invalid slicing for a 1-ndim "
"categorical")
key = key[1]
Expand Down
44 changes: 19 additions & 25 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
from pandas.core.dtypes.missing import isna, notna

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extras here


from pandas.core.common import (_try_sort,
_default_index,
_values_from_object,
_maybe_box_datetimelike,
_dict_compat,
standardize_mapping)
from pandas.core.generic import NDFrame, _shared_docs
from pandas.core.index import (Index, MultiIndex, _ensure_index,
_ensure_index_from_sequences)
Expand Down Expand Up @@ -387,9 +381,9 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
if isinstance(data[0], Series):
index = _get_names_from_index(data)
elif isinstance(data[0], Categorical):
index = _default_index(len(data[0]))
index = com._default_index(len(data[0]))
else:
index = _default_index(len(data))
index = com._default_index(len(data))

mgr = _arrays_to_mgr(arrays, columns, index, columns,
dtype=dtype)
Expand Down Expand Up @@ -466,7 +460,7 @@ def _init_dict(self, data, index, columns, dtype=None):
else:
keys = list(data.keys())
if not isinstance(data, OrderedDict):
keys = _try_sort(keys)
keys = com._try_sort(keys)
columns = data_names = Index(keys)
arrays = [data[k] for k in keys]

Expand All @@ -493,12 +487,12 @@ def _get_axes(N, K, index=index, columns=columns):
# return axes or defaults

if index is None:
index = _default_index(N)
index = com._default_index(N)
else:
index = _ensure_index(index)

if columns is None:
columns = _default_index(K)
columns = com._default_index(K)
else:
columns = _ensure_index(columns)
return index, columns
Expand Down Expand Up @@ -990,7 +984,7 @@ def to_dict(self, orient='dict', into=dict):
"columns will be omitted.", UserWarning,
stacklevel=2)
# GH16122
into_c = standardize_mapping(into)
into_c = com.standardize_mapping(into)
if orient.lower().startswith('d'):
return into_c(
(k, v.to_dict(into)) for k, v in compat.iteritems(self))
Expand All @@ -1000,13 +994,13 @@ def to_dict(self, orient='dict', into=dict):
return into_c((('index', self.index.tolist()),
('columns', self.columns.tolist()),
('data', lib.map_infer(self.values.ravel(),
_maybe_box_datetimelike)
com._maybe_box_datetimelike)
.reshape(self.values.shape).tolist())))
elif orient.lower().startswith('s'):
return into_c((k, _maybe_box_datetimelike(v))
return into_c((k, com._maybe_box_datetimelike(v))
for k, v in compat.iteritems(self))
elif orient.lower().startswith('r'):
return [into_c((k, _maybe_box_datetimelike(v))
return [into_c((k, com._maybe_box_datetimelike(v))
for k, v in zip(self.columns, np.atleast_1d(row)))
for row in self.values]
elif orient.lower().startswith('i'):
Expand Down Expand Up @@ -2006,7 +2000,7 @@ def _get_value(self, index, col, takeable=False):

if takeable:
series = self._iget_item_cache(col)
return _maybe_box_datetimelike(series._values[index])
return com._maybe_box_datetimelike(series._values[index])

series = self._get_item_cache(col)
engine = self.index._engine
Expand Down Expand Up @@ -3371,7 +3365,7 @@ def _maybe_casted_values(index, labels=None):
values, mask, np.nan)
return values

new_index = _default_index(len(new_obj))
new_index = com._default_index(len(new_obj))
if level is not None:
if not isinstance(level, (tuple, list)):
level = [level]
Expand Down Expand Up @@ -6084,7 +6078,7 @@ def extract_index(data):
(lengths[0], len(index)))
raise ValueError(msg)
else:
index = _default_index(lengths[0])
index = com._default_index(lengths[0])

return _ensure_index(index)

Expand Down Expand Up @@ -6155,7 +6149,7 @@ def _to_arrays(data, columns, coerce_float=False, dtype=None):
dtype=dtype)
elif isinstance(data[0], Categorical):
if columns is None:
columns = _default_index(len(data))
columns = com._default_index(len(data))
return data, columns
elif (isinstance(data, (np.ndarray, Series, Index)) and
data.dtype.names is not None):
Expand All @@ -6179,7 +6173,7 @@ def _masked_rec_array_to_mgr(data, index, columns, dtype, copy):
if index is None:
index = _get_names_from_index(fdata)
if index is None:
index = _default_index(len(data))
index = com._default_index(len(data))
index = _ensure_index(index)

if columns is not None:
Expand Down Expand Up @@ -6239,14 +6233,14 @@ def _list_of_series_to_arrays(data, columns, coerce_float=False, dtype=None):
for s in data:
index = getattr(s, 'index', None)
if index is None:
index = _default_index(len(s))
index = com._default_index(len(s))

if id(index) in indexer_cache:
indexer = indexer_cache[id(index)]
else:
indexer = indexer_cache[id(index)] = index.get_indexer(columns)

values = _values_from_object(s)
values = com._values_from_object(s)
aligned_values.append(algorithms.take_1d(values, indexer))

values = np.vstack(aligned_values)
Expand Down Expand Up @@ -6276,7 +6270,7 @@ def _list_of_dict_to_arrays(data, columns, coerce_float=False, dtype=None):

def _convert_object_array(content, columns, coerce_float=False, dtype=None):
if columns is None:
columns = _default_index(len(content))
columns = com._default_index(len(content))
else:
if len(columns) != len(content): # pragma: no cover
# caller's responsibility to check for this...
Expand All @@ -6298,7 +6292,7 @@ def convert(arr):
def _get_names_from_index(data):
has_some_name = any(getattr(s, 'name', None) is not None for s in data)
if not has_some_name:
return _default_index(len(data))
return com._default_index(len(data))

index = lrange(len(data))
count = 0
Expand Down Expand Up @@ -6333,7 +6327,7 @@ def _homogenize(data, index, dtype=None):
oindex = index.astype('O')

if isinstance(index, (DatetimeIndex, TimedeltaIndex)):
v = _dict_compat(v)
v = com._dict_compat(v)
else:
v = dict(v)
v = lib.fast_multiget(v, oindex.values, default=np.nan)
Expand Down
20 changes: 9 additions & 11 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
from pandas.core.dtypes.inference import is_hashable
from pandas.core.dtypes.missing import isna, notna
from pandas.core.dtypes.generic import ABCSeries, ABCPanel, ABCDataFrame
from pandas.core.common import (_count_not_none,
_maybe_box_datetimelike, _values_from_object,
AbstractMethodError, SettingWithCopyError,
from pandas.core.common import (AbstractMethodError, SettingWithCopyError,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is inconsistent with your change

SettingWithCopyWarning)

from pandas.core.base import PandasObject, SelectionMixin
Expand Down Expand Up @@ -1026,7 +1024,7 @@ def _indexed_same(self, other):
for a in self._AXIS_ORDERS)

def __neg__(self):
values = _values_from_object(self)
values = com._values_from_object(self)
if values.dtype == np.bool_:
arr = operator.inv(values)
else:
Expand All @@ -1035,7 +1033,7 @@ def __neg__(self):

def __invert__(self):
try:
arr = operator.inv(_values_from_object(self))
arr = operator.inv(com._values_from_object(self))
return self.__array_wrap__(arr)
except Exception:

Expand Down Expand Up @@ -1490,7 +1488,7 @@ def __round__(self, decimals=0):
# Array Interface

def __array__(self, dtype=None):
return _values_from_object(self)
return com._values_from_object(self)

def __array_wrap__(self, result, context=None):
d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
Expand Down Expand Up @@ -2696,7 +2694,7 @@ def xs(self, key, axis=0, level=None, drop_level=True):
# that means that their are list/ndarrays inside the Series!
# so just return them (GH 6394)
if not is_list_like(new_values) or self.ndim == 1:
return _maybe_box_datetimelike(new_values)
return com._maybe_box_datetimelike(new_values)

result = self._constructor_sliced(
new_values, index=self.columns,
Expand Down Expand Up @@ -3557,7 +3555,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
"""
import re

nkw = _count_not_none(items, like, regex)
nkw = com._count_not_none(items, like, regex)
if nkw > 1:
raise TypeError('Keyword arguments `items`, `like`, or `regex` '
'are mutually exclusive')
Expand Down Expand Up @@ -6357,7 +6355,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
if try_quick:

try:
new_other = _values_from_object(self).copy()
new_other = com._values_from_object(self).copy()
new_other[icond] = other
other = new_other
except Exception:
Expand Down Expand Up @@ -7318,7 +7316,7 @@ def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None,
rs = (data.div(data.shift(periods=periods, freq=freq, axis=axis,
**kwargs)) - 1)
if freq is None:
mask = isna(_values_from_object(self))
mask = isna(com._values_from_object(self))
np.putmask(rs.values, mask, np.nan)
return rs

Expand Down Expand Up @@ -7778,7 +7776,7 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs):
else:
axis = self._get_axis_number(axis)

y = _values_from_object(self).copy()
y = com._values_from_object(self).copy()

if (skipna and
issubclass(y.dtype.type, (np.datetime64, np.timedelta64))):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pandas.core.tools.timedeltas import to_timedelta

import numpy as np

from pandas.core.dtypes.common import (
_ensure_int64,
is_dtype_equal,
Expand All @@ -29,6 +30,8 @@
from pandas.core.dtypes.generic import (
ABCIndex, ABCSeries, ABCPeriodIndex, ABCIndexClass)
from pandas.core.dtypes.missing import isna
import pandas.core.dtypes.concat as _concat

from pandas.core import common as com, algorithms
from pandas.core.algorithms import checked_add_with_arr
from pandas.core.common import AbstractMethodError
Expand All @@ -41,7 +44,6 @@

from pandas.core.indexes.base import Index, _index_shared_docs
from pandas.util._decorators import Appender, cache_readonly
import pandas.core.dtypes.concat as _concat
import pandas.tseries.frequencies as frequencies

import pandas.core.indexes.base as ibase
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pandas.core.internals import (BlockManager,
create_block_manager_from_arrays,
create_block_manager_from_blocks)
from pandas.core.ops import _op_descriptions

from pandas.core.series import Series
from pandas.core.reshape.util import cartesian_product
from pandas.util._decorators import Appender
Expand Down Expand Up @@ -1545,9 +1545,9 @@ def na_op(x, y):
result = missing.fill_zeros(result, x, y, name, fill_zeros)
return result

if name in _op_descriptions:
if name in ops._op_descriptions:
op_name = name.replace('__', '')
op_desc = _op_descriptions[op_name]
op_desc = ops._op_descriptions[op_name]
if op_desc['reversed']:
equiv = 'other ' + op_desc['op'] + ' panel'
else:
Expand Down
Loading