示例#1
0
    def test_data_changed_events(self):
        # Test data.
        arr = np.zeros(16)
        arr2 = np.ones(16)

        df = DataFrame(index=np.arange(16))
        plot_data = DataFramePlotData(data_frame=df)

        assert_array_equal(plot_data.get_data('index'), df.index.values)

        with monitor_events(plot_data) as events:
            plot_data.set_data('arr', arr)
            self.assertEqual(events, [{'added': ['arr']}])

            assert_array_equal(df['arr'].values, arr)

            # While we're here, check that get_data works as advertised.
            out = plot_data.get_data('arr')
            assert_array_equal(arr, out)

        with monitor_events(plot_data) as events:
            plot_data.set_data('arr', arr2)
            self.assertEqual(events, [{'changed': ['arr']}])
            assert_array_equal(df['arr'].values, arr2)

        with monitor_events(plot_data) as events:
            plot_data.del_data('arr')
            self.assertEqual(events, [{'removed': ['arr']}])
    def test_data_changed_events(self):
        # Test data.
        arr = np.zeros(16)
        arr2 = np.ones(16)

        df = DataFrame(index=np.arange(16))
        plot_data = DataFramePlotData(data_frame=df)

        assert_array_equal(plot_data.get_data('index'), df.index.values)

        with monitor_events(plot_data) as events:
            plot_data.set_data('arr', arr)
            self.assertEqual(events, [{'added': ['arr']}])

            assert_array_equal(df['arr'].values, arr)

            # While we're here, check that get_data works as advertised.
            out = plot_data.get_data('arr')
            assert_array_equal(arr, out)

        with monitor_events(plot_data) as events:
            plot_data.set_data('arr', arr2)
            self.assertEqual(events, [{'changed': ['arr']}])
            assert_array_equal(df['arr'].values, arr2)

        with monitor_events(plot_data) as events:
            plot_data.del_data('arr')
            self.assertEqual(events, [{'removed': ['arr']}])
示例#3
0
    def test_index_column(self):
        # Test data.
        idx = np.arange(16)
        arr = np.zeros(16)
        arr2 = np.ones(16)
        data = {'index': arr}
        df = DataFrame(data, index=idx)
        plot_data = DataFramePlotData(data_frame=df)

        assert_array_equal(plot_data.get_data('index'), df['index'].values)

        # Can set 'index' column
        with monitor_events(plot_data) as events:
            plot_data.set_data('index', arr2)
            self.assertEqual(events, [{'changed': ['index']}])
            assert_array_equal(df['index'].values, arr2)

        # Can remove 'index' column
        with monitor_events(plot_data) as events:
            plot_data.del_data('index')
            self.assertNotIn('index', df.columns)
            # Since there is always an index, this will register a 'changed'
            # event instead of a 'removed' event.
            self.assertEqual(events, [{'changed': ['index']}])
            assert_array_equal(plot_data.get_data('index'), df.index.values)
    def test_index_column(self):
        # Test data.
        idx = np.arange(16)
        arr = np.zeros(16)
        arr2 = np.ones(16)
        data = {'index': arr}
        df = DataFrame(data, index=idx)
        plot_data = DataFramePlotData(data_frame=df)

        assert_array_equal(plot_data.get_data('index'), df['index'].values)

        # Can set 'index' column
        with monitor_events(plot_data) as events:
            plot_data.set_data('index', arr2)
            self.assertEqual(events, [{'changed': ['index']}])
            assert_array_equal(df['index'].values, arr2)

        # Can remove 'index' column
        with monitor_events(plot_data) as events:
            plot_data.del_data('index')
            self.assertNotIn('index', df.columns)
            # Since there is always an index, this will register a 'changed'
            # event instead of a 'removed' event.
            self.assertEqual(events, [{'changed': ['index']}])
            assert_array_equal(plot_data.get_data('index'), df.index.values)
示例#5
0
    def _plot_data_default(self):
        # Create a DataFrame with plottable data
        index = linspace(-2.0, 10.0, 100)
        df = DataFrame(index=index)
        for i in range(5):
            name = "y" + str(i)
            df[name] = jn(i, index)

        plot_data = DataFramePlotData(data_frame=df)
        return plot_data
示例#6
0
    def test_no_index_column(self):
        # Test data.
        idx = np.arange(16)
        arr = np.zeros(16)
        df = DataFrame(index=idx)
        plot_data = DataFramePlotData(data_frame=df)

        assert_array_equal(plot_data.get_data('index'), df.index.values)

        # Can set 'index'
        with monitor_events(plot_data) as events:
            plot_data.set_data('index', arr)
            self.assertEqual(events, [{'changed': ['index']}])
            self.assertNotIn('index', df.columns)
            assert_array_equal(df.index.values, arr)

        # Cannot remove 'index' column
        with self.assertRaises(KeyError):
            plot_data.del_data('index')
    def test_no_index_column(self):
        # Test data.
        idx = np.arange(16)
        arr = np.zeros(16)
        df = DataFrame(index=idx)
        plot_data = DataFramePlotData(data_frame=df)

        assert_array_equal(plot_data.get_data('index'), df.index.values)

        # Can set 'index'
        with monitor_events(plot_data) as events:
            plot_data.set_data('index', arr)
            self.assertEqual(events, [{'changed': ['index']}])
            self.assertNotIn('index', df.columns)
            assert_array_equal(df.index.values, arr)

        # Cannot remove 'index' column
        with self.assertRaises(KeyError):
            plot_data.del_data('index')