Skip to content

Commit

Permalink
exclude dask collections from meta check
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Jan 9, 2019
1 parent 8d51bbe commit 07b6889
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dask/dataframe/tests/test_utils_dataframe.py
Expand Up @@ -345,3 +345,6 @@ def test_is_dataframe_like():
assert not is_index_like(df)
assert not is_index_like(df.x)
assert is_index_like(df.index)

ddf = dd.from_pandas(df, npartitions=1)
assert is_dataframe_like(ddf)
7 changes: 6 additions & 1 deletion dask/dataframe/utils.py
Expand Up @@ -18,6 +18,7 @@
# pandas < 0.19.2
from pandas.core.common import is_datetime64tz_dtype

from ..base import is_dask_collection
from ..compatibility import PY2, Iterator, Mapping
from ..core import get_deps
from ..local import get_sync
Expand Down Expand Up @@ -450,14 +451,17 @@ def _nonempty_series(s, idx=None):


def is_dataframe_like(df):
""" Looks like a Pandas DataFrame """
return set(dir(df)) > {'dtypes', 'columns', 'groupby', 'head'}


def is_series_like(s):
""" Looks like a Pandas Series """
return set(dir(s)) > {'name', 'dtype', 'groupby', 'head'}


def is_index_like(s):
""" Looks like a Pandas Index """
attrs = set(dir(s))
return attrs > {'name', 'dtype'} and 'head' not in attrs

Expand Down Expand Up @@ -498,7 +502,8 @@ def equal_dtypes(a, b):
return a == b
return (a.kind in eq_types and b.kind in eq_types) or (a == b)

if not (is_dataframe_like(meta) or is_series_like(meta) or is_index_like(meta)):
if (not (is_dataframe_like(meta) or is_series_like(meta) or is_index_like(meta))
or is_dask_collection(meta)):
raise TypeError("Expected partition to be DataFrame, Series, or "
"Index, got `%s`" % type(meta).__name__)

Expand Down

0 comments on commit 07b6889

Please sign in to comment.