Skip to content

Commit

Permalink
refactor: deprecate unused flopy.utils.binaryfile.binaryread_struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed May 30, 2024
1 parent 31955a7 commit 725b33d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions autotest/test_binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,20 @@ def test_read_mf6_budgetfile(example_data_path):
assert len(rch_zone_1) == 120 * 3 + 1
assert len(rch_zone_2) == 120 * 3 + 1
assert len(rch_zone_3) == 120 * 3 + 1


def test_deprecated_binaryread_struct(example_data_path):
pth = example_data_path / "freyberg" / "freyberg.githds"
with open(pth, "rb") as fp:
with pytest.deprecated_call():
res = flopy.utils.binaryfile.binaryread_struct(fp, np.int32, 2)
np.testing.assert_array_equal(res, np.array([1, 1], np.int32))
with pytest.deprecated_call():
res = flopy.utils.binaryfile.binaryread_struct(fp, np.float32, 2)
np.testing.assert_array_equal(res, np.array([10, 10], np.float32))
with pytest.deprecated_call():
res = flopy.utils.binaryfile.binaryread_struct(fp, str)
assert res == b" HEAD"
with pytest.deprecated_call():
res = flopy.utils.binaryfile.binaryread_struct(fp, np.int32)
assert res == 20
5 changes: 4 additions & 1 deletion flopy/utils/binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,13 @@ def binaryread_struct(file, vartype, shape=(1,), charlen=16):
cannot be returned, only multi-character strings. Shape has no
affect on strings.
.. deprecated:: 3.8.0
Use :py:mod:`struct` or other methods to read binary data.
"""
import struct

import numpy as np
warnings.warn("binaryread_struct() is deprecated", DeprecationWarning)

# store the mapping from type to struct format (fmt)
typefmtd = {np.int32: "i", np.float32: "f", np.float64: "d"}
Expand Down

0 comments on commit 725b33d

Please sign in to comment.