From e154f3f75e54adedd489306cf6003e227a641dc7 Mon Sep 17 00:00:00 2001 From: Pierrick Rambaud Date: Sun, 14 Apr 2024 20:33:27 +0000 Subject: [PATCH 1/3] docs: use normal title instead of code --- docs/_templates/python/class.rst | 104 ++++++++++++++++ docs/_templates/python/function.rst | 21 ++++ docs/_templates/python/method.rst | 21 ++++ docs/_templates/python/module.rst | 176 ++++++++++++++++++++++++++++ docs/conf.py | 1 + 5 files changed, 323 insertions(+) create mode 100644 docs/_templates/python/class.rst create mode 100644 docs/_templates/python/function.rst create mode 100644 docs/_templates/python/method.rst create mode 100644 docs/_templates/python/module.rst diff --git a/docs/_templates/python/class.rst b/docs/_templates/python/class.rst new file mode 100644 index 00000000..f8041357 --- /dev/null +++ b/docs/_templates/python/class.rst @@ -0,0 +1,104 @@ +{% if obj.display %} + {% if is_own_page %} +{{ obj.id }} +{{ "=" * obj.id | length }} + + {% endif %} + {% set visible_children = obj.children|selectattr("display")|list %} + {% set own_page_children = visible_children|selectattr("type", "in", own_page_types)|list %} + {% if is_own_page and own_page_children %} +.. toctree:: + :hidden: + + {% for child in own_page_children %} + {{ child.include_path }} + {% endfor %} + + {% endif %} +.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}{% if obj.args %}({{ obj.args }}){% endif %} + + {% for (args, return_annotation) in obj.overloads %} + {{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %} + + {% endfor %} + {% if obj.bases %} + {% if "show-inheritance" in autoapi_options %} + + Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %} + {% endif %} + + + {% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %} + .. autoapi-inheritance-diagram:: {{ obj.obj["full_name"] }} + :parts: 1 + {% if "private-members" in autoapi_options %} + :private-bases: + {% endif %} + + {% endif %} + {% endif %} + {% if obj.docstring %} + + {{ obj.docstring|indent(3) }} + {% endif %} + {% for obj_item in visible_children %} + {% if obj_item.type not in own_page_types %} + + {{ obj_item.render()|indent(3) }} + {% endif %} + {% endfor %} + {% if is_own_page and own_page_children %} + {% set visible_attributes = own_page_children|selectattr("type", "in", ("attribute", "property"))|list %} + {% if visible_attributes %} +Attributes +---------- + +.. autoapisummary:: + + {% for attribute in visible_attributes %} + {{ attribute.id }} + {% endfor %} + + + {% endif %} + {% set visible_exceptions = own_page_children|selectattr("type", "equalto", "exception")|list %} + {% if visible_exceptions %} +Exceptions +---------- + +.. autoapisummary:: + + {% for exception in visible_exceptions %} + {{ exception.id }} + {% endfor %} + + + {% endif %} + {% set visible_classes = own_page_children|selectattr("type", "equalto", "class")|list %} + {% if visible_classes %} +Classes +------- + +.. autoapisummary:: + + {% for klass in visible_classes %} + {{ klass.id }} + {% endfor %} + + + {% endif %} + {% set visible_methods = own_page_children|selectattr("type", "equalto", "method")|list %} + {% if visible_methods %} +Methods +------- + +.. autoapisummary:: + + {% for method in visible_methods %} + {{ method.id }} + {% endfor %} + + + {% endif %} + {% endif %} +{% endif %} \ No newline at end of file diff --git a/docs/_templates/python/function.rst b/docs/_templates/python/function.rst new file mode 100644 index 00000000..ad214282 --- /dev/null +++ b/docs/_templates/python/function.rst @@ -0,0 +1,21 @@ +{% if obj.display %} + {% if is_own_page %} +{{ obj.id }} +{{ "=" * obj.id | length }} + + {% endif %} +.. py:function:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %} + {% for (args, return_annotation) in obj.overloads %} + + {%+ if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %} + {% endfor %} + {% for property in obj.properties %} + + :{{ property }}: + {% endfor %} + + {% if obj.docstring %} + + {{ obj.docstring|indent(3) }} + {% endif %} +{% endif %} \ No newline at end of file diff --git a/docs/_templates/python/method.rst b/docs/_templates/python/method.rst new file mode 100644 index 00000000..5526aa85 --- /dev/null +++ b/docs/_templates/python/method.rst @@ -0,0 +1,21 @@ +{% if obj.display %} + {% if is_own_page %} +{{ obj.id }} +{{ "=" * obj.id | length }} + + {% endif %} +.. py:method:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %} + {% for (args, return_annotation) in obj.overloads %} + + {%+ if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %} + {% endfor %} + {% for property in obj.properties %} + + :{{ property }}: + {% endfor %} + + {% if obj.docstring %} + + {{ obj.docstring|indent(3) }} + {% endif %} +{% endif %} \ No newline at end of file diff --git a/docs/_templates/python/module.rst b/docs/_templates/python/module.rst new file mode 100644 index 00000000..cbcb18ab --- /dev/null +++ b/docs/_templates/python/module.rst @@ -0,0 +1,176 @@ +{% if obj.display %} + {% if is_own_page %} +{{ obj.id }} +{{ "=" * obj.id|length }} + +.. py:module:: {{ obj.name }} + + {% if obj.docstring %} +.. autoapi-nested-parse:: + + {{ obj.docstring|indent(3) }} + + {% endif %} + + {% block subpackages %} + {% set visible_subpackages = obj.subpackages|selectattr("display")|list %} + {% if visible_subpackages %} +Subpackages +----------- + +.. toctree:: + :maxdepth: 1 + + {% for subpackage in visible_subpackages %} + {{ subpackage.include_path }} + {% endfor %} + + + {% endif %} + {% endblock %} + {% block submodules %} + {% set visible_submodules = obj.submodules|selectattr("display")|list %} + {% if visible_submodules %} +Submodules +---------- + +.. toctree:: + :maxdepth: 1 + + {% for submodule in visible_submodules %} + {{ submodule.include_path }} + {% endfor %} + + + {% endif %} + {% endblock %} + {% block content %} + {% if obj.all is not none %} + {% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %} + {% elif obj.type is equalto("package") %} + {% set visible_children = obj.children|selectattr("display")|list %} + {% else %} + {% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %} + {% endif %} + {% if visible_children %} + {% set visible_attributes = visible_children|selectattr("type", "equalto", "data")|list %} + {% if visible_attributes %} + {% if "attribute" in own_page_types or "show-module-summary" in autoapi_options %} +Attributes +---------- + + {% if "attribute" in own_page_types %} +.. toctree:: + :hidden: + + {% for attribute in visible_attributes %} + {{ attribute.include_path }} + {% endfor %} + + {% endif %} +.. autoapisummary:: + + {% for attribute in visible_attributes %} + {{ attribute.id }} + {% endfor %} + {% endif %} + + + {% endif %} + {% set visible_exceptions = visible_children|selectattr("type", "equalto", "exception")|list %} + {% if visible_exceptions %} + {% if "exception" in own_page_types or "show-module-summary" in autoapi_options %} +Exceptions +---------- + + {% if "exception" in own_page_types %} +.. toctree:: + :hidden: + + {% for exception in visible_exceptions %} + {{ exception.include_path }} + {% endfor %} + + {% endif %} +.. autoapisummary:: + + {% for exception in visible_exceptions %} + {{ exception.id }} + {% endfor %} + {% endif %} + + + {% endif %} + {% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %} + {% if visible_classes %} + {% if "class" in own_page_types or "show-module-summary" in autoapi_options %} +Classes +------- + + {% if "class" in own_page_types %} +.. toctree:: + :hidden: + + {% for klass in visible_classes %} + {{ klass.include_path }} + {% endfor %} + + {% endif %} +.. autoapisummary:: + + {% for klass in visible_classes %} + {{ klass.id }} + {% endfor %} + {% endif %} + + + {% endif %} + {% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %} + {% if visible_functions %} + {% if "function" in own_page_types or "show-module-summary" in autoapi_options %} +Functions +--------- + + {% if "function" in own_page_types %} +.. toctree:: + :hidden: + + {% for function in visible_functions %} + {{ function.include_path }} + {% endfor %} + + {% endif %} +.. autoapisummary:: + + {% for function in visible_functions %} + {{ function.id }} + {% endfor %} + {% endif %} + + + {% endif %} + {% set this_page_children = visible_children|rejectattr("type", "in", own_page_types)|list %} + {% if this_page_children %} +{{ obj.type|title }} Contents +{{ "-" * obj.type|length }}--------- + + {% for obj_item in this_page_children %} +{{ obj_item.render()|indent(0) }} + {% endfor %} + {% endif %} + {% endif %} + {% endblock %} + {% else %} +.. py:module:: {{ obj.name }} + + {% if obj.docstring %} + .. autoapi-nested-parse:: + + {{ obj.docstring|indent(6) }} + + {% endif %} + {% for obj_item in visible_children %} + {{ obj_item.render()|indent(3) }} + {% endfor %} + {% endif %} +{% endif %} \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 98fc04fe..32299022 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -98,6 +98,7 @@ autoapi_dirs = ["../geetools"] autoapi_python_class_content = "both" autoapi_member_order = "groupwise" +autoapi_template_dir = "_templates" autoapi_options = [ "members", "undoc-members", From d27b36cb7164b60e5f68dd8b514d4a83ba52759d Mon Sep 17 00:00:00 2001 From: Pierrick Rambaud Date: Sun, 14 Apr 2024 20:56:38 +0000 Subject: [PATCH 2/3] fix: force the dataArray to float64 in tessts --- tests/test_ImageCollection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_ImageCollection.py b/tests/test_ImageCollection.py index d6cac7ae..1e8eff4b 100644 --- a/tests/test_ImageCollection.py +++ b/tests/test_ImageCollection.py @@ -218,4 +218,5 @@ class TestToXarray: def test_to_xarray(self, s2_sr, data_regression): ds = s2_sr.geetools.to_xarray() + ds = ds.astype(np.float64) data_regression.check(ds.to_dict(data=False)) From ee10d9cbcb483e7c391522b645bfae81acff6961 Mon Sep 17 00:00:00 2001 From: Pierrick Rambaud Date: Mon, 15 Apr 2024 20:28:31 +0000 Subject: [PATCH 3/3] fix: edit the tests for new data type --- pyproject.toml | 2 +- tests/test_ImageCollection.py | 13 ++++- tests/test_ImageCollection/test_to_xarray.yml | 50 +++++++++---------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ae8d79f..0b30fd6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [ "geopandas", "deprecated", "ee-extra", - "xee", + "xee>=0.0.11", # xee change dtype management "yamlable", "matplotlib", "anyascii", diff --git a/tests/test_ImageCollection.py b/tests/test_ImageCollection.py index 1e8eff4b..4fc9d22e 100644 --- a/tests/test_ImageCollection.py +++ b/tests/test_ImageCollection.py @@ -218,5 +218,16 @@ class TestToXarray: def test_to_xarray(self, s2_sr, data_regression): ds = s2_sr.geetools.to_xarray() - ds = ds.astype(np.float64) + + # drop all the dtype as they are not consistently setup depending on the xarray version + def drop_dtype(d=ds): + for k, v in ds.items(): + if isinstance(v, dict): + drop_dtype(v) + elif k == "dtype": + del ds[k] + + drop_dtype() + + # ds = ds.astype(np.float64) data_regression.check(ds.to_dict(data=False)) diff --git a/tests/test_ImageCollection/test_to_xarray.yml b/tests/test_ImageCollection/test_to_xarray.yml index 8da57f25..9606a1fe 100644 --- a/tests/test_ImageCollection/test_to_xarray.yml +++ b/tests/test_ImageCollection/test_to_xarray.yml @@ -203,14 +203,14 @@ coords: attrs: {} dims: - lat - dtype: float32 + dtype: float64 shape: - 180 lon: attrs: {} dims: - lon - dtype: float32 + dtype: float64 shape: - 360 time: @@ -241,7 +241,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -266,7 +266,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -291,7 +291,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -316,7 +316,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -341,7 +341,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -366,7 +366,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -391,7 +391,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -416,7 +416,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -441,7 +441,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -466,7 +466,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -491,7 +491,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -516,7 +516,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -541,7 +541,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -566,7 +566,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -591,7 +591,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -616,7 +616,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -641,7 +641,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -666,7 +666,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -691,7 +691,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -716,7 +716,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -741,7 +741,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -766,7 +766,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360 @@ -791,7 +791,7 @@ data_vars: - time - lon - lat - dtype: int32 + dtype: float32 shape: - 2449 - 360