Skip to content

Commit

Permalink
Some typing fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnmabus committed Jan 17, 2024
1 parent 4315d37 commit 09a1e76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
14 changes: 8 additions & 6 deletions rdata/parser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import numpy as np
import numpy.typing as npt

R_INT_NA = -2**31 # noqa: WPS432
"""Value used to represent a missing integer in R."""
#: Value used to represent a missing integer in R.
R_INT_NA: Final = -2**31 # noqa: WPS432


@runtime_checkable
Expand Down Expand Up @@ -530,7 +530,7 @@ def __init__(

def _parse_array(
self,
dtype: np.dtype,
dtype: npt.DTypeLike,
) -> npt.NDArray[Any]:
"""Parse an array composed of an integer (array size) and values."""
length = self.parse_int()
Expand All @@ -539,7 +539,7 @@ def _parse_array(
@abc.abstractmethod
def _parse_array_values(
self,
dtype: np.dtype,
dtype: npt.DTypeLike,
length: int,
) -> npt.NDArray[Any]:
"""Parse values of an array."""
Expand Down Expand Up @@ -1034,7 +1034,8 @@ def parse_file(
tag=False,
gp=0,
reference=0),
value=RObject(info=RObjectInfo(type=<RObjectType.CHAR: 9>,
value=RObject(info=RObjectInfo(\
type=<RObjectType.CHAR: 9>,
object=False,
attributes=False,
tag=False,
Expand Down Expand Up @@ -1149,7 +1150,8 @@ def parse_data(
tag=False,
gp=0,
reference=0),
value=RObject(info=RObjectInfo(type=<RObjectType.CHAR: 9>,
value=RObject(info=RObjectInfo(\
type=<RObjectType.CHAR: 9>,
object=False,
attributes=False,
tag=False,
Expand Down
20 changes: 8 additions & 12 deletions rdata/parser/_xdr.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
from __future__ import annotations

import io
from typing import Any

import numpy as np
import numpy.typing as npt

from typing import (
Any,
)

from ._parser import (
AltRepConstructorMap,
DEFAULT_ALTREP_MAP,
Parser,
RData,
)
from ._parser import DEFAULT_ALTREP_MAP, AltRepConstructorMap, Parser, RData


class ParserXDR(Parser):
Expand All @@ -34,13 +27,16 @@ def __init__(

def _parse_array_values(
self,
dtype: np.dtype,
dtype: npt.DTypeLike,
length: int,
) -> npt.NDArray[Any]:
dtype = np.dtype(dtype)
buffer = self.file.read(length * dtype.itemsize)
# Read in big-endian order and convert to native byte order
return np.frombuffer(buffer, dtype=dtype.newbyteorder('>')).astype(dtype, copy=False)
return np.frombuffer(
buffer,
dtype=dtype.newbyteorder('>'),
).astype(dtype, copy=False)

def parse_string(self, length: int) -> bytes:
return self.file.read(length)
Expand Down

0 comments on commit 09a1e76

Please sign in to comment.