Skip to content

Commit

Permalink
Merge branch 'feature/columnar-data-docs' of https://github.com/Power…
Browse files Browse the repository at this point in the history
…GridModel/power-grid-model into feature/columnar-data-docs
  • Loading branch information
mgovers committed Oct 15, 2024
2 parents dfc692c + 4bb4bdf commit 6b66f4f
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
xcode-version: latest-stable

- name: Build wheels
uses: pypa/cibuildwheel@v2.21.2
uses: pypa/cibuildwheel@v2.21.3
# GitHub Actions specific build parameters
env:
# pass GitHub runner info into Linux container
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ PYPI_VERSION
# docs builds
docs/make.bat
docs/Makefile
docs/jupyter_execute/

# VSCode configurations
# it is ignored by default so the user does not accidentally change the configuration
Expand Down
5 changes: 5 additions & 0 deletions src/power_grid_model/core/buffer_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Power grid model buffer handler
"""

import warnings
from dataclasses import dataclass
from typing import cast

Expand Down Expand Up @@ -83,6 +84,8 @@ def _get_raw_data_view(data: np.ndarray, dtype: np.dtype) -> VoidPtr:
Returns:
a raw view on the data set.
"""
if data.dtype != dtype:
warnings.warn("Data type does not match schema. {VALIDATOR_MSG}", DeprecationWarning)
return np.ascontiguousarray(data, dtype=dtype).ctypes.data_as(VoidPtr)


Expand Down Expand Up @@ -115,6 +118,8 @@ def _get_raw_attribute_data_view(data: np.ndarray, schema: ComponentMetaData, at
Returns:
a raw view on the data set.
"""
if schema.dtype[attribute].shape == (3,) and data.shape[-1] != 3:
raise ValueError("Given data has a different schema than supported.")
return _get_raw_data_view(data, dtype=schema.dtype[attribute].base)


Expand Down
2 changes: 1 addition & 1 deletion src/power_grid_model/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- A set of :class:`ComponentType` or `str`
- A list of :class:`ComponentType`
- A list of :class:`ComponentType` or `str`
- A :class:`ComponentAttributeFilterOptions <power_grid_model.enum.ComponentAttributeFilterOptions>` value
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test_data_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
#
# SPDX-License-Identifier: MPL-2.0

import warnings

import numpy as np
import pytest

from power_grid_model._utils import is_columnar
from power_grid_model.core.data_handling import create_output_data
from power_grid_model.core.dataset_definitions import ComponentType as CT, DatasetType as DT
from power_grid_model.core.power_grid_core import VoidPtr
from power_grid_model.core.power_grid_dataset import CMutableDataset
from power_grid_model.core.power_grid_meta import initialize_array


Expand Down Expand Up @@ -69,3 +73,35 @@ def test_create_output_data(output_component_types, is_batch, expected):
else:
assert actual[comp].keys() == expected[comp].keys()
assert all(actual[comp][attr].dtype == expected[comp][attr].dtype for attr in expected[comp])


def test_dtype_compatibility_check_normal():
nodes = initialize_array(DT.sym_output, CT.node, (1, 2))
nodes_ptr = nodes.ctypes.data_as(VoidPtr)

data = {CT.node: nodes}
mutable_dataset = CMutableDataset(data, DT.sym_output)
buffer_views = mutable_dataset.get_buffer_views()

assert buffer_views[0].data.value == nodes_ptr.value


def test_dtype_compatibility_check_compatible():
nodes = initialize_array(DT.sym_output, CT.node, 4)
nodes = nodes[::2]
nodes_ptr = nodes.ctypes.data_as(VoidPtr)

data = {CT.node: nodes}
with warnings.catch_warnings():
warnings.simplefilter("error")
mutable_dataset = CMutableDataset(data, DT.sym_output)
buffer_views = mutable_dataset.get_buffer_views()

assert buffer_views[0].data.value != nodes_ptr.value


def test_dtype_compatibility_check__error():
nodes = initialize_array(DT.sym_output, CT.node, (1, 2))
data = {CT.node: nodes.astype(nodes.dtype.newbyteorder("S"))}
with pytest.warns(DeprecationWarning):
CMutableDataset(data, DT.sym_output)
Loading

0 comments on commit 6b66f4f

Please sign in to comment.