MCPcopy Create free account
hub / github.com/plotly/plotly.py / test_x_or_y

Function test_x_or_y

tests/test_optional/test_px/test_px_input.py:672–732  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

670
671@pytest.mark.parametrize("fn", [px.scatter, px.line, px.area, px.bar])
672def test_x_or_y(fn):
673 categorical = ["a", "a", "b", "b"]
674 numerical = [1, 2, 3, 4]
675 constant = [1, 1, 1, 1]
676 range_4 = [0, 1, 2, 3]
677 index = [11, 12, 13, 14]
678 numerical_df = pd.DataFrame(dict(col=numerical), index=index)
679 categorical_df = pd.DataFrame(dict(col=categorical), index=index)
680
681 fig = fn(x=numerical)
682 assert list(fig.data[0].x) == numerical
683 assert list(fig.data[0].y) == range_4
684 assert fig.data[0].orientation == "h"
685 fig = fn(y=numerical)
686 assert list(fig.data[0].x) == range_4
687 assert list(fig.data[0].y) == numerical
688 assert fig.data[0].orientation == "v"
689 fig = fn(numerical_df, x="col")
690 assert list(fig.data[0].x) == numerical
691 assert list(fig.data[0].y) == index
692 assert fig.data[0].orientation == "h"
693 fig = fn(numerical_df, y="col")
694 assert list(fig.data[0].x) == index
695 assert list(fig.data[0].y) == numerical
696 assert fig.data[0].orientation == "v"
697
698 if fn != px.bar:
699 fig = fn(x=categorical)
700 assert list(fig.data[0].x) == categorical
701 assert list(fig.data[0].y) == range_4
702 assert fig.data[0].orientation == "h"
703 fig = fn(y=categorical)
704 assert list(fig.data[0].x) == range_4
705 assert list(fig.data[0].y) == categorical
706 assert fig.data[0].orientation == "v"
707 fig = fn(categorical_df, x="col")
708 assert list(fig.data[0].x) == categorical
709 assert list(fig.data[0].y) == index
710 assert fig.data[0].orientation == "h"
711 fig = fn(categorical_df, y="col")
712 assert list(fig.data[0].x) == index
713 assert list(fig.data[0].y) == categorical
714 assert fig.data[0].orientation == "v"
715
716 else:
717 fig = fn(x=categorical)
718 assert list(fig.data[0].x) == categorical
719 assert list(fig.data[0].y) == constant
720 assert fig.data[0].orientation == "v"
721 fig = fn(y=categorical)
722 assert list(fig.data[0].x) == constant
723 assert list(fig.data[0].y) == categorical
724 assert fig.data[0].orientation == "h"
725 fig = fn(categorical_df, x="col")
726 assert list(fig.data[0].x) == categorical
727 assert list(fig.data[0].y) == constant
728 assert fig.data[0].orientation == "v"
729 fig = fn(categorical_df, y="col")

Callers

nothing calls this directly

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected