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

refactor: use custom types #160

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ jobs:
python-version: "3.10"
- uses: pre-commit/[email protected]

#mypy:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-python@v4
# with:
# python-version: "3.10"
# - name: Install nox
# run: pip install nox
# - name: run mypy checks
# run: nox -s mypy
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install nox
run: pip install nox
- name: run mypy checks
run: nox -s mypy

#docs:
# needs: [lint] #, mypy]
Expand All @@ -45,7 +45,7 @@ jobs:
# run: nox -s docs

build:
needs: [lint] #, mypy]
needs: [lint, mypy]
strategy:
fail-fast: false
matrix:
Expand Down
15 changes: 7 additions & 8 deletions geetools/Array/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Extra methods for the ``ee.Array`` class."""
from __future__ import annotations

from typing import Union

import ee

from geetools.accessors import geetools_accessor
from geetools.types import ee_int, ee_number

Check warning on line 7 in geetools/Array/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/Array/__init__.py#L7

Added line #L7 was not covered by tests

# hack to have the generated Array class available
# it might create issues in the future with libs that have exotic init methods
Expand All @@ -23,9 +22,9 @@
# -- alternative constructor -----------------------------------------------
def full(
self,
width: Union[int, float, ee.Number],
height: Union[int, float, ee.Number],
value: Union[int, ee.Number, float],
width: ee_number,
height: ee_number,
value: ee_number,
) -> ee.Array:
"""Create an array with the given dimensions, initialized to the given value.

Expand Down Expand Up @@ -53,9 +52,9 @@
# -- data maniputlation ----------------------------------------------------
def set(
self,
x: Union[int, ee.number],
y: Union[int, ee.number],
value: Union[int, float, ee.Number],
x: ee_int,
y: ee_int,
value: ee_number,
) -> ee.Array:
"""Set the value of a cell in an array.

Expand Down
9 changes: 5 additions & 4 deletions geetools/ComputedObject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

import json
from pathlib import Path
from typing import Type, Union
from typing import Type

Check warning on line 6 in geetools/ComputedObject/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/ComputedObject/__init__.py#L6

Added line #L6 was not covered by tests

import ee

from geetools.accessors import geetools_extend
from geetools.types import pathlike

Check warning on line 11 in geetools/ComputedObject/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/ComputedObject/__init__.py#L11

Added line #L11 was not covered by tests


# -- types management ----------------------------------------------------------
Expand Down Expand Up @@ -36,7 +37,7 @@

# -- .gee files ----------------------------------------------------------------
@geetools_extend(ee.ComputedObject)
def save(self, path: Union[str, Path]) -> Path:
def save(self, path: pathlike) -> Path:

Check warning on line 40 in geetools/ComputedObject/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/ComputedObject/__init__.py#L40

Added line #L40 was not covered by tests
"""Save a ``ComputedObject`` to a .gee file.

The file contains the JSON representation of the object. it still need to be computed via ``getInfo()`` to be used.
Expand Down Expand Up @@ -67,9 +68,9 @@
return path


@geetools_extend(ee.ComputedObject)
@geetools_extend(ee.ComputedObject) # type: ignore

Check warning on line 71 in geetools/ComputedObject/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/ComputedObject/__init__.py#L71

Added line #L71 was not covered by tests
@classmethod
def open(cls, path: Union[str, Path]) -> ee.ComputedObject:
def open(cls, path: pathlike) -> ee.ComputedObject:

Check warning on line 73 in geetools/ComputedObject/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/ComputedObject/__init__.py#L73

Added line #L73 was not covered by tests
"""Open a .gee file as a ComputedObject.

Parameters:
Expand Down
4 changes: 2 additions & 2 deletions geetools/Date/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
d = ee.Date.geetools.fromDOY(1, 2020)
d.getInfo()
"""
doy, year = ee.Number(doy).toInt(), ee.Number(year).toInt()
return ee.Date.fromYMD(year, 1, 1).advance(doy.subtract(1), "day")
d, y = ee.Number(doy).toInt(), ee.Number(year).toInt()
return ee.Date.fromYMD(y, 1, 1).advance(d.subtract(1), "day")

Check warning on line 68 in geetools/Date/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/Date/__init__.py#L67-L68

Added lines #L67 - L68 were not covered by tests

# -- export date -----------------------------------------------------------
def to_datetime(self) -> datetime:
Expand Down
5 changes: 2 additions & 3 deletions geetools/DateRange/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Extra tools for the ``ee.DateRange`` class."""
from __future__ import annotations

from typing import Union

import ee

from geetools.accessors import geetools_accessor
from geetools.types import ee_int

Check warning on line 7 in geetools/DateRange/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/DateRange/__init__.py#L7

Added line #L7 was not covered by tests


@geetools_accessor(ee.DateRange)
Expand All @@ -17,7 +16,7 @@
self._obj = obj

# -- date range operations -------------------------------------------------
def split(self, interval: Union[int, ee.Number], unit: str = "day") -> ee.List:
def split(self, interval: ee_int, unit: str = "day") -> ee.List:

Check warning on line 19 in geetools/DateRange/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/DateRange/__init__.py#L19

Added line #L19 was not covered by tests
"""Convert a ``ee.DateRange`` to a list of ``ee.DateRange``.

The DateRange will be split in multiple DateRanges of the specified interval and Unit.
Expand Down
7 changes: 3 additions & 4 deletions geetools/Dictionary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Extra methods for the ``ee.Dictionary`` class."""
from __future__ import annotations

from typing import Union

import ee

from geetools.accessors import geetools_accessor
from geetools.types import ee_list

Check warning on line 7 in geetools/Dictionary/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/Dictionary/__init__.py#L7

Added line #L7 was not covered by tests


@geetools_accessor(ee.Dictionary)
Expand All @@ -17,7 +16,7 @@
self._obj = obj

# -- alternative constructor -----------------------------------------------
def fromPairs(self, list: Union[list, ee.List]) -> ee.Dictionary:
def fromPairs(self, list: ee_list) -> ee.Dictionary:

Check warning on line 19 in geetools/Dictionary/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/Dictionary/__init__.py#L19

Added line #L19 was not covered by tests
"""Create a dictionary from a list of [[key, value], ...]] pairs.

Parameters:
Expand Down Expand Up @@ -62,7 +61,7 @@
values = orderededKeys.map(lambda key: self._obj.get(key))
return ee.Dictionary.fromLists(orderededKeys, values)

def getMany(self, list: Union[ee.List, list]) -> ee.List:
def getMany(self, list: ee_list) -> ee.List:

Check warning on line 64 in geetools/Dictionary/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/Dictionary/__init__.py#L64

Added line #L64 was not covered by tests
"""Extract values from a list of keys.

Parameters:
Expand Down
9 changes: 4 additions & 5 deletions geetools/FeatureCollection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ee

from geetools.accessors import geetools_accessor
from geetools.types import ee_int, ee_str

Check warning on line 9 in geetools/FeatureCollection/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/FeatureCollection/__init__.py#L9

Added line #L9 was not covered by tests


@geetools_accessor(ee.FeatureCollection)
Expand All @@ -18,8 +19,8 @@

def toImage(
self,
color: Union[ee.String, str, ee.Number, int] = 0,
width: Union[ee.String, str, ee.Number, int] = "",
color: Union[ee_str, ee_int] = 0,
width: Union[ee_str, ee_int] = "",
) -> ee.Image:
"""Paint the current FeatureCollection to an Image.

Expand All @@ -33,9 +34,7 @@
width == "" or params.update(width=width)
return ee.Image().paint(self._obj, **params)

def addId(
self, name: Union[str, ee.String] = "id", start: Union[int, ee.Number] = 1
) -> ee.FeatureCollection:
def addId(self, name: ee_str = "id", start: ee_int = 1) -> ee.FeatureCollection:

Check warning on line 37 in geetools/FeatureCollection/__init__.py

View check run for this annotation

Codecov / codecov/patch

geetools/FeatureCollection/__init__.py#L37

Added line #L37 was not covered by tests
"""Add a unique numeric identifier, starting from parameter ``start``.

Returns:
Expand Down
Loading