Esempio n. 1
0
    def test_numpy_same_methods(self):
        v = Variable([], np.float32(0.0))
        self.assertEqual(v.item(), 0)
        self.assertIs(type(v.item()), float)

        v = Coordinate('x', np.arange(5))
        self.assertEqual(2, v.searchsorted(2))
Esempio n. 2
0
 def test_data(self):
     x = Coordinate('x', np.arange(3.0))
     # data should be initially saved as an ndarray
     self.assertIs(type(x._data), NumpyArrayAdapter)
     self.assertEqual(float, x.dtype)
     self.assertArrayEqual(np.arange(3), x)
     self.assertEqual(float, x.values.dtype)
     # after inspecting x.values, the Coordinate value will be saved as an Index
     self.assertIsInstance(x._data, PandasIndexAdapter)
     with self.assertRaisesRegexp(TypeError, 'cannot be modified'):
         x[:] = 0
Esempio n. 3
0
 def test_avoid_index_dtype_inference(self):
     # verify our work-around for (pandas<0.14):
     # https://github.com/pydata/pandas/issues/6370
     data = pd.date_range('2000-01-01', periods=3).to_pydatetime()
     t = Coordinate('t', data)
     self.assertArrayEqual(t.values[:2], data[:2])
     self.assertArrayEqual(t[:2].values, data[:2])
     self.assertArrayEqual(t.values[:2], data[:2])
     self.assertArrayEqual(t[:2].values, data[:2])
     self.assertEqual(t.dtype, object)
     self.assertEqual(t[:2].dtype, object)
Esempio n. 4
0
    def test_name(self):
        coord = Coordinate('x', [10.0])
        self.assertEqual(coord.name, 'x')

        with self.assertRaises(AttributeError):
            coord.name = 'y'
Esempio n. 5
0
 def test_to_index(self):
     data = 0.5 * np.arange(10)
     v = Coordinate(['time'], data, {'foo': 'bar'})
     self.assertTrue(pd.Index(data, name='time').identical(v.to_index()))
Esempio n. 6
0
    def test_name(self):
        coord = Coordinate('x', [10.0])
        self.assertEqual(coord.name, 'x')

        with self.assertRaises(AttributeError):
            coord.name = 'y'
Esempio n. 7
0
 def test_to_index(self):
     data = 0.5 * np.arange(10)
     v = Coordinate(['time'], data, {'foo': 'bar'})
     self.assertTrue(pd.Index(data, name='time').identical(v.to_index()))
Esempio n. 8
0
 def test_init(self):
     with self.assertRaisesRegexp(ValueError, 'must be 1-dimensional'):
         Coordinate((), 0)
Esempio n. 9
0
    def test_name(self):
        coord = Coordinate("x", [10.0])
        self.assertEqual(coord.name, "x")

        with self.assertRaises(AttributeError):
            coord.name = "y"
Esempio n. 10
0
 def test_to_index(self):
     data = 0.5 * np.arange(10)
     v = Coordinate(["time"], data, {"foo": "bar"})
     self.assertTrue(pd.Index(data, name="time").identical(v.to_index()))