Skip to content

Commit

Permalink
Fix missing import (#75)
Browse files Browse the repository at this point in the history
* Fix missing import and add ruff
  • Loading branch information
aazuspan authored Dec 21, 2023
1 parent 254c650 commit 362e584
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]

steps:
- uses: actions/checkout@v3
Expand Down
28 changes: 15 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
- id: black
- id: ruff
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
args: [--disallow-untyped-defs, --no-implicit-optional, --warn-unused-ignores, --warn-redundant-casts, --warn-unreachable]
- id: mypy
args:
[
--disallow-untyped-defs,
--no-implicit-optional,
--warn-unused-ignores,
--warn-redundant-casts,
--warn-unreachable,
]
exclude: test
additional_dependencies: [types-requests, xarray]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile, black]
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

sys.path.insert(0, os.path.abspath(".."))

from wxee import __version__
from wxee import __version__ # noqa: E402


# -- Project information -----------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ path = "wxee/__init__.py"
[tool.hatch.build.targets.sdist]
include = ["/wxee"]

[tool.hatch.envs.default]
dependencies = ["pre-commit"]

[tool.hatch.envs.docs]
dependences = [
"nbsphinx",
Expand Down
2 changes: 0 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ee

import wxee


Expand Down
2 changes: 1 addition & 1 deletion test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import rasterio

import wxee
import wxee # noqa: F401
from wxee.exceptions import MissingPropertyError


Expand Down
22 changes: 22 additions & 0 deletions test/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,25 @@ def test_dataframe():
df["system:time_start"].dt.strftime("%Y-%m-%d").values.tolist() == start_dates
)
assert df["system:id"].values.tolist() == ids


@pytest.mark.ee
def test_timeline():
"""Test that you can generate a timeline figure from a time series."""
start_dates = ["2020-01-01", "2020-02-01", "2021-03-03"]
ids = ["id1", "id2", "id3"]

imgs = [
ee.Image.constant(1).set(
"system:time_start",
ee.Date(start_dates[i]).millis(),
"system:id",
ids[i],
)
for i in range(3)
]
ts = wxee.TimeSeries(imgs)

timeline = ts.timeline()

assert timeline.data
4 changes: 3 additions & 1 deletion wxee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import wxee.xarray
from wxee import xarray
from wxee.collection import ImageCollection
from wxee.image import Image
from wxee.time_series import TimeSeries
from wxee.utils import Initialize

__version__ = "0.4.1"

__all__ = ["xarray", "Image", "ImageCollection", "TimeSeries", "Initialize"]
2 changes: 1 addition & 1 deletion wxee/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _get_download_id(self) -> ee.String:
except ee.EEException as e:
if "Parameter 'value' is required" in str(e):
raise MissingPropertyError(
f"Image is missing a `system:time_start` property which is required for "
"Image is missing a `system:time_start` property which is required for "
"downloading.\n\nEarth Engine properties can be lost when modifying images, so make sure to manually "
"set or copy properties using the `.set` and `.copyProperties` methods after using methods like "
"`.multiply` or `.median`. If you don't need time information, you can set an arbitrary time with "
Expand Down
5 changes: 3 additions & 2 deletions wxee/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def dataframe(self, props: Union[None, List[str], ee.List] = None) -> pd.DataFra
df.index.id = collection_id
return df

def timeline(self) -> "go.Figure": # pragma: no cover
def timeline(self) -> "go.Figure":
"""Generate an interactive plot showing the acquisition time of each image in the time series.
Returns
Expand All @@ -181,6 +181,7 @@ def timeline(self) -> "go.Figure": # pragma: no cover
"""
try:
import plotly.express as px # type: ignore
import plotly.graph_objects as go
except ImportError:
raise ImportError(
"The `plotly` package is required for this feature. "
Expand Down Expand Up @@ -579,7 +580,7 @@ def climatology_anomaly(
)
if std.reducer != mean.reducer:
# There is no way to determine the type of reducer used after the fact, or else I would list them.
raise ValueError(f"Mean reducer does not match std reducer.")
raise ValueError("Mean reducer does not match std reducer.")

def image_anomaly(img: ee.Image) -> ee.Image:
"""Identify the climatological mean and std deviation for a given image
Expand Down
6 changes: 3 additions & 3 deletions wxee/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def rgb(
"""
if bands is not None:
if len(bands) != 3:
raise ValueError(f"Bands must be a list with exactly 3 names.")
raise ValueError("Bands must be a list with exactly 3 names.")
else:
bands = list(self._obj.var())[:3] # type: ignore

# Raise a different error if the bands were identified implicitly to avoid confusion
if len(bands) != 3: # type: ignore
raise ValueError(
f"The Dataset must contain at least 3 data variables for RGB plotting."
"The Dataset must contain at least 3 data variables for RGB plotting."
)

da = self._obj[bands].to_array(name="rgb")
Expand All @@ -83,7 +83,7 @@ def rgb(

if interactive:
try:
import hvplot.xarray # type: ignore
import hvplot.xarray # type: ignore # noqa F401
except ImportError:
raise ImportError(
"The `hvplot` package is required for interactive plots. Run `pip install hvplot`."
Expand Down

0 comments on commit 362e584

Please sign in to comment.