Skip to content

Commit

Permalink
REF: Remove numpy alias when importing (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Aug 30, 2023
1 parent 8c1320f commit 8010602
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
6 changes: 3 additions & 3 deletions docs/advanced_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ optimize your transformations.

.. code-block:: python
import numpy as np
import numpy
from pyproj import Transformer, transform
transformer = Transformer.from_crs(2263, 4326)
x_coords = np.random.randint(80000, 120000)
y_coords = np.random.randint(200000, 250000)
x_coords = numpy.random.randint(80000, 120000)
y_coords = numpy.random.randint(200000, 250000)
Example with :func:`pyproj.transformer.transform`:
Expand Down
54 changes: 34 additions & 20 deletions test/test_proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest
from unittest.mock import patch

import numpy as np
import numpy
import pytest
from numpy.testing import assert_almost_equal

Expand Down Expand Up @@ -441,11 +441,11 @@ def test_reset_errno():
@pytest.mark.parametrize("radians", [False, True])
def test_get_factors__2d_input(radians):
transformer = Proj(3857)
longitude = np.array([[0, 1], [2, 3]])
latitude = np.array([[1, 2], [3, 4]])
longitude = numpy.array([[0, 1], [2, 3]])
latitude = numpy.array([[1, 2], [3, 4]])
if radians:
longitude = np.radians(longitude)
latitude = np.radians(latitude)
longitude = numpy.radians(longitude)
latitude = numpy.radians(latitude)
factors = transformer.get_factors(
longitude=longitude, latitude=latitude, radians=radians
)
Expand Down Expand Up @@ -497,22 +497,36 @@ def test_get_factors():
def test_get_factors__nan_inf():
transformer = Proj(3857)
factors = transformer.get_factors(
longitude=[0, np.nan, np.inf, 0], latitude=[np.nan, 2, 2, np.inf]
longitude=[0, numpy.nan, numpy.inf, 0], latitude=[numpy.nan, 2, 2, numpy.inf]
)
assert_almost_equal(factors.meridional_scale, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.parallel_scale, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.areal_scale, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.angular_distortion, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(
factors.meridian_parallel_angle, [np.inf, np.inf, np.inf, np.inf]
factors.meridional_scale, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(factors.meridian_convergence, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.tissot_semimajor, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.tissot_semiminor, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.dx_dlam, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.dx_dphi, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.dy_dlam, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(factors.dy_dphi, [np.inf, np.inf, np.inf, np.inf])
assert_almost_equal(
factors.parallel_scale, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(
factors.areal_scale, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(
factors.angular_distortion, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(
factors.meridian_parallel_angle, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(
factors.meridian_convergence, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(
factors.tissot_semimajor, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(
factors.tissot_semiminor, [numpy.inf, numpy.inf, numpy.inf, numpy.inf]
)
assert_almost_equal(factors.dx_dlam, [numpy.inf, numpy.inf, numpy.inf, numpy.inf])
assert_almost_equal(factors.dx_dphi, [numpy.inf, numpy.inf, numpy.inf, numpy.inf])
assert_almost_equal(factors.dy_dlam, [numpy.inf, numpy.inf, numpy.inf, numpy.inf])
assert_almost_equal(factors.dy_dphi, [numpy.inf, numpy.inf, numpy.inf, numpy.inf])


def test_get_factors__errcheck():
Expand All @@ -523,7 +537,7 @@ def test_get_factors__errcheck():

def test_numpy_bool_kwarg_false():
# Issue 564
south = np.array(50) < 0
south = numpy.array(50) < 0
proj = Proj(
proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south
)
Expand All @@ -532,7 +546,7 @@ def test_numpy_bool_kwarg_false():

def test_numpy_bool_kwarg_true():
# Issue 564
south = np.array(50) > 0
south = numpy.array(50) > 0
proj = Proj(
proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south
)
Expand Down
44 changes: 26 additions & 18 deletions test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from unittest.mock import call, patch

import numpy as np
import numpy
import pytest
from numpy.testing import assert_almost_equal, assert_array_equal

Expand Down Expand Up @@ -65,8 +65,8 @@ def test_illegal_transformation():
xx, yy = pyproj.transform(
p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90)
)
assert np.all(np.isinf(xx))
assert np.all(np.isinf(yy))
assert numpy.all(numpy.isinf(xx))
assert numpy.all(numpy.isinf(yy))
with pytest.warns(FutureWarning), pytest.raises(ProjError):
pyproj.transform(
p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90), errcheck=True
Expand Down Expand Up @@ -413,15 +413,15 @@ def test_always_xy__itransform():
)


@pytest.mark.parametrize("empty_array", [(), [], np.array([])])
@pytest.mark.parametrize("empty_array", [(), [], numpy.array([])])
def test_transform_empty_array_xy(empty_array):
transformer = Transformer.from_crs(2193, 4326)
assert_array_equal(
transformer.transform(empty_array, empty_array), (empty_array, empty_array)
)


@pytest.mark.parametrize("empty_array", [(), [], np.array([])])
@pytest.mark.parametrize("empty_array", [(), [], numpy.array([])])
def test_transform_empty_array_xyzt(empty_array):
transformer = Transformer.from_pipeline("+init=ITRF2008:ITRF2000")
assert_array_equal(
Expand Down Expand Up @@ -1206,7 +1206,7 @@ def test_transform_bounds_densify(density, expected):
"+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 "
"+a=6370997 +b=6370997 +units=m +no_defs",
)
assert np.allclose(
assert numpy.allclose(
transformer.transform_bounds(40, -120, 64, -80, densify_pts=density),
expected,
)
Expand All @@ -1223,7 +1223,15 @@ def test_transform_bounds_densify(density, expected):
"input_bounds, radians",
[
((-120, 40, -80, 64), False),
((np.radians(-120), np.radians(40), np.radians(-80), np.radians(64)), True),
(
(
numpy.radians(-120),
numpy.radians(40),
numpy.radians(-80),
numpy.radians(64),
),
True,
),
],
)
def test_transform_bounds_densify__xy(density, expected, input_bounds, radians):
Expand All @@ -1233,7 +1241,7 @@ def test_transform_bounds_densify__xy(density, expected, input_bounds, radians):
"+a=6370997 +b=6370997 +units=m +no_defs",
always_xy=True,
)
assert np.allclose(
assert numpy.allclose(
transformer.transform_bounds(
*input_bounds, densify_pts=density, radians=radians
),
Expand Down Expand Up @@ -1460,8 +1468,8 @@ def test_transform_bounds__south_pole__xy():

@pytest.mark.parametrize("inplace", [True, False])
def test_transform__fortran_order(inplace):
lons, lats = np.arange(-180, 180, 20), np.arange(-90, 90, 10)
lats, lons = np.meshgrid(lats, lons)
lons, lats = numpy.arange(-180, 180, 20), numpy.arange(-90, 90, 10)
lats, lons = numpy.meshgrid(lats, lons)
f_lons, f_lats = lons.copy(order="F"), lats.copy(order="F")
transformer = Transformer.from_crs(
"EPSG:4326",
Expand Down Expand Up @@ -1520,10 +1528,10 @@ def test_4d_transform__inplace__array__int():

def test_4d_transform__inplace__numpy():
transformer = Transformer.from_crs(7789, 8401)
xarr = np.array([3496737.2679], dtype=np.float64)
yarr = np.array([743254.4507], dtype=np.float64)
zarr = np.array([5264462.9620], dtype=np.float64)
tarr = np.array([2019.0], dtype=np.float64)
xarr = numpy.array([3496737.2679], dtype=numpy.float64)
yarr = numpy.array([743254.4507], dtype=numpy.float64)
zarr = numpy.array([5264462.9620], dtype=numpy.float64)
tarr = numpy.array([2019.0], dtype=numpy.float64)
t_xarr, t_yarr, t_zarr, t_tarr = transformer.transform(
xx=xarr, yy=yarr, zz=zarr, tt=tarr, inplace=True
)
Expand All @@ -1539,10 +1547,10 @@ def test_4d_transform__inplace__numpy():

def test_4d_transform__inplace__numpy__int():
transformer = Transformer.from_crs(7789, 8401)
xarr = np.array([3496737], dtype=np.int32)
yarr = np.array([743254], dtype=np.int32)
zarr = np.array([5264462], dtype=np.int32)
tarr = np.array([2019], dtype=np.int32)
xarr = numpy.array([3496737], dtype=numpy.int32)
yarr = numpy.array([743254], dtype=numpy.int32)
zarr = numpy.array([5264462], dtype=numpy.int32)
tarr = numpy.array([2019], dtype=numpy.int32)
t_xarr, t_yarr, t_zarr, t_tarr = transformer.transform(
xx=xarr, yy=yarr, zz=zarr, tt=tarr, inplace=True
)
Expand Down

0 comments on commit 8010602

Please sign in to comment.