Skip to content

ENH: Support 3rd-party ExtensionArrays - #4379

Merged
mrocklin merged 2 commits into
dask:masterfrom
TomAugspurger:register-extensions
Jan 15, 2019
Merged

mrocklin merged 2 commits into
dask:masterfrom
TomAugspurger:register-extensions

Conversation

@TomAugspurger

Copy link
Copy Markdown
Member

This adds (basic) support for 3rd party ExtensionArrays in dask.dataframe.

The initial failures stemmed from note being able to create a _meta_nonempty for these dtypes. Rather than trying to guess, we request that authors register their extension dtypes with dask.dataframe.

It gets the bare minimum working. It's likely that we'll uncover additional issues, but I haven't thought much about how to test this more thoroughly. This is tested using the DecimalDtype, which isn't part of pandas public API (it's just a "3rd-party" extension array that's only meant for testing pandas extension array interface).

Closes #3240

Comment thread dask/dataframe/utils.py
cats = None
data = pd.Categorical(data, categories=cats,
ordered=s.cat.ordered)
elif type(dtype) in make_array_nonempty._lookup:

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 might be slightly cleaner to implement _nonempty_series using make_array_nonempty. I haven't attempted that yet.

@TomAugspurger

Copy link
Copy Markdown
Member Author

I'd recommend waiting on this till #4374 is merged. Until we're including the pandas>=0.24.0rc1 in our CI, this will be untested.

@mrocklin

Copy link
Copy Markdown
Member

I literally chortled with joy when I saw this header in my inbox this morning.

I look forward to reviewing this :)

@mrocklin mrocklin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thoughts on getting new elementwise operations out of Pandas' extension array API? Or should this be done separately in micro-libraries like dask-cyberpandas for example?


Developers implementing third-party extension arrays (outside of pandas) will
need to do register their ``ExtensionDtype`` with Dask so that it works
correctly in ``dask.dataframe``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Styling note. I think that @farrajota has been capitalizing consistently with the names Dask, Pandas, Dask DataFrame.

@TomAugspurger

Copy link
Copy Markdown
Member Author

Thoughts on getting new elementwise operations out of Pandas' extension array API?

By this, you mean things like the .ip accessor? I haven't decided what's best there yet.

Detecting 3rd-party accessors at run-time is easy. They're stored at e.g. Series._accessors, and I believe there's a pandas issue for adding this to the public API.

The hard part is what's done inside the accessor. There's no requirement that the accessor methods be elementwise operations. (e.g. Series.cat.ordered looks up something from the dtype). Many things may just work (ufuncs, composing methods on the parent object). So much so that it's tempting to just try things out by passing the dask object to the accessor. This may lead to surprising behavior though.

@mrocklin

Copy link
Copy Markdown
Member

Right, so we leave it off for now?

@TomAugspurger

Copy link
Copy Markdown
Member Author

Yes, that's probably best for now.

I realized that the tests here basically work for the currently released version of pandas (0.23.4) so this can probably be merged before
#4374 if we're happy with it.

@mrocklin

Copy link
Copy Markdown
Member

Fine by me. I'll merge later today if there are no further comments. Otherwise feel free to merge as you like.

@mrocklin
mrocklin merged commit 0dbe40d into dask:master Jan 15, 2019
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants