Esempio n. 1
0
 def test_widget_load_column_pivots_client(self):
     import perspective
     assert perspective.is_libpsp() is False
     # behavior should not change for client mode
     arrays = [
         np.array([
             'bar', 'bar', 'bar', 'bar', 'baz', 'baz', 'baz', 'baz', 'foo',
             'foo', 'foo', 'foo', 'qux', 'qux', 'qux', 'qux'
         ]),
         np.array([
             'one', 'one', 'two', 'two', 'one', 'one', 'two', 'two', 'one',
             'one', 'two', 'two', 'one', 'one', 'two', 'two'
         ]),
         np.array([
             'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y',
             'X', 'Y', 'X', 'Y'
         ])
     ]
     tuples = list(zip(*arrays))
     index = pd.MultiIndex.from_tuples(tuples,
                                       names=['first', 'second', 'third'])
     df_both = pd.DataFrame(np.random.randn(3, 16),
                            index=['A', 'B', 'C'],
                            columns=index)
     widget = perspective.PerspectiveWidget(df_both)
     assert hasattr(widget, "table") is False
     assert widget.columns == ['value']
     assert widget.column_pivots == ['first', 'second', 'third']
     assert widget.row_pivots == ['index']
Esempio n. 2
0
 def test_widget_client_np(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {"a": np.arange(0, 50)}
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {"a": [i for i in range(50)]}
Esempio n. 3
0
 def test_widget_client_np_structured_array(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = np.array([(1, 2), (3, 4)],
                     dtype=[("a", "int64"), ("b", "int64")])
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {"a": [1, 3], "b": [2, 4]}
Esempio n. 4
0
 def test_widget_delete_client(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {"a": np.arange(0, 50)}
     widget = perspective.PerspectiveWidget(data)
     mocked_post = partial(mock_post, assert_msg={"cmd": "delete"})
     widget.delete()
     widget.post = MethodType(mocked_post, widget)
Esempio n. 5
0
 def test_widget_client_datetime(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {"a": [datetime(2020, i, 1, 12, 30, 45) for i in range(1, 13)]}
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {
         "a": ["2020-{:02d}-01 12:30:45".format(i) for i in range(1, 13)]
     }
Esempio n. 6
0
 def test_widget_client_df_date_object(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = pd.DataFrame({"a": [date(2020, i, 1) for i in range(1, 13)]},
                         dtype="object")
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {
         "index": [i for i in range(12)],
         "a": ["2020-{:02d}-01".format(i) for i in range(1, 13)]
     }
Esempio n. 7
0
    def test_widget_client_date(self):
        import perspective
        assert perspective.is_libpsp() is False
        data = {"a": [date(2020, i, 1) for i in range(1, 13)]}
        widget = perspective.PerspectiveWidget(data)
        assert hasattr(widget, "table") is False

        # `data` is mutated at this point, so check against the expected
        # formatting just to make sure.
        assert widget._data == {
            "a": ["2020-{:02d}-01".format(i) for i in range(1, 13)]
        }
Esempio n. 8
0
 def test_widget_client_np_recarray_date_object(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = np.array([(date(2020, 1, 1), date(2020, 2, 1)),
                      (date(2020, 3, 1), date(2020, 4, 1))],
                     dtype=[("a", "object"), ("b", "object")])
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {
         "a": ["2020-01-01", "2020-03-01"],
         "b": ["2020-02-01", "2020-04-01"]
     }
Esempio n. 9
0
 def test_widget_client_np_date_object(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {
         "a": np.array([date(2020, i, 1) for i in range(1, 13)],
                       dtype="object")
     }
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {
         "a": ["2020-{:02d}-01".format(i) for i in range(1, 13)]
     }
Esempio n. 10
0
 def test_widget_client_replace(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {"a": np.arange(0, 50)}
     new_data = {"a": [1]}
     widget = perspective.PerspectiveWidget(data)
     mocked_post = partial(mock_post,
                           assert_msg={
                               "cmd": "replace",
                               "data": new_data
                           })
     widget.post = MethodType(mocked_post, widget)
     widget.replace(new_data)
     assert widget._data is new_data
Esempio n. 11
0
 def test_widget_client_update(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {"a": np.arange(0, 50)}
     comparison_data = {"a": [i for i in range(50)]}
     widget = perspective.PerspectiveWidget(data)
     mocked_post = partial(mock_post,
                           assert_msg={
                               "cmd": "update",
                               "data": comparison_data
                           })
     widget.post = MethodType(mocked_post, widget)
     widget.update(data)
     assert hasattr(widget, "table") is False
Esempio n. 12
0
 def test_widget_client_df(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = pd.DataFrame({
         "a": np.arange(10),
         "b": [True for i in range(10)],
         "c": [str(i) for i in range(10)]
     })
     widget = perspective.PerspectiveWidget(data)
     assert hasattr(widget, "table") is False
     assert widget._data == {
         "index": [i for i in range(10)],
         "a": [i for i in range(10)],
         "b": [True for i in range(10)],
         "c": [str(i) for i in range(10)]
     }
Esempio n. 13
0
 def test_widget_client_update_cached(self):
     import perspective
     assert perspective.is_libpsp() is False
     data = {"a": [1, 2]}
     widget = perspective.PerspectiveWidget(data)
     mocked_post = partial(mock_post,
                           assert_msg={
                               "cmd": "update",
                               "data": data
                           })
     widget.post = MethodType(mocked_post, widget)
     widget.update(data)
     assert widget._predisplay_update_cache == [data]
     widget._displayed = True
     widget.update(data)
     assert widget._predisplay_update_cache == [data]
Esempio n. 14
0
 def test_widget_client_schema(self):
     import perspective
     assert perspective.is_libpsp() is False
     widget = perspective.PerspectiveWidget({
         "a": int,
         "b": float,
         "c": bool,
         "d": date,
         "e": datetime,
         "f": str
     })
     assert hasattr(widget, "table") is False
     assert widget._data == {
         "a": "integer",
         "b": "float",
         "c": "boolean",
         "d": "date",
         "e": "datetime",
         "f": "string"
     }
Esempio n. 15
0
 def test_widget_client_schema_py2_types(self):
     import perspective
     assert perspective.is_libpsp() is False
     if six.PY2:
         widget = perspective.PerspectiveWidget({
             "a": long,  # noqa: F821
             "b": float,
             "c": bool,
             "d": date,
             "e": datetime,
             "f": unicode  # noqa: F821
         })
         assert hasattr(widget, "table") is False
         assert widget._data == {
             "a": "integer",
             "b": "float",
             "c": "boolean",
             "d": "date",
             "e": "datetime",
             "f": "string"
         }