MCPcopy Create free account
hub / github.com/dask/dask / test_is_dataframe_like

Function test_is_dataframe_like

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

Source from the content-addressed store, hash-verified

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