You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dask.dataframe __getitem__ does not work with subclasses of str in python 3.6 #3297
I am upgrading my code from python 2.7 to 3.6 and found that that the getitem of a dask dataframe does not work as before: I use a subclass of str for the column names and then I want to access the columns with df[column_name]. This works fine with pandas and had worked with dask also in python 2.7. Here is a short example for comparing pandas and dask:
class MyString(str):
pass
my_s = MyString('column_1')
import pandas as pd
df = df = pd.DataFrame({'column_1': [1, 1]})
print(df[my_s])
from dask import dataframe as dd
ddf = dd.from_pandas(df, npartitions=1)
print(ddf[my_s])
This appears to come from a reliance on np.isscalar, which checks for a specific set of classes, and so misses subclasses
In [1]: import numpy
In [2]: class str2(str):
...: pass
...:
In [3]: x1 = 'hi'
In [4]: x2 = str2('hi')
In [5]: x2
Out[5]: 'hi'
In [6]: numpy.isscalar(x1)
Out[6]: True
In [7]: numpy.isscalar(x2)
Out[7]: False
Activity
martindurant commentedon Mar 19, 2018
This appears to come from a reliance on
np.isscalar, which checks for a specific set of classes, and so misses subclassesjrbourbeau commentedon May 2, 2018
@ctrebing brings up a good point. I can add string subclass support for Dask DataFrames.