Merge pull request #330 from PyPSA/fix-clustering-with-infs

Fix clustering of p_nom_max values with pandas version > 1.4
This commit is contained in:
Fabian Neumann 2022-03-16 17:12:24 +01:00 committed by GitHub
commit 5a76493685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -263,9 +263,9 @@ def clustering_for_n_clusters(n, n_clusters, custom_busmap=False, aggregate_carr
algorithm="kmeans", extended_link_costs=0, focus_weights=None): algorithm="kmeans", extended_link_costs=0, focus_weights=None):
if potential_mode == 'simple': if potential_mode == 'simple':
p_nom_max_strategy = np.sum p_nom_max_strategy = pd.Series.sum
elif potential_mode == 'conservative': elif potential_mode == 'conservative':
p_nom_max_strategy = np.min p_nom_max_strategy = pd.Series.min
else: else:
raise AttributeError(f"potential_mode should be one of 'simple' or 'conservative' but is '{potential_mode}'") raise AttributeError(f"potential_mode should be one of 'simple' or 'conservative' but is '{potential_mode}'")
@ -281,7 +281,7 @@ def clustering_for_n_clusters(n, n_clusters, custom_busmap=False, aggregate_carr
aggregate_generators_carriers=aggregate_carriers, aggregate_generators_carriers=aggregate_carriers,
aggregate_one_ports=["Load", "StorageUnit"], aggregate_one_ports=["Load", "StorageUnit"],
line_length_factor=line_length_factor, line_length_factor=line_length_factor,
generator_strategies={'p_nom_max': p_nom_max_strategy, 'p_nom_min': np.sum}, generator_strategies={'p_nom_max': p_nom_max_strategy, 'p_nom_min': pd.Series.sum},
scale_link_capital_costs=False) scale_link_capital_costs=False)
if not n.links.empty: if not n.links.empty: