Skip to content

Commit

Permalink
BUG: Fix name=unknown backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Dec 1, 2021
1 parent 59f9b40 commit 9c31bd9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/xtgeo/grid3d/_gridprop_import_roff.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Importing grid props from ROFF, binary"""


import numpy as np
import warnings

import numpy as np
import xtgeo

from ._roff_parameter import RoffParameter
Expand All @@ -14,6 +15,15 @@

def import_roff(pfile, name=None, grid=None):
"""Import ROFF format"""

if name == "unknown":
warnings.warn(
"Using name='unknown' to select first property in roff file"
" is deprecated, use name=None instead",
DeprecationWarning,
)
name = None

result = dict()
roff_param = RoffParameter.from_file(pfile._file, name)
result["codes"] = roff_param.xtgeo_codes()
Expand Down
22 changes: 22 additions & 0 deletions tests/test_grid3d/test_grid_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Testing: test_grid_property"""


import io
import os
import pathlib

Expand Down Expand Up @@ -67,6 +68,27 @@ def test_create():
assert m.isdiscrete


@given(grid_properties())
def test_gridproperty_without_name(gridprop):
buf = io.BytesIO()
gridprop.to_file(buf, fformat="roff")

buf.seek(0)

gridprop2 = xtgeo.gridproperty_from_file(buf, fformat="roff")

assert gridprop2.name == gridprop.name
np.testing.assert_allclose(gridprop2.values, gridprop.values)

# deprecated name="unknown"
buf.seek(0)
with pytest.warns(DeprecationWarning, match="name='unknown'"):
gridprop3 = xtgeo.gridproperty_from_file(buf, name="unknown", fformat="roff")

assert gridprop3.name == gridprop.name
np.testing.assert_allclose(gridprop3.values, gridprop.values)


def test_banal7(show_plot):
"""Create a simple property in a small grid box"""

Expand Down

0 comments on commit 9c31bd9

Please sign in to comment.