Permalink
Browse files

Merge pull request #57 from terhorst/bugfixes

Bugfixes
  • Loading branch information...
2 parents e1709cd + 41cea54 commit b7af9f12b6ae95b15d19a4696c340ae70fc593ea @terhorst terhorst committed Jun 11, 2011
Showing with 36 additions and 16 deletions.
  1. +7 −13 datarray/datarray.py
  2. +3 −3 datarray/print_grid.py
  3. +26 −0 datarray/tests/test_bugfixes.py
View
@@ -292,7 +292,7 @@ def _copy(self, **kwargs):
labels = kwargs.pop('labels', copy.copy(self.labels))
ax.labels = labels
- if labels and len(labels) != len(self.labels):
+ if labels is not None and len(labels) != len(self.labels):
ax._label_dict = dict( zip(labels, xrange( len(labels) )) )
else:
ax._label_dict = copy.copy(self._label_dict)
@@ -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
@@ -273,8 +273,8 @@ def grid_layout(arr, width=75, height=10):
def labeled_layout(arr, width=75, height=10, row_label_width=9):
"""
Given a 2-D non-empty array that may have labeled axes, rows, or columns,
- render the array as strings to be joined and attach the axes in
- visually appropriate places.
+ render the array as strings to be joined and attach the axes in visually
+ appropriate places.
Returns a list of lists of strings to be joined.
"""
@@ -306,7 +306,7 @@ def labeled_layout(arr, width=75, height=10, row_label_width=9):
offset = 0
if arr.axes[1].labels: offset = 1
for r in xrange(cells_shown.shape[0]):
- layout[r+offset][0] = label_formatter.format(labels[r], row_label_width)
+ layout[r+offset][0] = label_formatter.format(str(labels[r]), row_label_width)
if row_header or col_header:
header0 = []
@@ -20,19 +20,45 @@ 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']
caps = DataArray(np.arange(5),[cap_ax_spec])
caps.axes.capitals["washington"]
+def test_bug22():
+ "Bug 22: DataArray does not accepting array as ticks"
+ A = DataArray([1, 2], [('time', ['a', 'b'])])
+ B = DataArray([1, 2], [('time', np.array(['a', 'b']))])
+ assert_datarray_equal(A, B)
+
def test_bug26():
"Bug 26: check that axes names are computed on demand."
a = DataArray([1,2,3])
nt.assert_true(a.axes[0].name is None)
a.axes[0].name = "a"
nt.assert_equal(a.axes[0].name, "a")
+def test_bug34():
+ "Bug 34: datetime.date ticks not handled by datarray_to_string"
+ from datarray.print_grid import datarray_to_string
+ from datetime import date as D
+ A = DataArray([[1,2],[3,4]], [('row', ('a', D(2010,1,1))),('col', 'cd')])
+ nt.assert_equal(datarray_to_string(A), """row col
+--------- -------------------
+ c d
+a 1 2
+2010-01-0 3 4""")
+
def test_bug35():
"Bug 35"
txt_array = DataArray(['a','b'], axes=['dummy'])

0 comments on commit b7af9f1

Please sign in to comment.