Skip to content

Commit

Permalink
Fix references to add_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Oct 21, 2024
1 parent 4234042 commit 4bbd26a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 80 deletions.
14 changes: 7 additions & 7 deletions tests/core/test_optimization_equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def test_create_equation(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
indexset_2.add(elements=2024)
indexset_2.add(data=2024)
equation_3 = run.optimization.equations.create(
"Equation 5",
constrained_to_indexsets=[indexset.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert equation_3.columns[0].dtype == "object"
assert equation_3.columns[1].dtype == "int64"

Expand Down Expand Up @@ -126,8 +126,8 @@ def test_equation_add_data(self, platform: ixmp4.Platform):
IndexSet(_backend=platform.backend, _model=model)
for model in create_indexsets_for_run(platform=platform, run_id=run.id)
)
indexset.add(elements=["foo", "bar", ""])
indexset_2.add(elements=[1, 2, 3])
indexset.add(data=["foo", "bar", ""])
indexset_2.add(data=[1, 2, 3])
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
# can remedy this. Or maybe we want to catch the resulting
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_equation_add_data(self, platform: ixmp4.Platform):
def test_equation_remove_data(self, platform: ixmp4.Platform):
run = platform.runs.create("Model", "Scenario")
indexset = run.optimization.indexsets.create("Indexset")
indexset.add(elements=["foo", "bar"])
indexset.add(data=["foo", "bar"])
test_data = {
"Indexset": ["bar", "foo"],
"levels": [2.0, 1],
Expand Down Expand Up @@ -326,8 +326,8 @@ def test_tabulate_equation(self, platform: ixmp4.Platform):
run.optimization.equations.tabulate(name="Equation 2"),
)

indexset.add(elements=["foo", "bar"])
indexset_2.add(elements=[1, 2, 3])
indexset.add(data=["foo", "bar"])
indexset_2.add(data=[1, 2, 3])
test_data_1 = {
indexset.name: ["foo"],
indexset_2.name: [1],
Expand Down
12 changes: 6 additions & 6 deletions tests/core/test_optimization_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def test_create_parameter(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
indexset_2.add(elements=2024)
indexset_2.add(data=2024)
parameter_3 = run.optimization.parameters.create(
"Parameter 5",
constrained_to_indexsets=[indexset.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert parameter_3.columns[0].dtype == "object"
assert parameter_3.columns[1].dtype == "int64"

Expand Down Expand Up @@ -127,8 +127,8 @@ def test_parameter_add_data(self, platform: ixmp4.Platform):
IndexSet(_backend=platform.backend, _model=model)
for model in create_indexsets_for_run(platform=platform, run_id=run.id)
)
indexset.add(elements=["foo", "bar", ""])
indexset_2.add(elements=[1, 2, 3])
indexset.add(data=["foo", "bar", ""])
indexset_2.add(data=[1, 2, 3])
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
# can remedy this. Or maybe we want to catch the resulting
Expand Down Expand Up @@ -308,8 +308,8 @@ def test_tabulate_parameter(self, platform: ixmp4.Platform):

unit = platform.units.create("Unit")
unit_2 = platform.units.create("Unit 2")
indexset.add(elements=["foo", "bar"])
indexset_2.add(elements=[1, 2, 3])
indexset.add(data=["foo", "bar"])
indexset_2.add(data=[1, 2, 3])
test_data_1 = {
indexset.name: ["foo"],
indexset_2.name: [1],
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_optimization_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def test_create_table(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
indexset_2.add(elements=2024)
indexset_2.add(data=2024)
table_3 = run.optimization.tables.create(
"Table 5",
constrained_to_indexsets=[indexset.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert table_3.columns[0].dtype == "object"
assert table_3.columns[1].dtype == "int64"

Expand Down Expand Up @@ -124,7 +124,7 @@ def test_table_add_data(self, platform: ixmp4.Platform):
IndexSet(_backend=platform.backend, _model=model) # type: ignore
for model in create_indexsets_for_run(platform=platform, run_id=run.id)
)
indexset.add(elements=["foo", "bar", ""])
indexset.add(data=["foo", "bar", ""])
indexset_2.add([1, 2, 3])
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
Expand Down Expand Up @@ -224,9 +224,9 @@ def test_table_add_data(self, platform: ixmp4.Platform):
indexset_3 = run.optimization.indexsets.create(name="Indexset 3")
test_data_5 = {
indexset.name: ["foo", "foo", "bar"],
indexset_3.name: [1, "2", 3.14],
indexset_3.name: [1.0, 2.2, 3.14],
}
indexset_3.add(elements=[1, "2", 3.14])
indexset_3.add(data=[1.0, 2.2, 3.14])
table_5 = run.optimization.tables.create(
name="Table 5",
constrained_to_indexsets=[indexset.name, indexset_3.name],
Expand Down
14 changes: 7 additions & 7 deletions tests/core/test_optimization_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ def test_create_variable(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
indexset_2.add(elements=2024)
indexset_2.add(data=2024)
variable_4 = run.optimization.variables.create(
"Variable 4",
constrained_to_indexsets=[indexset.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert variable_4.columns is not None
assert variable_4.columns[0].dtype == "object"
assert variable_4.columns[1].dtype == "int64"
Expand Down Expand Up @@ -151,8 +151,8 @@ def test_variable_add_data(self, platform: ixmp4.Platform):
IndexSet(_backend=platform.backend, _model=model)
for model in create_indexsets_for_run(platform=platform, run_id=run.id)
)
indexset.add(elements=["foo", "bar", ""])
indexset_2.add(elements=[1, 2, 3])
indexset.add(data=["foo", "bar", ""])
indexset_2.add(data=[1, 2, 3])
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
# can remedy this. Or maybe we want to catch the resulting
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_variable_add_data(self, platform: ixmp4.Platform):
def test_variable_remove_data(self, platform: ixmp4.Platform):
run = platform.runs.create("Model", "Scenario")
indexset = run.optimization.indexsets.create("Indexset")
indexset.add(elements=["foo", "bar"])
indexset.add(data=["foo", "bar"])
test_data = {
"Indexset": ["bar", "foo"],
"levels": [2.0, 1],
Expand Down Expand Up @@ -349,8 +349,8 @@ def test_tabulate_variable(self, platform: ixmp4.Platform):
run.optimization.variables.tabulate(name="Variable 2"),
)

indexset.add(elements=["foo", "bar"])
indexset_2.add(elements=[1, 2, 3])
indexset.add(data=["foo", "bar"])
indexset_2.add(data=[1, 2, 3])
test_data_1 = {
indexset.name: ["foo"],
indexset_2.name: [1],
Expand Down
26 changes: 12 additions & 14 deletions tests/data/test_optimization_equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def test_create_equation(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
platform.backend.optimization.indexsets.add_elements(
indexset_2.id, elements=2024
)
platform.backend.optimization.indexsets.add_data(indexset_2.id, data=2024)
indexset_2 = platform.backend.optimization.indexsets.get(
run.id, indexset_2.name
)
Expand All @@ -102,7 +100,7 @@ def test_create_equation(self, platform: ixmp4.Platform):
name="Equation 5",
constrained_to_indexsets=[indexset.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert equation_3.columns[0].dtype == "object"
assert equation_3.columns[1].dtype == "int64"

Expand All @@ -128,11 +126,11 @@ def test_equation_add_data(self, platform: ixmp4.Platform):
indexset, indexset_2 = create_indexsets_for_run(
platform=platform, run_id=run.id
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset.id, elements=["foo", "bar", ""]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset.id, data=["foo", "bar", ""]
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_2.id, elements=[1, 2, 3]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_2.id, data=[1, 2, 3]
)
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
Expand Down Expand Up @@ -280,8 +278,8 @@ def test_equation_remove_data(self, platform: ixmp4.Platform):
(indexset,) = create_indexsets_for_run(
platform=platform, run_id=run.id, amount=1
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset.id, elements=["foo", "bar"]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset.id, data=["foo", "bar"]
)
test_data = {
indexset.name: ["bar", "foo"],
Expand Down Expand Up @@ -363,11 +361,11 @@ def test_tabulate_equation(self, platform: ixmp4.Platform):
platform.backend.optimization.equations.tabulate(name="Equation 2"),
)

platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset.id, elements=["foo", "bar"]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset.id, data=["foo", "bar"]
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_2.id, elements=[1, 2, 3]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_2.id, data=[1, 2, 3]
)
test_data_1 = {
indexset.name: ["foo"],
Expand Down
22 changes: 10 additions & 12 deletions tests/data/test_optimization_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def test_create_parameter(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
platform.backend.optimization.indexsets.add_elements(
indexset_2.id, elements=2024
)
platform.backend.optimization.indexsets.add_data(indexset_2.id, data=2024)
indexset_2 = platform.backend.optimization.indexsets.get(
run.id, indexset_2.name
)
Expand All @@ -104,7 +102,7 @@ def test_create_parameter(self, platform: ixmp4.Platform):
name="Parameter 5",
constrained_to_indexsets=[indexset.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert parameter_3.columns[0].dtype == "object"
assert parameter_3.columns[1].dtype == "int64"

Expand All @@ -129,11 +127,11 @@ def test_parameter_add_data(self, platform: ixmp4.Platform):
indexset, indexset_2 = create_indexsets_for_run(
platform=platform, run_id=run.id
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset.id, elements=["foo", "bar", ""]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset.id, data=["foo", "bar", ""]
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_2.id, elements=[1, 2, 3]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_2.id, data=[1, 2, 3]
)
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
Expand Down Expand Up @@ -348,11 +346,11 @@ def test_tabulate_parameter(self, platform: ixmp4.Platform):

unit = platform.backend.units.create("Unit")
unit_2 = platform.backend.units.create("Unit 2")
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset.id, elements=["foo", "bar"]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset.id, data=["foo", "bar"]
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_2.id, elements=[1, 2, 3]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_2.id, data=[1, 2, 3]
)
test_data_1 = {
indexset.name: ["foo"],
Expand Down
28 changes: 13 additions & 15 deletions tests/data/test_optimization_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def test_create_table(self, platform: ixmp4.Platform):
)

# Test column.dtype is registered correctly
platform.backend.optimization.indexsets.add_elements(
indexset_2.id, elements=2024
)
platform.backend.optimization.indexsets.add_data(indexset_2.id, data=2024)
indexset_2 = platform.backend.optimization.indexsets.get(
run.id, indexset_2.name
)
Expand All @@ -100,7 +98,7 @@ def test_create_table(self, platform: ixmp4.Platform):
name="Table 5",
constrained_to_indexsets=[indexset_1.name, indexset_2.name],
)
# If indexset doesn't have elements, a generic dtype is registered
# If indexset doesn't have data, a generic dtype is registered
assert table_3.columns[0].dtype == "object"
assert table_3.columns[1].dtype == "int64"

Expand All @@ -122,11 +120,11 @@ def test_table_add_data(self, platform: ixmp4.Platform):
indexset_1, indexset_2 = create_indexsets_for_run(
platform=platform, run_id=run.id
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_1.id, elements=["foo", "bar", ""]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_1.id, data=["foo", "bar", ""]
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_2.id, elements=[1, 2, 3]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_2.id, data=[1, 2, 3]
)
# pandas can only convert dicts to dataframes if the values are lists
# or if index is given. But maybe using read_json instead of from_dict
Expand Down Expand Up @@ -268,11 +266,11 @@ def test_table_add_data(self, platform: ixmp4.Platform):
)
test_data_5 = {
indexset_1.name: ["foo", "foo", "bar"],
indexset_3.name: [1, "2", 3.14],
indexset_3.name: [1.0, 2.2, 3.14],
}

platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_3.id, elements=[1, "2", 3.14]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_3.id, data=[1.0, 2.2, 3.14]
)
table_5 = platform.backend.optimization.tables.create(
run_id=run.id,
Expand Down Expand Up @@ -341,11 +339,11 @@ def test_tabulate_table(self, platform: ixmp4.Platform):
platform.backend.optimization.tables.tabulate(name="Table 2"),
)

platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_1.id, elements=["foo", "bar"]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_1.id, data=["foo", "bar"]
)
platform.backend.optimization.indexsets.add_elements(
indexset_id=indexset_2.id, elements=[1, 2, 3]
platform.backend.optimization.indexsets.add_data(
indexset_id=indexset_2.id, data=[1, 2, 3]
)
test_data_1 = {indexset_1.name: ["foo"], indexset_2.name: [1]}
platform.backend.optimization.tables.add_data(
Expand Down
Loading

0 comments on commit 4bbd26a

Please sign in to comment.