Skip to content

Intermittent failure in pivot_table test #1685

Closed

Description

@mrocklin

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

  1. sinhrks commented on Oct 20, 2016

    @sinhrks
    Member

    maybe depends on nans included in intermedfiate results. will check this weekend.

  2. chmp commented on Oct 20, 2016

    @chmp
    Contributor

    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.

  3. mrocklin commented on Oct 23, 2016

    @mrocklin
    MemberAuthor

    @chmp do you happen to understand this problem well enough to create a smaller reproducible example than the test linked to above?

  4. chmp commented on Oct 23, 2016

    @chmp
    Contributor

    Actually, I misread the test, I assumed it was related to the mean. For count, the explanation of @sinhrks should be right.

  5. sinhrks commented on Oct 23, 2016

    @sinhrks
    Member

    I've just prepared a fix to always return np.float64 for "count". Because dtype cannot be determined until all partition results are combined. Sending a PR once travis is green.

  6. added this to the 0.12.0 milestone on Nov 7, 2016
  7. arita37 commented on Jan 9, 2017

    @arita37

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions