File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
src/power_grid_model_ds/_core/model/arrays/base Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -323,3 +323,13 @@ def as_df(self: Self):
323323 if pandas is None :
324324 raise ImportError ("pandas is not installed" )
325325 return pandas .DataFrame (self ._data )
326+
327+ @classmethod
328+ def from_extended (cls : Type [Self ], extended : Self ) -> Self :
329+ """Create an instance from an extended array."""
330+ if not isinstance (extended , cls ):
331+ raise TypeError (f"Extended array must be of type { cls .__name__ } , got { type (extended ).__name__ } " )
332+ new_array = cls .zeros (len (extended ), empty_id = False )
333+ for column in cls .get_dtype ().names :
334+ new_array [column ] = extended [column ]
335+ return new_array
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ class DifferentFancyTestArray(FancyArray):
3636 test_bool2 : NDArray [np .bool_ ]
3737
3838
39+ class ExtendedFancyTestArray (FancyTestArray ):
40+ """Test array with some extended attributes"""
41+
42+ test_int2 : NDArray [np .int64 ]
43+ test_float2 : NDArray [np .float64 ]
44+ test_str2 : NDArray [np .str_ ]
45+ test_bool2 : NDArray [np .bool_ ]
46+
47+
3948class LongColumnNameFancyTestArray (FancyArray ):
4049 """Test array with a very long column name"""
4150
Original file line number Diff line number Diff line change 1414from power_grid_model_ds ._core .model .arrays .pgm_arrays import TransformerArray
1515from power_grid_model_ds ._core .model .constants import EMPTY_ID , empty
1616from tests .conftest import FancyTestArray
17- from tests .fixtures .arrays import FancyTestArray3
17+ from tests .fixtures .arrays import ExtendedFancyTestArray , FancyTestArray3
1818
1919# pylint: disable=missing-function-docstring
2020
@@ -289,3 +289,10 @@ def test_overflow_value():
289289 with pytest .raises (OverflowError ):
290290 transformer .tap_min = - 167
291291 assert transformer .tap_min == - 128
292+
293+
294+ def test_from_extended_array ():
295+ extended_array = ExtendedFancyTestArray .zeros (2 )
296+ array = FancyTestArray .from_extended (extended_array )
297+ assert not isinstance (array , ExtendedFancyTestArray )
298+ assert_array_equal (array .data , extended_array [array .columns ])
You can’t perform that action at this time.
0 commit comments