-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
**Breaking**: data_kind: Now 'matrix' represents a 2-D numpy array and unrecognized data types fall back to 'vectors' #3351
Changes from all commits
0c82b3c
808755d
0eb4f8f
9891b2c
a9d094c
3d8be4d
7c104a9
5790923
6954c5d
9300ca3
2701a4a
7fcf57f
991f688
51569c8
4a4f192
2a6e788
2b054b6
cfa32ed
ef6e6aa
423e5dc
81e57f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,7 +195,7 @@ def x2sys_cross( | |
match data_kind(track): | ||
case "file": | ||
file_contexts.append(contextlib.nullcontext(track)) | ||
case "matrix": | ||
case "vectors": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pandas.DataFrame now is "vectors" kind. |
||
# find suffix (-E) of trackfiles used (e.g. xyz, csv, etc) from | ||
# $X2SYS_HOME/TAGNAME/TAGNAME.tag file | ||
tagfile = Path( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,11 @@ | |
import pandas as pd | ||
import pytest | ||
import xarray as xr | ||
from packaging.version import Version | ||
from pygmt import clib | ||
from pygmt.clib import __gmt_version__ | ||
from pygmt.exceptions import GMTInvalidInput | ||
from pygmt.helpers import GMTTempFile | ||
from pygmt.helpers import GMTTempFile, data_kind | ||
|
||
POINTS_DATA = Path(__file__).parent / "data" / "points.txt" | ||
|
||
|
@@ -101,3 +103,27 @@ def test_virtualfile_in_fail_non_valid_data(data): | |
z=data[:, 2], | ||
data=data, | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is added to address #3351 (comment). This new test passes a string dtype numpy array into GMT C API, which contains longitude/latitude strings. The data kind is The function is marked as xfail with GMT 6.5 due to a newly found upstream bug at GenericMappingTools/gmt#8600. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, and thanks for adding the test! |
||
|
||
@pytest.mark.xfail( | ||
condition=Version(__gmt_version__) <= Version("6.5.0"), | ||
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/8600", | ||
) | ||
def test_virtualfile_in_matrix_string_dtype(): | ||
""" | ||
Pass a string dtype matrix should work and the matrix should be passed via a series | ||
of vectors. | ||
""" | ||
data = np.array([["11:30W", "30:30S"], ["12:30W", "30:00S"]]) | ||
assert data_kind(data) == "matrix" # data is recognized as "matrix" kind | ||
assert data.dtype.type == np.str_ | ||
assert data.dtype.kind not in "iuf" # dtype is not in numeric dtypes | ||
|
||
with clib.Session() as lib: | ||
with lib.virtualfile_in(data=data) as vintbl: | ||
with GMTTempFile() as outfile: | ||
lib.call_module("info", [vintbl, "-C", f"->{outfile.name}"]) | ||
output = outfile.read(keep_tabs=False) | ||
assert output == "347.5 348.5 -30.5 -30\n" | ||
# Should check that lib.virtualfile_from_vectors is called once, | ||
# not lib.virtualfile_from_matrix, but it's technically complicated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for these lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add a test for it. Before adding more tests, I'm wondering if we should split the big "test_clib_virtualfiles.py" file (with more than 500 lines) into separate smaller test files, i.e., one test file for each Session method.
test_clib_virtualfile_in
test_clib_virtualfile_from_vectors
test_clib_virtualfile_from_matrix
test_clib_open_virtualfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've split it before in #2784, so yes, ok to split it again 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #3512.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test in cfa32ed to cover this line.