Skip to content

Commit 4e52e0d

Browse files
committed
BUG: don't cast to tuple except in failure, only test with namedtuple when it exists (py >= 2.7), GH #611
1 parent af839c5 commit 4e52e0d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

pandas/src/inference.pyx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,17 @@ def to_object_array_tuples(list rows):
447447

448448
result = np.empty((n, k), dtype=object)
449449

450-
for i from 0 <= i < n:
451-
row = tuple(rows[i]) # upcast any subclasses to tuple
452-
453-
for j from 0 <= j < len(row):
454-
result[i, j] = row[j]
450+
try:
451+
for i in range(n):
452+
row = rows[i]
453+
for j from 0 <= j < len(row):
454+
result[i, j] = row[j]
455+
except Exception:
456+
# upcast any subclasses to tuple
457+
for i in range(n):
458+
row = tuple(rows[i])
459+
for j from 0 <= j < len(row):
460+
result[i, j] = row[j]
455461

456462
return result
457463

pandas/tests/test_tseries.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,15 @@ def test_to_object_array_tuples(self):
280280
values = [r]
281281
result = lib.to_object_array_tuples(values)
282282

283-
# make sure record array works
284-
import collections as col
285-
record = col.namedtuple('record', 'x y')
286-
r = record(5,6)
287-
values = [r]
288-
result = lib.to_object_array_tuples(values)
283+
try:
284+
# make sure record array works
285+
from collections import namedtuple
286+
record = namedtuple('record', 'x y')
287+
r = record(5, 6)
288+
values = [r]
289+
result = lib.to_object_array_tuples(values)
290+
except ImportError:
291+
pass
289292

290293
class TestMoments(unittest.TestCase):
291294
pass

0 commit comments

Comments
 (0)