Skip to content
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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ name: CI Build
on:
push:
branches:
- main
# run pipeline on pull request
- main # run pipeline on pull request
pull_request:
# run pipeline on merge queue
merge_group:
# run this workflow manually from the Actions tab
workflow_dispatch:
merge_group: # run pipeline on merge queue
workflow_dispatch: # run this workflow manually from the Actions tab
inputs:
create_release:
type: boolean
Expand Down Expand Up @@ -87,7 +84,7 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
# To test, use the TestPyPI:
# repository-url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
# You must also create an account and project on TestPyPI,
# as well as set the trusted-publisher in the project settings:
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
Expand Down
13 changes: 7 additions & 6 deletions src/power_grid_model_ds/_core/model/arrays/base/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def build_array(*args: tuple[Any], dtype: np.dtype, defaults: dict[str, np.gener
return array

if isinstance(parsed_input, np.ndarray) and parsed_input.dtype.names:
_check_missing_columns(array.dtype.names, defaults, set(parsed_input.dtype.names))
_check_missing_columns(array.dtype.names or (), defaults, set(parsed_input.dtype.names))
return _parse_structured_array(parsed_input, array)
if isinstance(parsed_input, np.ndarray):
# Note: defaults are not supported when working with unstructured arrays
return _parse_array(parsed_input, array.dtype)

_check_missing_columns(array.dtype.names, defaults, set(parsed_input.keys()))
_check_missing_columns(array.dtype.names or (), defaults, set(parsed_input.keys()))
_fill_with_kwargs(array, parsed_input)
return array

Expand All @@ -54,7 +54,7 @@ def _parse_input(*args: Any, dtype: np.dtype, **kwargs):
return {}, 0


def _check_missing_columns(array_columns: tuple, defaults: dict[str, np.generic], provided_columns: set[str]):
def _check_missing_columns(array_columns: tuple[str, ...], defaults: dict[str, np.generic], provided_columns: set[str]):
required_columns = set(array_columns) - set(defaults.keys())
if missing_columns := required_columns - provided_columns:
raise ValueError(f"Missing required columns: {missing_columns}")
Expand All @@ -64,7 +64,8 @@ def _fill_defaults(array: np.ndarray, defaults: dict[str, np.generic]):
"""Fills the defaults into the array."""
for column, default in defaults.items():
if default is empty:
array[column] = empty(array.dtype[column]) # type: ignore[call-overload]
column_type: type = array.dtype[column]
array[column] = empty(column_type) # type: ignore[call-overload]
else:
array[column] = default # type: ignore[call-overload]

Expand All @@ -87,8 +88,8 @@ def _parse_structured_array(from_array: np.ndarray, to_array: np.ndarray) -> np.

def _determine_column_overlap(from_array: np.ndarray, to_array: np.ndarray) -> tuple[list[str], list[str]]:
"""Returns two lists: columns present in both arrays and the columns that are only present in from_array"""
from_columns = set(from_array.dtype.names)
to_columns = set(to_array.dtype.names)
from_columns = set(from_array.dtype.names or ())
to_columns = set(to_array.dtype.names or ())

return list(from_columns & to_columns), list(from_columns - to_columns)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_filter_mask(
"""Returns a mask that matches the input parameters."""
parsed_kwargs = _parse(args, kwargs)

if invalid_kwargs := set(parsed_kwargs.keys()) - set(array.dtype.names):
if invalid_kwargs := set(parsed_kwargs.keys()) - set(array.dtype.names or ()):
raise ValueError(f"Invalid kwargs: {invalid_kwargs}")

filter_mask = _initialize_filter_mask(mode_, array.size)
Expand Down
4 changes: 2 additions & 2 deletions src/power_grid_model_ds/_core/model/arrays/base/_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def re_order(array: np.ndarray, new_order: ArrayLike, column: str = "id") -> np.
"""Re-order an id-array by the id column so that it follows a new_order.
Expects the new_order input to contain the same values as self.id
"""
if column not in array.dtype.names:
if column not in (array.dtype.names or ()):
raise ValueError(f"Cannot re-order array: column {column} does not exist.")
if not np.array_equal(np.sort(array[column]), np.sort(new_order)):
raise ValueError(f"Cannot re-order array: mismatch between new_order and values in '{column}'-column.")
Expand Down Expand Up @@ -50,7 +50,7 @@ def update_by_id(array: np.ndarray, ids: ArrayLike, allow_missing: bool, **kwarg

def check_ids(array: np.ndarray, return_duplicates: bool = False) -> NDArray | None:
"""Check for duplicate ids within the array"""
if "id" not in array.dtype.names:
if "id" not in (array.dtype.names or ()):
raise AttributeError("Array has no 'id' column.")

unique, counts = np.unique(array["id"], return_counts=True)
Expand Down