From 855fc0a38690f1c5e0b1bbe5fc5c05e3b8d0255a Mon Sep 17 00:00:00 2001 From: mferrera Date: Fri, 19 Jul 2024 12:01:14 +0200 Subject: [PATCH] DEP: Complete xtgeo 4 wells deprecations --- src/xtgeo/well/_well_aux.py | 71 +---------------- src/xtgeo/well/blocked_well.py | 46 ----------- src/xtgeo/well/blocked_wells.py | 94 ----------------------- src/xtgeo/well/well1.py | 69 ----------------- src/xtgeo/well/wells.py | 66 ---------------- tests/test_well/test_well_deprecations.py | 53 ------------- 6 files changed, 1 insertion(+), 398 deletions(-) delete mode 100644 tests/test_well/test_well_deprecations.py diff --git a/src/xtgeo/well/_well_aux.py b/src/xtgeo/well/_well_aux.py index 8c1f8a3b3..7dffc5c0b 100644 --- a/src/xtgeo/well/_well_aux.py +++ b/src/xtgeo/well/_well_aux.py @@ -6,23 +6,12 @@ from __future__ import annotations -import functools -import warnings -from pathlib import Path -from typing import TYPE_CHECKING - -import pandas as pd - -from xtgeo.common._xyz_enum import _AttrName from xtgeo.common.exceptions import InvalidFileFormatError from xtgeo.common.log import null_logger -from xtgeo.io._file import FileFormat, FileWrapper +from xtgeo.io._file import FileFormat from . import _well_io -if TYPE_CHECKING: - from collections.abc import Callable - logger = null_logger(__name__) @@ -39,61 +28,3 @@ def _data_reader_factory(file_format: FileFormat): f"File format {file_format} is invalid for Well types. " f"Supported formats are {extensions}." ) - - -def allow_deprecated_init(func: Callable): - # This decorator is here to maintain backwards compatibility in the - # construction of Well and should be deleted once the deprecation period - # has expired, the construction will then follow the new pattern. - @functools.wraps(func) - def wrapper(self, *args, **kwargs): - if not args and not kwargs: - warnings.warn( - "Initializing empty well is deprecated, please provide " - "non-defaulted values, or use mywell = " - "xtgeo.well_from_file('filename')", - DeprecationWarning, - ) - return func( - self, - *([0.0] * 3), - "", - pd.DataFrame( - { - _AttrName.XNAME.value: [], - _AttrName.YNAME.value: [], - _AttrName.ZNAME.value: [], - } - ), - ) - - # Checking if we are doing an initialization from file and raise a - # deprecation warning if we are. - if "wfile" in kwargs or ( - len(args) >= 1 and isinstance(args[0], (str, Path, FileWrapper)) - ): - warnings.warn( - "Initializing directly from file name is deprecated and will be " - "removed in xtgeo version 4.0. Use: " - "mywell = xtgeo.well_from_file('filename') instead", - DeprecationWarning, - ) - if len(args) >= 1: - wfile = args[0] - args = args[1:] - else: - wfile = kwargs.pop("wfile", None) - if len(args) >= 1: - fformat = args[0] - args = args[1:] - else: - fformat = kwargs.pop("fformat", None) - - mfile = FileWrapper(wfile) - fmt = mfile.fileformat(fformat) - kwargs = _data_reader_factory(fmt)(mfile, *args, **kwargs) - kwargs["filesrc"] = mfile.file - return func(self, **kwargs) - return func(self, *args, **kwargs) - - return wrapper diff --git a/src/xtgeo/well/blocked_well.py b/src/xtgeo/well/blocked_well.py index 4af2971ee..420eb067c 100644 --- a/src/xtgeo/well/blocked_well.py +++ b/src/xtgeo/well/blocked_well.py @@ -1,11 +1,9 @@ """XTGeo blockedwell module""" -import deprecation import pandas as pd from xtgeo.common._xyz_enum import _AttrName from xtgeo.common.log import null_logger -from xtgeo.common.version import __version__ from . import _blockedwell_roxapi from .well1 import Well @@ -170,50 +168,6 @@ def copy(self): return newbw - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.blockedwell_from_roxar() instead", - ) - def from_roxar(self, *args, **kwargs): - """Import (retrieve) a single blocked well from roxar project. - - Note this method works only when inside RMS, or when RMS license is - activated. - - Args: - project (str): Magic string `project` or file path to project - gname (str): Name of GridModel icon in RMS - bwname (str): Name of Blocked Well icon in RMS, usually 'BW' - wname (str): Name of well, as shown in RMS. - lognames (list): List of lognames to include, or use 'all' for - all current blocked logs for this well. Default is 'all'. - realisation (int): Realisation index (0 is default) - ijk (bool): If True, then make additional logs with grid IJK as I_INDEX, - etc, default is False - """ - project = args[0] - gname = args[1] - bwname = args[2] - wname = args[3] - lognames = kwargs.get("lognames", "all") - ijk = kwargs.get("ijk", False) - realisation = kwargs.get("realisation", 0) - - _blockedwell_roxapi.import_bwell_roxapi( - self, - project, - gname, - bwname, - wname, - lognames=lognames, - ijk=ijk, - realisation=realisation, - ) - - self._ensure_consistency() - def to_roxar(self, *args, **kwargs): """Set (export) a single blocked well item inside roxar project. diff --git a/src/xtgeo/well/blocked_wells.py b/src/xtgeo/well/blocked_wells.py index b88f1c625..ab025febc 100644 --- a/src/xtgeo/well/blocked_wells.py +++ b/src/xtgeo/well/blocked_wells.py @@ -1,9 +1,6 @@ """BlockedWells module, (collection of BlockedWell objects)""" -import deprecation - from xtgeo.common.log import null_logger -from xtgeo.common.version import __version__ from xtgeo.common.xtgeo_dialog import XTGeoDialog from . import _blockedwells_roxapi @@ -97,97 +94,6 @@ def get_blocked_well(self, name): logger.debug("Calling super...") return super().get_well(name) - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.blockedwells_from_files() instead", - ) - def from_files( - self, - filelist, - fformat="rms_ascii", - mdlogname=None, - zonelogname=None, - strict=True, - append=True, - ): - """Import blocked wells from a list of files (filelist). - - Args: - filelist (list of str): List with file names - fformat (str): File format, rms_ascii (rms well) is - currently supported and default format. - mdlogname (str): Name of measured depth log, if any - zonelogname (str): Name of zonation log, if any - strict (bool): If True, then import will fail if - zonelogname or mdlogname are asked for but not present - in wells. - append (bool): If True, new wells will be added to existing - wells. - - Example: - Here the from_file method is used to initiate the object - directly:: - - mywells = BlockedWells(['31_2-6.w', '31_2-7.w', '31_2-8.w']) - """ - - if not append: - self._wells = [] - - # file checks are done within the Well() class - for wfile in filelist: - try: - wll = blockedwell_from_file( - wfile, - fformat=fformat, - mdlogname=mdlogname, - zonelogname=zonelogname, - strict=strict, - ) - self._wells.append(wll) - except ValueError as err: - xtg.warn(f"SKIP this well: {err}") - continue - if not self._wells: - xtg.warn("No wells imported!") - - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.blockedwells_from_roxar() instead", - ) - def from_roxar(self, *args, **kwargs): # pragma: no cover - """Import (retrieve) blocked wells from roxar project. - - Note this method works only when inside RMS, or when RMS license is - activated. - - All the wells present in the bwname icon will be imported. - - Args: - project (str): Magic string 'project' or file path to project - gname (str): Name of GridModel icon in RMS - bwname (str): Name of Blocked Well icon in RMS, usually 'BW' - lognames (list): List of lognames to include, or use 'all' for - all current blocked logs for this well. - ijk (bool): If True, then logs with grid IJK as I_INDEX, etc - realisation (int): Realisation index (0 is default) - """ - project = args[0] - gname = args[1] - bwname = args[2] - lognames = kwargs.get("lognames", None) - ijk = kwargs.get("ijk", True) - - _blockedwells_roxapi.import_bwells_roxapi( - self, project, gname, bwname, lognames=lognames, ijk=ijk - ) - - # this is a temporary solution to avoid the deprecation warning; ideally a class - # method shall be applied def _from_roxar(self, *args, **kwargs): # pragma: no cover """Import (retrieve) blocked wells from roxar project. diff --git a/src/xtgeo/well/well1.py b/src/xtgeo/well/well1.py index fca8d7e1d..c35a4fd17 100644 --- a/src/xtgeo/well/well1.py +++ b/src/xtgeo/well/well1.py @@ -6,7 +6,6 @@ from copy import deepcopy from typing import TYPE_CHECKING -import deprecation import numpy as np import pandas as pd @@ -15,7 +14,6 @@ from xtgeo.common.constants import UNDEF, UNDEF_INT, UNDEF_LIMIT from xtgeo.common.exceptions import InvalidFileFormatError from xtgeo.common.log import null_logger -from xtgeo.common.version import __version__ from xtgeo.common.xtgeo_dialog import XTGDescription from xtgeo.io._file import FileFormat, FileWrapper from xtgeo.metadata.metadata import MetaDataWell @@ -177,7 +175,6 @@ class Well: defaults to None. """ - @_well_aux.allow_deprecated_init def __init__( self, rkb: float = 0.0, @@ -208,8 +205,6 @@ def __init__( self._metadata = MetaDataWell() self._metadata.required = self - _reset = __init__ # workaround until deprecation .from_file(), etc are removed - def __repr__(self): # noqa: D105 # should (in theory...) be able to newobject = eval(repr(thisobject)) return ( @@ -492,26 +487,6 @@ def describe(self, flush=True): return dsc.astext() - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.well_from_file() instead", - ) - def from_file( - self, - wfile, - fformat="rms_ascii", - **kwargs, - ): - """Deprecated, see :meth:`xtgeo.well_from_file`""" - - wfile = FileWrapper(wfile) - fmt = wfile.fileformat(fformat) - kwargs = _well_aux._data_reader_factory(fmt)(wfile, **kwargs) - self._reset(**kwargs) - return self - @classmethod def _read_file( cls, @@ -603,19 +578,6 @@ def to_file( return wfile.file - @deprecation.deprecated( - deprecated_in="3.6", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.well_from_file() instead", - ) - def from_hdf( - self, - wfile: str | Path, - ): - """Deprecated, use :meth:`xtgeo.well_from_file()`""" - return self.from_file(wfile, fformat="hdf") - def to_hdf( self, wfile: str | Path, @@ -643,37 +605,6 @@ def to_hdf( return wfile.file - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.well_from_roxar() instead", - ) - def from_roxar( - self, - project: str | object, - name: str, - trajectory: str | None = "Drilled trajectory", - logrun: str | None = "log", - lognames: str | list[str] | None = "all", - lognames_strict: bool | None = False, - inclmd: bool | None = False, - inclsurvey: bool | None = False, - ): - """Deprecated, use :meth:`xtgeo.well_from_roxar()`""" - kwargs = _well_roxapi.import_well_roxapi( - project, - name, - trajectory=trajectory, - logrun=logrun, - lognames=lognames, - lognames_strict=lognames_strict, - inclmd=inclmd, - inclsurvey=inclsurvey, - ) - self._reset(**kwargs) - return self - @classmethod def _read_roxar( cls, diff --git a/src/xtgeo/well/wells.py b/src/xtgeo/well/wells.py index cac050e1c..86984f864 100644 --- a/src/xtgeo/well/wells.py +++ b/src/xtgeo/well/wells.py @@ -2,14 +2,9 @@ from __future__ import annotations -import functools -import warnings - -import deprecation import pandas as pd from xtgeo.common.log import null_logger -from xtgeo.common.version import __version__ from xtgeo.common.xtgeo_dialog import XTGDescription, XTGeoDialog from . import _wells_utils @@ -39,28 +34,6 @@ def wells_from_files(filelist, *args, **kwargs): return Wells([well_from_file(wfile, *args, **kwargs) for wfile in filelist]) -def _allow_deprecated_init(func): - # This decorator is here to maintain backwards compatibility in the construction - # of Wells and should be deleted once the deprecation period has expired, - # the construction will then follow the new pattern. - @functools.wraps(func) - def wrapper(cls, *args, **kwargs): - # Checking if we are doing an initialization - # from file and raise a deprecation warning if - # we are. - if args and args[0] and not isinstance(args[0][0], Well): - warnings.warn( - "Initializing directly from file name is deprecated and will be " - "removed in xtgeo version 4.0. Use: " - "mywells = xtgeo.wells_from_files(['some_name.w']) instead", - DeprecationWarning, - ) - return func(wells_from_files(*args, **kwargs)) - return func(cls, *args, **kwargs) - - return wrapper - - class Wells: """Class for a collection of Well objects, for operations that involves a number of wells. @@ -71,7 +44,6 @@ class Wells: wells: The list of Well objects. """ - @_allow_deprecated_init def __init__(self, wells: list[Well] = None): if wells is None: self._wells = [] @@ -139,44 +111,6 @@ def get_well(self, name): return well return None - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.wells_from_files() instead", - ) - def from_files( - self, - filelist, - fformat="rms_ascii", - mdlogname=None, - zonelogname=None, - strict=True, - append=True, - ): - """Deprecated see :func:`wells_from_files`""" - - if not append: - self._wells = [] - - # file checks are done within the Well() class - for wfile in filelist: - try: - self._wells.append( - well_from_file( - wfile, - fformat=fformat, - mdlogname=mdlogname, - zonelogname=zonelogname, - strict=strict, - ) - ) - except ValueError as err: - xtg.warn(f"SKIP this well: {err}") - continue - if not self._wells: - xtg.warn("No wells imported!") - # not having this as property but a get_ .. is intended, for flexibility def get_dataframe(self, filled=False, fill_value1=-999, fill_value2=-9999): """Get a big dataframe for all wells or blocked wells in instance, diff --git a/tests/test_well/test_well_deprecations.py b/tests/test_well/test_well_deprecations.py deleted file mode 100644 index e0449fa22..000000000 --- a/tests/test_well/test_well_deprecations.py +++ /dev/null @@ -1,53 +0,0 @@ -import pytest -import xtgeo -from packaging import version -from xtgeo import Well -from xtgeo.common.version import __version__ as xtgeo_version - - -@pytest.fixture(name="any_well") -def fixture_any_well(): - with pytest.warns(DeprecationWarning, match="empty"): - return Well() - - -@pytest.fixture(name="any_well_file") -def fixture_any_well_file(any_well, tmp_path): - any_well.to_file(tmp_path / "mywell.w") - return tmp_path / "mywell.w" - - -def test_default_well_warns(): - with pytest.warns(DeprecationWarning, match="default"): - Well() - - -def test_from_file_warns(any_well, tmp_path): - if version.parse(xtgeo_version) < version.parse("2.16"): - pytest.skip() - any_well.to_file(tmp_path / "mywell.w") - - with pytest.warns(DeprecationWarning, match="from_file is deprecated"): - any_well.from_file(tmp_path / "mywell.w") - - -def test_init_from_file_warns(any_well_file): - with pytest.warns(DeprecationWarning, match="from file"): - Well(any_well_file) - - -def test_blockedwell_init_from_file_warns(any_well_file): - with pytest.warns(DeprecationWarning, match="from file"): - xtgeo.BlockedWell(any_well_file) - - -def test_wells_init_warns(any_well_file): - with pytest.warns(DeprecationWarning, match="directly from file"): - xtgeo.Wells([any_well_file]) - - -def test_blockedwells_from_files_warns(any_well_file): - if version.parse(xtgeo_version) < version.parse("2.16"): - pytest.skip() - with pytest.warns(DeprecationWarning, match="from_files is deprecated"): - xtgeo.BlockedWells().from_files([any_well_file])