Exemplo 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))
Exemplo 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
Exemplo 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)
Exemplo n.º 4
0
    def test_name(self):
        coord = Coordinate('x', [10.0])
        self.assertEqual(coord.name, 'x')

        with self.assertRaises(AttributeError):
            coord.name = 'y'
Exemplo 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()))
Exemplo n.º 6
0
    def test_name(self):
        coord = Coordinate('x', [10.0])
        self.assertEqual(coord.name, 'x')

        with self.assertRaises(AttributeError):
            coord.name = 'y'
Exemplo 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()))
Exemplo n.º 8
0
 def test_init(self):
     with self.assertRaisesRegexp(ValueError, 'must be 1-dimensional'):
         Coordinate((), 0)
Exemplo n.º 9
0
    def test_name(self):
        coord = Coordinate("x", [10.0])
        self.assertEqual(coord.name, "x")

        with self.assertRaises(AttributeError):
            coord.name = "y"
Exemplo 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()))