Skip to content

Commit

Permalink
Added ndloc unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 18, 2017
1 parent 9a0601a commit d5e52d8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/testdataset.py
Expand Up @@ -911,6 +911,44 @@ def test_canonical_vdim(self):
self.assertEqual(dataset.dimension_values('z', flat=False),
canonical)

def test_dataset_ndloc_index(self):
xs, ys = np.linspace(0.12, 0.81, 10), np.linspace(0.12, 0.391, 5)
arr = np.arange(10)*np.arange(5)[np.newaxis].T
ds = Dataset((xs, ys, arr), kdims=['x', 'y'], vdims=['z'], datatype=[self.datatype])
self.assertEqual(ds.ndloc[0,0], arr[0, 0])

def test_dataset_ndloc_index2(self):
xs, ys = np.linspace(0.12, 0.81, 10), np.linspace(0.12, 0.391, 5)
arr = np.arange(10)*np.arange(5)[np.newaxis].T
ds = Dataset((xs, ys, arr), kdims=['x', 'y'], vdims=['z'], datatype=[self.datatype])
self.assertEqual(ds.ndloc[4, 9], arr[4, 9])

def test_dataset_ndloc_slice(self):
xs, ys = np.linspace(0.12, 0.81, 10), np.linspace(0.12, 0.391, 5)
arr = np.arange(10)*np.arange(5)[np.newaxis].T
ds = Dataset((xs, ys, arr), kdims=['x', 'y'], vdims=['z'], datatype=[self.datatype])
sliced = Dataset((xs[2:5], ys[1:], arr[1:, 2:5]), kdims=['x', 'y'], vdims=['z'],
datatype=[self.datatype])
self.assertEqual(ds.ndloc[1:, 2:5], sliced)

def test_dataset_ndloc_lists(self):
xs, ys = np.linspace(0.12, 0.81, 10), np.linspace(0.12, 0.391, 5)
arr = np.arange(10)*np.arange(5)[np.newaxis].T
ds = Dataset((xs, ys, arr), kdims=['x', 'y'], vdims=['z'], datatype=[self.datatype, 'dictionary'])
sliced = Dataset((xs[[1, 2, 3]], ys[[0, 1, 2]], arr[[0, 1, 2], [1, 2, 3]]), kdims=['x', 'y'], vdims=['z'],
datatype=['dictionary'])
self.assertEqual(ds.ndloc[[0, 1, 2], [1, 2, 3]], sliced)

def test_dataset_ndloc_slice_two_vdims(self):
xs, ys = np.linspace(0.12, 0.81, 10), np.linspace(0.12, 0.391, 5)
arr = np.arange(10)*np.arange(5)[np.newaxis].T
arr2 = (np.arange(10)*np.arange(5)[np.newaxis].T)[::-1]
ds = Dataset((xs, ys, arr, arr2), kdims=['x', 'y'], vdims=['z', 'z2'], datatype=[self.datatype, 'dictionary'])
sliced = Dataset((xs[[1, 2, 3]], ys[[0, 1, 2]], arr[[0, 1, 2], [1, 2, 3]],
arr2[[0, 1, 2], [1, 2, 3]]), kdims=['x', 'y'], vdims=['z', 'z2'],
datatype=['dictionary'])
self.assertEqual(ds.ndloc[[0, 1, 2], [1, 2, 3]], sliced)

def test_dataset_dim_vals_grid_kdims_xs(self):
self.assertEqual(self.dataset_grid.dimension_values(0, expanded=False),
np.array([0, 1]))
Expand Down Expand Up @@ -1248,6 +1286,9 @@ def test_dataset_groupby_drop_dims_with_vdim(self):
def test_dataset_groupby_drop_dims_dynamic_with_vdim(self):
raise SkipTest("Not supported")

def test_dataset_ndloc_slice_two_vdims(self):
raise SkipTest("Not supported")


@attr(optional=1)
class XArrayDatasetTest(GridDatasetTest):
Expand Down

0 comments on commit d5e52d8

Please sign in to comment.