Skip to content
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
5 changes: 3 additions & 2 deletions .github/workflows/run-pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
- name: Install dev dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: pre-commit checks
run: |
pre-commit run black --all-files
pre-commit run isort --all-files
# TODO enable once all cyclic imports have been fixed
# pre-commit run isort --all-files
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ repos:
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
1 change: 0 additions & 1 deletion packages/data/src/pyearthtools/data/derived/insolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def derive(self, time: pd.Timestamp) -> xr.Dataset:
coords={"time": time, "latitude": self._latitude[:, 0], "longitude": self._longitude[0, :]},
)


insolation.time.encoding.update(
{"dtype": "int32", "units": "hours since 1900-01-01 00:00:00.0", "calendar": "gregorian"}
)
Expand Down
1 change: 1 addition & 0 deletions packages/data/src/pyearthtools/data/save/save_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def __exit__(self, *args):

SLEEP_INTERVAL = 0.1


class ManageFiles:
"""
Automatically manage the saving of files.
Expand Down
10 changes: 3 additions & 7 deletions packages/data/src/pyearthtools/data/transforms/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ class ReIndex(Transform):
"""Reindex Coordinates"""

def __init__(
self,
coordinates: dict[str, Literal["reversed", "sorted"] | Iterable] | xr.Coordinates | None = None,
**coords
self, coordinates: dict[str, Literal["reversed", "sorted"] | Iterable] | xr.Coordinates | None = None, **coords
):
"""
Reindex coordinates
Expand Down Expand Up @@ -323,7 +321,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
return dataset



class Drop(Transform):
"""Drop items from Dataset"""

Expand Down Expand Up @@ -370,10 +367,10 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:


def weak_cast_to_int(value):
'''
"""
Basically, turns integer floats to int types, otherwise
does nothing.
'''
"""
try:
if int(value) == value:
value = int(value)
Expand Down Expand Up @@ -602,7 +599,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
# return dict(as_dataarray=self._as_dataarray, **self._coordinates)



class Pad(Transform):
"""
Pad data
Expand Down
13 changes: 4 additions & 9 deletions packages/data/tests/data/archive/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@


def test_register_archive():


@extensions.register_archive("NewData")
class NewData:
def __init__(self, args):
self.args = args

def __init__(self, args):
self.args = args

# If registering over the top of an existing name, confirm warning occurs
with pytest.warns(pyearthtools.data.AccessorRegistrationWarning):

@extensions.register_archive("NewData")
class NewData:

_pyearthtools_initialisation = {"class": {}}
_pyearthtools_initialisation = {"class": {}}

def __init__(self, args):
self.args = args

def __call__(self, *args, **kwargs):
pass



10 changes: 5 additions & 5 deletions packages/data/tests/data/derived/test_insolation.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from pyearthtools.data.derived import insolation
from pyearthtools.data.time import Petdt


def test_array():

a = insolation.array([1,2,3,4,5])
assert all(a == [1,2,3,4,5])
a = insolation.array([1, 2, 3, 4, 5])
assert all(a == [1, 2, 3, 4, 5])


def test_Insolation():

insol = insolation.Insolation(
[-10],
[40],
)
)

at_time = ['2021-01-01']
at_time = ["2021-01-01"]

# import pudb; pudb.set_trace()

Expand All @@ -23,4 +24,3 @@ def test_Insolation():

# TODO: Check the insolation calculation
# TODO: Check the result is the right type/contents

83 changes: 40 additions & 43 deletions packages/data/tests/data/indexes/test_indexes.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,66 @@

from pyearthtools.data import indexes
import pyearthtools.data.archive
from pyearthtools.data.time import Petdt
import pytest
import pathlib


def test_Index(monkeypatch):

monkeypatch.setattr("pyearthtools.data.indexes.Index.__abstractmethods__", set())
monkeypatch.setattr("pyearthtools.data.indexes.Index.__abstractmethods__", set())

idx = indexes.Index()
idx = indexes.Index()

with pytest.raises(NotImplementedError):
idx.get()
with pytest.raises(NotImplementedError):
idx.get()

with pytest.raises(NotImplementedError):
idx()

with pytest.raises(NotImplementedError):
idx()

def test_FileSystemIndex(monkeypatch):

monkeypatch.setattr("pyearthtools.data.indexes.Index.__abstractmethods__", set())
fsi = indexes.FileSystemIndex()
with pytest.raises(NotImplementedError):
fsi.filesystem("anything")
monkeypatch.setattr("pyearthtools.data.indexes.Index.__abstractmethods__", set())
fsi = indexes.FileSystemIndex()
with pytest.raises(NotImplementedError):
fsi.filesystem("anything")

# Confirm the test begins without a root directory set
monkeypatch.delattr(pyearthtools.data.archive, "ROOT_DIRECTORIES", raising=False)
fsi = indexes.FileSystemIndex()
with pytest.raises(KeyError):
fsi.ROOT_DIRECTORIES
# Confirm the test begins without a root directory set
monkeypatch.delattr(pyearthtools.data.archive, "ROOT_DIRECTORIES", raising=False)
fsi = indexes.FileSystemIndex()
with pytest.raises(KeyError):
fsi.ROOT_DIRECTORIES

# Confirm the FSI responds to the root directory variable correctly
monkeypatch.setattr(pyearthtools.data.archive, "ROOT_DIRECTORIES", "Hello", raising=False)
fsi = indexes.FileSystemIndex()
assert fsi.ROOT_DIRECTORIES == "Hello"
# Confirm the FSI responds to the root directory variable correctly
monkeypatch.setattr(pyearthtools.data.archive, "ROOT_DIRECTORIES", "Hello", raising=False)
fsi = indexes.FileSystemIndex()
assert fsi.ROOT_DIRECTORIES == "Hello"

monkeypatch.setattr(fsi, "filesystem", lambda x: __file__, raising=False)
assert fsi.search("needle") == __file__

monkeypatch.setattr(fsi, 'filesystem', lambda x: __file__, raising=False)
assert fsi.search("needle") == __file__
# Check the current Python file exists
assert fsi.exists(__file__)
assert fsi.exists(pathlib.Path(__file__))
assert fsi.exists({"a": __file__})
assert fsi.exists((__file__, __file__))

# Check the current Python file exists
assert fsi.exists(__file__)
assert fsi.exists(pathlib.Path(__file__))
assert fsi.exists({"a": __file__})
assert fsi.exists((__file__, __file__))
with pytest.raises(KeyError):
assert fsi.load(__file__) is not None
# TODO test actual netcdf file loading

with pytest.raises(KeyError):
assert fsi.load(__file__) is not None
# TODO test actual netcdf file loading
with pytest.raises(KeyError):
assert fsi.get(__file__) is not None
# TODO test actual netcdf file getting

with pytest.raises(KeyError):
assert fsi.get(__file__) is not None
# TODO test actual netcdf file getting

def test_AdvancedTimeIndex(monkeypatch):

monkeypatch.setattr("pyearthtools.data.indexes.AdvancedTimeIndex.__abstractmethods__", set())

data_interval = "day"
ati = indexes.AdvancedTimeIndex(data_interval)
dt = Petdt('2023-02')

monkeypatch.setattr(pyearthtools.data.indexes.Index, 'get', lambda x, y: x, raising=False)
ati.retrieve(dt, use_simple = True)


monkeypatch.setattr("pyearthtools.data.indexes.AdvancedTimeIndex.__abstractmethods__", set())

data_interval = "day"
ati = indexes.AdvancedTimeIndex(data_interval)
dt = Petdt("2023-02")

monkeypatch.setattr(pyearthtools.data.indexes.Index, "get", lambda x, y: x, raising=False)
ati.retrieve(dt, use_simple=True)
Loading