-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include optimization scalar #28
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Please note that there is support for upsert operations in sqlalchemy for sqlite and postgresql. I opted for separate |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
85fc68c
to
7055420
Compare
indexset_2 = run.optimization.IndexSet("Indexset 2") | ||
exp = df_from_list(indexsets=[indexset_1, indexset_2]) | ||
res = run.optimization.indexsets.tabulate() | ||
# utils.assert_unordered_equality doesn't like lists, so make sure the order in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "doesnt like lists" mean? assert_unordered_equality is meant only for DFs afaik...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, that's why it didn't work when I tried to pass in a list of DFs. That's why I added this auxiliary df_from_list()
function. We could rephrase this hint as "... only accepts pd.DataFrames,". Or we remove this comment entirely, but both the order of indexset_1, indexset_2
as arguments for df_from_list()
as well as the order of indexset.name, indexset.elements, ...
in the function's return-value-DF are important for the test to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm kind of confused by that. Nevertheless i think this test might break randomly. (im surprised it works tbh). assert_unordered_equality
exists because postgres will return items whichever way is the fastest. That means the same query might not always return a result in consistent order. That means there might actually not be a "correct order"...
aae2d72
to
6f1fe8e
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
316d9c7
to
692cab5
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Thanks @glatterf42 for rebasing and updating the PR. I think it's fine either way, whether the dimensionless unit comes pre-defined in a blank database or hast to be defined by a user. Whatever you prefer. But I still think that the keyword argument should be |
Thanks, then I'll keep the dimensionless unit as pre-defined. The syntax changed now so that you can supply @meksor, please update your review as all your points should be addressed by now. The last thing from my side is adding another DB migration. |
In fact, I don't think we need another migration here. There were some commits after d66a0a4 that affected def upgrade():
pass
def downgrade():
pass So I figure we don't need to push that migration here. |
* Introduce update() function * Call attention to that when trying to create existing Scalar * Fix DB UniqueConstraint
* Introduce update() function * Call attention to that when trying to create existing Scalar * Fix DB UniqueConstraint
* Allow specifying Unit via its name * Reflect setting Scalar.value and Scalar.unit in DB
d9bd7ee
to
ad5d2ac
Compare
Rebased onto latest main. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good thanks! Sorry for the delay!
indexset_2 = run.optimization.IndexSet("Indexset 2") | ||
exp = df_from_list(indexsets=[indexset_1, indexset_2]) | ||
res = run.optimization.indexsets.tabulate() | ||
# utils.assert_unordered_equality doesn't like lists, so make sure the order in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm kind of confused by that. Nevertheless i think this test might break randomly. (im surprised it works tbh). assert_unordered_equality
exists because postgres will return items whichever way is the fastest. That means the same query might not always return a result in consistent order. That means there might actually not be a "correct order"...
* Add data-tests for IndexSets * Add get_by_id for Units * Update/expand IndexSet tests * Introduce Optimization.Scalar * Correct Indexset UniqueConstraint and streamline core syntax * Update Optimization.Scalar as requested * Introduce update() function * Call attention to that when trying to create existing Scalar * Fix DB UniqueConstraint * Refine Optimization.Scalar facade syntax * Allow specifying Unit via its name * Reflect setting Scalar.value and Scalar.unit in DB * Clean up leftover comments * Fix scalar.value core setter * Include DB migration * Update/expand IndexSet tests * Introduce Optimization.Scalar * Correct Indexset UniqueConstraint and streamline core syntax * Update Optimization.Scalar as requested * Introduce update() function * Call attention to that when trying to create existing Scalar * Fix DB UniqueConstraint * Fix forgotten pytest.raises() in scalar tests * Refine Optimization.Scalar facade syntax * Allow specifying Unit via its name * Reflect setting Scalar.value and Scalar.unit in DB * Clean up leftover comments * Fix scalar.value core setter * Implement suggestions in data layer * Update tests according to suggestions * adjust ScalarRepository.update * adjust tests * Allow passing in Unit, unit.name or None for Scalar creation * Reduce ruff line-length, enable checking tests/ * Adapt long comment lines to new ruff line length * Converge IndexSet and Scalar get and create methods * Reapply formatting lost during rebase * Use updated syntax for run creation * Update black,ruff versions for pre-commit * Delete accidental blank line * Rename unit_or_name to name * Remove unused imports --------- Co-authored-by: Max Wolschlager <[email protected]>
Summary
This PR expands the data model required for message_ix by adding limited support for Scalars. One can now create, get, list, tabulate, and manage docs for scalars with the following syntax:
Implementation Details
Further Changes
While working on this PR, I added/updated a few other minor things:
TO-DOs