def test_axes_name_collision(self): "Test .axes object for attribute collisions with axis names" A = DataArray(np.arange(6).reshape([1, 2, 3]), ("_arr", "_axes", "_namemap")) nt.assert_true(A.axes[0] is A.axes("_arr") is A.axes._arr) nt.assert_true(A.axes[1] is A.axes("_axes") is A.axes._axes) nt.assert_true(A.axes[2] is A.axes("_namemap") is A.axes._namemap) # Try to invoke some methods that use these attributes internally B = A[np.newaxis, ...] nt.assert_equal(B.shape, (1, 1, 2, 3)) nt.assert_true(np.all(A + A == 2 * A))
def test_axes_name_collision(self): "Test .axes object for attribute collisions with axis names" A = DataArray( np.arange(6).reshape([1, 2, 3]), ('_arr', '_axes', '_namemap')) nt.assert_true(A.axes[0] is A.axes('_arr') is A.axes._arr) nt.assert_true(A.axes[1] is A.axes('_axes') is A.axes._axes) nt.assert_true(A.axes[2] is A.axes('_namemap') is A.axes._namemap) # Try to invoke some methods that use these attributes internally B = A[np.newaxis, ...] nt.assert_equal(B.shape, (1, 1, 2, 3)) nt.assert_true(np.all(A + A == 2 * A))
class TestAxesManager: def setUp(self): self.axes_spec = ('date', ('stocks', ('aapl', 'ibm', 'goog', 'msft')), 'metric') self.A = DataArray(np.random.randn(200, 4, 10), axes=self.axes_spec) def test_axes_name_collision(self): "Test .axes object for attribute collisions with axis names" A = DataArray( np.arange(6).reshape([1, 2, 3]), ('_arr', '_axes', '_namemap')) nt.assert_true(A.axes[0] is A.axes('_arr') is A.axes._arr) nt.assert_true(A.axes[1] is A.axes('_axes') is A.axes._axes) nt.assert_true(A.axes[2] is A.axes('_namemap') is A.axes._namemap) # Try to invoke some methods that use these attributes internally B = A[np.newaxis, ...] nt.assert_equal(B.shape, (1, 1, 2, 3)) nt.assert_true(np.all(A + A == 2 * A)) def test_axes_numeric_access(self): for i, spec in enumerate(self.axes_spec): try: name, labels = spec except ValueError: name, labels = spec, None nt.assert_true(self.A.axes[i] == Axis( name=name, index=i, parent_arr=self.A, labels=labels)) def test_axes_attribute_access(self): for spec in self.axes_spec: try: name, labels = spec except ValueError: name, labels = spec, None nt.assert_true(getattr(self.A.axes, name) is self.A.axes(name)) def test_equality(self): B = DataArray(np.random.randn(200, 4, 10), axes=self.axes_spec) nt.assert_true(self.A.axes == B.axes) # What if axes differ by labels only? D = DataArray(np.random.randn(200, 4, 10), axes=('date', 'stocks', 'metric')) nt.assert_false(self.A.axes == D.axes)
class TestAxesManager: def setUp(self): self.axes_spec = ('date', ('stocks', ('aapl', 'ibm', 'goog', 'msft')), 'metric') self.A = DataArray(np.random.randn(200, 4, 10), axes=self.axes_spec) def test_axes_name_collision(self): "Test .axes object for attribute collisions with axis names" A = DataArray(np.arange(6).reshape([1,2,3]), ('_arr', '_axes', '_namemap')) nt.assert_true(A.axes[0] is A.axes('_arr') is A.axes._arr) nt.assert_true(A.axes[1] is A.axes('_axes') is A.axes._axes) nt.assert_true(A.axes[2] is A.axes('_namemap') is A.axes._namemap) # Try to invoke some methods that use these attributes internally B = A[np.newaxis, ...] nt.assert_equal(B.shape, (1,1,2,3)) nt.assert_true(np.all(A + A == 2*A)) def test_axes_numeric_access(self): for i,spec in enumerate(self.axes_spec): try: name,labels = spec except ValueError: name,labels = spec,None nt.assert_true(self.A.axes[i] == Axis(name=name, index=i, parent_arr=self.A, labels=labels)) def test_axes_attribute_access(self): for spec in self.axes_spec: try: name,labels = spec except ValueError: name,labels = spec,None nt.assert_true(getattr(self.A.axes, name) is self.A.axes(name)) def test_equality(self): B = DataArray(np.random.randn(200, 4, 10), axes=self.axes_spec) nt.assert_true(self.A.axes == B.axes) # What if axes differ by labels only? D = DataArray(np.random.randn(200, 4, 10), axes=('date', 'stocks', 'metric')) nt.assert_false(self.A.axes == D.axes)