Skip to content

Commit 7602d51

Browse files
Merge branch 'master' into oetc-doc
2 parents 037ec2d + 84f6896 commit 7602d51

File tree

11 files changed

+155
-463
lines changed

11 files changed

+155
-463
lines changed

.github/workflows/claude.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
id-token: write
3232
steps:
3333
- name: Checkout repository
34-
uses: actions/checkout@v4
34+
uses: actions/checkout@v5
3535
with:
3636
fetch-depth: 1
3737

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
5656
steps:
5757
- name: Checkout repository
58-
uses: actions/checkout@v4
58+
uses: actions/checkout@v5
5959

6060
# Initializes the CodeQL tools for scanning.
6161
- name: Initialize CodeQL

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Build and verify package
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515
- uses: hynek/build-and-inspect-python-package@v2
1616

1717
release:
@@ -20,7 +20,7 @@ jobs:
2020
needs: [build]
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v5
2424
- uses: softprops/action-gh-release@v2
2525
with:
2626
generate_release_notes: true
@@ -36,7 +36,7 @@ jobs:
3636
permissions:
3737
id-token: write
3838
steps:
39-
- uses: actions/download-artifact@v4
39+
- uses: actions/download-artifact@v5
4040
with:
4141
name: Packages
4242
path: dist

.github/workflows/test-models.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
shell: bash -l {0}
3232

3333
steps:
34-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@v5
3535
with:
3636
repository: PyPSA/pypsa-eur
3737
ref: master

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Build and verify package
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v5
2222
with:
2323
fetch-depth: 0 # Needed for setuptools_scm
2424
- uses: hynek/build-and-inspect-python-package@v2
@@ -42,12 +42,12 @@ jobs:
4242
- windows-latest
4343

4444
steps:
45-
- uses: actions/checkout@v4
45+
- uses: actions/checkout@v5
4646
with:
4747
fetch-depth: 0 # Needed for setuptools_scm
4848

4949
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
50-
uses: actions/setup-python@v5
50+
uses: actions/setup-python@v6
5151
with:
5252
python-version: ${{ matrix.python-version }}
5353

@@ -74,7 +74,7 @@ jobs:
7474
choco install glpk
7575
7676
- name: Download package
77-
uses: actions/download-artifact@v4
77+
uses: actions/download-artifact@v5
7878
with:
7979
name: Packages
8080
path: dist
@@ -102,17 +102,17 @@ jobs:
102102
runs-on: ubuntu-latest
103103

104104
steps:
105-
- uses: actions/checkout@v4
105+
- uses: actions/checkout@v5
106106
with:
107107
fetch-depth: 0 # Needed for setuptools_scm
108108

109109
- name: Set up Python 3.12
110-
uses: actions/setup-python@v5
110+
uses: actions/setup-python@v6
111111
with:
112112
python-version: 3.12
113113

114114
- name: Download package
115-
uses: actions/download-artifact@v4
115+
uses: actions/download-artifact@v5
116116
with:
117117
name: Packages
118118
path: dist

doc/release_notes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Release Notes
22
=============
33

44
Upcoming Version
5-
-----------------
65

76
* Replace pandas-based LP file writing with polars implementation for significantly improved performance on large models
87
* Consolidate "lp" and "lp-polars" io_api options - both now use the optimized polars backend
@@ -22,7 +21,6 @@ Version 0.5.6
2221
**Breaking Changes**
2322

2423
* With this release, the package support for Python 3.9 was dropped and support for Python 3.10 was officially added.
25-
2624
* The selection of a single item in `__getitem__` now returns a `Variable` instead of a `ScalarVariable`.
2725

2826

linopy/common.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ def as_dataarray(
254254
arr = pandas_to_dataarray(arr, coords=coords, dims=dims, **kwargs)
255255
elif isinstance(arr, np.ndarray):
256256
arr = numpy_to_dataarray(arr, coords=coords, dims=dims, **kwargs)
257-
elif isinstance(arr, np.number | int | float | str | bool | list):
257+
elif isinstance(arr, np.number):
258+
arr = DataArray(float(arr), coords=coords, dims=dims, **kwargs)
259+
elif isinstance(arr, int | float | str | bool | list):
258260
arr = DataArray(arr, coords=coords, dims=dims, **kwargs)
259261

260262
elif not isinstance(arr, DataArray):
@@ -361,22 +363,35 @@ def to_polars(ds: Dataset, **kwargs: Any) -> pl.DataFrame:
361363

362364
def check_has_nulls_polars(df: pl.DataFrame, name: str = "") -> None:
363365
"""
364-
Checks if the given DataFrame contains any null values and raises a ValueError if it does.
366+
Checks if the given DataFrame contains any null or NaN values and raises a ValueError if it does.
365367
366368
Args:
367369
----
368-
df (pl.DataFrame): The DataFrame to check for null values.
370+
df (pl.DataFrame): The DataFrame to check for null or NaN values.
369371
name (str): The name of the data container being checked.
370372
371373
Raises:
372374
------
373-
ValueError: If the DataFrame contains null values,
374-
a ValueError is raised with a message indicating the name of the constraint and the fields containing null values.
375+
ValueError: If the DataFrame contains null or NaN values,
376+
a ValueError is raised with a message indicating the name of the constraint and the fields containing null/NaN values.
375377
"""
378+
# Check for null values in all columns
376379
has_nulls = df.select(pl.col("*").is_null().any())
377380
null_columns = [col for col in has_nulls.columns if has_nulls[col][0]]
378-
if null_columns:
379-
raise ValueError(f"{name} contains nan's in field(s) {null_columns}")
381+
382+
# Check for NaN values only in numeric columns (avoid enum/categorical columns)
383+
numeric_cols = [
384+
col for col, dtype in zip(df.columns, df.dtypes) if dtype.is_numeric()
385+
]
386+
387+
nan_columns = []
388+
if numeric_cols:
389+
has_nans = df.select(pl.col(numeric_cols).is_nan().any())
390+
nan_columns = [col for col in has_nans.columns if has_nans[col][0]]
391+
392+
invalid_columns = list(set(null_columns + nan_columns))
393+
if invalid_columns:
394+
raise ValueError(f"{name} contains nan's in field(s) {invalid_columns}")
380395

381396

382397
def filter_nulls_polars(df: pl.DataFrame) -> pl.DataFrame:

0 commit comments

Comments
 (0)