From 5cf7f6a0e5a0c1f4bf610eb0172be596c3918aa0 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 8 Oct 2024 21:10:57 +0800 Subject: [PATCH 1/3] clib.conversion: Remove the as_c_contiguous function and use np.ascontiguousarray instead (#3492) --- pygmt/clib/conversion.py | 46 ++-------------------------------------- pygmt/clib/session.py | 3 +-- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/pygmt/clib/conversion.py b/pygmt/clib/conversion.py index a296601e5a1..708d1656f12 100644 --- a/pygmt/clib/conversion.py +++ b/pygmt/clib/conversion.py @@ -123,7 +123,7 @@ def dataarray_to_matrix(grid): inc = [abs(i) for i in inc] grid = grid.sortby(variables=list(grid.dims), ascending=True) - matrix = as_c_contiguous(grid[::-1].to_numpy()) + matrix = np.ascontiguousarray(grid[::-1].to_numpy()) region = [float(i) for i in region] inc = [float(i) for i in inc] return matrix, region, inc @@ -200,53 +200,11 @@ def vectors_to_arrays(vectors): for vector in vectors: vec_dtype = str(getattr(vector, "dtype", "")) array = np.asarray(a=vector, dtype=dtypes.get(vec_dtype)) - arrays.append(as_c_contiguous(array)) + arrays.append(np.ascontiguousarray(array)) return arrays -def as_c_contiguous(array): - """ - Ensure a numpy array is C contiguous in memory. - - If the array is not C contiguous, a copy will be necessary. - - Parameters - ---------- - array : 1-D array - The numpy array - - Returns - ------- - array : 1-D array - Array is C contiguous order. - - Examples - -------- - - >>> import numpy as np - >>> data = np.array([[1, 2], [3, 4], [5, 6]]) - >>> x = data[:, 0] - >>> x - array([1, 3, 5]) - >>> x.flags.c_contiguous - False - >>> new_x = as_c_contiguous(x) - >>> new_x - array([1, 3, 5]) - >>> new_x.flags.c_contiguous - True - >>> x = np.array([8, 9, 10]) - >>> x.flags.c_contiguous - True - >>> as_c_contiguous(x).flags.c_contiguous - True - """ - if not array.flags.c_contiguous: - return array.copy(order="C") - return array - - def sequence_to_ctypes_array( sequence: Sequence | None, ctype, size: int ) -> ctp.Array | None: diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 376d441746a..0effa04ae8e 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -19,7 +19,6 @@ import xarray as xr from pygmt.clib.conversion import ( array_to_datetime, - as_c_contiguous, dataarray_to_matrix, sequence_to_ctypes_array, strings_to_ctypes_array, @@ -1499,7 +1498,7 @@ def virtualfile_from_matrix(self, matrix): # collected and the memory freed. Creating it in this context manager # guarantees that the copy will be around until the virtual file is # closed. - matrix = as_c_contiguous(matrix) + matrix = np.ascontiguousarray(matrix) rows, columns = matrix.shape family = "GMT_IS_DATASET|GMT_VIA_MATRIX" From 3824fa14859eb45f2957e1a64804b54fe52cc208 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:06:06 +0800 Subject: [PATCH 2/3] Build(deps): Bump mamba-org/setup-micromamba from 1.9.0 to 2.0.0 (#3495) Bumps [mamba-org/setup-micromamba](https://github.com/mamba-org/setup-micromamba) from 1.9.0 to 2.0.0. - [Release notes](https://github.com/mamba-org/setup-micromamba/releases) - [Commits](https://github.com/mamba-org/setup-micromamba/compare/v1.9.0...v2.0.0) --- updated-dependencies: - dependency-name: mamba-org/setup-micromamba dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/benchmarks.yml | 2 +- .github/workflows/cache_data.yaml | 2 +- .github/workflows/ci_docs.yml | 2 +- .github/workflows/ci_doctests.yaml | 2 +- .github/workflows/ci_tests.yaml | 2 +- .github/workflows/ci_tests_dev.yaml | 2 +- .github/workflows/ci_tests_legacy.yaml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 10ec173105c..f40aa96acdf 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -45,7 +45,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index fc3b29f394e..c8eb6f0839d 100644 --- a/.github/workflows/cache_data.yaml +++ b/.github/workflows/cache_data.yaml @@ -43,7 +43,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index 2d8c53b4bf9..57cf9c8c75c 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -80,7 +80,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | diff --git a/.github/workflows/ci_doctests.yaml b/.github/workflows/ci_doctests.yaml index cf1f1704d28..8fcd197b04f 100644 --- a/.github/workflows/ci_doctests.yaml +++ b/.github/workflows/ci_doctests.yaml @@ -42,7 +42,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 02c200c77ec..8cf81f4e809 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -114,7 +114,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index fe12e04432a..ea6c6edbe9a 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -57,7 +57,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | diff --git a/.github/workflows/ci_tests_legacy.yaml b/.github/workflows/ci_tests_legacy.yaml index b485e258a16..5204ccc34c3 100644 --- a/.github/workflows/ci_tests_legacy.yaml +++ b/.github/workflows/ci_tests_legacy.yaml @@ -51,7 +51,7 @@ jobs: # Install Micromamba with conda-forge dependencies - name: Setup Micromamba - uses: mamba-org/setup-micromamba@v1.9.0 + uses: mamba-org/setup-micromamba@v2.0.0 with: environment-name: pygmt condarc: | From 054d1489f157a9fd9d0ad73329f93dfc8682fdb2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:19:30 +0800 Subject: [PATCH 3/3] Build(deps): Bump pypa/gh-action-pypi-publish from 1.10.2 to 1.10.3 (#3494) Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.10.2 to 1.10.3. - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.10.2...v1.10.3) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/publish-to-pypi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index a8c3bc409dd..d408cd9ecbf 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -75,10 +75,10 @@ jobs: ls -lh dist/ - name: Publish to Test PyPI - uses: pypa/gh-action-pypi-publish@v1.10.2 + uses: pypa/gh-action-pypi-publish@v1.10.3 with: repository-url: https://test.pypi.org/legacy/ - name: Publish to PyPI if: startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@v1.10.2 + uses: pypa/gh-action-pypi-publish@v1.10.3