Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 13, 2025
1 parent 5ae429e commit 73588da
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/example5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@
" * vehicle_mfa_2.parameters[\"vehicle material content\"]\n",
" * 1e-9\n",
")\n",
"global_stock_by_material_type = stock_by_material_type.sum_nda_over(sum_over_dims=(\"r\"))\n",
"global_stock_by_material_type = stock_by_material_type.sum_over(sum_over_dims=(\"r\"))\n",
"global_stock_by_material_type_in_2017 = global_stock_by_material_type[{\"t\": 2017}]\n",
"\n",
"stock_df = global_stock_by_material_type_in_2017.to_df(index=False)\n",
Expand Down Expand Up @@ -833,7 +833,7 @@
],
"source": [
"np.nan_to_num(vehicle_mfa_2.flows[\"scrap => sysenv\"].values, copy=False)\n",
"scrap_outflow = vehicle_mfa_2.flows[\"scrap => sysenv\"].sum_nda_over(sum_over_dims=(\"m\"))\n",
"scrap_outflow = vehicle_mfa_2.flows[\"scrap => sysenv\"].sum_over(sum_over_dims=(\"m\"))\n",
"outflow_df = scrap_outflow.to_df(dim_to_columns=\"waste\")\n",
"outflow_df = outflow_df[outflow_df.index > 2017]\n",
"fig = px.line(outflow_df, title=\"Scrap outflow\")\n",
Expand Down
4 changes: 3 additions & 1 deletion flodym/_df_to_flodym_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def _check_data_complete(self):
if self.flodym_array.dims.ndim == 0:
expected_index_tuples = set()
else:
expected_index_tuples = set(itertools.product(*(dim.items for dim in self.flodym_array.dims)))
expected_index_tuples = set(
itertools.product(*(dim.items for dim in self.flodym_array.dims))
)

# Generate actual index tuples from DataFrame columns
actual_index_tuples = set(
Expand Down
8 changes: 5 additions & 3 deletions flodym/flodym_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def sum_values_to(self, result_dims: tuple[str] = ()):
result_dims = self._tuple_to_letters(result_dims)
return np.einsum(f"{self.dims.string}->{''.join(result_dims)}", self.values)

def sum_to(self, result_dims: tuple = ()) -> 'FlodymArray':
def sum_to(self, result_dims: tuple = ()) -> "FlodymArray":
"""Return the FlodymArray summed, such that only the dimensions given in the result_dims tuple are left.
Args:
Expand All @@ -228,7 +228,7 @@ def sum_to(self, result_dims: tuple = ()) -> 'FlodymArray':
name=self.name,
)

def sum_over(self, sum_over_dims: tuple = ()) -> 'FlodymArray':
def sum_over(self, sum_over_dims: tuple = ()) -> "FlodymArray":
"""Return the FlodymArray summed over a given tuple of dimensions.
Args:
Expand Down Expand Up @@ -565,7 +565,9 @@ def to_flodym_array(self) -> "FlodymArray":
"Use a new dimension object with the subset as values instead"
)

return FlodymArray(dims=self.dims_out, values=self.values_pointer, name=self.flodym_array.name)
return FlodymArray(
dims=self.dims_out, values=self.values_pointer, name=self.flodym_array.name
)

def _init_ids(self):
"""
Expand Down
4 changes: 1 addition & 3 deletions flodym/stock_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def stock_stack(stocks: list[Stock], dimension: Dimension) -> FlowDrivenStock:
"""
stacked_stock = flodym_array_stack([stock.stock for stock in stocks], dimension=dimension)
stacked_inflow = flodym_array_stack([stock.inflow for stock in stocks], dimension=dimension)
stacked_outflow = flodym_array_stack(
[stock.outflow for stock in stocks], dimension=dimension
)
stacked_outflow = flodym_array_stack([stock.outflow for stock in stocks], dimension=dimension)
return FlowDrivenStock(
stock=stacked_stock,
inflow=stacked_inflow,
Expand Down
2 changes: 1 addition & 1 deletion howtos/04_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
}
],
"source": [
"reduced = multiplied.sum_nda_to(result_dims=(\"t\", \"r\"))\n",
"reduced = multiplied.sum_to(result_dims=(\"t\", \"r\"))\n",
"print(\"reduced:\")\n",
"show_array(reduced)"
]
Expand Down

0 comments on commit 73588da

Please sign in to comment.