Skip to content

Commit d0627cf

Browse files
committed
Avoid calling dir on dataframes
See pandas-dev/pandas#25509
1 parent 6b0c4e0 commit d0627cf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

dask/dataframe/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,24 @@ def _nonempty_series(s, idx=None):
497497

498498
def is_dataframe_like(df):
499499
""" Looks like a Pandas DataFrame """
500-
return set(dir(df)) > {'dtypes', 'columns', 'groupby', 'head'} and not isinstance(df, type)
500+
typ = type(df)
501+
return all(hasattr(typ, name) for name in ('dtypes', 'columns', 'groupby', 'head'))
501502

502503

503504
def is_series_like(s):
504505
""" Looks like a Pandas Series """
505-
return set(dir(s)) > {'name', 'dtype', 'groupby', 'head'} and not isinstance(s, type)
506+
typ = type(s)
507+
return all(hasattr(typ, name) for name in ('name', 'dtype', 'groupby', 'head'))
506508

507509

508510
def is_index_like(s):
509511
""" Looks like a Pandas Index """
510-
attrs = set(dir(s))
511-
return attrs > {'name', 'dtype'} and 'head' not in attrs and not isinstance(s, type)
512+
typ = type(s)
513+
return (
514+
hasattr(typ, 'name') and
515+
hasattr(typ, 'dtype') and
516+
not hasattr(typ, 'head')
517+
)
512518

513519

514520
def check_meta(x, meta, funcname=None, numeric_equal=True):

0 commit comments

Comments
 (0)