Skip to content

Commit 7e1fa00

Browse files
authored
Add a doctest for checking ndims when the input is a sequence of scalars (#3497)
1 parent 0b59e2f commit 7e1fa00

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: pygmt/clib/conversion.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ def vectors_to_arrays(vectors):
171171
>>> all(isinstance(i, np.ndarray) for i in vectors_to_arrays(data))
172172
True
173173
174+
>>> # Sequence of scalars are converted to 1-D arrays
175+
>>> data = vectors_to_arrays([1, 2, 3.0])
176+
>>> data
177+
[array([1]), array([2]), array([3.])]
178+
>>> [i.ndim for i in data] # Check that they are 1-D arrays
179+
[1, 1, 1]
180+
174181
>>> import datetime
175182
>>> import pytest
176183
>>> pa = pytest.importorskip("pyarrow")
@@ -199,9 +206,7 @@ def vectors_to_arrays(vectors):
199206
arrays = []
200207
for vector in vectors:
201208
vec_dtype = str(getattr(vector, "dtype", ""))
202-
array = np.asarray(a=vector, dtype=dtypes.get(vec_dtype))
203-
arrays.append(np.ascontiguousarray(array))
204-
209+
arrays.append(np.ascontiguousarray(vector, dtype=dtypes.get(vec_dtype)))
205210
return arrays
206211

207212

0 commit comments

Comments
 (0)