diff --git a/pyproject.toml b/pyproject.toml index 9f3a4c62..107281a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,6 +89,7 @@ lint.select=[ "NPY", "PD", "PL", + "RUF", ] line-length = 88 diff --git a/src/pyscal/factory.py b/src/pyscal/factory.py index 3fc2e94c..aea3bdd2 100644 --- a/src/pyscal/factory.py +++ b/src/pyscal/factory.py @@ -48,7 +48,7 @@ def slicedict(dct: dict, keys: Iterable): WO_SIMPLE_J = ["a", "b", "poro_ref", "perm_ref", "drho"] # "g" is optional WO_SWLHEIGHT = ["swlheight"] WO_SWCR_ADD = ["swcr_add"] # Relevant when swlheight is in use. -WO_SWL_FROM_HEIGHT = WO_SWLHEIGHT + ["swirr", "a", "b", "poro_ref", "perm_ref"] +WO_SWL_FROM_HEIGHT = [*WO_SWLHEIGHT, "swirr", "a", "b", "poro_ref", "perm_ref"] WO_NORM_J = ["a", "b", "poro", "perm", "sigma_costau"] # 'a' in WO_NORM_J is the same as a_petro, but should possibly kept as is. WO_SIMPLE_J_PETRO = [ @@ -267,9 +267,9 @@ def create_water_oil( ) # Capillary pressure: - params_simple_j = slicedict(params, WO_SIMPLE_J + ["g"]) + params_simple_j = slicedict(params, [*WO_SIMPLE_J, "g"]) params_norm_j = slicedict(params, WO_NORM_J) - params_simple_j_petro = slicedict(params, WO_SIMPLE_J_PETRO + ["g"]) + params_simple_j_petro = slicedict(params, [*WO_SIMPLE_J_PETRO, "g"]) params_let_pc_pd = slicedict(params, WO_LET_PC_PD) params_let_pc_imb = slicedict(params, WO_LET_PC_IMB) params_skjaeveland_pc = slicedict(params, WO_SKJAEVELAND_PC) @@ -899,7 +899,7 @@ def create_scal_recommendation_list( ) ) except ValueError as err: - raise ValueError(f"Error for SATNUM {satnum}: {str(err)}") from err + raise ValueError(f"Error for SATNUM {satnum}: {err}") from err return scal_l @@ -957,7 +957,7 @@ def create_wateroilgas_list( try: wogl.append(create_water_oil_gas(params.to_dict(), fast=fast)) except (AssertionError, ValueError, TypeError) as err: - raise ValueError(f"Error for SATNUM {row_idx + 1}: {str(err)}") from err + raise ValueError(f"Error for SATNUM {row_idx + 1}: {err}") from err return wogl @@ -983,9 +983,7 @@ def create_wateroil_list( try: wol.append(create_water_oil(params.to_dict(), fast=fast)) except (AssertionError, ValueError, TypeError) as err: - raise ValueError( - f"Error for SATNUM {params['SATNUM']}: {str(err)}" - ) from err + raise ValueError(f"Error for SATNUM {params['SATNUM']}: {err}") from err return wol @@ -1011,9 +1009,7 @@ def create_gasoil_list( try: gol.append(create_gas_oil(params.to_dict(), fast=fast)) except (AssertionError, ValueError, TypeError) as err: - raise ValueError( - f"Error for SATNUM {params['SATNUM']}: {str(err)}" - ) from err + raise ValueError(f"Error for SATNUM {params['SATNUM']}: {err}") from err return gol @@ -1039,9 +1035,7 @@ def create_gaswater_list( try: gwl.append(create_gas_water(params.to_dict(), fast=fast)) except (AssertionError, ValueError, TypeError) as err: - raise ValueError( - f"Error for SATNUM {params['SATNUM']}: {str(err)}" - ) from err + raise ValueError(f"Error for SATNUM {params['SATNUM']}: {err}") from err return gwl diff --git a/src/pyscal/gasoil.py b/src/pyscal/gasoil.py index 5630aba6..964fd494 100644 --- a/src/pyscal/gasoil.py +++ b/src/pyscal/gasoil.py @@ -143,14 +143,14 @@ def __init__( "No saturation range left for gas curve between endpoints, check input" ) - sg_list = ( - [0.0] - + [self.sgl] - + [self.sgcr] - + list(np.arange(self.sgcr + self.h, 1 - self.sorg - self.swl, self.h)) - + [1 - self.sorg - self.swl] - + [1 - self.swl] - ) + sg_list = [ + 0.0, + self.sgl, + self.sgcr, + *list(np.arange(self.sgcr + self.h, 1 - self.sorg - self.swl, self.h)), + 1 - self.sorg - self.swl, + 1 - self.swl, + ] sg_list.sort() self.table = pd.DataFrame(sg_list, columns=["SG"]) self.table["sgint"] = list(map(round, self.table["SG"] * SWINTEGERS)) diff --git a/src/pyscal/utils/testing.py b/src/pyscal/utils/testing.py index 540dab42..3001e754 100644 --- a/src/pyscal/utils/testing.py +++ b/src/pyscal/utils/testing.py @@ -80,9 +80,9 @@ def sat_table_str_ok(sat_table_str: str) -> None: # This must be a constant: assert len(floats_pr_line) == 1 # And not more than 4: - if not list(floats_pr_line)[0] <= 4: + if not next(iter(floats_pr_line)) <= 4: print(sat_table_str) - assert list(floats_pr_line)[0] <= 4 + assert next(iter(floats_pr_line)) <= 4 float_characters = {len(flt) for flt in " ".join(number_lines).split()} digits = 7 # This is the default value in utils.df2str() @@ -92,7 +92,7 @@ def sat_table_str_ok(sat_table_str: str) -> None: # or above digits + 1, otherwise it is a sign of some error. # And pyscal only emits three or four floats pr. line for all keywords: - assert list(set(floats_pr_line))[0] in [3, 4] + assert next(iter(set(floats_pr_line))) in [3, 4] # So we should be able to parse this to a dataframe: dframe = pd.read_csv(io.StringIO("\n".join(number_lines)), sep=" ", header=None) diff --git a/src/pyscal/wateroil.py b/src/pyscal/wateroil.py index 07cb0d2d..26cd97e0 100644 --- a/src/pyscal/wateroil.py +++ b/src/pyscal/wateroil.py @@ -150,13 +150,13 @@ def __init__( self.tag = tag self.fast = fast - sw_list = ( - list(np.arange(self.swl, 1 - self.sgl, self.h)) - + [self.swcr] - + [1 - self.sorw] - + [1 - self.socr] - + [1 - self.sgl] - ) + sw_list = [ + *list(np.arange(self.swl, 1 - self.sgl, self.h)), + self.swcr, + 1 - self.sorw, + 1 - self.socr, + 1 - self.sgl, + ] sw_list.sort() # Using default timsort on nearly sorted data. self.table = pd.DataFrame(sw_list, columns=["SW"])