Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcube server STAC API now returns a conformant collection time extent #1080

Merged
merged 4 commits into from
Oct 8, 2024

Conversation

konstntokas
Copy link
Contributor

@konstntokas konstntokas commented Oct 7, 2024

Closes #1077

Checklist:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/source/*
  • Changes documented in CHANGES.md
  • GitHub CI passes
  • AppVeyor CI passes
  • Test coverage remains or increases (target 100%)

@@ -148,6 +148,16 @@
}


def assert_equal_deep_dict(self, dict1, dict2):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add this function to test for nested dictionaries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. However, you should keep track of the path and output it as part of the error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But actually it is strange why this is needed. TestCase.assertEquals() actually does a deep equality comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. However, you should keep track of the path and output it as part of the error message.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But actually it is strange why this is needed. TestCase.assertEquals() actually does a deep equality comparison.

TestCase.assertEqual() also checks for the order of the keys in the dictionary, which gives me an error.

@@ -174,7 +184,7 @@ def test_get_datasets_collection_item(self):
"demo-1w",
)
self.assertIsInstance(result, dict)
self.assertCountEqual(self.read_json("stac-datacubes-item.json"), result)
assert_equal_deep_dict(self, self.read_json("stac-datacubes-item.json"), result)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, it was only tested that the keys in the first layer of the dictionaries are equal. Now I test the full content of the dictionaries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you define assert_equal_deep_dict rather than just using self.assertEqual(), and eventually realized that you presumably need something that's insensitive to the order of iterables within the dictionaries. I suggest adding a short docstring to assert_equal_deep_dict to explain this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you define assert_equal_deep_dict rather than just using self.assertEqual(), and eventually realized that you presumably need something that's insensitive to the order of iterables within the dictionaries. I suggest adding a short docstring to assert_equal_deep_dict to explain this.

done

@forman forman requested review from forman and pont-us October 7, 2024 14:31
@konstntokas konstntokas changed the title Konstntokas 1077 stac non conformant collection Xcube server STAC API now returns a conformant collection time extent Oct 7, 2024
Copy link
Member

@forman forman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comments. Please have a look.

@@ -148,6 +148,16 @@
}


def assert_equal_deep_dict(self, dict1, dict2):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. However, you should keep track of the path and output it as part of the error message.

@@ -632,7 +632,7 @@ def _get_single_dataset_collection(
{"cellsCount": gm.size[1], "resolution": gm.xy_res[1]},
],
},
"temporal": {"interval": [[time_interval]], "grid": get_time_grid(dataset)},
"temporal": {"interval": [time_interval], "grid": get_time_grid(dataset)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, the actual fix.

@@ -102,7 +102,7 @@ def _convert_default(obj: Any) -> Any:
elif np.issubdtype(obj.dtype, np.floating):
return float(obj)
elif np.issubdtype(obj.dtype, np.datetime64):
return np.datetime_as_string(obj, timezone="UTC", unit="s")
return str(np.datetime_as_string(obj, timezone="UTC", unit="s"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment why this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -148,6 +148,16 @@
}


def assert_equal_deep_dict(self, dict1, dict2):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But actually it is strange why this is needed. TestCase.assertEquals() actually does a deep equality comparison.

Copy link
Member

@pont-us pont-us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had one suggestion (see comment), but approving since I don't need to review again.

@@ -174,7 +184,7 @@ def test_get_datasets_collection_item(self):
"demo-1w",
)
self.assertIsInstance(result, dict)
self.assertCountEqual(self.read_json("stac-datacubes-item.json"), result)
assert_equal_deep_dict(self, self.read_json("stac-datacubes-item.json"), result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you define assert_equal_deep_dict rather than just using self.assertEqual(), and eventually realized that you presumably need something that's insensitive to the order of iterables within the dictionaries. I suggest adding a short docstring to assert_equal_deep_dict to explain this.

@konstntokas konstntokas merged commit 033af87 into main Oct 8, 2024
3 checks passed
@konstntokas konstntokas deleted the konstntokas-1077-stac_non_conformant_collection branch October 8, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xcube v1.7.0 OGC API returns STAC non-conformant collection time extent.
3 participants