-
Notifications
You must be signed in to change notification settings - Fork 225
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
Wrap GMT_Put_Strings to pass str columns into GMT C API directly #520
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c811e65
Move test_put_* from test_clib to test_clib_put
weiji14 5c5f152
Initial wrapper for GMT_Put_Strings C API function
weiji14 d7c3053
Merge branch 'master' into gmt_put_strings
weiji14 fccedae
Try using GMT_TEXT for numpy string types
weiji14 07b95ed
Remove column argument from put_strings function
weiji14 88eef3a
Set valid GMT data mode as GMT_IS_OUTPUT
weiji14 6390e04
Try passing "GMT_IS_VECTOR" family type to put_strings
weiji14 42af00e
Do `put_vector` x and y before `put_strings` s, dim is 2 only
weiji14 9ef04b0
Refactor text to use virtualfile_from_vectors instead of pandas tempfile
weiji14 ab1e041
Split test_clib_put into separate _strings, _matrix and _vector files
weiji14 01754fc
Try using ctypes.POINTER in argtypes of c_put_strings
weiji14 452d3d3
Merge branch 'master' into gmt_put_strings
seisman 9c8dad9
Merge branch 'master' into gmt_put_strings
seisman 6dff9ba
Merge branch 'master' into gmt_put_strings
seisman cfb9124
Merge branch 'master' into gmt_put_strings
seisman 2485437
Pass strings using "GMT_IS_VECTOR|GMT_IS_DUPLICATE"
seisman 7fa1f0c
Merge branch 'master' into gmt_put_strings
seisman e8e7768
Use GMT_IS_VECTOR|GMT_IS_DUPLICATE when calling put_strings
seisman 2f0c798
Improve the put_strings test
seisman 6d6ea24
Merge branch 'master' into gmt_put_strings
seisman 9d063b3
Add back import pandas as pd
weiji14 2d81f76
Merge branch 'master' into gmt_put_strings
seisman 95afa90
Merge branch 'master' into gmt_put_strings
weiji14 ed0dce6
Revert refactor text to use virtualfile_from_vectors
weiji14 aeabd8e
Add test for passing in one string column to virtualfile_from_vectors
weiji14 abcbcf7
Refactor virtualfile_from_vectors to handle up to 2 string columns
weiji14 129135e
Fix test_plot_datetime by not passing first two columns into put_strings
weiji14 4f1ccda
Refactor to handle any number of string type columns
weiji14 30c18eb
Test for put_strings failing to increase code coverage
weiji14 62469cb
Expect failures for tests using GMT_Put_strings on GMT < 6.1.1
weiji14 26f51c9
Fix an incorrect note in virtualfile_from_vectors
weiji14 726de44
Concatenate last string columns instead of allowing arbitrary positions
weiji14 4c99477
Test variable length strings
weiji14 2f9d689
Replace gmt info with select in test_virtualfile_from_vectors_str_cols
weiji14 fe794c9
Fix truncated strings and an incorrect test
weiji14 f59d970
Replace gmt select with convert in test_virttualfile_from_vectors_str…
weiji14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Test the functions that put string data into GMT. | ||
""" | ||
import numpy as np | ||
import numpy.testing as npt | ||
import pytest | ||
from packaging.version import Version | ||
|
||
from .. import clib | ||
from ..exceptions import GMTCLibError | ||
from ..helpers import GMTTempFile | ||
|
||
with clib.Session() as _lib: | ||
gmt_version = Version(_lib.info["version"]) | ||
|
||
|
||
@pytest.mark.xfail( | ||
condition=gmt_version < Version("6.1.1"), | ||
reason="GMT_Put_Strings only works for GMT 6.1.1 and above", | ||
) | ||
def test_put_strings(): | ||
"Check that assigning a numpy array of dtype str to a dataset works" | ||
with clib.Session() as lib: | ||
dataset = lib.create_data( | ||
family="GMT_IS_DATASET|GMT_VIA_VECTOR", | ||
geometry="GMT_IS_POINT", | ||
mode="GMT_CONTAINER_ONLY", | ||
dim=[2, 5, 1, 0], # columns, rows, layers, dtype | ||
) | ||
x = np.array([1, 2, 3, 4, 5], dtype=np.int32) | ||
y = np.array([6, 7, 8, 9, 10], dtype=np.int32) | ||
strings = np.array(["a", "bc", "defg", "hijklmn", "opqrst"], dtype=np.str) | ||
lib.put_vector(dataset, column=lib["GMT_X"], vector=x) | ||
lib.put_vector(dataset, column=lib["GMT_Y"], vector=y) | ||
lib.put_strings( | ||
dataset, family="GMT_IS_VECTOR|GMT_IS_DUPLICATE", strings=strings | ||
) | ||
# Turns out wesn doesn't matter for Datasets | ||
wesn = [0] * 6 | ||
# Save the data to a file to see if it's being accessed correctly | ||
with GMTTempFile() as tmp_file: | ||
lib.write_data( | ||
"GMT_IS_VECTOR", | ||
"GMT_IS_POINT", | ||
"GMT_WRITE_SET", | ||
wesn, | ||
tmp_file.name, | ||
dataset, | ||
) | ||
# Load the data and check that it's correct | ||
newx, newy, newstrings = tmp_file.loadtxt( | ||
unpack=True, dtype=[("x", np.int32), ("y", np.int32), ("text", "<U7")] | ||
) | ||
npt.assert_array_equal(newx, x) | ||
npt.assert_array_equal(newy, y) | ||
npt.assert_array_equal(newstrings, strings) | ||
|
||
|
||
def test_put_strings_fails(): | ||
"Check that put_strings raises an exception if return code is not zero" | ||
with clib.Session() as lib: | ||
with pytest.raises(GMTCLibError): | ||
lib.put_strings( | ||
dataset=None, | ||
family="GMT_IS_VECTOR|GMT_IS_DUPLICATE", | ||
strings=np.empty(shape=(3,), dtype=np.str), | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Temporarily using xfail so all the tests will be green. If it looks alright, we can merge this in first and remove these
xfail
s after bumping the minimum required GMT version to 6.1.1. Can also do it when we refactortext
to useput_strings
😄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.
Xfails have been removed in #577 at c0bb8be.