Skip to content

Commit 65434f0

Browse files
committed
merge main
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent f2aabd6 commit 65434f0

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uv build
6363
6464
- name: Store built wheel file
65-
uses: actions/upload-artifact@v4
65+
uses: actions/upload-artifact@v5
6666
with:
6767
name: power-grid-model-ds
6868
path: dist/
@@ -91,7 +91,7 @@ jobs:
9191
run: uv tool install poethepoet
9292

9393
- name: Load built wheel file
94-
uses: actions/download-artifact@v4
94+
uses: actions/download-artifact@v6
9595
with:
9696
name: power-grid-model-ds
9797
path: dist/
@@ -117,7 +117,7 @@ jobs:
117117
uses: actions/checkout@v5
118118

119119
- name: Load built wheel file
120-
uses: actions/download-artifact@v4
120+
uses: actions/download-artifact@v6
121121
with:
122122
name: power-grid-model-ds
123123
path: dist/

src/power_grid_model_ds/_core/model/arrays/base/array.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class FancyArray(ABC):
5959
_defaults: dict[str, Any] = {}
6060
_str_lengths: dict[str, int] = {}
6161

62-
def __init__(self: Self, *args, data: NDArray | None = None, **kwargs):
62+
def __init__(self, *args, data: NDArray | None = None, **kwargs):
6363
if data is None:
6464
self._data = build_array(*args, dtype=self.get_dtype(), defaults=self.get_defaults(), **kwargs)
6565
else:
6666
self._data = data
6767

6868
@property
69-
def data(self: Self) -> NDArray:
69+
def data(self) -> NDArray:
7070
return self._data
7171

7272
@classmethod
@@ -110,7 +110,7 @@ def get_dtype(cls):
110110
dtype_list.append((name, dtype))
111111
return np.dtype(dtype_list)
112112

113-
def __repr__(self: Self) -> str:
113+
def __repr__(self) -> str:
114114
try:
115115
data = getattr(self, "data")
116116
if data.size > 3:
@@ -125,7 +125,7 @@ def __str__(self) -> str:
125125
def __len__(self) -> int:
126126
return len(self._data)
127127

128-
def __iter__(self: Self):
128+
def __iter__(self):
129129
for record in self._data:
130130
yield self.__class__(data=np.array([record]))
131131

@@ -190,16 +190,18 @@ def __contains__(self: Self, item: Self) -> bool:
190190
return item.data in self._data
191191
return False
192192

193-
def __hash__(self: Self):
193+
def __hash__(self):
194194
return hash(f"{self.__class__} {self}")
195195

196-
def __eq__(self: Self, other):
197-
return self._data.__eq__(other.data)
196+
def __eq__(self, other):
197+
if not isinstance(other, self.__class__):
198+
return False
199+
return self.data.__eq__(other.data)
198200

199-
def __copy__(self: Self):
201+
def __copy__(self):
200202
return self.__class__(data=copy(self._data))
201203

202-
def copy(self: Self):
204+
def copy(self):
203205
"""Return a copy of this array including its data"""
204206
return copy(self)
205207

@@ -294,15 +296,15 @@ def get(
294296
return self.__class__(data=apply_get(*args, array=self._data, mode_=mode_, **kwargs))
295297

296298
def filter_mask(
297-
self: Self,
299+
self,
298300
*args: int | Iterable[int] | np.ndarray,
299301
mode_: Literal["AND", "OR"] = "AND",
300302
**kwargs: Any | list[Any] | np.ndarray,
301303
) -> np.ndarray:
302304
return get_filter_mask(*args, array=self._data, mode_=mode_, **kwargs)
303305

304306
def exclude_mask(
305-
self: Self,
307+
self,
306308
*args: int | Iterable[int] | np.ndarray,
307309
mode_: Literal["AND", "OR"] = "AND",
308310
**kwargs: Any | list[Any] | np.ndarray,
@@ -312,7 +314,7 @@ def exclude_mask(
312314
def re_order(self: Self, new_order: ArrayLike, column: str = "id") -> Self:
313315
return self.__class__(data=re_order(self._data, new_order, column=column))
314316

315-
def update_by_id(self: Self, ids: ArrayLike, allow_missing: bool = False, **kwargs) -> None:
317+
def update_by_id(self, ids: ArrayLike, allow_missing: bool = False, **kwargs) -> None:
316318
try:
317319
_ = update_by_id(self._data, ids, allow_missing, **kwargs)
318320
except ValueError as error:
@@ -325,13 +327,13 @@ def get_updated_by_id(self: Self, ids: ArrayLike, allow_missing: bool = False, *
325327
except ValueError as error:
326328
raise ValueError(f"Cannot update {self.__class__.__name__}. {error}") from error
327329

328-
def check_ids(self: Self, return_duplicates: bool = False) -> NDArray | None:
330+
def check_ids(self, return_duplicates: bool = False) -> NDArray | None:
329331
return check_ids(self._data, return_duplicates=return_duplicates)
330332

331-
def as_table(self: Self, column_width: int | str = "auto", rows: int = 10) -> str:
333+
def as_table(self, column_width: int | str = "auto", rows: int = 10) -> str:
332334
return convert_array_to_string(self, column_width=column_width, rows=rows)
333335

334-
def as_df(self: Self):
336+
def as_df(self):
335337
"""Convert to pandas DataFrame"""
336338
if pandas is None:
337339
raise ImportError("pandas is not installed")

tests/unit/model/arrays/test_array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_getitem_array_one_column(fancy_test_array: FancyTestArray):
6565

6666
def test_getitem_array_multiple_columns(fancy_test_array: FancyTestArray):
6767
columns = ["id", "test_int", "test_float"]
68+
assert fancy_test_array.data[columns].tolist() == fancy_test_array[columns].tolist()
6869
assert_array_equal(fancy_test_array[columns].dtype.names, ("id", "test_int", "test_float"))
6970

7071

0 commit comments

Comments
 (0)