pyoframe 0.0.9__py3-none-any.whl → 0.0.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyoframe/constants.py +6 -1
- pyoframe/core.py +28 -6
- {pyoframe-0.0.9.dist-info → pyoframe-0.0.11.dist-info}/METADATA +3 -2
- {pyoframe-0.0.9.dist-info → pyoframe-0.0.11.dist-info}/RECORD +7 -7
- {pyoframe-0.0.9.dist-info → pyoframe-0.0.11.dist-info}/WHEEL +1 -1
- {pyoframe-0.0.9.dist-info → pyoframe-0.0.11.dist-info}/LICENSE +0 -0
- {pyoframe-0.0.9.dist-info → pyoframe-0.0.11.dist-info}/top_level.txt +0 -0
pyoframe/constants.py
CHANGED
|
@@ -6,12 +6,17 @@ Code is heavily based on the `linopy` package by Fabian Hofmann.
|
|
|
6
6
|
MIT License
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
import importlib.metadata
|
|
10
|
+
import typing
|
|
9
11
|
from dataclasses import dataclass
|
|
10
12
|
from enum import Enum
|
|
11
|
-
import typing
|
|
12
13
|
from typing import Literal, Optional, Union
|
|
14
|
+
|
|
13
15
|
import polars as pl
|
|
16
|
+
from packaging import version
|
|
14
17
|
|
|
18
|
+
# We want to try and support multiple major versions of polars
|
|
19
|
+
POLARS_VERSION = version.parse(importlib.metadata.version("polars"))
|
|
15
20
|
|
|
16
21
|
COEF_KEY = "__coeff"
|
|
17
22
|
VAR_KEY = "__variable_id"
|
pyoframe/core.py
CHANGED
|
@@ -15,6 +15,7 @@ from typing import (
|
|
|
15
15
|
|
|
16
16
|
import pandas as pd
|
|
17
17
|
import polars as pl
|
|
18
|
+
from packaging import version
|
|
18
19
|
|
|
19
20
|
from pyoframe._arithmetic import _add_expressions, _get_dimensions
|
|
20
21
|
from pyoframe.constants import (
|
|
@@ -22,6 +23,7 @@ from pyoframe.constants import (
|
|
|
22
23
|
CONST_TERM,
|
|
23
24
|
CONSTRAINT_KEY,
|
|
24
25
|
DUAL_KEY,
|
|
26
|
+
POLARS_VERSION,
|
|
25
27
|
RC_COL,
|
|
26
28
|
RESERVED_COL_KEYS,
|
|
27
29
|
SLACK_COL,
|
|
@@ -271,7 +273,18 @@ class Set(ModelElement, SupportsMath, SupportPolarsMethodMixin):
|
|
|
271
273
|
elif isinstance(set, Constraint):
|
|
272
274
|
df = set.data.select(set.dimensions_unsafe)
|
|
273
275
|
elif isinstance(set, SupportsMath):
|
|
274
|
-
|
|
276
|
+
if POLARS_VERSION.major < 1:
|
|
277
|
+
df = (
|
|
278
|
+
set.to_expr()
|
|
279
|
+
.data.drop(RESERVED_COL_KEYS)
|
|
280
|
+
.unique(maintain_order=True)
|
|
281
|
+
)
|
|
282
|
+
else:
|
|
283
|
+
df = (
|
|
284
|
+
set.to_expr()
|
|
285
|
+
.data.drop(RESERVED_COL_KEYS, strict=False)
|
|
286
|
+
.unique(maintain_order=True)
|
|
287
|
+
)
|
|
275
288
|
elif isinstance(set, pd.Index):
|
|
276
289
|
df = pl.from_pandas(pd.DataFrame(index=set).reset_index())
|
|
277
290
|
elif isinstance(set, pd.DataFrame):
|
|
@@ -601,7 +614,7 @@ class Expression(ModelElement, SupportsMath, SupportPolarsMethodMixin):
|
|
|
601
614
|
data = (
|
|
602
615
|
self.data.join(
|
|
603
616
|
multiplier,
|
|
604
|
-
on=dims_in_common,
|
|
617
|
+
on=dims_in_common if len(dims_in_common) > 0 else None,
|
|
605
618
|
how="inner" if dims_in_common else "cross",
|
|
606
619
|
)
|
|
607
620
|
.with_columns(pl.col(COEF_KEY) * pl.col(COEF_KEY + "_right"))
|
|
@@ -1258,7 +1271,10 @@ class Variable(ModelElementWithId, SupportsMath, SupportPolarsMethodMixin):
|
|
|
1258
1271
|
)
|
|
1259
1272
|
|
|
1260
1273
|
def to_expr(self) -> Expression:
|
|
1261
|
-
|
|
1274
|
+
if POLARS_VERSION.major < 1:
|
|
1275
|
+
return self._new(self.data.drop(SOLUTION_KEY))
|
|
1276
|
+
else:
|
|
1277
|
+
return self._new(self.data.drop(SOLUTION_KEY, strict=False))
|
|
1262
1278
|
|
|
1263
1279
|
def _new(self, data: pl.DataFrame):
|
|
1264
1280
|
e = Expression(data.with_columns(pl.lit(1.0).alias(COEF_KEY)))
|
|
@@ -1334,7 +1350,13 @@ class Variable(ModelElementWithId, SupportsMath, SupportPolarsMethodMixin):
|
|
|
1334
1350
|
|
|
1335
1351
|
expr = self.to_expr()
|
|
1336
1352
|
data = expr.data.rename({dim: "__prev"})
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1353
|
+
|
|
1354
|
+
if POLARS_VERSION.major < 1:
|
|
1355
|
+
data = data.join(
|
|
1356
|
+
wrapped, left_on="__prev", right_on="__next", how="inner"
|
|
1357
|
+
).drop(["__prev", "__next"])
|
|
1358
|
+
else:
|
|
1359
|
+
data = data.join(
|
|
1360
|
+
wrapped, left_on="__prev", right_on="__next", how="inner"
|
|
1361
|
+
).drop(["__prev", "__next"], strict=False)
|
|
1340
1362
|
return expr._new(data)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyoframe
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.11
|
|
4
4
|
Summary: Blazing fast linear program interface
|
|
5
5
|
Author-email: Bravos Power <dev@bravospower.com>
|
|
6
6
|
Project-URL: Homepage, https://bravos-power.github.io/pyoframe/
|
|
@@ -15,10 +15,11 @@ Classifier: Natural Language :: English
|
|
|
15
15
|
Requires-Python: >=3.8
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
|
-
Requires-Dist: polars
|
|
18
|
+
Requires-Dist: polars <2,>=0.20
|
|
19
19
|
Requires-Dist: numpy
|
|
20
20
|
Requires-Dist: pyarrow
|
|
21
21
|
Requires-Dist: pandas
|
|
22
|
+
Requires-Dist: packaging
|
|
22
23
|
Provides-Extra: dev
|
|
23
24
|
Requires-Dist: black ; extra == 'dev'
|
|
24
25
|
Requires-Dist: bumpver ; extra == 'dev'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
pyoframe/__init__.py,sha256=D7HHQPy2Me-LLyfPCcSE74dn83PeMK3aOby7i7oiLTs,507
|
|
2
2
|
pyoframe/_arithmetic.py,sha256=riyN2JC-BnOgTIxGfXKIS-X_p7zm8JaKrLk_KDwKAAw,9046
|
|
3
|
-
pyoframe/constants.py,sha256=
|
|
4
|
-
pyoframe/core.py,sha256=
|
|
3
|
+
pyoframe/constants.py,sha256=WoWNVsTeAqOHdUPkaZqFR3X3swrsf7OQnZ9AOaUF3uE,7358
|
|
4
|
+
pyoframe/core.py,sha256=co4Z-i2AZ4jpvqfTKG67AKcBSFputZ0QrTtrglfkOzQ,51915
|
|
5
5
|
pyoframe/io.py,sha256=DJUQ-WlxYe-Ya49pn_T3z6HhJxSD2LSdxm43AGqLuXw,7106
|
|
6
6
|
pyoframe/io_mappers.py,sha256=Op5451Yo4gNa-2BiPPCAjPYdFLo8jIeKHCYXUcGPRug,7385
|
|
7
7
|
pyoframe/model.py,sha256=xod3hSf__WWDy0V9pao9wPlQTc7-7x56FJoKKidsMbw,3768
|
|
@@ -11,8 +11,8 @@ pyoframe/objective.py,sha256=JzuyMAQZ2OxEoAaK-splWwZei2hHPbCLdG-X2-yRkD0,1338
|
|
|
11
11
|
pyoframe/solvers.py,sha256=yf-hzUHDvKgmIHk2FobmygzE9-LnOzTBL5ps-nqGo8I,11875
|
|
12
12
|
pyoframe/user_defined.py,sha256=UWZSTpFj0a8n1_RHwC8Ubwqr4FO-gRPBqqfNUut1IZg,1717
|
|
13
13
|
pyoframe/util.py,sha256=KJubFV66E7WPI5UhcuUNsVwCm7WOcQBiLN1af1MAAgA,9647
|
|
14
|
-
pyoframe-0.0.
|
|
15
|
-
pyoframe-0.0.
|
|
16
|
-
pyoframe-0.0.
|
|
17
|
-
pyoframe-0.0.
|
|
18
|
-
pyoframe-0.0.
|
|
14
|
+
pyoframe-0.0.11.dist-info/LICENSE,sha256=L1pXz6p_1OW5XGWb2UCR6PNu6k3JAT0XWhi8jV0cuRg,1137
|
|
15
|
+
pyoframe-0.0.11.dist-info/METADATA,sha256=qtlWiEBTxnFXguG57ZfmJ0rG4AcjOad5HM3a2CFJym8,3461
|
|
16
|
+
pyoframe-0.0.11.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
17
|
+
pyoframe-0.0.11.dist-info/top_level.txt,sha256=10z3OOJSVLriQ0IrFLMH8CH9zByugPWolqhlHlkNjV4,9
|
|
18
|
+
pyoframe-0.0.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|