Repository navigation
Closed
Description
As reported by @chmp in #1678 and captured in this travis.ci run. cc @sinhrks
[gw2] FAILED dask/dataframe/tests/test_reshape.py::test_pivot_table[count]
=================================== FAILURES ===================================
___________________________ test_pivot_table[count] ____________________________
[gw2] linux -- Python 3.3.5 /home/travis/miniconda/envs/test-environment/bin/python3
aggfunc = 'count'
@pytest.mark.parametrize('aggfunc', ['mean', 'sum', 'count'])
def test_pivot_table(aggfunc):
df = pd.DataFrame({'A': np.random.choice(list('XYZ'), size=100),
'B': np.random.randn(100),
'C': pd.Categorical(np.random.choice(list('abc'), size=100))})
ddf = dd.from_pandas(df, 5)
res = dd.pivot_table(ddf, index='A', columns='C', values='B',
aggfunc=aggfunc)
exp = pd.pivot_table(df, index='A', columns='C', values='B',
aggfunc=aggfunc)
if aggfunc == 'count':
# dask result cannot be int64 dtype depending on divisions because of NaN
exp = exp.astype(np.float64)
if PANDAS_ge_0190:
assert_eq(res, exp)
else:
# because of a pandas 0.18.x bug, categorical dtype is not preserved
> assert_eq(res, exp, check_names=False, check_column_type=False)
dask/dataframe/tests/test_reshape.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dask/dataframe/utils.py:427: in assert_eq
tm.assert_frame_equal(a, b, **kwargs)
../../../miniconda/envs/test-environment/lib/python3.3/site-packages/pandas/util/testing.py:1166: in assert_frame_equal
obj='DataFrame.iloc[:, {0}]'.format(i))
../../../miniconda/envs/test-environment/lib/python3.3/site-packages/pandas/util/testing.py:1026: in assert_series_equal
assert_attr_equal('dtype', left, right)
../../../miniconda/envs/test-environment/lib/python3.3/site-packages/pandas/util/testing.py:804: in assert_attr_equal
left_attr, right_attr)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
obj = 'Attributes', message = 'Attribute "dtype" are different'
left = dtype('int64'), right = dtype('float64')
def raise_assert_detail(obj, message, left, right):
if isinstance(left, np.ndarray):
left = pprint_thing(left)
if isinstance(right, np.ndarray):
right = pprint_thing(right)
msg = """{0} are different
{1}
[left]: {2}
[right]: {3}""".format(obj, message, left, right)
> raise AssertionError(msg)
E AssertionError: Attributes are different
E
E Attribute "dtype" are different
E [left]: int64
E [right]: float64
Activity
sinhrks commentedon Oct 20, 2016
maybe depends on nans included in intermedfiate results. will check this weekend.
chmp commentedon Oct 20, 2016
After I added additional tests in #1678, I encounter similar errors myself. At least for my code, I'm pretty sure it is caused by the fact that pandas tries to downcast the result back to the original type in groupby aggregations. The relevant code can be found in _GroupBy._try_cast. Maybe a similar process is at play here.
mrocklin commentedon Oct 23, 2016
@chmp do you happen to understand this problem well enough to create a smaller reproducible example than the test linked to above?
chmp commentedon Oct 23, 2016
Actually, I misread the test, I assumed it was related to the mean. For count, the explanation of @sinhrks should be right.
sinhrks commentedon Oct 23, 2016
I've just prepared a fix to always return
np.float64for"count". Becausedtypecannot be determined until all partition results are combined. Sending a PR once travis is green.arita37 commentedon Jan 9, 2017
There is similar issue on float16:
if one column is float16 and you sum the whole in aggfunc, the result is overflow float16.
The remedy is to convert to float32 the column.... (for very large table, float16 saves memory......), so having aggregated results in float64 is better.