Skip to content

Commit 35ee11b

Browse files
author
Thomas Zilio
committed
feat: Updating pre-commit hooks and fixing errors.
Refs: #13
1 parent c6c2f0c commit 35ee11b

File tree

6 files changed

+48
-41
lines changed

6 files changed

+48
-41
lines changed

.pre-commit-config.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-case-conflict
66
- id: check-docstring-first
@@ -15,16 +15,16 @@ repos:
1515
- id: trailing-whitespace
1616
exclude: conda/meta.yaml
1717
- repo: https://github.com/asottile/pyupgrade
18-
rev: "v3.17.0"
18+
rev: "v3.19.1"
1919
hooks:
2020
- id: pyupgrade
2121
args: [--py310-plus]
2222
- repo: https://github.com/PyCQA/isort
23-
rev: 5.13.2
23+
rev: 6.0.1
2424
hooks:
2525
- id: isort
2626
- repo: https://github.com/PyCQA/flake8
27-
rev: 7.1.1
27+
rev: 7.1.2
2828
hooks:
2929
- id: flake8
3030
exclude: tests
@@ -47,11 +47,11 @@ repos:
4747
hooks:
4848
- id: docformatter
4949
- repo: https://github.com/codespell-project/codespell
50-
rev: "v2.3.0"
50+
rev: "v2.4.1"
5151
hooks:
5252
- id: codespell
5353
- repo: https://github.com/pre-commit/mirrors-mypy
54-
rev: v1.11.2
54+
rev: v1.15.0
5555
hooks:
5656
- id: mypy
5757
exclude: docs

conda/meta.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ requirements:
2323
- numpy >=1.20
2424
- python
2525
- xarray
26-
- zarr
26+
- zarr < 3
2727
test:
2828
requires:
2929
- pytest

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ install_requires =
3333
numpy>=1.20
3434
pandas
3535
xarray
36-
zarr>=2.11
36+
zarr>=2.11,<3
3737
package_dir =
3838
= .
3939
packages = find:

zcollection/merging/period.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
from __future__ import annotations
1010

11-
from typing import Any
11+
from typing import Any, Final, Literal
1212
from collections.abc import Callable
1313
import enum
1414
import re
@@ -23,8 +23,8 @@
2323
r'(?:datetime|timedelta)64\[(\w+)\]').search
2424

2525
#: Numpy time units
26-
RESOLUTION = ('as', 'fs', 'ps', 'ns', 'us', 'ms', 's', 'm', 'h', 'D', 'W', 'M',
27-
'Y')
26+
RESOLUTION: Final = ('as', 'fs', 'ps', 'ns', 'us', 'ms', 's', 'm', 'h', 'D',
27+
'W', 'M', 'Y')
2828

2929

3030
def _time64_unit(dtype: DType[Any]) -> str:
@@ -35,7 +35,10 @@ def _time64_unit(dtype: DType[Any]) -> str:
3535
return match.group(1)
3636

3737

38-
def _min_time64_unit(*args: DType[Any]) -> str:
38+
def _min_time64_unit(
39+
*args: DType[Any]
40+
) -> Literal['as', 'fs', 'ps', 'ns', 'us', 'ms', 's', 'm', 'h', 'D', 'W', 'M',
41+
'Y']:
3942
"""Get the minimum unit of time."""
4043
index = min(RESOLUTION.index(_time64_unit(item)) for item in args)
4144
return RESOLUTION[index]
@@ -212,7 +215,7 @@ def __init__(self,
212215
end: numpy.datetime64,
213216
*,
214217
within: bool = False) -> None:
215-
duration_unit: str = _min_time64_unit(begin.dtype, end.dtype)
218+
duration_unit = _min_time64_unit(begin.dtype, end.dtype)
216219

217220
#: The beginning of the period.
218221
self._begin: numpy.datetime64 = begin

zcollection/partitioning/tests/test_date.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
from __future__ import annotations
1010

11+
from typing import Literal
1112
import dataclasses
1213
import pickle
1314
import random
@@ -84,29 +85,30 @@ def test_split_dataset(
8485
delayed: bool,
8586
) -> None:
8687
"""Test the split_dataset method."""
87-
for end_date, indices, resolution in [
88-
(
89-
numpy.datetime64('2001-12-31', 'Y'),
90-
slice(0, 1),
91-
'Y',
92-
),
93-
(
94-
numpy.datetime64('2000-12-31', 'M'),
95-
slice(0, 2),
96-
'M',
97-
),
98-
(
99-
numpy.datetime64('2000-12-31', 'D'),
100-
slice(0, 3),
101-
'D',
102-
),
103-
(
104-
numpy.datetime64('2000-01-31', 'h'),
105-
slice(0, 4),
106-
'h',
107-
),
108-
]:
109-
88+
splits: list[tuple[numpy.datetime64, slice,
89+
Literal['Y', 'M', 'D', 'h']]] = [
90+
(
91+
numpy.datetime64('2001-12-31', 'Y'),
92+
slice(0, 1),
93+
'Y',
94+
),
95+
(
96+
numpy.datetime64('2000-12-31', 'M'),
97+
slice(0, 2),
98+
'M',
99+
),
100+
(
101+
numpy.datetime64('2000-12-31', 'D'),
102+
slice(0, 3),
103+
'D',
104+
),
105+
(
106+
numpy.datetime64('2000-01-31', 'h'),
107+
slice(0, 4),
108+
'h',
109+
),
110+
]
111+
for end_date, indices, resolution in splits:
110112
# Time delta between two partitions
111113
timedelta = numpy.timedelta64(1, resolution)
112114

@@ -128,7 +130,7 @@ def test_split_dataset(
128130
assert len(partitioning) == len(range(indices.start, indices.stop))
129131

130132
# Date of the current partition
131-
date = numpy.datetime64(START_DATE, resolution)
133+
date = START_DATE.astype(f'datetime64[{resolution}]')
132134

133135
# Build the test dataset
134136
zds = dataset.Dataset.from_xarray(xds)

zcollection/tests/test_expression.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import timeit
1212

1313
import numpy
14+
import numpy as np
1415
import pytest
1516
import xarray
1617

@@ -25,11 +26,12 @@
2526

2627
def make_dataset(num_samples: int | None = None) -> dataset.Dataset:
2728
"""Creation of a data set for testing purposes."""
28-
dates = numpy.arange(numpy.datetime64('2000-01-01', 'ns'),
29-
numpy.datetime64('2009-12-31', 'ns'),
30-
numpy.timedelta64(1, 'h')).astype('datetime64[ns]')
29+
dates: np.ndarray = numpy.arange(numpy.datetime64('2000-01-01', 'ns'),
30+
numpy.datetime64('2009-12-31', 'ns'),
31+
numpy.timedelta64(
32+
1, 'h')).astype('datetime64[ns]')
3133
if num_samples is not None:
32-
dates = dates[:num_samples + 1]
34+
dates = dates[0:num_samples + 1]
3335
observation = numpy.random.rand(dates.size) # type: ignore
3436
return dataset.Dataset.from_xarray(
3537
xarray.Dataset({

0 commit comments

Comments
 (0)