Skip to content

Commit

Permalink
BUGFIX: Seems like the Array DataSource deserialization has been brok…
Browse files Browse the repository at this point in the history
…en for a while. I'm now catching the native_coordinates definition at instantiation to make sure it's a Coordinates object. It would be and OrderedDict if created throught Node.from_definition...

Also, native_coordinates cannot be None for an Array datasource, so had to update the tests.
  • Loading branch information
mpu-creare committed Nov 20, 2019
1 parent dcb76dd commit 55fcf30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions podpac/core/data/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,23 @@ def test_native_coordinates(self):
assert native_coordinates == get_native_coordinates

def test_base_definition(self):
node = Array(source=self.data)
node = Array(source=self.data, native_coordinates=self.coordinates)
d = node.base_definition
source = np.array(d["source"])
np.testing.assert_array_equal(source, self.data)

def test_definition(self):
node = Array(source=self.data)
node = Array(source=self.data, native_coordinates=self.coordinates)
node2 = Node.from_definition(node.definition)
assert isinstance(node2, Array)
np.testing.assert_array_equal(node2.source, self.data)

def test_json(self):
node = Array(source=self.data, native_coordinates=self.coordinates)
node2 = Node.from_json(node.json)
assert isinstance(node2, Array)
np.testing.assert_array_equal(node2.source, self.data)


class TestPyDAP(object):
"""test pydap datasource"""
Expand Down
11 changes: 11 additions & 0 deletions podpac/core/data/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def _validate_source(self, d):
raise ValueError("Array source must be numerical")
return a

def _first_init(self, **kwargs):
# If Array is being created from Node.from_definition or Node.from_json, then we have to handle the
# native coordinates specifically. This is special. No other DataSource node needs to deserialize
# native_coordinates in this way because it is implemented specifically in the node through get_coordinates
if isinstance(kwargs["native_coordinates"], OrderedDict):
kwargs["native_coordinates"] = Coordinates.from_definition(kwargs["native_coordinates"])
elif isinstance(kwargs["native_coordinates"], string_types):
kwargs["native_coordinates"] = Coordinates.from_json(kwargs["native_coordinates"])

return kwargs

@common_doc(COMMON_DATA_DOC)
def get_data(self, coordinates, coordinates_index):
"""{get_data}
Expand Down

0 comments on commit 55fcf30

Please sign in to comment.