From 590a523dcb49fbff426fb08c2de9d8251ee47d34 Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Thu, 21 May 2020 10:27:51 +1200 Subject: [PATCH 1/4] Fix test due to different mount paths on WIndows Exact error message was "ValueError: path is on mount 'C:', start on mount 'D:'." --- pygmt/tests/test_sphinx_gallery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_sphinx_gallery.py b/pygmt/tests/test_sphinx_gallery.py index ae2afaf0325..7c0cacdf962 100644 --- a/pygmt/tests/test_sphinx_gallery.py +++ b/pygmt/tests/test_sphinx_gallery.py @@ -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])} From 6d804d7d90edceff569d84be2ab2a83371f9d45b Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Thu, 21 May 2020 13:53:08 +1200 Subject: [PATCH 2/4] Use to_numpy() to convert pd.Series to np.array The .values method isn't recommended anymore for pandas 1.0, see https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.values.html#pandas.Series.values. Using to_numpy() instead. --- pygmt/clib/conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/clib/conversion.py b/pygmt/clib/conversion.py index f86a1c6261d..1a3d9b019f5 100644 --- a/pygmt/clib/conversion.py +++ b/pygmt/clib/conversion.py @@ -241,7 +241,7 @@ def _as_array(vector): """ if isinstance(vector, pandas.Series): - return vector.values + return vector.to_numpy() return np.asarray(vector) From efe35ec760332438081d5a12ac113c3b33d04227 Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Thu, 21 May 2020 14:18:14 +1200 Subject: [PATCH 3/4] Just use numpy.asarray to convert a vector to numpy array Because running np.asarray on a pandas.Series returns a numpy.ndarray anyway. --- pygmt/clib/conversion.py | 44 +--------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/pygmt/clib/conversion.py b/pygmt/clib/conversion.py index 1a3d9b019f5..47cda74fbd5 100644 --- a/pygmt/clib/conversion.py +++ b/pygmt/clib/conversion.py @@ -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 @@ -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) - - >>> x_array - array([1, 2, 3, 4]) - >>> import numpy as np - >>> type(_as_array(np.array([5, 6, 7]))) - - >>> type(_as_array([3, 4, 5])) - - >>> type(_as_array((6, 7, 8))) - - >>> type(_as_array(range(15))) - - - """ - if isinstance(vector, pandas.Series): - return vector.to_numpy() - return np.asarray(vector) - - def kwargs_to_ctypes_array(argument, kwargs, dtype): """ Convert an iterable argument from kwargs into a ctypes array variable. From 92029417db518ed3ed51a4ba823a242328f2ccc8 Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Thu, 21 May 2020 14:45:42 +1200 Subject: [PATCH 4/4] Change ctypes.c_int to ctypes.c_long since they're the same According to https://docs.python.org/3/library/ctypes.html#ctypes-tutorial, `c_int` is just an alias for `c_long`. --- pygmt/clib/conversion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/clib/conversion.py b/pygmt/clib/conversion.py index 47cda74fbd5..2e0c35d210b 100644 --- a/pygmt/clib/conversion.py +++ b/pygmt/clib/conversion.py @@ -226,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) - + >>> should_be_none = kwargs_to_ctypes_array( ... 'swallow', {'bla': 1, 'foo': [20, 30]}, ct.c_int*2) >>> print(should_be_none)