Esempio n. 1
0
    def test__stream_good_dict_of_index_and_series_data_transformed(self, pd):
        df = pd.DataFrame(index=pd.date_range('now', periods=30, freq='T'),
                          columns=['A'],
                          data=np.cumsum(np.random.standard_normal(30),
                                         axis=0))
        ds = ColumnDataSource(data={
            'index': convert_datetime_array(df.index.values),
            'A': df.A
        })
        ds._document = "doc"
        stuff = {}
        mock_setter = object()

        def mock(*args, **kw):
            stuff['args'] = args
            stuff['kw'] = kw

        ds.data._stream = mock
        new_df = pd.DataFrame(index=df.index + pd.to_timedelta('30m'),
                              columns=df.columns,
                              data=np.random.standard_normal(30))
        ds._stream({'index': new_df.index, 'A': new_df.A}, "foo", mock_setter)
        assert np.array_equal(stuff['args'][2]['index'],
                              convert_datetime_array(new_df.index.values))
        assert np.array_equal(stuff['args'][2]['A'], new_df.A.values)
Esempio n. 2
0
 def test_pandas_datetime_types(self, pd):
     """ should convert to millis """
     idx = pd.date_range('2001-1-1', '2001-1-5')
     df = pd.DataFrame({'vals': idx}, index=idx)
     serialized = self.serialize({'vals': df.vals, 'idx': df.index})
     deserialized = self.deserialize(serialized)
     baseline = {
         u'vals': [
             978307200000, 978393600000, 978480000000, 978566400000,
             978652800000
         ],
         u'idx': [
             978307200000, 978393600000, 978480000000, 978566400000,
             978652800000
         ]
     }
     assert deserialized == baseline