Skip to content

Commit

Permalink
TypeError: unhashable type: 'numpy.ndarray' (#431)
Browse files Browse the repository at this point in the history
* Bug fixed. (#430)

* Type hint fixed. (#430)

* Bug fixed: unmatched types. (#430)
  • Loading branch information
ATATC authored Oct 3, 2024
1 parent a4b4453 commit e3daf5a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion leads/data_persistence/_computational/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
minimum: type[_np.min] = _np.min
maximum: type[_np.max] = _np.max
diff: type[_np.diff] = _np.diff
sum_up: type[_np.sum] = _np.sum

read_csv: type[_pandas.read_csv] = _pandas.read_csv
DataFrame: type[_pandas.DataFrame] = _pandas.DataFrame
Expand Down
13 changes: 8 additions & 5 deletions leads/data_persistence/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
from leads.types import Compressor as _Compressor, VisualHeader as _VisualHeader, \
VisualHeaderFull as _VisualHeaderFull, DefaultHeaderFull as _DefaultHeaderFull, DefaultHeader as _DefaultHeader
from ._computational import array as _array, norm as _norm, read_csv as _read_csv, DataFrame as _DataFrame, \
TextFileReader as _TextFileReader, sum_up as _sum_up, diff as _diff
TextFileReader as _TextFileReader, diff as _diff, ndarray as _ndarray

T = _TypeVar("T", bound=_SupportsFloat)


def weighed_sum(elements: _Sequence[T], indexes: _Sequence[float], a: int = 0, b: int | None = None) -> T:
return _sum_up(_array(elements[a: b]) * _diff(_array(indexes[a: b + 1]))) if b else (_sum_up(_array(
elements[a: -1]) * _diff(_array(indexes[a:]))) + elements[-1])
def weighed_sum(elements: tuple[T, ...], indexes: tuple[float, ...], a: int = 0, b: int | None = None) -> T:
e = _array(elements[a: b if b else -1])
w = _diff(_array(indexes[a: b + 1] if b else indexes[a:] + (1,)))
if len(e.shape) > 1:
w = w.reshape((-1, 1))
return Vector(*tuple(s)) if isinstance(s := (e * w).sum(0, keepdims=True)[0], _ndarray) else float(s)


def weighed_mean(elements: _Sequence[T], indexes: _Sequence[float], a: int = 0, b: int | None = None) -> T:
def weighed_mean(elements: tuple[T, ...], indexes: tuple[float, ...], a: int = 0, b: int | None = None) -> T:
return weighed_sum(elements, indexes, a, b) / (indexes[b] - indexes[a]) if b else weighed_sum(
elements, indexes, a, b) / (indexes[-1] - indexes[a] + 1)

Expand Down
2 changes: 1 addition & 1 deletion leads_vec_rc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

time_stamp_record: DataPersistence[int] = DataPersistence(2000)
speed_record: DataPersistence[float] = DataPersistence(2000)
acceleration_record: DataPersistence[float] = DataPersistence(2000)
acceleration_record: DataPersistence[Vector[float]] = DataPersistence(2000)
voltage_record: DataPersistence[float] = DataPersistence(2000)
gps_record: DataPersistence[Vector[float]] = DataPersistence(2000)
csv: CSV | None = None
Expand Down

0 comments on commit e3daf5a

Please sign in to comment.