Esempio n. 1
0
    def test_pandas(self):
        import pandas as pd
        from perspective.core.data import type_detect

        df = pd.DataFrame([1, 2])
        o = type_detect(df)

        expected = {0: [1, 2], 'index': [0, 1]}
        print(o.data)
        print(expected)
        assert o.data == expected
        assert o.type == 'json'

        # series check
        df = pd.DataFrame([1, 2])
        o = type_detect(df[0])

        expected = {0: [1, 2], 'index': [0, 1]}
        print(o.data)
        print(expected)
        assert o.data == expected
        assert o.type == 'json'

        df = pd.DataFrame([[1, 2]], columns=['1', '2'], index=[datetime.today(), datetime.today()])
        o = type_detect(df)
        assert o.type == 'json'

        import sys
        sys.modules['pandas'] = Nope()
        type_detect('test')
        sys.modules['pandas'] = pd
Esempio n. 2
0
    def test_dict(self):
        from perspective.core.data import type_detect
        x = {'a': 'simple test'}

        o = type_detect(x)
        print(o.data)
        assert o.data == [{"a": "simple test"}]
        assert o.type == 'json'
Esempio n. 3
0
    def test_list(self):
        from perspective.core.data import type_detect
        x = [{'1': 'a'}, {'1': 'simple'}, {'1': 'test'}]

        o = type_detect(x)
        print(o.data)
        assert o.data == x
        assert o.type == 'json'
Esempio n. 4
0
 def test_other(self):
     from perspective.core.data import type_detect
     o = type_detect('test')
     assert o.data == []
     assert o.type == ''