Skip to content

Fixes #8933 simple renaming #8959

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 1 commit into from
Dec 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pandas.core.common import (CategoricalDtype, ABCSeries, isnull, notnull,
is_categorical_dtype, is_integer_dtype, is_object_dtype,
_possibly_infer_to_datetimelike, get_dtype_kinds,
is_list_like, _is_sequence,
is_list_like, is_sequence,
_ensure_platform_int, _ensure_object, _ensure_int64,
_coerce_indexer_dtype, _values_from_object, take_1d)
from pandas.util.terminal import get_terminal_size
Expand Down Expand Up @@ -1477,7 +1477,7 @@ def _convert_to_list_like(list_like):
return list_like
if isinstance(list_like, list):
return list_like
if (_is_sequence(list_like) or isinstance(list_like, tuple)
if (is_sequence(list_like) or isinstance(list_like, tuple)
or isinstance(list_like, types.GeneratorType)):
return list(list_like)
elif np.isscalar(list_like):
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2504,14 +2504,15 @@ def is_list_like(arg):
not isinstance(arg, compat.string_and_binary_types))


def _is_sequence(x):
def is_sequence(x):
try:
iter(x)
len(x) # it has a length
return not isinstance(x, compat.string_and_binary_types)
except (TypeError, AttributeError):
return False


def _get_callable_name(obj):
# typical case has name
if hasattr(obj, '__name__'):
Expand Down Expand Up @@ -3093,7 +3094,7 @@ def as_escaped_unicode(thing, escape_chars=escape_chars):
elif (isinstance(thing, dict) and
_nest_lvl < get_option("display.pprint_nest_depth")):
result = _pprint_dict(thing, _nest_lvl, quote_strings=True)
elif _is_sequence(thing) and _nest_lvl < \
elif is_sequence(thing) and _nest_lvl < \
get_option("display.pprint_nest_depth"):
result = _pprint_seq(thing, _nest_lvl, escape_chars=escape_chars,
quote_strings=quote_strings)
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import numpy.ma as ma

from pandas.core.common import (isnull, notnull, PandasError, _try_sort,
_default_index, _maybe_upcast, _is_sequence,
_default_index, _maybe_upcast, is_sequence,
_infer_dtype_from_scalar, _values_from_object,
is_list_like, _get_dtype, _maybe_box_datetimelike,
is_categorical_dtype)
Expand Down Expand Up @@ -2255,7 +2255,7 @@ def reindexer(value):
elif isinstance(value, Categorical):
value = value.copy()

elif (isinstance(value, Index) or _is_sequence(value)):
elif (isinstance(value, Index) or is_sequence(value)):
from pandas.core.series import _sanitize_index
value = _sanitize_index(value, self.index, copy=False)
if not isinstance(value, (np.ndarray, Index)):
Expand Down Expand Up @@ -2844,7 +2844,7 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False,
'(rows)')
if not isinstance(by, list):
by = [by]
if com._is_sequence(ascending) and len(by) != len(ascending):
if com.is_sequence(ascending) and len(by) != len(ascending):
raise ValueError('Length of ascending (%d) != length of by'
' (%d)' % (len(ascending), len(by)))
if len(by) > 1:
Expand Down Expand Up @@ -3694,7 +3694,7 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True):
com.pprint_thing(k),)
raise

if len(results) > 0 and _is_sequence(results[0]):
if len(results) > 0 and is_sequence(results[0]):
if not isinstance(results[0], Series):
index = res_columns
else:
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def _align_series(self, indexer, ser):
# we have a frame, with multiple indexers on both axes; and a
# series, so need to broadcast (see GH5206)
if (sum_aligners == self.ndim and
all([com._is_sequence(_) for _ in indexer])):
all([com.is_sequence(_) for _ in indexer])):
ser = ser.reindex(obj.axes[0][indexer[0]], copy=True).values

# single indexer
Expand All @@ -555,7 +555,7 @@ def _align_series(self, indexer, ser):
ax = obj.axes[i]

# multiple aligners (or null slices)
if com._is_sequence(idx) or isinstance(idx, slice):
if com.is_sequence(idx) or isinstance(idx, slice):
if single_aligner and _is_null_slice(idx):
continue
new_ix = ax[idx]
Expand Down Expand Up @@ -625,7 +625,7 @@ def _align_frame(self, indexer, df):
sindexers = []
for i, ix in enumerate(indexer):
ax = self.obj.axes[i]
if com._is_sequence(ix) or isinstance(ix, slice):
if com.is_sequence(ix) or isinstance(ix, slice):
if idx is None:
idx = ax[ix].ravel()
elif cols is None:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_mut_exclusive():


def test_is_sequence():
is_seq = com._is_sequence
is_seq = com.is_sequence
assert(is_seq((1, 2)))
assert(is_seq([1, 2]))
assert(not is_seq("abcd"))
Expand Down
4 changes: 2 additions & 2 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from numpy.testing import assert_array_equal

import pandas as pd
from pandas.core.common import _is_sequence, array_equivalent, is_list_like
from pandas.core.common import is_sequence, array_equivalent, is_list_like
import pandas.core.index as index
import pandas.core.series as series
import pandas.core.frame as frame
Expand Down Expand Up @@ -945,7 +945,7 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None,

if ndupe_l is None:
ndupe_l = [1] * nlevels
assert (_is_sequence(ndupe_l) and len(ndupe_l) <= nlevels)
assert (is_sequence(ndupe_l) and len(ndupe_l) <= nlevels)
assert (names is None or names is False
or names is True or len(names) is nlevels)
assert idx_type is None or \
Expand Down