Skip to content

Commit

Permalink
STY: Update to new ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Jun 28, 2024
1 parent 4fa8336 commit 576518f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 48 deletions.
5 changes: 1 addition & 4 deletions src/xtgeo/common/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ def point_in_tetrahedron(
status = _cxtgeo.x_point_in_tetrahedron(x0, y0, z0, vertices)
if status == 1:
raise XTGeoCLibError("Error in x_point_in_tetrahedron")
if status == 100:
return True

return False
return status == 100


def point_in_hexahedron(
Expand Down
4 changes: 1 addition & 3 deletions src/xtgeo/grid3d/_roff_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def from_file(filelike: FileLike, name: str | None = None) -> RoffParameter:

def should_skip_parameter(tag: str, key: str) -> bool:
if tag == "parameter" and key[0] == "name":
if name is None or key[1] == name:
return False
return True
return not (name is None or key[1] == name)
return False

translate_kws = {
Expand Down
6 changes: 1 addition & 5 deletions src/xtgeo/grid3d/grid_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,7 @@ def __str__(self) -> str:

def __contains__(self, name: str) -> bool:
"""bool: Emulate 'if "PORO" in props'."""
prop = self.get_prop_by_name(name, raiseserror=False)
if prop:
return True

return False
return bool(self.get_prop_by_name(name, raiseserror=False))

def __getitem__(self, name: str) -> GridProperty: # noqa: D105
prop = self.get_prop_by_name(name, raiseserror=False)
Expand Down
4 changes: 1 addition & 3 deletions src/xtgeo/surface/_zmap_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ def parse_header(zmap_data):


def is_comment(line):
if line.startswith(("!", "+")):
return True
return False
return line.startswith(("!", "+"))


def parse_values(zmap_data, nan_value):
Expand Down
11 changes: 3 additions & 8 deletions src/xtgeo/well/well1.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,12 +845,10 @@ def isdiscrete(self, logname):
.. versionadded:: 2.2.0
"""
if (
return (
logname in self.get_lognames()
and self.get_logtype(logname) == _AttrType.DISC.value
):
return True
return False
)

def copy(self):
"""Copy a Well instance to a new unique Well instance."""
Expand Down Expand Up @@ -1132,10 +1130,7 @@ def may_overlap(self, other):

if xmin1 > xmax2 or ymin1 > ymax2:
return False
if xmin2 > xmax1 or ymin2 > ymax1:
return False

return True
return not (xmin2 > xmax1 or ymin2 > ymax1)

def limit_tvd(self, tvdmin, tvdmax):
"""Truncate the part of the well that is outside tvdmin, tvdmax.
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def fixture_xtgshow():
"""For eventual plotting, to be uses in an if sence inside a test."""
if "ROXENV" in os.environ:
pytest.skip("Skip plotting tests in roxar environment")
if any(word in os.environ for word in ["XTGSHOW", "XTG_SHOW"]):
return True
return False
return any(word in os.environ for word in ["XTGSHOW", "XTG_SHOW"])


@pytest.fixture(name="generate_plot")
Expand Down
10 changes: 4 additions & 6 deletions tests/test_cube/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
_import_segy_all_traces,
_import_segy_incomplete_traces,
)
from xtgeo.io._file import FileWrapper

xtg = XTGeoDialog()
logger = xtg.basiclogger(__name__)
Expand Down Expand Up @@ -214,13 +213,12 @@ def test_internal_segy_import_full_vs_partial(testdata_path):
Most prominent, a full SEGY cube should be possible to parse using the same routine
as used for cubes with missing traces.
"""
segyfile = FileWrapper(testdata_path / SFILE5)

with segyio.open(testdata_path / SFILE5, "r") as segyfile:
attrs1 = _import_segy_all_traces(segyfile)
with segyio.open(testdata_path / SFILE5, "r") as f:
attrs1 = _import_segy_all_traces(f)

with segyio.open(testdata_path / SFILE5, "r") as segyfile:
attrs2 = _import_segy_incomplete_traces(segyfile)
with segyio.open(testdata_path / SFILE5, "r") as f:
attrs2 = _import_segy_incomplete_traces(f)

for key, val in attrs1.items():
if isinstance(val, np.ndarray):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_well/test_well.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_import(loadwell1, snapshot, helpers):
"loadwell1.csv",
)

assert {
assert expected_result == {
"well_name": mywell.wellname,
"xpos": mywell.xpos,
"wpos": mywell.ypos,
Expand All @@ -112,7 +112,7 @@ def test_import(loadwell1, snapshot, helpers):
"nlogs": mywell.nlogs,
"lognames": mywell.lognames,
"lognames_all": mywell.lognames_all,
} == expected_result
}


def test_import_long_well(loadwell3):
Expand Down
28 changes: 14 additions & 14 deletions tests/test_well/test_well_to_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def test_simple_points(well_spec, expected_result, string_to_well, zonelist, use
kwargs = {"zonelogname": "Zonelog"}
well = string_to_well(well_spec, **kwargs)
points = well.get_zonation_points(use_undef=use_undef, tops=True, zonelist=zonelist)
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}


def test_simple_points_two(string_to_well):
Expand All @@ -181,16 +181,16 @@ def test_simple_points_two(string_to_well):
well = string_to_well(wellstring, **kwargs)
points = well.get_zonation_points(use_undef=False, tops=True, zonelist=[1, 2, 3])
expected_result = {"X_UTME": [7.0, 13.0], "Y_UTMN": [8.0, 14.0]}
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}
assert len(points) == 2
points = well.get_zonation_points(use_undef=False, tops=True, zonelist=[2, 3])
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}
assert len(points) == 2


Expand All @@ -214,10 +214,10 @@ def test_break_zonation(string_to_well):
"X_UTME": [4.0, 4.0, 10.0, 13.0],
"Y_UTMN": [5.0, 5.0, 11.0, 14.0],
}
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}


@pytest.mark.parametrize(
Expand Down Expand Up @@ -273,10 +273,10 @@ def test_tops_value(string_to_well, tops_flag, expected_result):
kwargs = {"zonelogname": "Zonelog"}
well = string_to_well(wellstring, **kwargs)
points = well.get_zonation_points(use_undef=False, tops=tops_flag, zonelist=[2, 3])
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}


@pytest.mark.parametrize(
Expand Down Expand Up @@ -308,10 +308,10 @@ def test_include_limit(string_to_well, include_limit, expected_result):
points = well.get_zonation_points(
use_undef=False, tops=False, zonelist=(1, 5), incl_limit=include_limit
)
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}


@pytest.mark.parametrize(
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_zonelist(string_to_well, zone_list, expected_result):
tops=True,
zonelist=zone_list,
)
assert {
assert expected_result == {
"X_UTME": points["X_UTME"].to_list(),
"Y_UTMN": points["Y_UTMN"].to_list(),
} == expected_result
}

0 comments on commit 576518f

Please sign in to comment.