Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruff specific rules issues #459

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ lint.select=[
"NPY",
"PD",
"PL",
"RUF",
]

line-length = 88
Expand Down
22 changes: 8 additions & 14 deletions src/pyscal/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand Down
16 changes: 8 additions & 8 deletions src/pyscal/gasoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/pyscal/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/pyscal/wateroil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down