Permalink
Browse files

fixes bug #5

  • Loading branch information...
1 parent c71124d commit 5b2a6d63a7fd9fc16c98752030735bc55d9d1d29 @terhorst terhorst committed Jun 1, 2011
Showing with 15 additions and 12 deletions.
  1. +6 −12 datarray/datarray.py
  2. +9 −0 datarray/tests/test_bugfixes.py
View
18 datarray/datarray.py
@@ -631,16 +631,10 @@ def _names_to_numbers(axes, ax_ids):
proc_ids.append(int(ax_id))
return proc_ids
-
-
-def _validate_axes(axes):
- """
- This should always be true our axis lists....
- """
- p = axes[0].parent_arr
- for i, a in enumerate(axes):
- assert i == a.index
- assert p is a.parent_arr
+def _validate_axes(arr):
+ # This should always be true our axis lists....
+ assert all(i == a.index and arr is a.parent_arr
+ for i,a in enumerate(arr.axes))
def _pull_axis(axes, target_axis):
"""
@@ -801,7 +795,7 @@ def __new__(cls, data, axes=None, dtype=None, copy=False):
axlist.append(Axis(name, i, arr, labels=labels))
_set_axes(arr, axlist)
- _validate_axes(axlist)
+ _validate_axes(arr)
return arr
@@ -848,7 +842,7 @@ def __array_finalize__(self, obj):
_set_axes(self, obj.axes)
# validate the axes
- _validate_axes(self.axes)
+ _validate_axes(self)
def __array_prepare__(self, obj, context=None):
"Called at the beginning of each ufunc."
View
9 datarray/tests/test_bugfixes.py
@@ -20,6 +20,15 @@ def test_bug3():
nt.assert_equal( x.sum(), y.sum() )
nt.assert_equal( x.max(), y.max() )
+def test_bug5():
+ "Bug 5: Support 0d arrays"
+ A = DataArray(10)
+ # Empty tuples evaluate to false
+ nt.assert_false(tuple(A.axes))
+ nt.assert_equal(len(A.axes), 0)
+ nt.assert_raises(IndexError, lambda: A.axes[0])
+ nt.assert_false(A.names)
+
def test_1d_label_indexing():
# issue #18
cap_ax_spec = 'capitals', ['washington', 'london', 'berlin', 'paris', 'moscow']

0 comments on commit 5b2a6d6

Please sign in to comment.