Skip to content

Commit

Permalink
Fix dev readme and formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire Donnelly authored and Claire Donnelly committed Mar 6, 2024
1 parent 7089e48 commit 8bc7abd
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

### Fixed
- Fixed issue with calendar generation when the (rightmost) target period crossed into the new year ([#70](https://github.com/AI4S2S/lilio/pull/70)).
- Fixed issue with Pandas 2.2 where 'M' changed to 'ME' ([#71](https://github.com/AI4S2S/lilio/pull/71))
- Fixed issue where pd.Interval now shows time where it is not wanted ([#71](https://github.com/AI4S2S/lilio/pull/71)). The issue was raised with Pandas ([#57748] https://github.com/pandas-dev/pandas/issues/57748).

## 0.4.2 (2024-01-19)
### Changed
Expand Down
6 changes: 2 additions & 4 deletions docs/README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,19 @@ This runs tests and prints the results to the command line, as well as storing t

## Running linters locally

For linting and code style we use `ruff`, `black` and `isort`. We additionally use `mypy` to check the type hints.
For linting and code style we use `ruff`. We additionally use `mypy` to check the type hints.
All tools can simply be run by doing:

```shell
hatch run lint
```

To easily comply with `black` and `isort`, you can also run:
To comply with formatting you can run:

```shell
hatch run format
```

This will apply the `black` and `isort` formatting, and then check the code style.

## Generating the documentation
To generate the documentation, simply run the following command. This will also test the documentation code snippets. Note that you might need to install [`pandoc`](https://pandoc.org/) to be able to generate the documentation.

Expand Down
1 change: 1 addition & 0 deletions lilio/_bokeh_plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Calendar plotting implementations (bokeh specific code)."""

import sys
import typing
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions lilio/_plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Calendar plotting implementations (general and matplotlib)."""

import typing
import matplotlib.pyplot as plt
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion lilio/calendar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Lilio's main Calendar module."""

import copy
import re
import warnings
Expand Down Expand Up @@ -576,7 +577,7 @@ def show(self) -> pd.DataFrame:
"""
df = self.get_intervals()
df = df.astype("str")

for i in range(df.shape[0]):
df.iloc[i] = [el.replace(" 00:00:00", "") for el in df.iloc[i].values]

Expand Down
1 change: 1 addition & 0 deletions lilio/calendar_shifter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Calendar shifter to create staggered calendars."""

import copy
from typing import Union
import xarray as xr
Expand Down
1 change: 1 addition & 0 deletions lilio/calendar_shorthands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Shorthands for calendars, to make generating commonly used calendars a one-liner."""

import re
import pandas as pd
from .calendar import Calendar
Expand Down
12 changes: 5 additions & 7 deletions lilio/resampling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The implementation of the resampling methods for use with the Calendar."""

import typing
from typing import Callable
from typing import Literal
Expand Down Expand Up @@ -244,22 +245,19 @@ def _resample_dataset(


@overload
def resample(calendar: Calendar, input_data: xr.Dataset) -> xr.Dataset:
...
def resample(calendar: Calendar, input_data: xr.Dataset) -> xr.Dataset: ...


@overload
def resample(calendar: Calendar, input_data: xr.DataArray) -> xr.DataArray:
...
def resample(calendar: Calendar, input_data: xr.DataArray) -> xr.DataArray: ...


@overload
def resample(
calendar: Calendar, input_data: Union[pd.Series, pd.DataFrame]
) -> pd.DataFrame:
...

) -> pd.DataFrame: ...

# ruff: noqa: E501 / Ignoring line length issue until pd.Interval fixed to drop time.
def resample(
calendar: Calendar,
input_data: Union[pd.Series, pd.DataFrame, xr.DataArray, xr.Dataset],
Expand Down
7 changes: 3 additions & 4 deletions lilio/traintest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Wrapper around sklearn splitters for working with (multiple) xarray dataarrays.
"""

from collections.abc import Iterable
from typing import Optional
from typing import Union
Expand Down Expand Up @@ -56,8 +57,7 @@ def split(
x_args: xr.DataArray,
y: Optional[xr.DataArray] = None,
dim: str = "anchor_year",
) -> Iterable[tuple[xr.DataArray, xr.DataArray, xr.DataArray, xr.DataArray]]:
...
) -> Iterable[tuple[xr.DataArray, xr.DataArray, xr.DataArray, xr.DataArray]]: ...

@overload
def split(
Expand All @@ -69,8 +69,7 @@ def split(
tuple[
Iterable[xr.DataArray], Iterable[xr.DataArray], xr.DataArray, xr.DataArray
]
]:
...
]: ...

def split(
self,
Expand Down
5 changes: 3 additions & 2 deletions lilio/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Commonly used utility functions for Lilio."""

import re
import typing
import warnings
Expand Down Expand Up @@ -115,8 +116,8 @@ def infer_input_data_freq(
if data_freq is None: # Manually infer the frequency
data_freq = (data.time.values[1:] - data.time.values[:-1]).min()

if "ME" or "MS" in data_freq:
data_freq = data_freq.replace("ME","M").replace("MS", "M")
if "ME" or "MS" in data_freq:
data_freq = data_freq.replace("ME", "M").replace("MS", "M")

if isinstance(data_freq, str):
data_freq.replace("-", "") # Get the absolute frequency
Expand Down
4 changes: 2 additions & 2 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for the lilio.Calendar module.
"""
"""Tests for the lilio.Calendar module."""

from typing import Literal
import numpy as np
import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions tests/test_calendar_shifter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the s2s.nwp_calendar module."""

import copy
import numpy as np
import pandas as pd
Expand Down
Binary file modified tests/test_data/era5_dummy_2000.nc
Binary file not shown.
Binary file modified tests/test_data/era5_dummy_2001.nc
Binary file not shown.
Binary file modified tests/test_data/era5_dummy_2002.nc
Binary file not shown.
1 change: 1 addition & 0 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the lilio._bokeh_plots module."""

import matplotlib as mpl
import matplotlib.pyplot as plt
import pytest
Expand Down
4 changes: 2 additions & 2 deletions tests/test_resample.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for lilio's resample module.
"""
"""Tests for lilio's resample module."""

import tempfile
from pathlib import Path
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions tests/test_traintest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for Lilio's traintest module."""

import numpy as np
import pandas as pd
import pytest
Expand Down

0 comments on commit 8bc7abd

Please sign in to comment.