Skip to content

Pandas 0.24.0 compat - #4374

Merged
TomAugspurger merged 26 commits into
dask:masterfrom
TomAugspurger:pandas-rc-test
Jan 17, 2019
Merged

TomAugspurger merged 26 commits into
dask:masterfrom
TomAugspurger:pandas-rc-test

Conversation

@TomAugspurger

Copy link
Copy Markdown
Member

No description provided.


def test_meta_nonempty_empty_categories():
for dtype in ['O', 'f8', 'M8']:
for dtype in ['O', 'f8', 'M8[ns]']:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this worked by accident previously: pandas-dev/pandas#24753

Not sure if pandas will put in a compat layer for now, or whether we'll just raise.

res = dd.get_dummies(ds, sparse=True)
assert_eq(exp, res)

assert res.compute().a.dtype == 'uint8'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a deliberate break by pandas.

@mrocklin

Copy link
Copy Markdown
Member

Thank you for doing this @TomAugspurger

I'll be especially happy to see dask dataframe support IntegerNA when Pandas does :) It's a nice example of gaining features for free from playing nicely with the ecosystem.

@TomAugspurger

Copy link
Copy Markdown
Member Author

It's a nice example of gaining features for free from playing nicely with the ecosystem.

Stay tuned for a future blogpost :)


I'm also working on getting support for 3rd party extension dtypes working. I suspect that we'll get decently far by providing a make_arary_nonempty that's an instance of Dispatch, which 3rd party authors can implement.

@TomAugspurger

Copy link
Copy Markdown
Member Author

Looking into the groupby segfault... Good news, it's easy to reproduce. Bad news, I'm not sure what the solution is...

In [4]: import numpy as np

In [5]: np.dtype(dask.delayed(3))

(segfault).

Pandas hits this in ops like Series + Delayed when checking dtypes (and many other places I'm sure).

@TomAugspurger

Copy link
Copy Markdown
Member Author

Running under lldb, I see a whole lot of calls to PyArray_DescrConverter

    frame #131026: 0x00000001043df616 _multiarray_umath.cpython-37m-darwin.so`PyArray_DescrConverter + 1030
    frame #131027: 0x00000001043df616 _multiarray_umath.cpython-37m-darwin.so`PyArray_DescrConverter + 1030
    frame #131028: 0x00000001043e21f1 _multiarray_umath.cpython-37m-darwin.so`arraydescr_new + 145
    frame #131029: 0x00000001000f6a30 Python`type_call + 50
    frame #131030: 0x00000001000bb5a1 Python`_PyObject_FastCallKeywords + 359
    frame #131031: 0x000000010015140a Python`call_function + 746
    frame #131032: 0x0000000100149fdd Python`_PyEval_EvalFrameDefault + 7016
    frame #131033: 0x0000000100151ca3 Python`_PyEval_EvalCodeWithName + 1835
    frame #131034: 0x00000001001483ed Python`PyEval_EvalCode + 42
    frame #131035: 0x0000000100177195 Python`run_mod + 54
    frame #131036: 0x00000001001761b0 Python`PyRun_FileExFlags + 164
    frame #131037: 0x000000010017586a Python`PyRun_SimpleFileExFlags + 266
    frame #131038: 0x000000010018e5f7 Python`pymain_main + 5665
    frame #131039: 0x000000010018ec1b Python`_Py_UnixMain + 75
    frame #131040: 0x00007fff732c5015 libdyld.dylib`start + 1
    frame #131041: 0x00007fff732c5015 libdyld.dylib`start + 1

everything less that frame 131026 is the same as far back as my terminal history goes.

@TomAugspurger

Copy link
Copy Markdown
Member Author

@jcrist do you have any thoughts on the np.dtype(Delayed) issue from
#4374 (comment)? I'm not sure how realistic it'll be to avoid calling np.dtype on these objects in pandas (we're pretty cavalier about what we call our dtype methods on, and it's caused issues in the past as well, but it's done all over the place).

@jcrist

jcrist commented Jan 15, 2019

Copy link
Copy Markdown
Member

@jcrist do you have any thoughts on the np.dtype(Delayed) issue from
#4374 (comment)?

Interesting, this is due to a recursion error. I think we can special case this in dask delayed, working on a patch now.

jcrist added a commit to jcrist/dask that referenced this pull request Jan 15, 2019
Calling `np.dtype(dask.delayed(...))` used to result in a segfault, as
numpy recursively tries to get `dtype` from the object. This is likely a
bug in numpy. For now, we can do a dumb for if `x.dtype().dtype()` is
called (which shouldn't ever show up in real code).

See dask#4374 (comment).
@jcrist

jcrist commented Jan 15, 2019

Copy link
Copy Markdown
Member

Should be fixed by #4387

jcrist added a commit that referenced this pull request Jan 15, 2019
* Calling np.dtype on a delayed object works

Calling `np.dtype(dask.delayed(...))` used to result in a segfault, as
numpy recursively tries to get `dtype` from the object. This is likely a
bug in numpy. For now, we can do a dumb for if `x.dtype().dtype()` is
called (which shouldn't ever show up in real code).

See #4374 (comment).

* Add test that dtype attribute still works if computed
@TomAugspurger

Copy link
Copy Markdown
Member Author

This is passing now. How should we proceed? I don't really think we should include the CI changes here, since they'll go stale after the pandas release.

Instead, I think that I'll revert the CI changes, and in theory the upstream-dev build should be passing again with these changes.

@TomAugspurger

Copy link
Copy Markdown
Member Author

Actually, spoke too soon, as I don't think this was tested against the RC. Need to remove the pin.

@TomAugspurger

Copy link
Copy Markdown
Member Author

The latest should fix all the remaining failures, expect

dask/dataframe/io/tests/test_csv.py:308: AssertionError
________________________ test_rearrange[threads-tasks] _________________________
shuffle = 'tasks', scheduler = 'threads'
    @pytest.mark.parametrize('shuffle', ['tasks', 'disk'])
    @pytest.mark.parametrize('scheduler', ['threads', 'processes'])
    def test_rearrange(shuffle, scheduler):
        df = pd.DataFrame({'x': np.random.random(10)})
        ddf = dd.from_pandas(df, npartitions=4)
        ddf2 = ddf.assign(y=ddf.x % 4)
    
        result = rearrange_by_column(ddf2, 'y', max_branch=32, shuffle=shuffle)
        assert result.npartitions == ddf.npartitions
        assert set(ddf.dask).issubset(result.dask)
    
        # Every value in exactly one partition
        a = result.compute(scheduler=scheduler)
        get = dask.base.get_scheduler(scheduler=scheduler)
        parts = get(result.dask, result.__dask_keys__())
        for i in a.y.drop_duplicates():
>           assert sum(i in part.y for part in parts) == 1
E           assert 0 == 1
E            +  where 0 = sum(<generator object test_rearrange.<locals>.<genexpr> at 0x7f24a8a2bbf8>)
dask/dataframe/tests/test_shuffle.py:263: AssertionError
_______________________ test_rearrange[processes-tasks] ________________________
shuffle = 'tasks', scheduler = 'processes'
    @pytest.mark.parametrize('shuffle', ['tasks', 'disk'])
    @pytest.mark.parametrize('scheduler', ['threads', 'processes'])
    def test_rearrange(shuffle, scheduler):
        df = pd.DataFrame({'x': np.random.random(10)})
        ddf = dd.from_pandas(df, npartitions=4)
        ddf2 = ddf.assign(y=ddf.x % 4)
    
        result = rearrange_by_column(ddf2, 'y', max_branch=32, shuffle=shuffle)
        assert result.npartitions == ddf.npartitions
        assert set(ddf.dask).issubset(result.dask)
    
        # Every value in exactly one partition
        a = result.compute(scheduler=scheduler)
        get = dask.base.get_scheduler(scheduler=scheduler)
        parts = get(result.dask, result.__dask_keys__())
        for i in a.y.drop_duplicates():
>           assert sum(i in part.y for part in parts) == 1
E           assert 0 == 1
E            +  where 0 = sum(<generator object test_rearrange.<locals>.<genexpr> at 0x7f24ab7132b0>)

Haven't had time to debug that yet.

Some of the doctests will fail. The bad docstrings are in pandas and have been fixed on master.

@TomAugspurger

Copy link
Copy Markdown
Member Author

8474bde fixes the test in
#4374 (comment). The test intended to check that the unique values in the Series show up once with an sum(i in series for series in parts). For Series, x in Series checks whether x is in the index, not the values. pandas-dev/pandas#22085 fixed a bug where a in Series previously reported True for float a and a series with an integer index.

I believe that all the tests will now pass aside from the failing doctests in pandas. Skipping just those proved difficult, so I'm going to verify that just those doctests fail and revert the CI changes.

@TomAugspurger

Copy link
Copy Markdown
Member Author

https://travis-ci.org/dask/dask/jobs/480356385 is the build, here are the failures

Details
=================================== FAILURES ===================================
__________________ [doctest] dask.dataframe.core.DataFrame.eq __________________
3014     cost  revenue
3015 A  False     True
3016 B  False    False
3017 C   True    False
3018 
3019 Compare to a list and Series by axis and operator version. As shown,
3020 for list axis is by default 'index', but for Series axis is by
3021 default 'columns'.
3022 
3023 >>> df != [100, 250, 300]
UNEXPECTED EXCEPTION: ValueError('Unable to coerce to Series, length must be 2: given 3',)
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/doctest.py", line 1330, in __run
    compileflags, 1), test.globs)
  File "<doctest dask.dataframe.core.DataFrame.eq[4]>", line 1, in <module>
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 2085, in f
    other = _align_method_FRAME(self, other, axis=None)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1979, in _align_method_FRAME
    right = to_series(right)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1941, in to_series
    given_len=len(right)))
ValueError: Unable to coerce to Series, length must be 2: given 3
/home/travis/build/dask/dask/dask/dataframe/core.py:3023: UnexpectedException
__________________ [doctest] dask.dataframe.core.DataFrame.ge __________________
3014     cost  revenue
3015 A  False     True
3016 B  False    False
3017 C   True    False
3018 
3019 Compare to a list and Series by axis and operator version. As shown,
3020 for list axis is by default 'index', but for Series axis is by
3021 default 'columns'.
3022 
3023 >>> df != [100, 250, 300]
UNEXPECTED EXCEPTION: ValueError('Unable to coerce to Series, length must be 2: given 3',)
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/doctest.py", line 1330, in __run
    compileflags, 1), test.globs)
  File "<doctest dask.dataframe.core.DataFrame.ge[4]>", line 1, in <module>
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 2085, in f
    other = _align_method_FRAME(self, other, axis=None)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1979, in _align_method_FRAME
    right = to_series(right)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1941, in to_series
    given_len=len(right)))
ValueError: Unable to coerce to Series, length must be 2: given 3
/home/travis/build/dask/dask/dask/dataframe/core.py:3023: UnexpectedException
__________________ [doctest] dask.dataframe.core.DataFrame.gt __________________
3014     cost  revenue
3015 A  False     True
3016 B  False    False
3017 C   True    False
3018 
3019 Compare to a list and Series by axis and operator version. As shown,
3020 for list axis is by default 'index', but for Series axis is by
3021 default 'columns'.
3022 
3023 >>> df != [100, 250, 300]
UNEXPECTED EXCEPTION: ValueError('Unable to coerce to Series, length must be 2: given 3',)
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/doctest.py", line 1330, in __run
    compileflags, 1), test.globs)
  File "<doctest dask.dataframe.core.DataFrame.gt[4]>", line 1, in <module>
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 2085, in f
    other = _align_method_FRAME(self, other, axis=None)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1979, in _align_method_FRAME
    right = to_series(right)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1941, in to_series
    given_len=len(right)))
ValueError: Unable to coerce to Series, length must be 2: given 3
/home/travis/build/dask/dask/dask/dataframe/core.py:3023: UnexpectedException
__________________ [doctest] dask.dataframe.core.DataFrame.le __________________
3014     cost  revenue
3015 A  False     True
3016 B  False    False
3017 C   True    False
3018 
3019 Compare to a list and Series by axis and operator version. As shown,
3020 for list axis is by default 'index', but for Series axis is by
3021 default 'columns'.
3022 
3023 >>> df != [100, 250, 300]
UNEXPECTED EXCEPTION: ValueError('Unable to coerce to Series, length must be 2: given 3',)
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/doctest.py", line 1330, in __run
    compileflags, 1), test.globs)
  File "<doctest dask.dataframe.core.DataFrame.le[4]>", line 1, in <module>
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 2085, in f
    other = _align_method_FRAME(self, other, axis=None)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1979, in _align_method_FRAME
    right = to_series(right)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1941, in to_series
    given_len=len(right)))
ValueError: Unable to coerce to Series, length must be 2: given 3
/home/travis/build/dask/dask/dask/dataframe/core.py:3023: UnexpectedException
__________________ [doctest] dask.dataframe.core.DataFrame.lt __________________
3014     cost  revenue
3015 A  False     True
3016 B  False    False
3017 C   True    False
3018 
3019 Compare to a list and Series by axis and operator version. As shown,
3020 for list axis is by default 'index', but for Series axis is by
3021 default 'columns'.
3022 
3023 >>> df != [100, 250, 300]
UNEXPECTED EXCEPTION: ValueError('Unable to coerce to Series, length must be 2: given 3',)
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/doctest.py", line 1330, in __run
    compileflags, 1), test.globs)
  File "<doctest dask.dataframe.core.DataFrame.lt[4]>", line 1, in <module>
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 2085, in f
    other = _align_method_FRAME(self, other, axis=None)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1979, in _align_method_FRAME
    right = to_series(right)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1941, in to_series
    given_len=len(right)))
ValueError: Unable to coerce to Series, length must be 2: given 3
/home/travis/build/dask/dask/dask/dataframe/core.py:3023: UnexpectedException
__________________ [doctest] dask.dataframe.core.DataFrame.ne __________________
3014     cost  revenue
3015 A  False     True
3016 B  False    False
3017 C   True    False
3018 
3019 Compare to a list and Series by axis and operator version. As shown,
3020 for list axis is by default 'index', but for Series axis is by
3021 default 'columns'.
3022 
3023 >>> df != [100, 250, 300]
UNEXPECTED EXCEPTION: ValueError('Unable to coerce to Series, length must be 2: given 3',)
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/doctest.py", line 1330, in __run
    compileflags, 1), test.globs)
  File "<doctest dask.dataframe.core.DataFrame.ne[4]>", line 1, in <module>
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 2085, in f
    other = _align_method_FRAME(self, other, axis=None)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1979, in _align_method_FRAME
    right = to_series(right)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/pandas/core/ops.py", line 1941, in to_series
    given_len=len(right)))
ValueError: Unable to coerce to Series, length must be 2: given 3
/home/travis/build/dask/dask/dask/dataframe/core.py:3023: UnexpectedException

so just the expected doctest failures.

@TomAugspurger TomAugspurger left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All green. Planning to merge later today if there are no objections.

Comment thread dask/dataframe/utils.py
elif is_integer_na_dtype(dtype):
data = pd.array([1, None], dtype=dtype)
elif is_period_dtype(dtype):
# pandas 0.24.0+ should infer this to be Series[Period[freq]]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear from the comment, but for pandas<0.24.0, it's impossible to have a period-dtype Series. So pandas 0.24.0+ is the only case we need to worry about here.

Comment thread dask/dataframe/utils.py
freq = dtype.freq
data = [pd.Period('2000', freq), pd.Period('2001', freq)]
elif is_sparse(dtype):
# TODO: pandas <0.24

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grr this is out of date. But I'm planning to rewrite all this soon, so just going to leave it for now.

@TomAugspurger TomAugspurger changed the title [WIP]: Pandas 0.24.0 compat Pandas 0.24.0 compat Jan 16, 2019
@TomAugspurger
TomAugspurger merged commit cbc1311 into dask:master Jan 17, 2019
@TomAugspurger
TomAugspurger deleted the pandas-rc-test branch January 17, 2019 14:59
jorge-pessoa pushed a commit to jorge-pessoa/dask that referenced this pull request May 14, 2019
* Calling np.dtype on a delayed object works

Calling `np.dtype(dask.delayed(...))` used to result in a segfault, as
numpy recursively tries to get `dtype` from the object. This is likely a
bug in numpy. For now, we can do a dumb for if `x.dtype().dtype()` is
called (which shouldn't ever show up in real code).

See dask#4374 (comment).

* Add test that dtype attribute still works if computed
jorge-pessoa pushed a commit to jorge-pessoa/dask that referenced this pull request May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants