From 81d71aeae59ef591fd4f76b35b291be77e968fc8 Mon Sep 17 00:00:00 2001 From: JB Lovland Date: Fri, 24 Nov 2023 16:28:50 +0100 Subject: [PATCH] CLN: Add types to gridprop-import-roff --- mypy.ini | 3 --- src/xtgeo/grid3d/_gridprop_import_roff.py | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mypy.ini b/mypy.ini index cb88743e2..774e19e1e 100644 --- a/mypy.ini +++ b/mypy.ini @@ -96,9 +96,6 @@ ignore_errors = True [mypy-xtgeo.grid3d._gridprop_import_grdecl] ignore_errors = True -[mypy-xtgeo.grid3d._gridprop_import_roff] -ignore_errors = True - [mypy-xtgeo.grid3d._gridprop_import_xtgcpprop] ignore_errors = True diff --git a/src/xtgeo/grid3d/_gridprop_import_roff.py b/src/xtgeo/grid3d/_gridprop_import_roff.py index 43aafe673..a044f2cfd 100644 --- a/src/xtgeo/grid3d/_gridprop_import_roff.py +++ b/src/xtgeo/grid3d/_gridprop_import_roff.py @@ -1,7 +1,9 @@ """Importing grid props from ROFF, binary""" +from __future__ import annotations import warnings +from typing import TYPE_CHECKING, Any import numpy as np @@ -9,10 +11,18 @@ from ._roff_parameter import RoffParameter +if TYPE_CHECKING: + from xtgeo.common import _XTGeoFile + from xtgeo.grid3d import Grid + logger = null_logger(__name__) -def import_roff(pfile, name=None, grid=None): +def import_roff( + pfile: _XTGeoFile, + name: str | None = None, + grid: Grid | None = None, +) -> dict[str, Any]: """Import ROFF format""" if name == "unknown": @@ -23,7 +33,7 @@ def import_roff(pfile, name=None, grid=None): ) name = None - result = dict() + result: dict[str, Any]= dict() roff_param = RoffParameter.from_file(pfile._file, name) result["codes"] = roff_param.xtgeo_codes() result["name"] = roff_param.name @@ -32,9 +42,10 @@ def import_roff(pfile, name=None, grid=None): result["nlay"] = int(roff_param.nz) result["discrete"] = roff_param.is_discrete result["values"] = roff_param.xtgeo_values() - if grid is not None: + + if grid is not None and (actnum := grid.get_actnum()): result["values"] = np.ma.masked_where( - grid.get_actnum().values < 1, + actnum.values < 1, result["values"], )