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