Skip to content

Commit 79b0231

Browse files
committed
autofix by pre-commit
1 parent 2a9dff9 commit 79b0231

23 files changed

+53
-73
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,3 @@ dmypy.json
227227

228228
# Cython debug symbols
229229
cython_debug/
230-

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

ciftools/binary/data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, List, Optional, Union
22

33
import numpy as np
4+
45
from ciftools.binary.decoder import decode_cif_data
56
from ciftools.binary.encoded_data import EncodedCIFCategory, EncodedCIFColumn, EncodedCIFFile
67
from ciftools.models.data import CIFCategory, CIFColumn, CIFDataBlock, CIFFile, CIFValuePresenceEnum

ciftools/binary/decoder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
23
from ciftools.binary.data_types import DataType
34
from ciftools.binary.encoded_data import EncodedCIFData
45
from ciftools.binary.encoding_types import (

ciftools/binary/encoded_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional, TypedDict, Union
22

33
import numpy as np
4+
45
from ciftools.binary.encoding_types import EncodingBase
56

67

ciftools/binary/encoder.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import math
22
import sys
3-
from typing import Any, Dict, List, Protocol, Tuple, Union
3+
from typing import Any, List, Protocol, Tuple, Union
44

55
import numpy as np
6+
from numba import jit
7+
68
from ciftools.binary.data_types import DataType, DataTypeEnum
79
from ciftools.binary.encoded_data import EncodedCIFData
810
from ciftools.binary.encoding_types import (
@@ -15,12 +17,10 @@
1517
RunLengthEncoding,
1618
StringArrayEncoding,
1719
)
18-
from numba import jit
1920

2021

2122
class BinaryCIFEncoder(Protocol):
22-
def encode(self, data: Any) -> EncodedCIFData:
23-
...
23+
def encode(self, data: Any) -> EncodedCIFData: ...
2424

2525

2626
class ComposeEncoders(BinaryCIFEncoder):
@@ -109,7 +109,6 @@ def encode(self, data: np.ndarray, *args, **kwargs) -> EncodedCIFData:
109109

110110
class IntegerPacking(BinaryCIFEncoder):
111111
def encode(self, data: np.ndarray) -> EncodedCIFData:
112-
113112
# TODO: must be 32bit integer?
114113
packing = _determine_packing(data)
115114
if packing.bytesPerElement == 4:
@@ -325,8 +324,8 @@ def _pack_strings(data: List[str]) -> Tuple[str, np.ndarray, np.ndarray]:
325324
str_map = {s: i for i, s in enumerate(strings)}
326325
string_data = "".join(strings)
327326

328-
indices = np.array([str_map[s] for s in data], dtype='<i4')
329-
offset_data = np.empty(len(strings) + 1, dtype='<i4')
327+
indices = np.array([str_map[s] for s in data], dtype="<i4")
328+
offset_data = np.empty(len(strings) + 1, dtype="<i4")
330329
offset_data[0] = 0
331330
np.cumsum([len(s) for s in strings], out=offset_data[1:])
332331

ciftools/binary/writer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import msgpack
44
import numpy as np
5+
56
from ciftools.binary.encoded_data import (
67
EncodedCIFCategory,
78
EncodedCIFColumn,
@@ -86,14 +87,14 @@ def _encode_field(field: CIFFieldDesc, data: List[_DataWrapper], total_count: in
8687
category_array = field.value_array and field.value_array(d)
8788
if category_array is not None:
8889
if len(category_array) != category.count:
89-
raise ValueError(f"provided values array must have the same length as the category count field")
90+
raise ValueError("provided values array must have the same length as the category count field")
9091

9192
array[offset : offset + category.count] = category_array # type: ignore
9293

9394
category_mask = field.presence_array and field.presence_array(d)
9495
if category_mask is not None:
9596
if len(category_mask) != category.count:
96-
raise ValueError(f"provided mask array must have the same length as the category count field")
97+
raise ValueError("provided mask array must have the same length as the category count field")
9798
mask[offset : offset + category.count] = category_mask
9899

99100
offset += category.count

ciftools/models/data.py

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@ class CIFValuePresenceEnum(IntEnum):
1111

1212

1313
class CIFColumn(Protocol):
14-
def get_string(self, row: int) -> Optional[str]:
15-
...
14+
def get_string(self, row: int) -> Optional[str]: ...
1615

17-
def get_integer(self, row: int) -> int:
18-
...
16+
def get_integer(self, row: int) -> int: ...
1917

20-
def get_float(self, row: int) -> float:
21-
...
18+
def get_float(self, row: int) -> float: ...
2219

23-
def get_value_presence(self, row: int) -> CIFValuePresenceEnum:
24-
...
20+
def get_value_presence(self, row: int) -> CIFValuePresenceEnum: ...
2521

26-
def are_values_equal(self, row_a: int, row_b: int) -> bool:
27-
...
22+
def are_values_equal(self, row_a: int, row_b: int) -> bool: ...
2823

29-
def string_equals(self, row: int, value: str) -> bool:
30-
...
24+
def string_equals(self, row: int, value: str) -> bool: ...
3125

3226
def as_ndarray(
3327
self, *, dtype: Optional[Union[np.dtype, str]] = None, start: Optional[int] = None, end: Optional[int] = None
@@ -40,11 +34,9 @@ def as_ndarray(
4034
"""
4135
...
4236

43-
def __getitem__(self, idx: Any) -> Any:
44-
...
37+
def __getitem__(self, idx: Any) -> Any: ...
4538

46-
def __len__(self) -> int:
47-
...
39+
def __len__(self) -> int: ...
4840

4941
@property
5042
def value_presences(self) -> Optional[np.ndarray]:
@@ -56,29 +48,23 @@ def value_presences(self) -> Optional[np.ndarray]:
5648

5749
class CIFCategory(Protocol):
5850
@property
59-
def name(self) -> str:
60-
...
51+
def name(self) -> str: ...
6152

6253
@property
63-
def n_rows(self) -> int:
64-
...
54+
def n_rows(self) -> int: ...
6555

6656
@property
67-
def n_columns(self) -> int:
68-
...
57+
def n_columns(self) -> int: ...
6958

7059
@property
71-
def field_names(self) -> List[str]:
72-
...
60+
def field_names(self) -> List[str]: ...
7361

7462
def __getattr__(self, name: str) -> CIFColumn:
7563
return self[name]
7664

77-
def __getitem__(self, name: str) -> CIFColumn:
78-
...
65+
def __getitem__(self, name: str) -> CIFColumn: ...
7966

80-
def __contains__(self, key: str) -> bool:
81-
...
67+
def __contains__(self, key: str) -> bool: ...
8268

8369
# Category Helpers
8470
def get_matrix(self, field: str, rows: int, cols: int, row_index: int) -> np.ndarray:
@@ -120,19 +106,15 @@ class CIFDataBlock(Protocol):
120106
def __getattr__(self, name: str) -> CIFCategory:
121107
return self[name]
122108

123-
def __getitem__(self, name: str) -> CIFCategory:
124-
...
109+
def __getitem__(self, name: str) -> CIFCategory: ...
125110

126-
def __contains__(self, key: str):
127-
...
111+
def __contains__(self, key: str): ...
128112

129113
@property
130-
def header(self) -> str:
131-
...
114+
def header(self) -> str: ...
132115

133116
@property
134-
def categories(self) -> Dict[str, CIFCategory]:
135-
...
117+
def categories(self) -> Dict[str, CIFCategory]: ...
136118

137119

138120
class CIFFile(Protocol):
@@ -145,12 +127,10 @@ def __getitem__(self, index_or_name: Union[int, str]) -> CIFDataBlock:
145127
def __getattr__(self, name: str) -> CIFDataBlock:
146128
return self[name]
147129

148-
def __len__(self) -> int:
149-
...
130+
def __len__(self) -> int: ...
150131

151132
def __contains__(self, key: str) -> bool:
152133
return key in self._block_map
153134

154135
@property
155-
def data_blocks(self) -> List[CIFDataBlock]:
156-
...
136+
def data_blocks(self) -> List[CIFDataBlock]: ...

ciftools/models/writer.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any, Callable, Collection, Generic, List, Optional, Protocol, TypeVar, Union
33

44
import numpy as np
5+
56
from ciftools.binary.encoder import BYTE_ARRAY, STRING_ARRAY, BinaryCIFEncoder
67
from ciftools.models.data import CIFValuePresenceEnum
78

@@ -87,24 +88,18 @@ def string_array(
8788

8889
class CIFCategoryDesc(Protocol):
8990
@property
90-
def name(self) -> str:
91-
...
91+
def name(self) -> str: ...
9292

9393
@staticmethod
94-
def get_row_count(data: Any) -> int:
95-
...
94+
def get_row_count(data: Any) -> int: ...
9695

9796
@staticmethod
98-
def get_field_descriptors(data: Any) -> Collection[CIFFieldDesc]:
99-
...
97+
def get_field_descriptors(data: Any) -> Collection[CIFFieldDesc]: ...
10098

10199

102100
class CIFWriter(Protocol):
103-
def start_data_block(self, header: str) -> None:
104-
...
101+
def start_data_block(self, header: str) -> None: ...
105102

106-
def write_category(self, category: CIFCategoryDesc, data: List[Any]) -> None:
107-
...
103+
def write_category(self, category: CIFCategoryDesc, data: List[Any]) -> None: ...
108104

109-
def encode(self) -> Union[str, bytes]:
110-
...
105+
def encode(self) -> Union[str, bytes]: ...

ciftools/serialization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import msgpack
2+
23
from ciftools.binary.data import BinaryCIFFile
34
from ciftools.binary.writer import BinaryCIFWriter
45
from ciftools.models.data import CIFFile

0 commit comments

Comments
 (0)