Skip to content

Commit ce226d1

Browse files
remove future warned scalar get item (#433)
* remove future warned scalar get item * fix: remove tests on single variable getter * update release notes
1 parent e01cfed commit ce226d1

3 files changed

Lines changed: 7 additions & 19 deletions

File tree

doc/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Version 0.5.6
1414

1515
* With this release, the package support for Python 3.9 was dropped and support for Python 3.10 was officially added.
1616

17+
* The selection of a single item in `__getitem__` now returns a `Variable` instead of a `ScalarVariable`.
18+
19+
1720
Version 0.5.5
1821
--------------
1922

linopy/variables.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,9 @@ def __init__(
199199
def __getitem__(
200200
self, selector: list[int] | int | slice | tuple[int64, str_]
201201
) -> Variable | ScalarVariable:
202-
keys = selector if isinstance(selector, tuple) else (selector,)
203-
if all(map(pd.api.types.is_scalar, keys)):
204-
warn(
205-
"Accessing a single value with `Variable[...]` and return type "
206-
"ScalarVariable is deprecated. In future, this will return a Variable."
207-
"To get a ScalarVariable use `Variable.at[...]` instead.",
208-
FutureWarning,
209-
)
210-
return self.at[keys]
211-
212-
else:
213-
# return selected Variable
214-
data = Dataset(
215-
{k: self.data[k][selector] for k in self.data}, attrs=self.attrs
216-
)
217-
return self.__class__(data, self.model, self.name)
202+
# return selected Variable
203+
data = Dataset({k: self.data[k][selector] for k in self.data}, attrs=self.attrs)
204+
return self.__class__(data, self.model, self.name)
218205

219206
@property
220207
def attrs(self) -> dict[str, Hashable]:

test/test_variable.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def test_wrong_variable_init(m: Model, x: linopy.Variable) -> None:
7373

7474

7575
def test_variable_getter(x: linopy.Variable, z: linopy.Variable) -> None:
76-
with pytest.warns(FutureWarning):
77-
assert isinstance(x[0], linopy.variables.ScalarVariable)
78-
assert isinstance(z[0], linopy.variables.ScalarVariable)
76+
assert isinstance(x[0], linopy.variables.Variable)
7977

8078
assert isinstance(x.at[0], linopy.variables.ScalarVariable)
8179

0 commit comments

Comments
 (0)