From 19a7988e3671970adf0c0a2e83b5b9efce94a9ac Mon Sep 17 00:00:00 2001 From: Ashish Bastola <41137160+abastola0@users.noreply.github.com> Date: Wed, 29 Nov 2023 00:30:29 -0500 Subject: [PATCH] CLN: Replace OrderedDict instances with dict --- bin/xtgls.py | 7 ++-- src/xtgeo/cube/_cube_import.py | 4 +-- src/xtgeo/grid3d/_grid_etc1.py | 5 ++- src/xtgeo/grid3d/_grid_import_xtgcpgeom.py | 19 +++++----- src/xtgeo/grid3d/_grid_refine.py | 9 +++-- src/xtgeo/grid3d/_grid_roxapi.py | 5 ++- src/xtgeo/grid3d/_gridprop_import_roff.py | 2 +- .../grid3d/_gridprop_import_xtgcpprop.py | 3 +- src/xtgeo/grid3d/_roff_grid.py | 6 ++-- src/xtgeo/grid3d/grid.py | 36 +++++++++---------- src/xtgeo/metadata/metadata.py | 24 ++++++------- src/xtgeo/plot/xsection.py | 3 +- src/xtgeo/surface/_regsurf_import.py | 5 ++- src/xtgeo/surface/regular_surface.py | 3 +- src/xtgeo/well/_well_io.py | 9 +++-- src/xtgeo/well/_wellmarkers.py | 6 ++-- src/xtgeo/xyz/_xyz_io.py | 3 +- src/xtgeo/xyz/points.py | 3 +- tests/test_grid3d/test_grid.py | 9 +++-- tests/test_grid3d/test_grid_operations.py | 17 ++++----- tests/test_grid3d/test_grid_roff.py | 15 ++++---- tests/test_grid3d/test_grid_xtgformats_io.py | 5 ++- tests/test_roxarapi/test_roxarapi_reek.py | 3 +- tests/test_well/test_well_hdf5.py | 8 ++--- tests/test_xyz/test_polygon.py | 3 +- 25 files changed, 90 insertions(+), 122 deletions(-) diff --git a/bin/xtgls.py b/bin/xtgls.py index f146ca45f..30f3effae 100644 --- a/bin/xtgls.py +++ b/bin/xtgls.py @@ -4,7 +4,6 @@ import pathlib # import yaml -from collections import OrderedDict from struct import unpack VALIDEXT = [".xtgregsurf", ".xtgregcube", ".xtgcpgeom"] @@ -25,7 +24,7 @@ def extract_meta_regsurf(fil): with open(fil, "rb") as fhandle: fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) return meta @@ -44,7 +43,7 @@ def extract_meta_regcube(fil): with open(fil, "rb") as fhandle: fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) return meta @@ -70,7 +69,7 @@ def extract_meta_cpgeom(fil): with open(fil, "rb") as fhandle: fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) return meta diff --git a/src/xtgeo/cube/_cube_import.py b/src/xtgeo/cube/_cube_import.py index 1a2576959..9069537f1 100644 --- a/src/xtgeo/cube/_cube_import.py +++ b/src/xtgeo/cube/_cube_import.py @@ -29,7 +29,7 @@ from __future__ import annotations import json -from collections import OrderedDict, defaultdict +from collections import defaultdict from copy import deepcopy from struct import unpack from warnings import warn @@ -596,7 +596,7 @@ def import_xtgregcube(mfile, values=True): fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) req = meta["_required_"] reqattrs = xtgeo.MetaDataRegularCube.REQUIRED diff --git a/src/xtgeo/grid3d/_grid_etc1.py b/src/xtgeo/grid3d/_grid_etc1.py index de4ae6b47..5a68d77fb 100644 --- a/src/xtgeo/grid3d/_grid_etc1.py +++ b/src/xtgeo/grid3d/_grid_etc1.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections import OrderedDict from copy import deepcopy from math import atan2, degrees @@ -350,7 +349,7 @@ def get_ijk_from_points( jarr -= 1 karr -= 1 - proplist = OrderedDict() + proplist = dict() if includepoints: proplist["X_UTME"] = points.dataframe[points.xname].values proplist["Y_UTME"] = points.dataframe[points.yname].values @@ -1066,7 +1065,7 @@ def crop(self, spec, props=None): # pylint: disable=too-many-locals self._nlay = nnlay if isinstance(self.subgrids, dict): - newsub = OrderedDict() + newsub = dict() # easier to work with numpies than lists newarr = np.array(range(1, oldnlay + 1)) newarr[newarr < kc1] = 0 diff --git a/src/xtgeo/grid3d/_grid_import_xtgcpgeom.py b/src/xtgeo/grid3d/_grid_import_xtgcpgeom.py index 449bc3905..793f0ceb5 100644 --- a/src/xtgeo/grid3d/_grid_import_xtgcpgeom.py +++ b/src/xtgeo/grid3d/_grid_import_xtgcpgeom.py @@ -2,7 +2,6 @@ """Private module, Grid Import private functions for xtgeo based formats.""" import json -from collections import OrderedDict from struct import unpack import h5py @@ -21,16 +20,16 @@ def convert_subgrids(sdict): The simplified dictionary is on the form {"name1": 3, "name2": 5} - Note that the input must be an OrderedDict! + Note that the input must be an dict! """ if sdict is None: return None - if not isinstance(sdict, OrderedDict): - raise ValueError("Input sdict is not an OrderedDict") + if not isinstance(sdict, dict): + raise ValueError("Input sdict is not an dict") - newsub = OrderedDict() + newsub = dict() inn1 = 1 for name, nsub in sdict.items(): @@ -124,7 +123,7 @@ def import_xtgcpgeom( fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) handle_metadata(result, meta, ncol, nrow, nlay) return result @@ -143,7 +142,7 @@ def import_hdf5_cpgeom(mfile, ijkrange=None, zerobased=False): logger.info("Provider is %s", provider) jmeta = grp.attrs["metadata"] - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) req = meta["_required_"] ncol = req["ncol"] @@ -187,10 +186,10 @@ def filter_subgrids_partial(subgrids, k1, k2, nlay, zerobased): ... 12, ... True ... ) - OrderedDict([('subgrid2', 1), ('subgrid3', 1)]) + dict([('subgrid2', 1), ('subgrid3', 1)]) Args: - subgrids: The OrderedDict of subgrids. + subgrids: The dict of subgrids. k1: Start of subgrid layers (can be "min" to mean 0 or 1 dependent on zerobased) k2: End of subgrid layers (cna be "max" to mean nlay or nlay -1 dependent on zerobased. @@ -213,7 +212,7 @@ def filter_subgrids_partial(subgrids, k1, k2, nlay, zerobased): k1 -= 1 k2 -= 1 - partial_subgrid = OrderedDict() + partial_subgrid = dict() start = 0 for key, value in subgrids.items(): end = value + start diff --git a/src/xtgeo/grid3d/_grid_refine.py b/src/xtgeo/grid3d/_grid_refine.py index 8b55798ac..196f9fac6 100644 --- a/src/xtgeo/grid3d/_grid_refine.py +++ b/src/xtgeo/grid3d/_grid_refine.py @@ -1,7 +1,6 @@ """Private module for refinement of a grid.""" from __future__ import annotations -from collections import OrderedDict from typing import TYPE_CHECKING import numpy as np @@ -30,7 +29,7 @@ def refine_vertically( """ self._xtgformat1() - rfactord = OrderedDict() + rfactord = dict() # case 1 rfactor as scalar value. if isinstance(rfactor, int): @@ -40,12 +39,12 @@ def refine_vertically( rfactord[i + 1] = rfactor else: rfactord[0] = rfactor - subgrids = OrderedDict() + subgrids = dict() subgrids[1] = self.nlay # case 2 rfactor is a dict else: - rfactord = OrderedDict(sorted(rfactor.items())) # redefined to ordered + rfactord = dict(sorted(rfactor.items())) # redefined to ordered # 2a: zoneprop is present if zoneprop is not None: oldsubgrids = None @@ -76,7 +75,7 @@ def refine_vertically( self.set_subgrids(subgrids) # Now, based on dict, give a value per subgrid for key, val in rfactor - newsubgrids = OrderedDict() + newsubgrids = dict() newnlay = 0 for (_x, rfi), (snam, sran) in zip(rfactord.items(), subgrids.items()): newsubgrids[snam] = sran * rfi diff --git a/src/xtgeo/grid3d/_grid_roxapi.py b/src/xtgeo/grid3d/_grid_roxapi.py index 3ca1dc205..c60c7b93d 100644 --- a/src/xtgeo/grid3d/_grid_roxapi.py +++ b/src/xtgeo/grid3d/_grid_roxapi.py @@ -2,7 +2,6 @@ """Roxar API functions for XTGeo Grid Geometry.""" import os import tempfile -from collections import OrderedDict import numpy as np @@ -188,7 +187,7 @@ def _convert_to_xtgeo_grid_v1(rox, roxgrid, corners, gname): # pragma: no cover # subgrids if len(indexer.zonation) > 1: logger.debug("Zonation length (N subzones) is %s", len(indexer.zonation)) - subz = OrderedDict() + subz = dict() for inum, zrange in indexer.zonation.items(): logger.debug("inum: %s, zrange: %s", inum, zrange) zname = roxgrid.zone_names[inum] @@ -278,7 +277,7 @@ def _convert_to_xtgeo_grid_v2(roxgrid, gname): # subgrids if len(indexer.zonation) > 1: logger.debug("Zonation length (N subzones) is %s", len(indexer.zonation)) - subz = OrderedDict() + subz = dict() for inum, zrange in indexer.zonation.items(): logger.debug("inum: %s, zrange: %s", inum, zrange) zname = roxgrid.zone_names[inum] diff --git a/src/xtgeo/grid3d/_gridprop_import_roff.py b/src/xtgeo/grid3d/_gridprop_import_roff.py index a044f2cfd..526b6c345 100644 --- a/src/xtgeo/grid3d/_gridprop_import_roff.py +++ b/src/xtgeo/grid3d/_gridprop_import_roff.py @@ -33,7 +33,7 @@ def import_roff( ) name = None - result: dict[str, Any]= 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 diff --git a/src/xtgeo/grid3d/_gridprop_import_xtgcpprop.py b/src/xtgeo/grid3d/_gridprop_import_xtgcpprop.py index 2286a19f7..f44731acb 100644 --- a/src/xtgeo/grid3d/_gridprop_import_xtgcpprop.py +++ b/src/xtgeo/grid3d/_gridprop_import_xtgcpprop.py @@ -1,7 +1,6 @@ """GridProperty import function of xtgcpprop format.""" import json -from collections import OrderedDict from struct import unpack import numpy as np @@ -58,7 +57,7 @@ def import_xtgcpprop(mfile, ijrange=None, zerobased=False): fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) req = meta["_required_"] reqattrs = xtgeo.MetaDataCPProperty.REQUIRED diff --git a/src/xtgeo/grid3d/_roff_grid.py b/src/xtgeo/grid3d/_roff_grid.py index 089dd29f9..5d6fc8364 100644 --- a/src/xtgeo/grid3d/_roff_grid.py +++ b/src/xtgeo/grid3d/_roff_grid.py @@ -1,7 +1,7 @@ from __future__ import annotations import pathlib -from collections import OrderedDict, defaultdict +from collections import defaultdict from collections.abc import MutableMapping, Sequence from dataclasses import dataclass from typing import IO, TYPE_CHECKING, Any @@ -284,14 +284,14 @@ def xtgeo_zcorn(self) -> np.ndarray: else: raise ValueError(f"Unknown error {retval} occurred") - def xtgeo_subgrids(self) -> OrderedDict[str, range] | None: + def xtgeo_subgrids(self) -> dict[str, range] | None: """ Returns: The z values for nodes in the format of xtgeo.Grid.zcornsv """ if self.subgrids is None: return None - result = OrderedDict() + result = dict() next_ind = 1 for i, current in enumerate(self.subgrids): result[f"subgrid_{i}"] = range(next_ind, current + next_ind) diff --git a/src/xtgeo/grid3d/grid.py b/src/xtgeo/grid3d/grid.py index 6c26de890..4237b97a9 100644 --- a/src/xtgeo/grid3d/grid.py +++ b/src/xtgeo/grid3d/grid.py @@ -5,7 +5,6 @@ import json import pathlib import warnings -from collections import OrderedDict from collections.abc import Callable, Hashable, Sequence from typing import TYPE_CHECKING, Any, Literal, NoReturn @@ -384,7 +383,7 @@ def __init__( actnumsv: np.ndarray, dualporo: bool = False, dualperm: bool = False, - subgrids: OrderedDict | None = None, + subgrids: dict | None = None, units: Units | None = None, filesrc: pathlib.Path | str | None = None, props: GridProperties | None = None, @@ -450,7 +449,7 @@ def _reset( actnumsv: np.ndarray, dualporo: bool = False, dualperm: bool = False, - subgrids: OrderedDict[str, range | list[int]] | None = None, + subgrids: dict[str, range | list[int]] | None = None, units: Units | None = None, filesrc: pathlib.Path | str | None = None, props: GridProperties | None = None, @@ -591,7 +590,7 @@ def ijk_handedness(self, value: Literal["left", "right"]) -> None: self._ijk_handedness = value @property - def subgrids(self) -> OrderedDict[str, range | list[int]] | None: + def subgrids(self) -> dict[str, range | list[int]] | None: """:obj:`list` of :obj:`int`: A dict with subgrid name and an array as value. I.e. a dict on the form ``{"name1": [1, 2, 3, 4], "name2": [5, 6, 7], @@ -615,13 +614,13 @@ def subgrids(self) -> OrderedDict[str, range | list[int]] | None: @subgrids.setter def subgrids( self, - sgrids: OrderedDict[str, range | list[int]] | None, + sgrids: dict[str, range | list[int]] | None, ) -> None: if sgrids is None: self._subgrids = None return - if not isinstance(sgrids, OrderedDict): + if not isinstance(sgrids, dict): raise ValueError("Input to subgrids must be an ordered dictionary") lengths = 0 @@ -1374,22 +1373,22 @@ def append_prop(self, prop: GridProperty) -> None: self._props.append_props([prop]) - def set_subgrids(self, sdict: OrderedDict[str, int] | None) -> None: + def set_subgrids(self, sdict: dict[str, int] | None) -> None: """Set the subgrid from a simplified ordered dictionary. The simplified dictionary is on the form {"name1": 3, "name2": 5} - Note that the input must be an OrderedDict! + Note that the input must be an dict! """ if sdict is None: return None - if not isinstance(sdict, OrderedDict): - raise ValueError("Input sdict is not an OrderedDict") + if not isinstance(sdict, dict): + raise ValueError("Input sdict is not an dict") - newsub: OrderedDict[str, range | list[int]] = OrderedDict() + newsub: dict[str, range | list[int]] = dict() inn1 = 1 for name, nsub in sdict.items(): @@ -1399,7 +1398,7 @@ def set_subgrids(self, sdict: OrderedDict[str, int] | None) -> None: self.subgrids = newsub - def get_subgrids(self) -> OrderedDict[str, int] | None: + def get_subgrids(self) -> dict[str, int] | None: """Get the subgrids on a simplified ordered dictionary. The simplified dictionary is on the form {"name1": 3, "name2": 5} @@ -1407,7 +1406,7 @@ def get_subgrids(self) -> OrderedDict[str, int] | None: if not self.subgrids: return None - return OrderedDict((name, len(subb)) for name, subb in self.subgrids.items()) + return dict((name, len(subb)) for name, subb in self.subgrids.items()) def rename_subgrids(self, names: list[str] | tuple[str, ...]) -> None: """Rename the names in the subgrids with the new names. @@ -1419,9 +1418,8 @@ def rename_subgrids(self, names: list[str] | tuple[str, ...]) -> None: Example:: - >>> from collections import OrderedDict >>> grd = create_box_grid((3, 3, 3)) - >>> grd.subgrids = OrderedDict( + >>> grd.subgrids = dict( ... [("1", range(1,2)), ("2", range(2,3)), ("3", range(3,4))] ... ) >>> grd.rename_subgrids(["Inky", "Tinky", "Pinky"]) @@ -1473,7 +1471,7 @@ def estimate_design( >>> import xtgeo >>> grd = xtgeo.grid_from_file(emerald_dir + "/emerald_hetero_grid.roff") >>> print(grd.subgrids) - OrderedDict([('subgrid_0', range(1, 17)), ('subgrid_1', range(17, 47))]) + dict([('subgrid_0', range(1, 17)), ('subgrid_1', range(17, 47))]) >>> res = grd.estimate_design(nsub="subgrid_0") >>> print("Subgrid design is", res["design"]) Subgrid design is P @@ -1519,9 +1517,7 @@ def estimate_flip(self) -> Literal[1, -1]: """ return _grid_etc1.estimate_flip(self) - def subgrids_from_zoneprop( - self, zoneprop: GridProperty - ) -> OrderedDict[str, int] | None: + def subgrids_from_zoneprop(self, zoneprop: GridProperty) -> dict[str, int] | None: """Estimate subgrid index from a zone property. The new will esimate which will replace the current if any. @@ -1539,7 +1535,7 @@ def subgrids_from_zoneprop( minzone = int(zprval.min()) maxzone = int(zprval.max()) - newd: OrderedDict[str, range] = OrderedDict() + newd: dict[str, range] = dict() for izone in range(minzone, maxzone + 1): mininzn = int(kval[zprval == izone].min()) # 1 base maxinzn = int(kval[zprval == izone].max()) # 1 base diff --git a/src/xtgeo/metadata/metadata.py b/src/xtgeo/metadata/metadata.py index 9644889b3..c0fb4d479 100644 --- a/src/xtgeo/metadata/metadata.py +++ b/src/xtgeo/metadata/metadata.py @@ -6,12 +6,10 @@ >>> import xtgeo >>> surf = xtgeo.surface_from_file(surface_dir + "/topreek_rota.gri") >>> surf.metadata.required - OrderedDict([('ncol', 554),... + dict([('ncol', 554),... >>> surf.metadata.optional.mean = surf.values.mean() """ -# import datetime -from collections import OrderedDict # from datetime import date import xtgeo @@ -131,8 +129,8 @@ def md5sum(self, newhash): self._md5sum = newhash def get_meta(self): - """Return metadata as an OrderedDict.""" - meta = OrderedDict() + """Return metadata as an dict.""" + meta = dict() for key in self.__slots__: newkey = key[1:] meta[newkey] = getattr(self, key) @@ -145,15 +143,15 @@ class MetaData: def __init__(self): """Generic metadata class __init__, not be used directly.""" - self._required = OrderedDict() + self._required = dict() self._optional = _OptionalMetaData() - self._freeform = OrderedDict() + self._freeform = dict() self._freeform = {"smda": "whatever"} def get_metadata(self): """Get all metadata that are present.""" - allmeta = OrderedDict() + allmeta = dict() allmeta["_required_"] = self._required allmeta["_optional_"] = self._optional.get_meta() allmeta["_freeform_"] = self._freeform @@ -229,7 +227,7 @@ def generate_fmu_name(self): class MetaDataRegularSurface(MetaData): """Metadata for RegularSurface() objects.""" - REQUIRED = OrderedDict( + REQUIRED = dict( [ ("ncol", 1), ("nrow", 1), @@ -274,7 +272,7 @@ class MetaDataRegularCube(MetaData): """Metadata for Cube() objects.""" # allowed optional keys; these are set to avoid discussions - REQUIRED = OrderedDict( + REQUIRED = dict( [ ("ncol", 1), ("nrow", 1), @@ -326,7 +324,7 @@ def required(self, obj): class MetaDataCPGeometry(MetaData): """Metadata for Grid() objects of type simplified CornerPoint Geometry.""" - REQUIRED = OrderedDict( + REQUIRED = dict( [ ("ncol", 1), ("nrow", 1), @@ -371,7 +369,7 @@ def required(self, obj): class MetaDataCPProperty(MetaData): """Metadata for GridProperty() objects belonging to CPGeometry.""" - REQUIRED = OrderedDict( + REQUIRED = dict( [ ("ncol", 1), ("nrow", 1), @@ -407,7 +405,7 @@ def required(self, obj): class MetaDataWell(MetaData): """Metadata for single Well() objects.""" - REQUIRED = OrderedDict( + REQUIRED = dict( [ ("rkb", 0.0), ("xpos", 0.0), diff --git a/src/xtgeo/plot/xsection.py b/src/xtgeo/plot/xsection.py index 8946cc900..ed071abe9 100644 --- a/src/xtgeo/plot/xsection.py +++ b/src/xtgeo/plot/xsection.py @@ -3,7 +3,6 @@ import math import warnings -from collections import OrderedDict import numpy as np import numpy.ma as ma @@ -277,7 +276,7 @@ def canvas(self, title=None, subtitle=None, infotext=None, figscaling=1.0): # self._fig, (ax1, ax2) = plt.subplots(2, figsize=(11.69, 8.27)) self._fig, _ = plt.subplots(figsize=(11.69 * figscaling, 8.27 * figscaling)) self._allfigs.append(self._fig) - ax1 = OrderedDict() + ax1 = dict() # since the plan is to at some point remove plotting from xtgeo: warnings.filterwarnings("ignore", category=DeprecationWarning) diff --git a/src/xtgeo/surface/_regsurf_import.py b/src/xtgeo/surface/_regsurf_import.py index 63e93aab5..88534a40e 100644 --- a/src/xtgeo/surface/_regsurf_import.py +++ b/src/xtgeo/surface/_regsurf_import.py @@ -2,7 +2,6 @@ # pylint: disable=protected-access import json -from collections import OrderedDict from struct import unpack import h5py @@ -484,7 +483,7 @@ def import_xtg(mfile, values=True, **kwargs): fhandle.seek(pos) jmeta = fhandle.read().decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) req = meta["_required_"] reqattrs = xtgeo.MetaDataRegularSurface.REQUIRED @@ -518,7 +517,7 @@ def import_hdf5_regsurf(mfile, values=True, **_): invalues = grp["values"][:] jmeta = grp.attrs["metadata"] - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) req = meta["_required_"] diff --git a/src/xtgeo/surface/regular_surface.py b/src/xtgeo/surface/regular_surface.py index 810348dc2..7a1fcd884 100644 --- a/src/xtgeo/surface/regular_surface.py +++ b/src/xtgeo/surface/regular_surface.py @@ -40,7 +40,6 @@ import numbers import pathlib import warnings -from collections import OrderedDict from copy import deepcopy from types import FunctionType from typing import Dict, List, Literal, Optional, Tuple, Type, Union @@ -1957,7 +1956,7 @@ def get_dataframe( order=order, activeonly=activeonly, fill_value=fill_value ) - entry = OrderedDict() + entry = dict() if ijcolumns or ij: ixn, jyn = self.get_ij_values1d(order=order, activeonly=activeonly) diff --git a/src/xtgeo/well/_well_io.py b/src/xtgeo/well/_well_io.py index a502b802d..28b1bd875 100644 --- a/src/xtgeo/well/_well_io.py +++ b/src/xtgeo/well/_well_io.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """Well input and ouput, private module""" import json -from collections import OrderedDict from copy import deepcopy import numpy as np @@ -272,14 +271,14 @@ def export_hdf5_well(self, wfile, compression="lzf"): logger.debug("Export to hdf5 format... done!") -def import_wlogs(wlogs: OrderedDict): +def import_wlogs(wlogs: dict): """ This converts joined wlogtypes/wlogrecords such as found in the hdf5 format to the format used in the Well object. - >>> import_wlogs(OrderedDict()) + >>> import_wlogs(dict()) {'wlogtypes': {}, 'wlogrecords': {}} - >>> import_wlogs(OrderedDict([("X_UTME", ("CONT", None))])) + >>> import_wlogs(dict([("X_UTME", ("CONT", None))])) {'wlogtypes': {'X_UTME': 'CONT'}, 'wlogrecords': {'X_UTME': None}} Returns: @@ -318,7 +317,7 @@ def import_hdf5_well(wfile, **kwargs): if isinstance(jmeta, bytes): jmeta = jmeta.decode() - meta = json.loads(jmeta, object_pairs_hook=OrderedDict) + meta = json.loads(jmeta, object_pairs_hook=dict) req = meta["_required_"] result = dict() for myattr in reqattrs: diff --git a/src/xtgeo/well/_wellmarkers.py b/src/xtgeo/well/_wellmarkers.py index d4c695060..5a064777e 100644 --- a/src/xtgeo/well/_wellmarkers.py +++ b/src/xtgeo/well/_wellmarkers.py @@ -2,8 +2,6 @@ """Well marker data; private module""" -from collections import OrderedDict - import numpy as np import pandas as pd @@ -354,7 +352,7 @@ def get_fraction_per_zone( else: self.geometrics() - result = OrderedDict() + result = dict() result[self.xname] = [] result[self.yname] = [] result["DFRAC"] = [] @@ -458,7 +456,7 @@ def get_surface_picks(self, surf): mres[mres > xtgeo.UNDEF_LIMIT] = np.nan - res = OrderedDict() + res = dict() res[poi.xname] = xres[:nval] res[poi.yname] = yres[:nval] res[poi.zname] = zres[:nval] diff --git a/src/xtgeo/xyz/_xyz_io.py b/src/xtgeo/xyz/_xyz_io.py index 75a8b82dc..bccadf140 100644 --- a/src/xtgeo/xyz/_xyz_io.py +++ b/src/xtgeo/xyz/_xyz_io.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """Private import and export routines for XYZ stuff.""" -from collections import OrderedDict import numpy as np import pandas as pd @@ -120,7 +119,7 @@ def import_rms_attr(pfile, zname="Z_TVDSS"): dtypes = {_xn: np.float64, _yn: np.float64, _zn: np.float64} names = list(dtypes.keys()) - _attrs = OrderedDict() + _attrs = dict() # parse header skiprows = 0 diff --git a/src/xtgeo/xyz/points.py b/src/xtgeo/xyz/points.py index 10b2f6940..3eb11525b 100644 --- a/src/xtgeo/xyz/points.py +++ b/src/xtgeo/xyz/points.py @@ -5,7 +5,6 @@ import io import pathlib import warnings -from collections import OrderedDict from copy import deepcopy from typing import Any @@ -691,7 +690,7 @@ def from_dataframe(self, dfr, east="X", north="Y", tvdmsl="Z", attributes=None): if attributes and not all(item in dfr.columns for item in attributes.values()): raise ValueError("One or more attribute column names are not correct") - input_ = OrderedDict() + input_ = dict() input_["X_UTME"] = dfr[east] input_["Y_UTMN"] = dfr[north] input_["Z_TVDSS"] = dfr[tvdmsl] diff --git a/tests/test_grid3d/test_grid.py b/tests/test_grid3d/test_grid.py index 6bb4ea6ef..2d4a12753 100644 --- a/tests/test_grid3d/test_grid.py +++ b/tests/test_grid3d/test_grid.py @@ -1,7 +1,6 @@ """Tests for 3D grid.""" import math import warnings -from collections import OrderedDict from os.path import join import numpy as np @@ -176,7 +175,7 @@ def test_roffbin_get_dataframe_for_grid(emerald_grid): def test_subgrids(): grd = xtgeo.create_box_grid((10, 10, 46)) - newsub = OrderedDict() + newsub = dict() newsub["XX1"] = 20 newsub["XX2"] = 2 newsub["XX3"] = 24 @@ -260,7 +259,7 @@ def run(): def test_roffbin_import_wsubgrids(): - assert xtgeo.grid_from_file(REEKFIL5).subgrids == OrderedDict( + assert xtgeo.grid_from_file(REEKFIL5).subgrids == dict( [ ("subgrid_0", range(1, 21)), ("subgrid_1", range(21, 41)), @@ -695,7 +694,7 @@ def test_grid_get_dxdydz_bad_metric(): def test_grid_roff_subgrids_import_regression(tmp_path): grid = xtgeo.create_box_grid(dimension=(5, 5, 67)) - grid.subgrids = OrderedDict( + grid.subgrids = dict( [ ("subgrid_0", list(range(1, 21))), ("subgrid_1", list(range(21, 53))), @@ -705,7 +704,7 @@ def test_grid_roff_subgrids_import_regression(tmp_path): grid.to_file(tmp_path / "grid.roff") grid2 = xtgeo.grid_from_file(tmp_path / "grid.roff") - assert grid2.subgrids == OrderedDict( + assert grid2.subgrids == dict( [ ("subgrid_0", range(1, 21)), ("subgrid_1", range(21, 53)), diff --git a/tests/test_grid3d/test_grid_operations.py b/tests/test_grid3d/test_grid_operations.py index 9f64eb7d0..67c6197b0 100644 --- a/tests/test_grid3d/test_grid_operations.py +++ b/tests/test_grid3d/test_grid_operations.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- """Testing: test_grid_operations""" -from collections import OrderedDict from os.path import join import pytest @@ -44,7 +43,7 @@ def test_hybridgrid1(tmpdir, snapshot, helpers): rotation=30.0, increment=(100, 150, 5), ) - grd.subgrids = OrderedDict({"name1": [1], "name2": [2, 3], "name3": [4, 5]}) + grd.subgrids = dict({"name1": [1], "name2": [2, 3], "name3": [4, 5]}) assert grd.subgrids is not None # initially, prior to subgrids grd.to_file(join(tmpdir, "test_hybridgrid1_asis.bgrdecl"), fformat="bgrdecl") @@ -112,9 +111,7 @@ def test_refine_vertically(): """Do a grid refinement vertically.""" emerald_grid = xtgeo.grid_from_file(EMEGFILE) - assert emerald_grid.get_subgrids() == OrderedDict( - [("subgrid_0", 16), ("subgrid_1", 30)] - ) + assert emerald_grid.get_subgrids() == dict([("subgrid_0", 16), ("subgrid_1", 30)]) avg_dz1 = emerald_grid.get_dz().values3d.mean() @@ -125,9 +122,7 @@ def test_refine_vertically(): assert avg_dz1 == pytest.approx(3 * avg_dz2, abs=0.0001) - assert emerald_grid.get_subgrids() == OrderedDict( - [("subgrid_0", 48), ("subgrid_1", 90)] - ) + assert emerald_grid.get_subgrids() == dict([("subgrid_0", 48), ("subgrid_1", 90)]) emerald_grid.inactivate_by_dz(0.001) @@ -141,19 +136,19 @@ def test_refine_vertically_per_zone(tmpdir): assert emerald2_zone.values.min() == 1 assert emerald2_zone.values.max() == 2 - assert grd.subgrids == OrderedDict( + assert grd.subgrids == dict( [("subgrid_0", range(1, 17)), ("subgrid_1", range(17, 47))] ) refinement = {1: 4, 2: 2} grd.refine_vertically(refinement, zoneprop=emerald2_zone) - assert grd.get_subgrids() == OrderedDict([("zone1", 64), ("zone2", 60)]) + assert grd.get_subgrids() == dict([("zone1", 64), ("zone2", 60)]) grd = emerald2_grid.copy() grd.refine_vertically(refinement) # no zoneprop - assert grd.get_subgrids() == OrderedDict([("subgrid_0", 64), ("subgrid_1", 60)]) + assert grd.get_subgrids() == dict([("subgrid_0", 64), ("subgrid_1", 60)]) def test_reverse_row_axis_box(tmpdir): diff --git a/tests/test_grid3d/test_grid_roff.py b/tests/test_grid3d/test_grid_roff.py index 80491c494..46fff9e3c 100644 --- a/tests/test_grid3d/test_grid_roff.py +++ b/tests/test_grid3d/test_grid_roff.py @@ -1,6 +1,5 @@ import io import re -from collections import OrderedDict from itertools import product import hypothesis.strategies as st @@ -305,19 +304,19 @@ def test_eq_transitivity(roff_grid1, roff_grid2, roff_grid3): def test_from_xtgeo_subgrids(): - assert list(RoffGrid._from_xtgeo_subgrids(OrderedDict())) == [] - assert list( - RoffGrid._from_xtgeo_subgrids(OrderedDict([("subgrid_0", range(1, 2))])) - ) == [1] - assert list(RoffGrid._from_xtgeo_subgrids(OrderedDict([("subgrid_0", [1])]))) == [1] + assert list(RoffGrid._from_xtgeo_subgrids(dict())) == [] + assert list(RoffGrid._from_xtgeo_subgrids(dict([("subgrid_0", range(1, 2))]))) == [ + 1 + ] + assert list(RoffGrid._from_xtgeo_subgrids(dict([("subgrid_0", [1])]))) == [1] assert list( RoffGrid._from_xtgeo_subgrids( - OrderedDict([("subgrid_0", [1, 2, 3]), ("subgrid_1", [4])]) + dict([("subgrid_0", [1, 2, 3]), ("subgrid_1", [4])]) ) ) == [3, 1] assert list( RoffGrid._from_xtgeo_subgrids( - OrderedDict([("subgrid_0", range(1, 4)), ("subgrid_1", range(4, 5))]) + dict([("subgrid_0", range(1, 4)), ("subgrid_1", range(4, 5))]) ) ) == [3, 1] diff --git a/tests/test_grid3d/test_grid_xtgformats_io.py b/tests/test_grid3d/test_grid_xtgformats_io.py index 96318e529..0813f1aa6 100644 --- a/tests/test_grid3d/test_grid_xtgformats_io.py +++ b/tests/test_grid3d/test_grid_xtgformats_io.py @@ -1,6 +1,5 @@ # coding: utf-8 """Testing new xtgf and hdf5/h5 formats.""" -from collections import OrderedDict from os.path import join import hypothesis.strategies as st @@ -455,9 +454,9 @@ def test_hdf5_import(benchmark_grid, tmp_path): benchmark_grid._zcornsv += 1.0 nlay = benchmark_grid.nlay - benchmark_grid._subgrids = OrderedDict({"1": range(1, nlay + 1)}) + benchmark_grid._subgrids = dict({"1": range(1, nlay + 1)}) fna = benchmark_grid.to_hdf(fname, compression="blosc") grd2 = xtgeo.grid_from_file(fna, fformat="hdf") - assert grd2._subgrids == OrderedDict({"1": range(1, nlay + 1)}) + assert grd2._subgrids == dict({"1": range(1, nlay + 1)}) diff --git a/tests/test_roxarapi/test_roxarapi_reek.py b/tests/test_roxarapi/test_roxarapi_reek.py index 67547c86b..eb82ea833 100644 --- a/tests/test_roxarapi/test_roxarapi_reek.py +++ b/tests/test_roxarapi/test_roxarapi_reek.py @@ -8,7 +8,6 @@ This requires a ROXAPI license, and to be ran in a "roxenvbash" environment if Equinor. """ -from collections import OrderedDict from os.path import join import numpy as np @@ -313,7 +312,7 @@ def test_rox_get_modify_set_get_grid_with_subzones(roxar_project, roxinstance): grd = xtgeo.grid_from_roxar(roxar_project, GRIDNAME1) - zonation = OrderedDict() + zonation = dict() zonation["intva"] = 4 zonation["intvb"] = 7 zonation["intvc"] = 3 diff --git a/tests/test_well/test_well_hdf5.py b/tests/test_well/test_well_hdf5.py index 7e19f5ffa..24ea9e921 100644 --- a/tests/test_well/test_well_hdf5.py +++ b/tests/test_well/test_well_hdf5.py @@ -1,5 +1,3 @@ -from collections import OrderedDict - import pytest from xtgeo.well._well_io import import_wlogs @@ -8,13 +6,13 @@ @pytest.mark.parametrize( "wlogs, expected_output", [ - (OrderedDict(), {"wlogtypes": {}, "wlogrecords": {}}), + (dict(), {"wlogtypes": {}, "wlogrecords": {}}), ( - OrderedDict([("X_UTME", ("CONT", None))]), + dict([("X_UTME", ("CONT", None))]), {"wlogtypes": {"X_UTME": "CONT"}, "wlogrecords": {"X_UTME": None}}, ), ( - OrderedDict([("ZONELOG", ("DISC", {"0": "ZONE00"}))]), + dict([("ZONELOG", ("DISC", {"0": "ZONE00"}))]), { "wlogtypes": {"ZONELOG": "DISC"}, "wlogrecords": {"ZONELOG": {"0": "ZONE00"}}, diff --git a/tests/test_xyz/test_polygon.py b/tests/test_xyz/test_polygon.py index d33952dea..d3bc833bd 100644 --- a/tests/test_xyz/test_polygon.py +++ b/tests/test_xyz/test_polygon.py @@ -1,5 +1,4 @@ import pathlib -from collections import OrderedDict import numpy as np import pandas as pd @@ -61,7 +60,7 @@ def test_polygons_from_list_and_attrs(): (235, 559, 14, 1, "attr", 1.1), (255, 577, 12, 1, "here", 1.2), ] - attrs = OrderedDict() + attrs = dict() attrs["sometxt"] = "str" attrs["somefloat"] = "float"