MCPcopy Index your code
hub / github.com/dask/dask / test_is_dataframe_like

Function test_is_dataframe_like

dask/dataframe/tests/test_utils_dataframe.py:522–579  ·  view source on GitHub ↗
(monkeypatch, frame_value_counts)

Source from the content-addressed store, hash-verified

520
521@pytest.mark.parametrize("frame_value_counts", [True, False])
522def test_is_dataframe_like(monkeypatch, frame_value_counts):
523 # When we drop support for pandas 1.0, this compat check can
524 # be dropped
525 if frame_value_counts:
526 monkeypatch.setattr(pd.DataFrame, "value_counts", lambda x: None, raising=False)
527
528 df = pd.DataFrame({"x": [1, 2, 3]})
529 ddf = dd.from_pandas(df, npartitions=1)
530
531 assert is_dataframe_like(df)
532 assert is_dataframe_like(ddf)
533 assert not is_dataframe_like(df.x)
534 assert not is_dataframe_like(ddf.x)
535 assert not is_dataframe_like(df.index)
536 assert not is_dataframe_like(ddf.index)
537 assert not is_dataframe_like(pd.DataFrame)
538
539 assert not is_series_like(df)
540 assert not is_series_like(ddf)
541 assert is_series_like(df.x)
542 assert is_series_like(ddf.x)
543 assert not is_series_like(df.index)
544 assert not is_series_like(ddf.index)
545 assert not is_series_like(pd.Series)
546
547 assert not is_index_like(df)
548 assert not is_index_like(ddf)
549 assert not is_index_like(df.x)
550 assert not is_index_like(ddf.x)
551 assert is_index_like(df.index)
552 assert is_index_like(ddf.index)
553 assert not is_index_like(pd.Index)
554
555 # The following checks support of class wrappers, which
556 # requires the comparisons of `x.__class__` instead of `type(x)`
557 class DataFrameWrapper:
558 __class__ = pd.DataFrame
559
560 wrap = DataFrameWrapper()
561 wrap.dtypes = None
562 wrap.columns = None
563 assert is_dataframe_like(wrap)
564
565 class SeriesWrapper:
566 __class__ = pd.Series
567
568 wrap = SeriesWrapper()
569 wrap.dtype = None
570 wrap.name = None
571 assert is_series_like(wrap)
572
573 class IndexWrapper:
574 __class__ = pd.Index
575
576 wrap = IndexWrapper()
577 wrap.dtype = None
578 wrap.name = None
579 assert is_index_like(wrap)

Callers

nothing calls this directly

Calls 6

is_dataframe_likeFunction · 0.90
is_series_likeFunction · 0.90
is_index_likeFunction · 0.90
DataFrameWrapperClass · 0.85
SeriesWrapperClass · 0.85
IndexWrapperClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…