Skip to content

Commit

Permalink
fix CoordString asarray when empty and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njwilson23 committed Oct 8, 2016
1 parent f375e3f commit 238a9eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions karta/vector/coordstring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,6 @@ cdef class CoordString:
return x, y, z

def asarray(self):
if self.rank == -1:
return np.array([[]], dtype=np.float64)
return np.array(self.coords).reshape([-1, self.rank])
13 changes: 13 additions & 0 deletions tests/coordstring_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,18 @@ def test_slicing_stepped(self):
self.assertTrue(np.all(cs.slice(10, 35, 3) == np.c_[x, y][10:35:3]))
return

def test_asarray(self):
x = np.linspace(0, 5)
y = x**2
cs = CoordString(np.c_[x, y])
arr = cs.asarray()
self.assertTrue(np.all(arr == np.c_[x, y]))
return

def test_asarray_empty(self):
cs = CoordString([])
arr = cs.asarray()
self.assertTrue(np.all(arr == np.array([[]], dtype=np.float64)))

if __name__ == "__main__":
unittest.main()

0 comments on commit 238a9eb

Please sign in to comment.