Skip to content

Commit 59678a6

Browse files
committed
ENH: Raise and catch FloatingPointException due to overflow
* Modify tests to only cover windows platforms
1 parent b44ca16 commit 59678a6

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

pandas/core/reshape/reshape.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,12 @@ def __init__(self, values, index, level=-1, value_columns=None,
130130
num_rows = np.max([index_level.size for index_level
131131
in self.new_index_levels])
132132
num_columns = self.removed_level.size
133-
if num_rows * num_columns > (2 ** 31 - 1):
134-
raise ValueError('Unstacked DataFrame is too big, '
135-
'causing int32 overflow')
133+
with np.errstate(all='raise'):
134+
try:
135+
num_columns * num_rows
136+
except FloatingPointError:
137+
raise ValueError('Unstacked DataFrame is too big, '
138+
'causing int32 overflow')
136139

137140
self._make_sorted_values_labels()
138141
self._make_selectors()

pandas/tests/reshape/test_pivot.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from datetime import datetime, date, timedelta
4+
import sys
45

56
import pytest
67

@@ -1279,12 +1280,14 @@ def test_pivot_string_func_vs_func(self, f, f_numpy):
12791280
@pytest.mark.slow
12801281
def test_pivot_number_of_levels_larger_than_int32(self):
12811282
# GH 20601
1282-
df = DataFrame({'ind1': np.arange(2 ** 16),
1283-
'ind2': np.arange(2 ** 16),
1284-
'count': np.arange(2 ** 16)})
1285-
with tm.assert_raises_regex(ValueError, 'int32 overflow'):
1286-
df.pivot_table(index='ind1', columns='ind2',
1287-
values='count', aggfunc='count')
1283+
if sys.platform == 'win32':
1284+
df = DataFrame({'ind1': np.arange(2 ** 16),
1285+
'ind2': np.arange(2 ** 16),
1286+
'count': 0})
1287+
1288+
with tm.assert_raises_regex(ValueError, 'int32 overflow'):
1289+
df.pivot_table(index='ind1', columns='ind2',
1290+
values='count', aggfunc='count')
12881291

12891292

12901293
class TestCrosstab(object):

pandas/tests/test_multilevel.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from warnings import catch_warnings, simplefilter
44
import datetime
55
import itertools
6+
import sys
7+
68
import pytest
79
import pytz
810

@@ -1214,11 +1216,12 @@ def test_unstack_unobserved_keys(self):
12141216

12151217
@pytest.mark.slow
12161218
def test_unstack_number_of_levels_larger_than_int32(self):
1217-
# GH 20601
1218-
df = DataFrame(np.random.randn(2 ** 16, 2),
1219-
index=[np.arange(2 ** 16), np.arange(2 ** 16)])
1220-
with tm.assert_raises_regex(ValueError, 'int32 overflow'):
1221-
df.unstack()
1219+
if sys.platform == 'win32':
1220+
# GH 20601
1221+
df = DataFrame(np.random.randn(2 ** 16, 2),
1222+
index=[np.arange(2 ** 16), np.arange(2 ** 16)])
1223+
with tm.assert_raises_regex(ValueError, 'int32 overflow'):
1224+
df.unstack()
12221225

12231226
def test_stack_order_with_unsorted_levels(self):
12241227
# GH 16323

0 commit comments

Comments
 (0)