From 7a511282449603b3bf3d6a02688120e60594ca28 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 10 Oct 2024 18:22:18 +0800 Subject: [PATCH] Remove unnecessary np.atleast_1d calls from Figure.text and Session.virtualfile_in (#3498) --- pygmt/clib/session.py | 4 ++-- pygmt/src/text.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index e559c703a18..a0c019b79ba 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1809,9 +1809,9 @@ def virtualfile_in( # noqa: PLR0912 warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) _data = (data,) if not isinstance(data, pathlib.PurePath) else (str(data),) elif kind == "vectors": - _data = [np.atleast_1d(x), np.atleast_1d(y)] + _data = [x, y] if z is not None: - _data.append(np.atleast_1d(z)) + _data.append(z) if extra_arrays: _data.extend(extra_arrays) elif kind == "matrix": # turn 2-D arrays into list of vectors diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 6315b22af9f..3d072ba4a56 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -223,19 +223,19 @@ def text_( # noqa: PLR0912 kwargs["F"] += flag # angle is numeric type and font/justify are str type. if name == "angle": - extra_arrays.append(np.atleast_1d(arg)) + extra_arrays.append(arg) else: - extra_arrays.append(np.atleast_1d(np.asarray(arg, dtype=str))) + extra_arrays.append(np.asarray(arg, dtype=str)) # If an array of transparency is given, GMT will read it from the last numerical # column per data record. if is_nonstr_iter(kwargs.get("t")): - extra_arrays.append(np.atleast_1d(kwargs["t"])) + extra_arrays.append(kwargs["t"]) kwargs["t"] = True # Append text to the last column. Text must be passed in as str type. - text = np.atleast_1d(np.asarray(text, dtype=str)) - encoding = _check_encoding("".join(text)) + text = np.asarray(text, dtype=str) + encoding = _check_encoding("".join(text.flatten())) if encoding != "ascii": text = np.vectorize(non_ascii_to_octal, excluded="encoding")( text, encoding=encoding