Repository navigation
Description
Some background: pandas 0.23 will support 3rd party array types (think
Categorical, but defined outside of pandas). What would it take to ensure that
these also work with dask, ideally with minimal effort on the part of the
library author?
from cyberpandas import IPArray
import pandas as pd
import dask.dataframe as dd
arr = IPArray([0, 1, 2, 3])
ser = pd.Series(arr)
dser = dd.from_pandas(ser, 2)Extension Accessors
Pandas 0.23 will have an official mechanism for 3rd party libraries to add
accessors like .dt, .cat, etc. Libraries decorate their accessor with
register_{series,frame,index}_accessor and that attaches an instance of the
accessor to the class.
In principal, dask could also attach that accessor to dd.Series, dd.DataFrame,
and dd.Index. pandas-dev/pandas#19963 will make
discovery of the accessors easier. Given an accessor name, dask could attach
it to our classes
dd.Series.ip = object.__getattribute__(pd.Series, 'ip')I'm not sure where this would be done. It might have to be dynamic in
_Frame.__getattribute__, since accessors can be added at any time.
Not all accessors will naively work with dask, but I think many will. All of the
ones I've implemented in cyberpandas are just transformations. They return a
Series or array of the same shape, possibly with a different dtype.
(This exact example fails because of the next issue).
Extension Types
We're allowing 3rd party libraries to define custom array types by subclassing
some pandas ABCs. As far as dask is concerned, we'll need to update blocks like
if is_datetime64tz_dtype(dtype):
...
elif is_categorical_dtype(dtype):
...
else:
... To include an elif is_extension_array_dtype(dtype) (in practice, some of the
is_categorical_dtype checks can be simply replaced with
is_extension_array_dtype, since Categorical is officially an ExtensionArray).
I'm not exactly sure how things like _meta_nonempty will work. This could be
challenging, as we don't know what a sample looks like. I haven't thought
through this much, hopefully there's a decent solution. There are probably other
issues, but that's the first one I ran into.
Activity
mrocklin commentedon May 17, 2018
Update, extension arrays are in the latest Pandas release. http://pandas.pydata.org/pandas-docs/stable/extending.html#extending-extension-types