Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ArrayLike data in to_xarray #825

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dianna/utils/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import inspect
import warnings
from pathlib import Path
import numpy as np
import numpy.typing


def get_function(model_or_function, preprocess_function=None):
Expand Down Expand Up @@ -49,7 +51,7 @@ def get_kwargs_applicable_to_function(function, kwargs):
}


def to_xarray(data, axis_labels, required_labels=None):
def to_xarray(data: numpy.typing.ArrayLike, axis_labels, required_labels=None):
"""Converts numpy data and axes labels to an xarray object."""
if isinstance(axis_labels, dict):
# key = axis index, value = label
Expand All @@ -59,10 +61,10 @@ def to_xarray(data, axis_labels, required_labels=None):
indices = list(axis_labels.keys())
for index in indices:
if index < 0:
axis_labels[data.ndim + index] = axis_labels.pop(index)
axis_labels[np.ndim(data) + index] = axis_labels.pop(index)
labels = [
axis_labels[index] if index in axis_labels else f'dim_{index}'
for index in range(data.ndim)
for index in range(np.ndim(data))
]
else:
labels = list(axis_labels)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install_requires =
ipython
lime
matplotlib
numpy
numpy>=1.20
onnx==1.14.1
onnx_tf
onnxruntime
Expand Down
Loading