Skip to content

Commit

Permalink
Resolve pylint reported issues
Browse files Browse the repository at this point in the history
Refactor Unnecessarily calls dunder method __getitem__
Remove useless bad-continuation keyword from pylint
Remove useless pylint suppressions
Replace dict calls with dict syntax
Avoid uneccessary list lookup
Avoid constructing additional lists in memory
Formatting single line
Iterate over enum class instead of list comprehension
Use shim to use StrEnum depending on python version
Be more liberal with type defs
Classes are not StrEnum but Enum
Classes that are IntEnum not StrEnums
Avoid using extra lists when calculating
Use different escape for the multiply sign in markdown
  • Loading branch information
andreas-el authored and anders-kiaer committed May 7, 2024
1 parent 666385f commit 9fa61e3
Show file tree
Hide file tree
Showing 47 changed files with 338 additions and 318 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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
disable = missing-docstring, duplicate-code, logging-fstring-interpolation, unspecified-encoding
enable = useless-suppression

[DESIGN]
Expand Down
2 changes: 1 addition & 1 deletion webviz_subsurface/_components/color_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _show_color_picker(
return dash_daq.ColorPicker( # pylint: disable=not-callable
{"id": self._uuid, "element": "picker"},
label=f"Color for {[col for col in self._dframe.iloc[row_no] if col != 'COLOR']}",
value=dict(hex=current_color_store[row_no]),
value={"hex": current_color_store[row_no]},
)

@app.callback(
Expand Down
60 changes: 30 additions & 30 deletions webviz_subsurface/_components/tornado/_tornado_bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,46 +140,46 @@ def hover_labels(self) -> List:
def data(self) -> List:
colors = self.create_color_list(self._tornadotable["sensname"].unique())
return [
dict(
type="bar",
y=self._tornadotable["sensname"],
x=self._tornadotable["low"],
name="low",
base=self._tornadotable["low_base"]
{
"type": "bar",
"y": self._tornadotable["sensname"],
"x": self._tornadotable["low"],
"name": "low",
"base": self._tornadotable["low_base"]
if not self._use_true_base
else (self._reference_average + self._tornadotable["low_base"]),
customdata=self._tornadotable["low_reals"],
text=self.bar_labels("low"),
textposition="auto",
insidetextanchor="middle",
hoverinfo="text",
hovertext=self.hover_labels(),
orientation="h",
marker={
"customdata": self._tornadotable["low_reals"],
"text": self.bar_labels("low"),
"textposition": "auto",
"insidetextanchor": "middle",
"hoverinfo": "text",
"hovertext": self.hover_labels(),
"orientation": "h",
"marker": {
"line": {"width": 1.5, "color": "black"},
"color": colors if self._color_by_sens else None,
},
),
dict(
type="bar",
y=self._tornadotable["sensname"],
x=self._tornadotable["high"],
name="high",
base=self._tornadotable["high_base"]
},
{
"type": "bar",
"y": self._tornadotable["sensname"],
"x": self._tornadotable["high"],
"name": "high",
"base": self._tornadotable["high_base"]
if not self._use_true_base
else (self._reference_average + self._tornadotable["high_base"]),
customdata=self._tornadotable["high_reals"],
text=self.bar_labels("high"),
textposition="auto",
insidetextanchor="middle",
hoverinfo="text",
hovertext=self.hover_labels(),
orientation="h",
marker={
"customdata": self._tornadotable["high_reals"],
"text": self.bar_labels("high"),
"textposition": "auto",
"insidetextanchor": "middle",
"hoverinfo": "text",
"hovertext": self.hover_labels(),
"orientation": "h",
"marker": {
"line": {"width": 1.5, "color": "black"},
"color": colors if self._color_by_sens else None,
},
),
},
]

def calculate_scatter_value(self, case_values: pd.Series) -> List:
Expand Down
6 changes: 3 additions & 3 deletions webviz_subsurface/_datainput/eclipse_init_io/pvt_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,15 @@ def surface_mass_density(
else:
raise AttributeError("Phase must be Liquid, Water or Vapour.")

tabdims = ecl_file.__getitem__("TABDIMS")
tab = ecl_file.__getitem__("TAB")
tabdims = ecl_file["TABDIMS"]
tab = ecl_file["TAB"]

start = tabdims[InitFileDefinitions.TABDIMS_IBDENS_OFFSET_ITEM] - 1
nreg = tabdims[InitFileDefinitions.TABDIMS_NTDENS_ITEM]

rho = tab[start + nreg * (col + 0) : start + nreg * (col + 1)]

intehead = ecl_file.__getitem__(InitFileDefinitions.INTEHEAD_KW)
intehead = ecl_file[InitFileDefinitions.INTEHEAD_KW]
unit_system = EclUnits.create_unit_system(
intehead[InitFileDefinitions.INTEHEAD_UNIT_INDEX]
)
Expand Down
8 changes: 4 additions & 4 deletions webviz_subsurface/_datainput/eclipse_init_io/pvt_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,16 @@ def from_ecl_init_file(
A Gas object or None if the data in the Eclipse file was invalid
"""
intehead = ecl_init_file.__getitem__(InitFileDefinitions.INTEHEAD_KW)
intehead = ecl_init_file[InitFileDefinitions.INTEHEAD_KW]
intehead_phase = intehead[InitFileDefinitions.INTEHEAD_PHASE_INDEX]

if (intehead_phase & (1 << 2)) == 0:
return None

raw = EclPropertyTableRawData()

tab_dims = ecl_init_file.__getitem__("TABDIMS")
tab = ecl_init_file.__getitem__("TAB")
tab_dims = ecl_init_file["TABDIMS"]
tab = ecl_init_file["TAB"]

num_rv = tab_dims[InitFileDefinitions.TABDIMS_NRPVTG_ITEM]
num_pg = tab_dims[InitFileDefinitions.TABDIMS_NPPVTG_ITEM]
Expand All @@ -547,7 +547,7 @@ def from_ecl_init_file(
if raw.num_tables == 0:
return None

logihead = ecl_init_file.__getitem__(InitFileDefinitions.LOGIHEAD_KW)
logihead = ecl_init_file[InitFileDefinitions.LOGIHEAD_KW]

if logihead[InitFileDefinitions.LOGIHEAD_RV_INDEX]:
raw.num_primary = num_pg
Expand Down
8 changes: 4 additions & 4 deletions webviz_subsurface/_datainput/eclipse_init_io/pvt_oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,15 +753,15 @@ def from_ecl_init_file(
An Oil object or None if the data in the Eclipse file was invalid
"""
intehead = ecl_init_file.__getitem__(InitFileDefinitions.INTEHEAD_KW)
intehead = ecl_init_file[InitFileDefinitions.INTEHEAD_KW]

logihead = ecl_init_file.__getitem__(InitFileDefinitions.LOGIHEAD_KW)
logihead = ecl_init_file[InitFileDefinitions.LOGIHEAD_KW]
is_is_const_compr = bool(logihead[is_const_compr_index()])

raw = EclPropertyTableRawData()

tab_dims = ecl_init_file.__getitem__("TABDIMS")
tab = ecl_init_file.__getitem__("TAB")
tab_dims = ecl_init_file["TABDIMS"]
tab = ecl_init_file["TAB"]

num_rs = tab_dims[InitFileDefinitions.TABDIMS_NRPVTO_ITEM]

Expand Down
6 changes: 3 additions & 3 deletions webviz_subsurface/_datainput/eclipse_init_io/pvt_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,16 @@ def from_ecl_init_file(
A Water object or None if the data in the Eclipse file was invalid
"""
intehead = ecl_init_file.__getitem__(InitFileDefinitions.INTEHEAD_KW)
intehead = ecl_init_file[InitFileDefinitions.INTEHEAD_KW]
intehead_phase = intehead[InitFileDefinitions.INTEHEAD_PHASE_INDEX]

if (intehead_phase & (1 << 2)) == 0:
return None

raw = EclPropertyTableRawData()

tab_dims = ecl_init_file.__getitem__("TABDIMS")
tab = ecl_init_file.__getitem__("TAB")
tab_dims = ecl_init_file["TABDIMS"]
tab = ecl_init_file["TAB"]

raw.num_primary = 1 # Single record per region
raw.num_rows = 1 # Single record per region
Expand Down
1 change: 0 additions & 1 deletion webviz_subsurface/_datainput/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class Base(UnitBase):
care of keeping its symbol tidy.
"""

# pylint: disable=super-init-not-called
def __init__(
self,
value: Union[float, UnitBase], # type: ignore[name-defined]
Expand Down
37 changes: 20 additions & 17 deletions webviz_subsurface/_figures/px_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def update_traces(figure: go.Figure, **kwargs: Any) -> go.Figure:
),
selector=lambda t: t["type"] in ["scatter", "scattergl"],
)
.update_traces(textposition="inside", selector=dict(type="pie"))
.update_traces(textposition="inside", selector={"type": "pie"})
.for_each_trace(lambda t: set_marker_color(t))
.for_each_trace(
lambda t: (
Expand All @@ -139,7 +139,7 @@ def update_traces(figure: go.Figure, **kwargs: Any) -> go.Figure:
if is_numeric_dtype(t["x"])
else None
),
selector=dict(type="histogram"),
selector={"type": "histogram"},
)
)

Expand All @@ -154,7 +154,7 @@ def set_marker_color(trace: go) -> go:
opacity = marker_attributes.get(
"opacity", 0.5 if trace.type in ["scatter", "scattergl"] else 0.7
)
trace.update(marker_line=dict(color=trace.marker.color, width=1))
trace.update(marker_line={"color": trace.marker.color, "width": 1})
trace.update(marker_color=hex_to_rgb(trace.marker.color, opacity=opacity))
trace.update(marker_opacity=1)
return trace
Expand All @@ -180,20 +180,20 @@ def for_each_annotation(figure: go.Figure, **kwargs: Any) -> go.Figure:

def empty_figure_layout() -> go.Figure:
return go.Figure(
layout=dict(
xaxis={"visible": False},
yaxis={"visible": False},
plot_bgcolor="white",
annotations=[
dict(
text="No data available for figure",
xref="paper",
yref="paper",
showarrow=False,
font={"size": 20},
)
layout={
"xaxis": {"visible": False},
"yaxis": {"visible": False},
"plot_bgcolor": "white",
"annotations": [
{
"text": "No data available for figure",
"xref": "paper",
"yref": "paper",
"showarrow": False,
"font": {"size": 20},
}
],
)
},
)


Expand Down Expand Up @@ -246,7 +246,10 @@ def create_hover_boxes_for_violin_plots(
showlegend=False,
text=hover_text,
hoverinfo="text",
hoverlabel=dict(bgcolor="#E6FAEC", font=dict(color="#243746", size=15)),
hoverlabel={
"bgcolor": "#E6FAEC",
"font": {"color": "#243746", "size": 15},
},
)
)
return hovertraces
Expand Down
4 changes: 2 additions & 2 deletions webviz_subsurface/_figures/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def add_trace(
x=x_values,
y=y_values,
mode=mode,
line=dict(dash=dash, color=color),
line={"dash": dash, "color": color},
showlegend=showlegend,
hovertext=text,
name=text,
Expand Down Expand Up @@ -110,4 +110,4 @@ def add_vertical_line_with_error(
"Observation Error",
dash="dash",
)
self._figure.update_layout(legend=dict(orientation="h"))
self._figure.update_layout(legend={"orientation": "h"})
4 changes: 2 additions & 2 deletions webviz_subsurface/_figures/timeseries_figure.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import datetime
from enum import Enum
from typing import Dict, List, Optional

import numpy as np
import pandas as pd

from webviz_subsurface._utils.colors import find_intermediate_color, rgba_to_str
from webviz_subsurface._utils.enum_shim import StrEnum
from webviz_subsurface._utils.simulation_timeseries import (
get_simulation_line_shape,
set_simulation_line_shape_fallback,
)


class Colors(str, Enum):
class Colors(StrEnum):
RED = rgba_to_str((255, 18, 67, 1))
MID = rgba_to_str((220, 220, 220, 1))
GREEN = rgba_to_str((62, 208, 62, 1))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
import shutil
from enum import Enum
from pathlib import Path
from typing import List, Optional

import pandas as pd
import xtgeo

from webviz_subsurface._utils.enum_shim import StrEnum
from webviz_subsurface._utils.perf_timer import PerfTimer

from ._fault_polygons_discovery import FaultPolygonsFileInfo
Expand All @@ -31,7 +31,7 @@ class Col:
REL_PATH = "rel_path"


class FaultPolygonsType(str, Enum):
class FaultPolygonsType(StrEnum):
SIMULATED = "simulated"


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging
import shutil
from enum import Enum
from pathlib import Path
from typing import List, Optional

import numpy as np
import pandas as pd
import xtgeo

from webviz_subsurface._utils.enum_shim import StrEnum
from webviz_subsurface._utils.perf_timer import PerfTimer

from ._egrid_file_discovery import EclipseCaseFileInfo
Expand All @@ -16,15 +16,14 @@
LOGGER = logging.getLogger(__name__)


# pylint: disable=too-few-public-methods
class Col:
class Col(StrEnum):
REAL = "realization"
EGRID = "egrid_path"
INIT = "init_path"
UNRST = "unrst_path"


class GridType(str, Enum):
class GridType(StrEnum):
GEOMETRY = "geometry"
STATIC_PROPERTY = "static_property"
DYNAMIC_PROPERTY = "dynamic_property"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging
import shutil
from enum import Enum
from pathlib import Path
from typing import List, Optional

import numpy as np
import pandas as pd
import xtgeo

from webviz_subsurface._utils.enum_shim import StrEnum
from webviz_subsurface._utils.perf_timer import PerfTimer

from ._roff_file_discovery import GridFileInfo, GridParameterFileInfo
Expand All @@ -27,7 +27,7 @@ class Col:
REL_PATH = "rel_path"


class GridType(str, Enum):
class GridType(StrEnum):
GEOMETRY = "geometry"
STATIC_PROPERTY = "static_property"
DYNAMIC_PROPERTY = "dynamic_property"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def generate_normalized_sample_dates(
def interpolate_backfill(
x: np.ndarray, xp: np.ndarray, yp: np.ndarray, yleft: float, yright: float
) -> np.ndarray:
# pylint: disable=invalid-name
"""Do back-filling interpolation of the coordinates in xp and yp, evaluated at the
x-coordinates specified in x.
Note that xp and yp must be arrays of the same length.
Expand Down Expand Up @@ -253,7 +252,6 @@ def resample_segmented_multi_real_table(table: pa.Table, freq: Frequency) -> pa.
def _compute_interpolation_weight(
d: np.datetime64, d0: np.datetime64, d1: np.datetime64
) -> float:
# pylint: disable=invalid-name
d_as_uint = d.astype(np.uint64)
d0_as_uint = d0.astype(np.uint64)
d1_as_uint = d1.astype(np.uint64)
Expand Down
Loading

0 comments on commit 9fa61e3

Please sign in to comment.