Skip to content

Commit e6c3cd6

Browse files
committed
Tentative fix for pandas-dev#4297.
The problem finally seem to be an odd restriction: acceptable sequences were list, tuple, or numpy.ndarray. A guess is that strings in Python wanted to be considered scalars, but the above restriction was implemented rather than take anything with a __len__ except str (or unicode for Python 2.x) in. Considerations about the use of the buffer interface are not needed for now. note: I cannot run tests on Python 2.7. ``` nosetests pandas ``` ends with: ``` from . import hashtable, tslib, lib ImportError: cannot import name hashtable ```
1 parent d2b85ff commit e6c3cd6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pandas/core/frame.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -5700,9 +5700,20 @@ def extract_index(data):
57005700
elif isinstance(v, dict):
57015701
have_dicts = True
57025702
indexes.append(v.keys())
5703-
elif isinstance(v, (list, tuple, np.ndarray)):
5704-
have_raw_arrays = True
5705-
raw_lengths.append(len(v))
5703+
elif not (isinstance(v, str) or \
5704+
isinstance(v, unicode)):
5705+
# Although strings have a __len__,
5706+
# they are likely to be considered scalars.
5707+
try:
5708+
l = len(v)
5709+
except TypeError:
5710+
continue
5711+
# Anything else with a __len__ is considered
5712+
# a sequence (to be safe, we check
5713+
# that there is __getitem__)
5714+
if hasattr(v, '__getitem__'):
5715+
have_raw_arrays = True
5716+
raw_lengths.append(l)
57065717

57075718
if not indexes and not raw_lengths:
57085719
raise ValueError('If using all scalar values, you must pass'

0 commit comments

Comments
 (0)