From 55fcf3080c90b0f07f95a07dc2720d56f4c0ac7f Mon Sep 17 00:00:00 2001 From: Matt Ueckermann Date: Wed, 20 Nov 2019 16:31:43 -0500 Subject: [PATCH] BUGFIX: Seems like the Array DataSource deserialization has been broken 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. --- podpac/core/data/test/test_types.py | 10 ++++++++-- podpac/core/data/types.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/podpac/core/data/test/test_types.py b/podpac/core/data/test/test_types.py index f5ec3cfd4..b43088343 100644 --- a/podpac/core/data/test/test_types.py +++ b/podpac/core/data/test/test_types.py @@ -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""" diff --git a/podpac/core/data/types.py b/podpac/core/data/types.py index 798cc6f11..6cfbf234b 100644 --- a/podpac/core/data/types.py +++ b/podpac/core/data/types.py @@ -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}