Skip to content

Finalize fixes on WIndows test suite for v0.1.1 #441

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

Merged
merged 5 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 3 additions & 45 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def vectors_to_arrays(vectors):
True

"""
arrays = [as_c_contiguous(_as_array(i)) for i in vectors]
arrays = [as_c_contiguous(np.asarray(i)) for i in vectors]
return arrays


Expand Down Expand Up @@ -203,48 +203,6 @@ def as_c_contiguous(array):
return array


def _as_array(vector):
"""
Convert a vector (pandas.Series, tuple, list or numpy array) to a numpy
array.

If vector is already an array, do nothing.

Parameters
----------
vector : tuple, list, pandas.Series or numpy 1d array
The vector to convert.

Returns
-------
array : numpy array

Examples
--------

>>> import pandas as pd
>>> x_series = pd.Series(data=[1, 2, 3, 4])
>>> x_array = _as_array(x_series)
>>> type(x_array)
<class 'numpy.ndarray'>
>>> x_array
array([1, 2, 3, 4])
>>> import numpy as np
>>> type(_as_array(np.array([5, 6, 7])))
<class 'numpy.ndarray'>
>>> type(_as_array([3, 4, 5]))
<class 'numpy.ndarray'>
>>> type(_as_array((6, 7, 8)))
<class 'numpy.ndarray'>
>>> type(_as_array(range(15)))
<class 'numpy.ndarray'>

"""
if isinstance(vector, pandas.Series):
return vector.values
return np.asarray(vector)


def kwargs_to_ctypes_array(argument, kwargs, dtype):
"""
Convert an iterable argument from kwargs into a ctypes array variable.
Expand All @@ -268,9 +226,9 @@ def kwargs_to_ctypes_array(argument, kwargs, dtype):
--------

>>> import ctypes as ct
>>> value = kwargs_to_ctypes_array('bla', {'bla': [10, 10]}, ct.c_int*2)
>>> value = kwargs_to_ctypes_array('bla', {'bla': [10, 10]}, ct.c_long*2)
>>> type(value)
<class 'pygmt.clib.conversion.c_int_Array_2'>
<class 'pygmt.clib.conversion.c_long_Array_2'>
Comment on lines -271 to +231
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c_int is just an alias for c_long according to https://docs.python.org/3/library/ctypes.html#ctypes-tutorial. Changing it to c_long should make this test pass in a cross-platform way.

>>> should_be_none = kwargs_to_ctypes_array(
... 'swallow', {'bla': 1, 'foo': [20, 30]}, ct.c_int*2)
>>> print(should_be_none)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_sphinx_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_pygmtscraper():
assert len(SHOWED_FIGURES) == 1
assert SHOWED_FIGURES[0] is fig
scraper = PyGMTScraper()
with TemporaryDirectory() as tmpdir:
with TemporaryDirectory(dir=os.getcwd()) as tmpdir:
conf = {"src_dir": "meh"}
fname = os.path.join(tmpdir, "meh.png")
block_vars = {"image_path_iterator": (i for i in [fname])}
Expand Down