Repository: e2nIEE/pandapower

Issue:
copying results in select_subnet
In the function `select_subnet` the flag 'keep_everything_else' overrides the flag 'include_results'. In my case this lead to a pandas warning, as the results in my net were computed before adding some elements. The problem is that using .loc with missing labels is deprecated (cf. https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike). I don't think that including the results when the user sets include_results=False is a good idea. Therefore I would suggest to use `clear_result_tables(net)`.

Another idea: it might be wise to change the flag 'include_results' to a flag called 'remove_results' which is False by default. If it is set to False, then the results will be reindexed. This would be more clear, but I am not sure if it is good practice to change the signature.


Discussion:
@lthurner and @SteffenMeinecke what do you think about this solution:

```
    if keep_everything_else:
        p2 = copy.deepcopy(net)
        if not include_results:
            clear_result_tables(p2)
```

instead of

```
    if keep_everything_else:
        p2 = copy.deepcopy(net)
        include_results = True  # assumption: the user doesn't want to old results without selection
```

Resolving patch:
diff --git a/pandapower/create.py b/pandapower/create.py
--- a/pandapower/create.py
+++ b/pandapower/create.py
@@ -3231,7 +3231,7 @@ def create_pwl_cost(net, element, et, points, power_type="p", index=None):
     EXAMPLE:
         The cost function is given by the x-values p1 and p2 with the slope m between those points. The constant part
         b of a linear function y = m*x + b can be neglected for OPF purposes. The intervals have to be continuous (the
-        starting point of an interval has to be equal to th end point of the previous interval).
+        starting point of an interval has to be equal to the end point of the previous interval).
 
         To create a gen with costs of 1€/MW between 0 and 20 MW and 2€/MW between 20 and 30:
 
diff --git a/pandapower/run.py b/pandapower/run.py
--- a/pandapower/run.py
+++ b/pandapower/run.py
@@ -327,18 +327,20 @@ def runopp(net, verbose=False, calculate_voltage_angles=False, check_connectivit
 
         **trafo3w_losses** (str, "hv") - defines where open loop losses of three-winding transformers are considered. Valid options are "hv", "mv", "lv" for HV/MV/LV side or "star" for the star point.
 
-        **consider_line_temperature** (bool, False) - adjustment of line impedance based on provided
-            line temperature. If True, net.line must contain a column "temperature_degree_celsius".
-            The temperature dependency coefficient alpha must be provided in the net.line.alpha
+        **consider_line_temperature** (bool, False) - adjustment of line impedance based on provided\
+            line temperature. If True, net.line must contain a column "temperature_degree_celsius".\
+            The temperature dependency coefficient alpha must be provided in the net.line.alpha\
             column, otherwise the default value of 0.004 is used
 
-         **kwargs** - Pypower / Matpower keyword arguments: - OPF_VIOLATION (5e-6) constraint violation tolerance
-                                                            - PDIPM_COSTTOL (1e-6) optimality tolerance
-                                                            - PDIPM_GRADTOL (1e-6) gradient tolerance
-                                                            - PDIPM_COMPTOL (1e-6) complementarity condition (inequality) tolerance
-                                                            - PDIPM_FEASTOL (set to OPF_VIOLATION if not specified) feasibiliy (equality) tolerance
-                                                            - PDIPM_MAX_IT  (150) maximum number of iterations
-                                                            - SCPDIPM_RED_IT(20) maximum number of step size reductions per iteration
+         **kwargs** - Pypower / Matpower keyword arguments:
+
+         - OPF_VIOLATION (5e-6) constraint violation tolerance
+         - PDIPM_COSTTOL (1e-6) optimality tolerance
+         - PDIPM_GRADTOL (1e-6) gradient tolerance
+         - PDIPM_COMPTOL (1e-6) complementarity condition (inequality) tolerance
+         - PDIPM_FEASTOL (set to OPF_VIOLATION if not specified) feasibiliy (equality) tolerance
+         - PDIPM_MAX_IT  (150) maximum number of iterations
+         - SCPDIPM_RED_IT(20) maximum number of step size reductions per iteration
 
     """
     _check_necessary_opf_parameters(net, logger)
diff --git a/pandapower/toolbox.py b/pandapower/toolbox.py
--- a/pandapower/toolbox.py
+++ b/pandapower/toolbox.py
@@ -1348,7 +1348,9 @@ def select_subnet(net, buses, include_switch_buses=False, include_results=False,
 
     if keep_everything_else:
         p2 = copy.deepcopy(net)
-        include_results = True  # assumption: the user doesn't want to old results without selection
+        if not include_results:
+            clear_result_tables(p2)
+        # include_results = True  # assumption: the user doesn't want to old results without selection
     else:
         p2 = create_empty_network(add_stdtypes=False)
         p2["std_types"] = copy.deepcopy(net["std_types"])


Test patch: