Skip to content

Commit 056fe4c

Browse files
committed
Minor updates to the cache data workflow file
1 parent ca8973b commit 056fe4c

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

.github/workflows/cache_data.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
with:
8181
name: gmt-cache
8282
path: |
83-
~/.gmt/cache
84-
~/.gmt/server
85-
~/.gmt/gmt_data_server.txt
86-
~/.gmt/gmt_hash_server.txt
83+
~/.gmt/cache
84+
~/.gmt/server
85+
~/.gmt/gmt_data_server.txt
86+
~/.gmt/gmt_hash_server.txt

pygmt/datatypes/dataset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ def to_strings(self) -> np.ndarray[Any, np.dtype[np.str_]]:
158158
# Workaround for upstream GMT bug reported in
159159
# https://github.com/GenericMappingTools/pygmt/issues/3170.
160160
msg = (
161-
"The trailing text column contains `None' values, "
162-
"likely due to upstream GMT API bug. Please consider reporting to us."
161+
"The trailing text column contains `None' values and has been replace "
162+
"with an empty string to avoid TypeError exceptions. "
163+
"It's likely caused by an upstream GMT API bug. "
164+
"Please consider reporting to us."
163165
)
164-
raise warnings.warn(msg, stacklevel=2)
165-
textvector = np.where(textvector == None, b"", textvector) # noqa: E711
166+
warnings.warn(msg, category=RuntimeWarning, stacklevel=1)
167+
textvector = [item if item is not None else b"" for item in textvector]
166168
return np.char.decode(textvector) if textvector else np.array([], dtype=str)
167169

168170
def to_dataframe(

pygmt/tests/test_datatypes_dataset.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pandas as pd
88
import pytest
9+
from pygmt import which
910
from pygmt.clib import Session
1011
from pygmt.helpers import GMTTempFile
1112

@@ -81,3 +82,28 @@ def test_dataset_empty():
8182
assert df.empty # Empty DataFrame
8283
expected_df = dataframe_from_pandas(tmpfile.name)
8384
pd.testing.assert_frame_equal(df, expected_df)
85+
86+
87+
def test_dataset_to_strings_with_none_values():
88+
"""
89+
Test that None values in the trailing text doesn't raise an excetion.
90+
91+
Due to a likely upstream bug, the trailing texts sometimes can be ``None'' when
92+
downloading tiled grids. The temporary workaround is to replace any None values with
93+
an empty string.
94+
95+
See the bug report at https://github.com/GenericMappingTools/pygmt/issues/3170.
96+
"""
97+
tiles = ["@N30W120.earth_relief_15s_p.nc", "@N00E000.earth_relief_15s_p.nc"]
98+
paths = which(fname=tiles, download="a")
99+
assert len(paths) == 2
100+
# 'paths' may contain an empty string or not, depending on if the tiles are cached.
101+
if "" not in paths: # Contains two valid paths.
102+
# Delete the cached tiles and try again.
103+
for path in paths:
104+
Path(path).unlink()
105+
with pytest.warns(expected_warning=RuntimeWarning) as record:
106+
paths = which(fname=tiles, download="a")
107+
assert len(record) == 1
108+
assert len(paths) == 2
109+
assert "" in paths

0 commit comments

Comments
 (0)