Skip to content

Fix bug with floating subdtypes #36

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

Merged
merged 1 commit into from
Feb 7, 2025
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
2 changes: 1 addition & 1 deletion src/power_grid_model_ds/_core/model/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def empty(dtype: type):
return ""
if np.issubdtype(dtype, np.dtype("bool")):
return False
if np.issubdtype(dtype, np.float64):
if np.issubdtype(dtype, np.floating):
return np.nan
try:
return np.iinfo(dtype).min
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/model/arrays/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class ChildArray(DefaultedFancyTestArray):
test_float4: NDArray[np.float64]


class SizedDTypesArray(FancyArray):
test_float16: NDArray[np.float16]
test_float32: NDArray[np.float32]
test_float64: NDArray[np.float64]

test_int8: NDArray[np.int8]
test_int16: NDArray[np.int16]
test_int32: NDArray[np.int32]
test_int64: NDArray[np.int64]


def test_build_without_array_definition():
with pytest.raises(ArrayDefinitionError):
FancyArray()
Expand Down Expand Up @@ -166,6 +177,19 @@ def test_empty():
assert_array_equal([min_int64] * 3, array.test_int)


def test_empty_with_sized_dtypes():
array = SizedDTypesArray.empty(1)

assert_array_equal([np.iinfo(np.int8).min], array.test_int8)
assert_array_equal([np.iinfo(np.int16).min], array.test_int16)
assert_array_equal([np.iinfo(np.int32).min], array.test_int32)
assert_array_equal([np.iinfo(np.int64).min], array.test_int64)

assert_array_equal([np.nan], array.test_float16)
assert_array_equal([np.nan], array.test_float32)
assert_array_equal([np.nan], array.test_float64)


def test_empty_with_defaults():
array = DefaultedFancyTestArray.empty(3)
assert 3 == array.size
Expand Down