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: improve typing and delete mutable default arguments #421

Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 14 additions & 14 deletions geetools/ee_authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class AuthenticateAccessor:
"""Create an accessor for the :py:func:`ee.Authenticate` function."""

@staticmethod
def new_user(name: str = "", credential_pathname: str = "") -> None:
def new_user(name: str = "", credential_pathname: str | Path = "") -> None:
12rambau marked this conversation as resolved.
Show resolved Hide resolved
"""Authenticate the user and save the credentials in a specific folder.

Equivalent to :py:func:`ee.Authenticate` but where the registered user will not be the default one (the one you get when running :py:func:`ee.Initialize`)
Equivalent to :py:func:`ee.Authenticate` but where the registered user will not be the default one (the one you get when running :py:func:`ee.Initialize`).

Args:
name: The name of the user. If not set, it will reauthenticate default.
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path.

Example:
.. code-block:: python
Expand Down Expand Up @@ -55,12 +55,12 @@ def new_user(name: str = "", credential_pathname: str = "") -> None:
move(Path(dir) / default.name, default)

@staticmethod
def delete_user(name: str = "", credential_pathname: str = "") -> None:
def delete_user(name: str = "", credential_pathname: str | Path = "") -> None:
"""Delete a user credential file.

Args:
name: The name of the user. If not set, it will delete the default user
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path
name: The name of the user. If not set, it will delete the default user.
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path.

Example:
.. code-block:: python
Expand All @@ -80,16 +80,16 @@ def delete_user(name: str = "", credential_pathname: str = "") -> None:
(credential_path / name).unlink()

@staticmethod
def list_user(credential_pathname: str = "") -> list[str]:
def list_user(credential_pathname: str | Path = "") -> list[str]:
"""return all the available users in the set folder.

To reach "default" simply omit the ``name`` parameter in the User methods
To reach "default" simply omit the ``name`` parameter in the User methods.

Args:
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path.

Returns:
A list of strings with the names of the users
A list of strings with the names of the users.

Example:
.. code-block:: python
Expand All @@ -105,13 +105,13 @@ def list_user(credential_pathname: str = "") -> list[str]:
return [f.name.replace("credentials", "") or "default" for f in files]

@staticmethod
def rename_user(new: str, old: str = "", credential_pathname: str = "") -> None:
def rename_user(new: str, old: str = "", credential_pathname: str | Path = "") -> None:
"""Rename a user without changing the credentials.

Args:
new: The new name of the user
old: The name of the user to rename
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path
new: The new name of the user.
old: The name of the user to rename.
credential_pathname: The path to the folder where the credentials are stored. If not set, it uses the default path.

Example:
.. code-block:: python
Expand Down
8 changes: 4 additions & 4 deletions geetools/ee_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def toFeatureCollection(self) -> ee.FeatureCollection:
"""Convert a :py:class:`ee.Feature` composed of a multiGeometry geometry into a :py:class:`ee.FeatureCollection`.

Returns:
The :py:class:`ee.FeatureCollection`
The :py:class:`ee.FeatureCollection`.

Example:
.. jupyter-execute::
Expand All @@ -37,14 +37,14 @@ def toFeatureCollection(self) -> ee.FeatureCollection:
fc = geoms.map(lambda g: self._obj.setGeometry(g))
return ee.FeatureCollection(fc)

def removeProperties(self, properties: list | ee.List) -> ee.Feature:
def removeProperties(self, properties: list[str] | ee.List) -> ee.Feature:
"""Remove properties from a feature.

Args:
properties : List of properties to remove
properties : List of properties to remove.

Returns:
The feature without the properties
The feature without the properties.

Example:
.. jupyter-execute::
Expand Down
30 changes: 16 additions & 14 deletions geetools/ee_feature_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def toImage(
return ee.Image().paint(self._obj, **params)

def toDictionary(
self, keyColumn: str | ee.String = "system:index", selectors: list | ee.List = []
self,
keyColumn: str | ee.String = "system:index",
selectors: list[str] | ee.List | None = None,
) -> ee.Dictionary:
"""Convert to Dictionary.

Expand Down Expand Up @@ -270,8 +272,8 @@ def removeNonPoly(feat):
def byProperties(
self,
featureId: str | ee.String = "system:index",
properties: list | ee.List = [],
labels: list = [],
properties: list[str] | ee.List | None = None,
12rambau marked this conversation as resolved.
Show resolved Hide resolved
labels: list[str] | None = None,
) -> ee.Dictionary:
"""Get a dictionary with all feature values for each property.

Expand All @@ -289,7 +291,7 @@ def byProperties(

Args:
featureId: The property used to label features. Defaults to ``"system:index"``.
properties: A list of properties to get the values from.
properties: A list of properties to get the values from. By default, all properties will be used.
labels: A list of names to replace properties names. Default to the properties names.

Returns:
Expand Down Expand Up @@ -333,8 +335,8 @@ def byProperties(
def byFeatures(
self,
featureId: str | ee.String = "system:index",
properties: list | ee.List = [],
labels: list = [],
properties: list[str] | ee.List | None = None,
labels: list[str] | None = None,
) -> ee.Dictionary:
"""Get a dictionary with all property values for each feature.

Expand All @@ -352,7 +354,7 @@ def byFeatures(

Args:
featureId: The property to use as the feature id. Defaults to ``"system:index"``. This property needs to be a string property.
properties: A list of properties to get the values from.
properties: A list of properties to get the values from. By default, all properties will be used.
labels: A list of names to replace properties names. Default to the properties names.

Returns:
Expand Down Expand Up @@ -401,9 +403,9 @@ def plot_by_features(
self,
type: str = "bar",
featureId: str = "system:index",
properties: list = [],
labels: list = [],
colors: list = [],
properties: list[str] | None = None,
labels: list[str] | None = None,
colors: list[str] | None = None,
ax: Axes | None = None,
**kwargs,
) -> Axes:
Expand Down Expand Up @@ -469,9 +471,9 @@ def plot_by_properties(
self,
type: str = "bar",
featureId: str = "system:index",
properties: list | ee.List = [],
labels: list = [],
colors: list = [],
properties: list[str] | ee.List | None = None,
labels: list[str] | None = None,
colors: list[str] | None = None,
ax: Axes | None = None,
**kwargs,
) -> Axes:
Expand Down Expand Up @@ -533,7 +535,7 @@ def plot_hist(
property: str | ee.String,
label: str = "",
ax: Axes | None = None,
color=None,
color: str | None = None,
**kwargs,
) -> Axes:
"""Plot the histogram of a specific property.
Expand Down
Loading
Loading