Skip to content

Commit 50a3c96

Browse files
author
y-p
committed
BUG: pathological objects cause infinite loop when passed to pprint_thing
1 parent 1c1e9a8 commit 50a3c96

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

doc/source/v0.11.0.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ Bug Fixes
208208
datetime(2011,1,1,3,5) - s
209209
timedelta(minutes=5) + s
210210

211+
- Fix pretty-printing of infinite data structures, GH2978
212+
213+
211214
See the `full release notes
212215
<https://github.com/pydata/pandas/blob/master/RELEASE.rst>`__ or issue tracker
213216
on GitHub for a complete list.
@@ -216,4 +219,4 @@ on GitHub for a complete list.
216219
.. _GH2810: https://github.com/pydata/pandas/issues/2810
217220
.. _GH2837: https://github.com/pydata/pandas/issues/2837
218221
.. _GH2898: https://github.com/pydata/pandas/issues/2898
219-
222+
.. _GH2978: https://github.com/pydata/pandas/issues/2978

pandas/core/common.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def _get_take_nd_function(ndim, arr_dtype, out_dtype, axis=0, mask_info=None):
440440
if func is not None:
441441
func = _convert_wrapper(func, out_dtype)
442442
return func
443-
443+
444444
def func(arr, indexer, out, fill_value=np.nan):
445445
_take_nd_generic(arr, indexer, out, axis=axis,
446446
fill_value=fill_value, mask_info=mask_info)
@@ -695,7 +695,7 @@ def _maybe_promote(dtype, fill_value=np.nan):
695695
except:
696696
# the proper thing to do here would probably be to upcast to
697697
# object (but numpy 1.6.1 doesn't do this properly)
698-
fill_value = tslib.iNaT
698+
fill_value = tslib.iNaT
699699
elif is_float(fill_value):
700700
if issubclass(dtype.type, np.bool_):
701701
dtype = np.object_
@@ -895,7 +895,7 @@ def _possibly_convert_objects(values, convert_dates=True, convert_numeric=True):
895895
if convert_numeric and values.dtype == np.object_:
896896
try:
897897
new_values = lib.maybe_convert_numeric(values,set(),coerce_numeric=True)
898-
898+
899899
# if we are all nans then leave me alone
900900
if not isnull(new_values).all():
901901
values = new_values
@@ -1154,7 +1154,7 @@ def _long_prod(vals):
11541154
result *= x
11551155
return result
11561156

1157-
1157+
11581158
class groupby(dict):
11591159
"""
11601160
A simple groupby different from the one in itertools.
@@ -1343,6 +1343,7 @@ def is_list_like(arg):
13431343
def _is_sequence(x):
13441344
try:
13451345
iter(x)
1346+
len(x) # it has a length
13461347
return not isinstance(x, basestring) and True
13471348
except Exception:
13481349
return False
@@ -1647,7 +1648,8 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
16471648
rather then calling this directly.
16481649
"""
16491650
fmt = u"[%s]" if hasattr(seq, '__setitem__') else u"(%s)"
1650-
return fmt % ", ".join(pprint_thing(e, _nest_lvl + 1, **kwds) for e in seq)
1651+
return fmt % ", ".join(pprint_thing(e, _nest_lvl + 1, **kwds)
1652+
for e in seq[:len(seq)])
16511653

16521654

16531655
def _pprint_dict(seq, _nest_lvl=0):

0 commit comments

Comments
 (0)