Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dc11bb6
add required_z parameters, and if statement to handle missing z vector
yohaimagen Sep 1, 2021
df1b0d5
add required_z parameters and pass it to data_kind
yohaimagen Sep 1, 2021
1b7a8a6
test requierd_z
yohaimagen Sep 2, 2021
e471f9e
Update pygmt/helpers/utils.py
yohaimagen Sep 3, 2021
11d98ee
Update pygmt/helpers/utils.py
yohaimagen Sep 3, 2021
bcfc03a
Update pygmt/helpers/utils.py
yohaimagen Sep 3, 2021
ba73d5b
checks that when required z data matrix has at least 3 columns
yohaimagen Sep 3, 2021
ed1419d
[format-command] fixes
actions-bot Sep 3, 2021
166b439
add required_z=True to _blockm
yohaimagen Sep 3, 2021
7675449
add required_z=True to contour
yohaimagen Sep 3, 2021
09c68cd
add required_z=True to plot3d
yohaimagen Sep 3, 2021
8b3eeb2
add required_z=True to surface
yohaimagen Sep 3, 2021
2a77656
reformat
yohaimagen Sep 3, 2021
e1d8248
remove unnecessary import
yohaimagen Sep 3, 2021
15a5bf2
Merge branch 'main' into raise_GMTInvalidInput_exception_when_z_missing
yohaimagen Sep 4, 2021
8aa06cf
Merge branch 'main' into raise_GMTInvalidInput_exception_when_z_missing
yohaimagen Sep 12, 2021
306a5c6
add required_z to wiggle
yohaimagen Sep 12, 2021
8451465
remove insuficent data test from test_contour
yohaimagen Sep 12, 2021
da51487
add test for sufficent data to test_clib
yohaimagen Sep 12, 2021
4559284
remove test for sufficent data test_plot3d
yohaimagen Sep 12, 2021
6a0042e
remove test for passing z value test_surface
yohaimagen Sep 12, 2021
bb51fc5
reformat
yohaimagen Sep 12, 2021
5eb4cc0
remove unused imports
yohaimagen Sep 12, 2021
ba10dbb
Apply suggestions from code review
yohaimagen Sep 14, 2021
1639a5b
Merge branch 'main' into raise_GMTInvalidInput_exception_when_z_missing
yohaimagen Sep 14, 2021
15075e8
Apply suggestions from code review
yohaimagen Sep 14, 2021
91c446f
Merge branch 'main' into raise_GMTInvalidInput_exception_when_z_missing
seisman Sep 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,14 @@ def virtualfile_from_grid(self, grid):

@fmt_docstring
def virtualfile_from_data(
self, check_kind=None, data=None, x=None, y=None, z=None, extra_arrays=None
self,
check_kind=None,
data=None,
x=None,
y=None,
z=None,
extra_arrays=None,
required_z=False,
):
"""
Store any data inside a virtual file.
Expand Down Expand Up @@ -1414,7 +1421,7 @@ def virtualfile_from_data(
...
<vector memory>: N = 3 <7/9> <4/6> <1/3>
"""
kind = data_kind(data, x, y, z)
kind = data_kind(data, x, y, z, required_z=required_z)

if check_kind == "raster" and kind not in ("file", "grid"):
raise GMTInvalidInput(f"Unrecognized data type for grid: {type(data)}")
Expand Down
4 changes: 3 additions & 1 deletion pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pygmt.exceptions import GMTInvalidInput


def data_kind(data, x=None, y=None, z=None):
def data_kind(data, x=None, y=None, z=None, required_z=False):
"""
Check what kind of data is provided to a module.

Expand Down Expand Up @@ -65,6 +65,8 @@ def data_kind(data, x=None, y=None, z=None):
raise GMTInvalidInput("Too much data. Use either data or x and y.")
if data is None and (x is None or y is None):
raise GMTInvalidInput("Must provided both x and y.")
Comment thread
yohaimagen marked this conversation as resolved.
Outdated
if data is None and required_z and (x is None or y is None or z is None):
Comment thread
yohaimagen marked this conversation as resolved.
Outdated
raise GMTInvalidInput("Must provided both x, y, and z.")
Comment thread
yohaimagen marked this conversation as resolved.
Outdated

if isinstance(data, str):
kind = "file"
Expand Down
13 changes: 13 additions & 0 deletions pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ def test_virtual_file_bad_direction():
print("This should have failed")


def test_virtualfile_from_data_required_z():
"""
Test that function fails when needs and do not provide z columns.
"""
x = np.arange(5)
y = np.arange(5)
z = None
with clib.Session() as lib:
with pytest.raises(GMTInvalidInput):
with lib.virtualfile_from_data(x=x, y=y, z=z, required_z=True):
print("This should have failed")


def test_virtualfile_from_vectors():
"""
Test the automation for transforming vectors to virtual file dataset.
Expand Down