Skip to content

Commit

Permalink
Unpin pylint (#1277)
Browse files Browse the repository at this point in the history
* Unpin pylint

* Avoid using non-existant variable

* Remove useless pylint control

* Fix warning string

* Replace range calculation with quadratic calculation

* Actually raise exceptions if failures occur

* Replace badly chained expression

* Formatting with black

* Lower pylint standards slightly

* Use bash exit codes to determine pylint status
  • Loading branch information
andreas-el authored May 2, 2024
1 parent 5de520c commit 99b83b5
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 71 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/subsurface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ jobs:
if: github.event_name != 'release'
run: |
black --check webviz_subsurface tests setup.py
pylint webviz_subsurface tests setup.py
pylint_exit_code=0
pylint webviz_subsurface tests setup.py || pylint_exit_code=$?
error_bitmask=$((1 | 2 | 4)) # Fatal, Error, Warning
result=$(($pylint_exit_code & $error_bitmask))
if [[ $result != 0 ]]; then
echo "Error: Pylint returned exit code $pylint_exit_code"
exit $pylint_exit_code
fi
bandit -r -c ./bandit.yml webviz_subsurface tests setup.py
isort --check-only webviz_subsurface tests setup.py
mypy --package webviz_subsurface
Expand Down
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ init-hook = "import astroid; astroid.context.InferenceContext.max_inferred = 500
[MESSAGES CONTROL]

disable = bad-continuation, missing-docstring, duplicate-code, logging-fstring-interpolation, unspecified-encoding
enable = useless-suppression, no-print
enable = useless-suppression

[DESIGN]

Expand All @@ -27,6 +27,7 @@ good-names = i,
df,
_


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dash[testing]",
"isort",
"mypy",
"pylint<=2.13.9", # Locked due to https://github.com/equinor/webviz-subsurface/issues/1052
"pylint",
"pytest-mock",
"pytest-xdist",
"pytest-forked",
Expand Down
4 changes: 3 additions & 1 deletion webviz_subsurface/_components/color_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def get_color(self, color_list: List, filter_query: Dict[str, str]) -> str:
warnings.warn("No color found for filter!")
return "#ffffff"
if len(df["COLOR"].unique()) > 1:
warnings.warn("Multiple colors found for filter. " "Return first color.")
warnings.warn(
f"Multiple colors found for filter, using first color: {color_list[df.index[0]]}"
)
return color_list[df.index[0]]

@property
Expand Down
66 changes: 39 additions & 27 deletions webviz_subsurface/_figures/px_figure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import math
from typing import Any, Callable, List, Optional, Union

import pandas as pd
Expand Down Expand Up @@ -40,11 +41,12 @@ def set_default_args(**plotargs: Any) -> dict:

if plotargs.get("facet_col") is not None:
facet_cols = plotargs["data_frame"][plotargs["facet_col"]].nunique()

x = math.ceil((math.sqrt(1 + 4 * facet_cols) - 1) / 2)
facet_col_wrap = min(x, 20)

plotargs.update(
facet_col_wrap=min(
min([x for x in range(100) if (x * (x + 1)) >= facet_cols]),
20,
),
facet_col_wrap=facet_col_wrap,
facet_row_spacing=max((0.08 - (0.00071 * facet_cols)), 0.03),
facet_col_spacing=max((0.06 - (0.00071 * facet_cols)), 0.03),
)
Expand Down Expand Up @@ -77,16 +79,20 @@ def update_xaxes(figure: go.Figure, plot_type: str, **kwargs: Any) -> go.Figure:
linewidth=2,
linecolor="black",
mirror=True,
title=None
if facet_col is not None or not isinstance(kwargs.get("x"), str)
else kwargs.get("x"),
showticklabels=(data_frame[facet_col].nunique() <= 100)
if facet_col is not None
else None,
title=(
None
if facet_col is not None or not isinstance(kwargs.get("x"), str)
else kwargs.get("x")
),
showticklabels=(
(data_frame[facet_col].nunique() <= 100) if facet_col is not None else None
),
tickangle=0,
tickfont_size=max((20 - (0.4 * data_frame[facet_col].nunique())), 10)
if facet_col is not None
else None,
tickfont_size=(
max((20 - (0.4 * data_frame[facet_col].nunique())), 10)
if facet_col is not None
else None
),
fixedrange=plot_type == "distribution",
).update_xaxes(**kwargs.get("xaxis", {}))

Expand Down Expand Up @@ -116,19 +122,23 @@ def update_traces(figure: go.Figure, **kwargs: Any) -> go.Figure:
facet_col = kwargs.get("facet_col")
return (
figure.update_traces(
marker_size=max((20 - (1.5 * data_frame[facet_col].nunique())), 5)
if facet_col is not None
else 20,
marker_size=(
max((20 - (1.5 * data_frame[facet_col].nunique())), 5)
if facet_col is not None
else 20
),
selector=lambda t: t["type"] in ["scatter", "scattergl"],
)
.update_traces(textposition="inside", selector=dict(type="pie"))
.for_each_trace(lambda t: set_marker_color(t))
.for_each_trace(
lambda t: t.update(
xbins_size=(t["x"].max() - t["x"].min()) / kwargs.get("nbins", 15)
)
if is_numeric_dtype(t["x"])
else None,
lambda t: (
t.update(
xbins_size=(t["x"].max() - t["x"].min()) / kwargs.get("nbins", 15)
)
if is_numeric_dtype(t["x"])
else None
),
selector=dict(type="histogram"),
)
)
Expand Down Expand Up @@ -156,12 +166,14 @@ def for_each_annotation(figure: go.Figure, **kwargs: Any) -> go.Figure:
return figure.for_each_annotation(
lambda a: a.update(
text=(a.text.split("=")[-1]),
visible=data_frame[facet_col].nunique() <= 42
if facet_col is not None
else None,
font_size=max((18 - (0.4 * data_frame[facet_col].nunique())), 10)
if facet_col is not None
else None,
visible=(
data_frame[facet_col].nunique() <= 42 if facet_col is not None else None
),
font_size=(
max((18 - (0.4 * data_frame[facet_col].nunique())), 10)
if facet_col is not None
else None
),
)
)

Expand Down
4 changes: 2 additions & 2 deletions webviz_subsurface/plugins/_prod_misfit/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def _get_wells_vectors_phases(
wells, vectors = sorted(wells), sorted(vectors)

if not vectors:
RuntimeError("No WOPT, WWPT or WGPT vectors found.")
raise RuntimeError("No WOPT, WWPT or WGPT vectors found.")

if drop_list:
logging.debug(
Expand Down Expand Up @@ -496,7 +496,7 @@ def _get_well_collections_from_attr(
df_well_groups = well_attributes.dataframe_melted.dropna()
df_cols = df_well_groups.columns
if "WELL" not in df_cols or "VALUE" not in df_cols:
RuntimeError(
raise RuntimeError(
f"The {well_attributes.file_name} file must contain the columns"
" 'WELL' and 'VALUE'"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def _update_tornado_pages(
if page_selected == "torn_bulk_inplace"
else [selections["Response"]]
)
realplot = None
for response in responses:
if not (response == "BULK" and page_selected == "torn_bulk_inplace"):
if selections["Reference"] not in selections["Sensitivities"]:
Expand Down Expand Up @@ -132,29 +133,33 @@ def _update_tornado_pages(
height="39vh",
table_id={"table_id": f"{page_selected}-torntable"},
)
elif selections["bottom_viz"] == "realplot" and figures:
elif realplot and selections["bottom_viz"] == "realplot" and figures:
bottom_display = [
wcc.Graph(
config={"displayModeBar": False},
style={"height": "40vh"},
figure=realplot,
(
wcc.Graph(
config={"displayModeBar": False},
style={"height": "40vh"},
figure=realplot,
)
if not subplots
else "Realization plot not available when `Subplots` is active"
)
if not subplots
else "Realization plot not available when `Subplots` is active"
]

return update_relevant_components(
id_list=id_list,
update_info=[
{
"new_value": tornado_plots_layout(
figures=figures, bottom_display=bottom_display
)
if figures
else tornado_error_layout(
"No data left after filtering"
if dframe.empty
else f"Reference sensitivity '{selections['Reference']}' not in input data"
"new_value": (
tornado_plots_layout(
figures=figures, bottom_display=bottom_display
)
if figures
else tornado_error_layout(
"No data left after filtering"
if dframe.empty
else f"Reference sensitivity '{selections['Reference']}' not in input data"
)
),
"conditions": {"page": page_selected},
}
Expand Down Expand Up @@ -209,9 +214,9 @@ def _update_tornado_selections(
]
settings["Response"] = {
"options": [{"label": i, "value": i} for i in volume_options],
"value": volume_options[0]
if initial_page_load
else selections["Response"],
"value": (
volume_options[0] if initial_page_load else selections["Response"]
),
"disabled": len(volume_options) == 1,
}
else:
Expand Down Expand Up @@ -288,10 +293,12 @@ def tornado_figure_and_table(
).figure

figure.update_xaxes(side="bottom", title=None).update_layout(
title_text=f"Tornadoplot for {response} <br>"
+ f"Fluid zone: {(' + ').join(selections['filters']['FLUID_ZONE'])}"
if group is None
else f"{response} {group}",
title_text=(
f"Tornadoplot for {response} <br>"
+ f"Fluid zone: {(' + ').join(selections['filters']['FLUID_ZONE'])}"
if group is None
else f"{response} {group}"
),
title_font_size=font_size,
margin={"t": 70},
)
Expand Down Expand Up @@ -328,12 +335,14 @@ def create_realplot(df: pd.DataFrame, sensitivity_colors: dict) -> go.Figure:
.update_layout(legend_title_text="")
.for_each_trace(
lambda t: (
t.update(marker_line_color="black")
if t["customdata"][0][0] == "high"
else t.update(marker_line_color="white", marker_line_width=2)
(
t.update(marker_line_color="black")
if t["customdata"][0][0] == "high"
else t.update(marker_line_color="white", marker_line_width=2)
)
if t["customdata"][0][0] != "mc"
else None
)
if t["customdata"][0][0] != "mc"
else None
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ def add_correlation_line(figure: go.Figure, xy_min: float, xy_max: float) -> go.

def create_figure_matrix(figures: List[go.Figure]) -> List[List[go.Figure]]:
"""Convert a list of figures into a matrix for display"""
figs_in_row = min(
min([x for x in range(100) if (x * (x + 1)) > len(figures)]),
20,
)

x = math.ceil((math.sqrt(1 + 4 * len(figures)) - 1) / 2)
figs_in_row = min(x, 20)

len_of_matrix = figs_in_row * math.ceil(len(figures) / figs_in_row)
# extend figure list with None to fit size of matrix
figures.extend([None] * (len_of_matrix - len(figures)))
Expand Down
16 changes: 9 additions & 7 deletions webviz_subsurface/plugins/_well_cross_section_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ def __init__(
):
super().__init__()

if wellfiles is not None == wellfolder is not None:
raise ValueError(
'Incorrent arguments. Either provide "wellfiles" or "wellfolder"'
)
self.wellfolder = wellfolder
self.wellsuffix = wellsuffix
self.wellfiles: List[str]
if wellfolder is not None:
self.wellfiles = json.load(find_files(wellfolder, wellsuffix))
elif wellfiles is not None:
self.wellfiles = [str(well) for well in wellfiles]
else:
raise ValueError(
"Incorrect arguments, either provide wellfiles or wellfolder"
)

self.surfacefolder = surfacefolder
self.surfacefiles = surfacefiles
Expand Down Expand Up @@ -243,9 +243,11 @@ def ensemble_layout(self) -> html.Div:
def seismic_layout(self) -> html.Div:
if self.segyfiles:
return html.Div(
style=self.set_style(marginTop="20px")
if self.segyfiles
else {"display": "none"},
style=(
self.set_style(marginTop="20px")
if self.segyfiles
else {"display": "none"}
),
children=html.Label(
children=[
html.Span("Seismic:", style={"font-weight": "bold"}),
Expand Down

0 comments on commit 99b83b5

Please sign in to comment.