Skip to content

Commit

Permalink
BUG: Don't convert uint64 object in DataFrame init
Browse files Browse the repository at this point in the history
The hack used to resolve pandas-devgh-2355 is no longer needed.
Removes the hack and patches several tests that relied
on this hacky (and buggy) behavior.

Closes pandas-devgh-14881.
  • Loading branch information
gfyoung committed Dec 19, 2016
1 parent f1cfe5b commit d79a475
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
5 changes: 0 additions & 5 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4314,11 +4314,6 @@ def form_blocks(arrays, names, axes):
elif is_datetimetz(v):
datetime_tz_items.append((i, k, v))
elif issubclass(v.dtype.type, np.integer):
if v.dtype == np.uint64:
# HACK #2355 definite overflow
if (v > 2**63 - 1).any():
object_items.append((i, k, v))
continue
int_items.append((i, k, v))
elif v.dtype == np.bool_:
bool_items.append((i, k, v))
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ def test_constructor_bool(self):
self.assertEqual(df.values.dtype, np.bool_)

def test_constructor_overflow_int64(self):
# see gh-14881
values = np.array([2 ** 64 - i for i in range(1, 10)],
dtype=np.uint64)

result = DataFrame({'a': values})
self.assertEqual(result['a'].dtype, object)
self.assertEqual(result['a'].dtype, np.uint64)

# #2355
# see gh-2355
data_scores = [(6311132704823138710, 273), (2685045978526272070, 23),
(8921811264899370420, 45),
(long(17019687244989530680), 270),
Expand All @@ -198,7 +199,7 @@ def test_constructor_overflow_int64(self):
data = np.zeros((len(data_scores),), dtype=dtype)
data[:] = data_scores
df_crawls = DataFrame(data)
self.assertEqual(df_crawls['uid'].dtype, object)
self.assertEqual(df_crawls['uid'].dtype, np.uint64)

def test_constructor_ordereddict(self):
import random
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ def test_arith_flex_frame(self):
result = getattr(self.mixed_int, op)(2 + self.mixed_int)
exp = f(self.mixed_int, 2 + self.mixed_int)

# overflow in the uint
# no overflow in the uint
dtype = None
if op in ['sub']:
dtype = dict(B='object', C=None)
dtype = dict(B='uint64', C=None)
elif op in ['add', 'mul']:
dtype = dict(C=None)
assert_frame_equal(result, exp)
Expand Down Expand Up @@ -410,10 +410,10 @@ def test_arith_flex_frame(self):
2 + self.mixed_int)
exp = f(self.mixed_int, 2 + self.mixed_int)

# overflow in the uint
# no overflow in the uint
dtype = None
if op in ['sub']:
dtype = dict(B='object', C=None)
dtype = dict(B='uint64', C=None)
elif op in ['add', 'mul']:
dtype = dict(C=None)
assert_frame_equal(result, exp)
Expand Down

0 comments on commit d79a475

Please sign in to comment.