Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Sep 16, 2024
1 parent 926dd5c commit 60133f4
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 40 deletions.
14 changes: 8 additions & 6 deletions doc/source/tutorials/notebooks/DCSC_txnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@
}
],
"source": [
"import datetime\n",
"import sys\n",
"from pathlib import Path\n",
"\n",
"import cartopy.crs as ccrs\n",
"import cftime\n",
"import icclim\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"import xclim\n",
"from xclim.core.calendar import select_time \n",
"from xclim.core.calendar import select_time\n",
"\n",
"import icclim\n",
"from icclim.frequency import FrequencyRegistry\n",
"\n",
"print(\"python: \", sys.version)\n",
Expand All @@ -68,7 +68,7 @@
"print(\"pandas: \", pd.__version__)\n",
"print(\"icclim: \", icclim.__version__)\n",
"print(\"cftime: \", cftime.__version__)\n",
"print(\"xclim: \", xclim.__version__)\n"
"print(\"xclim: \", xclim.__version__)"
]
},
{
Expand Down Expand Up @@ -664,7 +664,9 @@
],
"source": [
"historical_tas = xr.open_mfdataset(historical_files).tas\n",
"filtered_tas = select_time(historical_tas, month=FrequencyRegistry.AMJJAS.indexer[\"month\"], drop=True)\n",
"filtered_tas = select_time(\n",
" historical_tas, month=FrequencyRegistry.AMJJAS.indexer[\"month\"], drop=True\n",
")\n",
"normal = filtered_tas.mean(dim=\"time\", keep_attrs=True)\n",
"normal"
]
Expand Down Expand Up @@ -1291,7 +1293,7 @@
"source": [
"icclim.dcsc.txnd(\n",
" in_files=studied_files[0:1],\n",
" normal = normal,\n",
" normal=normal,\n",
" var_name=\"tas\",\n",
" slice_mode=FrequencyRegistry.AMJJAS,\n",
" out_file=out_f,\n",
Expand Down
4 changes: 2 additions & 2 deletions doc/source/tutorials/notebooks/averaged_tas_anomaly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@
"import sys\n",
"from pathlib import Path\n",
"\n",
"import icclim\n",
"\n",
"# provides cftime axis in matplotlib\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"import icclim\n",
"\n",
"print(\"python: \", sys.version)\n",
"print(\"numpy: \", np.__version__)\n",
"print(\"xarray: \", xr.__version__)\n",
Expand Down
6 changes: 3 additions & 3 deletions doc/source/tutorials/notebooks/cold_spell_duration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@
"# CDS API\n",
"import cdsapi\n",
"\n",
"# icclim package for calculating climate indices\n",
"import icclim\n",
"\n",
"# Libraries for plotting and visualising data\n",
"import matplotlib.pyplot as plt\n",
"\n",
Expand All @@ -346,6 +343,9 @@
"import urllib3\n",
"import xarray as xr\n",
"\n",
"# icclim package for calculating climate indices\n",
"import icclim\n",
"\n",
"# To add specific units spelling\n",
"\n",
"urllib3.disable_warnings()\n",
Expand Down
3 changes: 2 additions & 1 deletion doc/source/tutorials/notebooks/custom_freezing_tas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@
"\n",
"import cartopy.crs as ccrs\n",
"import cftime\n",
"import icclim\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"import icclim\n",
"\n",
"print(\"python: \", sys.version)\n",
"print(\"numpy: \", np.__version__)\n",
"print(\"xarray: \", xr.__version__)\n",
Expand Down
3 changes: 2 additions & 1 deletion doc/source/tutorials/notebooks/deltaT_deltaP_anomaly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@
"from pathlib import Path\n",
"\n",
"import cftime\n",
"import icclim\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"import icclim\n",
"\n",
"print(\"python: \", sys.version)\n",
"print(\"numpy: \", np.__version__)\n",
"print(\"xarray: \", xr.__version__)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@
"\n",
"import cartopy.crs as ccrs\n",
"import cftime\n",
"import icclim\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"import icclim\n",
"\n",
"print(\"python: \", sys.version)\n",
"print(\"numpy: \", np.__version__)\n",
"print(\"xarray: \", xr.__version__)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@
"import cartopy.crs as ccrs\n",
"import cftime\n",
"import dask\n",
"import icclim\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"import icclim\n",
"\n",
"print(\"python: \", sys.version)\n",
"print(\"numpy: \", np.__version__)\n",
"print(\"pandas: \", pd.__version__)\n",
Expand Down
1 change: 1 addition & 0 deletions tests/test_cf_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd
import pytest
import xarray as xr

from icclim._core.model.cf_calendar import CfCalendarRegistry
from icclim.exception import InvalidIcclimArgumentError

Expand Down
1 change: 0 additions & 1 deletion tests/test_dcsc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from icclim.dcsc import txnd

from tests.testing_utils import stub_tas


Expand Down
1 change: 1 addition & 0 deletions tests/test_ecad_indices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pytest

from icclim._core.model.standard_index import StandardIndex
from icclim.ecad.registry import EcadIndexRegistry
from icclim.exception import InvalidIcclimArgumentError
Expand Down
2 changes: 1 addition & 1 deletion tests/test_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import numpy as np
import pandas as pd
import pytest

from icclim.exception import InvalidIcclimArgumentError
from icclim.frequency import FrequencyRegistry, get_seasonal_time_updater

from tests.testing_utils import stub_tas


Expand Down
20 changes: 10 additions & 10 deletions tests/test_generated_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch

import icclim
import numpy as np
import pytest

import icclim
from icclim._core.constants import QUANTILE_BASED, REFERENCE_PERIOD_INDEX
from icclim._core.legacy.user_index.calc_operation import (
CalcOperation,
Expand All @@ -20,7 +21,6 @@
from icclim.generic.registry import GenericIndicatorRegistry
from icclim.logger import VerbosityRegistry
from icclim.threshold.factory import build_threshold

from tests.testing_utils import stub_tas

if TYPE_CHECKING:
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_txx__season_slice_mode() -> None:
res = icclim.txx(tas, slice_mode=["season", [11, 12, 1, 2]]).compute()
# THEN
# missing values for nov, dec of first period
np.testing.assert_array_equal(res.TXx.isel(time=0), np.NAN)
np.testing.assert_array_equal(res.TXx.isel(time=0), np.nan)
np.testing.assert_array_equal(res.TXx.isel(time=1), 30.0)
np.testing.assert_array_equal(
res.time_bounds.isel(time=0),
Expand All @@ -151,7 +151,7 @@ def test_txx__months_slice_mode() -> None:
tas.loc[{"time": "2042-01-01"}] = 303.15 # 30°C 273.15
res = icclim.txx(tas, slice_mode=["months", [11, 1]]).compute()
np.testing.assert_array_equal(res.TXx.isel(time=0), 30)
np.testing.assert_array_equal(res.TXx.isel(time=1), np.NAN)
np.testing.assert_array_equal(res.TXx.isel(time=1), np.nan)
np.testing.assert_almost_equal(res.TXx.sel(time="2042-11"), 21.85)
np.testing.assert_array_equal(
res.time_bounds.isel(time=0),
Expand Down Expand Up @@ -192,8 +192,8 @@ def test_custom_index__season_slice_mode(
},
).compute()
# missing values algo applied for first and last years
np.testing.assert_almost_equal(res.pouet.isel(time=0), np.NAN)
np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.NAN)
np.testing.assert_almost_equal(res.pouet.isel(time=0), np.nan)
np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.nan)
np.testing.assert_almost_equal(res.pouet.isel(time=1), expectation_year_1)
np.testing.assert_almost_equal(res.pouet.isel(time=2), expectation_year_2)

Expand Down Expand Up @@ -225,8 +225,8 @@ def test_custom_index_run_algos__season_slice_mode(
},
)
# missing values algo applied for first and last years
np.testing.assert_almost_equal(res.pouet.isel(time=0), np.NAN)
np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.NAN)
np.testing.assert_almost_equal(res.pouet.isel(time=0), np.nan)
np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.nan)
np.testing.assert_almost_equal(res.pouet.isel(time=1), expectation_year_1)
np.testing.assert_almost_equal(res.pouet.isel(time=2), expectation_year_2)

Expand Down Expand Up @@ -280,12 +280,12 @@ def test_custom_index_anomaly__datetime_ref_period() -> None:
},
).compute()
# missing values algo applied for first and last years
np.testing.assert_almost_equal(res.anomaly.sel(time="2041"), np.NAN)
np.testing.assert_almost_equal(res.anomaly.sel(time="2041"), np.nan)
np.testing.assert_almost_equal(res.anomaly.sel(time="2042"), 0)
np.testing.assert_almost_equal(res.anomaly.sel(time="2043"), 0)
np.testing.assert_almost_equal(res.anomaly.sel(time="2044"), 4.80645161)
np.testing.assert_almost_equal(res.anomaly.sel(time="2045"), 0)
np.testing.assert_almost_equal(res.anomaly.sel(time="2046"), np.NAN)
np.testing.assert_almost_equal(res.anomaly.sel(time="2046"), np.nan)


def test_custom_index_anomaly__groupby_and_resample_month() -> None:
Expand Down
1 change: 0 additions & 1 deletion tests/test_generic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from icclim._core.model.standard_variable import StandardVariableRegistry
from icclim.frequency import FrequencyRegistry
from icclim.threshold.factory import build_threshold

from tests.testing_utils import stub_tas


Expand Down
1 change: 1 addition & 0 deletions tests/test_index_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pytest

from icclim._core.model.index_group import IndexGroupRegistry
from icclim.exception import InvalidIcclimArgumentError

Expand Down
1 change: 1 addition & 0 deletions tests/test_input_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
import pytest
import xarray as xr

from icclim._core.constants import UNITS_KEY
from icclim._core.input_parsing import (
PercentileDataArray,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
from unittest.mock import MagicMock, patch

import cftime
import icclim
import numpy as np
import pandas as pd
import pint
import pytest
import xarray as xr

import icclim
from icclim import __version__ as icclim_version
from icclim._core.constants import PART_OF_A_WHOLE_UNIT, REFERENCE_PERIOD_ID, UNITS_KEY
from icclim._core.model.index_group import IndexGroupRegistry
from icclim.ecad.registry import EcadIndexRegistry
from icclim.exception import InvalidIcclimArgumentError
from icclim.frequency import FrequencyRegistry
from icclim.threshold.factory import build_threshold

from tests.testing_utils import K2C, stub_pr, stub_tas


Expand All @@ -38,7 +38,7 @@ def test_deprecated_indice(log_mock: MagicMock, index_mock: MagicMock) -> None:
HEAT_INDICES = ["SU", "TR", "WSDI", "TG90p", "TN90p", "TX90p", "TXx", "TNx", "CSU"]


@pytest.mark.slow()
@pytest.mark.slow
class TestIntegration:
"""
Integration tests.
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_index_su__djf_cf_time(self) -> None:
out_file=self.OUTPUT_FILE,
slice_mode=FrequencyRegistry.DJF,
)
np.testing.assert_array_equal(res.SU.isel(time=0), np.NAN)
np.testing.assert_array_equal(res.SU.isel(time=0), np.nan)
np.testing.assert_array_equal(res.SU.isel(time=1), 0)
# "+ 1" because DJF sampling create a december month with nans before first year
np.testing.assert_array_equal(
Expand Down
1 change: 1 addition & 0 deletions tests/test_rechunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas as pd
import pytest
import xarray as xr

from icclim import create_optimized_zarr_store
from icclim._core.constants import UNITS_KEY
from icclim.exception import InvalidIcclimArgumentError
Expand Down
5 changes: 3 additions & 2 deletions tests/test_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import pint
import pytest
import xarray as xr
from xclim.core.calendar import percentile_doy
from xclim.core.units import units as xc_units

from icclim._core.constants import UNITS_KEY
from icclim._core.generic.threshold.basic import BasicThreshold
from icclim._core.generic.threshold.bounded import BoundedThreshold
Expand All @@ -18,8 +21,6 @@
from icclim._core.model.operator import OperatorRegistry
from icclim.exception import InvalidIcclimArgumentError
from icclim.threshold.factory import build_threshold
from xclim.core.calendar import percentile_doy
from xclim.core.units import units as xc_units


def test_value_error() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_user_index.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

from xclim.core.calendar import build_climatology_bounds

import icclim
from icclim._core.constants import (
UNITS_KEY,
USER_INDEX_PRECIPITATION_STAMP,
USER_INDEX_TEMPERATURE_STAMP,
)
from icclim._core.model.operator import OperatorRegistry
from xclim.core.calendar import build_climatology_bounds

from tests.testing_utils import stub_tas


Expand Down
1 change: 1 addition & 0 deletions tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pandas as pd
import xarray as xr

from icclim._core.constants import UNITS_KEY

VALUE_COUNT = 365 * 5 + 1 # 5 years of data (with 1 leap year)
Expand Down
Loading

0 comments on commit 60133f4

Please sign in to comment.