Skip to content

Commit

Permalink
General py3 cleanup: drop extra parentheses, adjust user inputs with …
Browse files Browse the repository at this point in the history
…format, remove future imports
  • Loading branch information
zbruick committed Oct 21, 2019
1 parent a6f9ba1 commit 5fe6f23
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env:
# Shapely dependency needed to keep from using Shapely's manylinux wheels
# which use a different geos that what we build cartopy with on Travis
# Codecov only works with coverage < 4.4
- EXTRA_PACKAGES="shapely<1.5.17.post1 coverage<4.4 docutils"
- EXTRA_PACKAGES="shapely<1.5.17.post1 coverage<4.4"
- EXTRA_INSTALLS="test"
- MPLLOCALFREETYPE="1"
- TEST_OUTPUT_CONTROL="-s"
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its
# containing dir.
Expand Down Expand Up @@ -51,7 +50,7 @@
},
'examples_dirs': [os.path.join('..', 'examples'), os.path.join('..', 'tutorials')],
'gallery_dirs': ['examples', 'tutorials'],
'filename_pattern': '\.py',
'filename_pattern': r'\.py',
'backreferences_dir': os.path.join('api', 'generated'),
'default_thumb_file': os.path.join('_static', 'metpy_150x150_white_bg.png'),
'abort_on_example_error': True
Expand Down
4 changes: 2 additions & 2 deletions examples/gridding/Inverse_Distance_Verification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2016 MetPy Developers.
# Copyright (c) 2016,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
Expand Down Expand Up @@ -83,7 +83,7 @@ def draw_circle(ax, x, y, r, m, label):
barnes_dist = dist_2(sim_gridx[1], sim_gridy[1], x2, y2)
barnes_obs = zp[indices[1]]

ave_spacing = np.mean((cdist(list(zip(xp, yp)), list(zip(xp, yp)))))
ave_spacing = np.mean(cdist(list(zip(xp, yp)), list(zip(xp, yp))))
kappa = calc_kappa(ave_spacing)

barnes_val = barnes_point(barnes_dist, barnes_obs, kappa)
Expand Down
4 changes: 2 additions & 2 deletions src/metpy/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015,2016,2018 MetPy Developers.
# Copyright (c) 2015,2016,2018,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
r"""Collection of utilities for testing.
Expand Down Expand Up @@ -37,7 +37,7 @@ def get_upper_air_data(date, station):
dict : upper air data
"""
sounding_key = '{0:%Y-%m-%dT%HZ}_{1:}'.format(date, station)
sounding_key = '{:%Y-%m-%dT%HZ}_{}'.format(date, station)
sounding_files = {'2016-05-22T00Z_DDC': 'may22_sounding.txt',
'2013-01-20T12Z_OUN': 'jan20_sounding.txt',
'1999-05-04T00Z_OUN': 'may4_sounding.txt',
Expand Down
2 changes: 1 addition & 1 deletion src/metpy/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def wrapper(*args, **kwargs):
# If there are any bad units, emit a proper error message making it clear
# what went wrong.
if bad:
msg = '`{0}` given arguments with incorrect units: {1}.'.format(
msg = '`{}` given arguments with incorrect units: {}.'.format(
func.__name__,
', '.join('`{}` requires "{}" but given "{}"'.format(arg, req, given)
for arg, given, req in bad))
Expand Down
2 changes: 1 addition & 1 deletion tests/calc/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_storm_relative_helicity():
hgt_int = np.arange(0, 2050, 50)
hgt_int = hgt_int * units('meter')
dir_int = np.arange(180, 272.25, 2.25)
spd_int = np.zeros((hgt_int.shape[0]))
spd_int = np.zeros(hgt_int.shape[0])
spd_int[:] = 2.
u_int, v_int = wind_components(spd_int * units('m/s'), dir_int * units.degree)

Expand Down
3 changes: 1 addition & 2 deletions tests/interpolate/test_geometry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright (c) 2018 MetPy Developers.
# Copyright (c) 2018,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Test the `geometry` module."""

from __future__ import division

import logging

Expand Down
10 changes: 5 additions & 5 deletions tests/interpolate/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: BSD-3-Clause
"""Test the `grid` module."""

from __future__ import division

import logging

Expand Down Expand Up @@ -196,8 +195,8 @@ def test_inverse_distance_to_grid(method, test_data, test_grid):

@pytest.mark.parametrize('method', interp_methods)
@pytest.mark.parametrize('boundary_coords', boundary_types)
def test_interpolate_to_grid(method, test_coords, boundary_coords):
r"""Test main grid interpolation function."""
def test_interpolate(method, test_coords, boundary_coords):
r"""Test deprecated main interpolate function."""
xp, yp = test_coords

xp *= 10
Expand All @@ -218,9 +217,10 @@ def test_interpolate_to_grid(method, test_coords, boundary_coords):
if boundary_coords is not None:
extra_kw['boundary_coords'] = boundary_coords

_, _, img = interpolate_to_grid(xp, yp, z, hres=10, interp_type=method, **extra_kw)
with pytest.warns(MetpyDeprecationWarning):
_, _, img = interpolate(xp, yp, z, hres=10, interp_type=method, **extra_kw)

with get_test_data('{0}_test.npz'.format(method)) as fobj:
with get_test_data('{}_test.npz'.format(method)) as fobj:
truth = np.load(fobj)['img']

assert_array_almost_equal(truth, img)
Expand Down
7 changes: 3 additions & 4 deletions tests/interpolate/test_interpolate_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright (c) 2018 MetPy Developers.
# Copyright (c) 2018,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Test the `tools` module."""

from __future__ import division

import numpy as np
from numpy.testing import assert_almost_equal, assert_array_almost_equal
Expand All @@ -30,8 +29,8 @@ def test_calc_kappa(test_coords):
r"""Test calculate kappa parameter function."""
x, y = test_coords

spacing = np.mean((cdist(list(zip(x, y)),
list(zip(x, y)))))
spacing = np.mean(cdist(list(zip(x, y)),
list(zip(x, y))))

value = calc_kappa(spacing)

Expand Down
7 changes: 3 additions & 4 deletions tests/interpolate/test_points.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright (c) 2018 MetPy Developers.
# Copyright (c) 2018,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Test the `points` module."""

from __future__ import division

import logging

Expand Down Expand Up @@ -99,7 +98,7 @@ def test_barnes_point(test_data):

truth = 4.08718241061

ave_spacing = np.mean((cdist(list(zip(xp, yp)), list(zip(xp, yp)))))
ave_spacing = np.mean(cdist(list(zip(xp, yp)), list(zip(xp, yp))))

kappa = calc_kappa(ave_spacing)

Expand Down Expand Up @@ -188,7 +187,7 @@ def test_interpolate_to_points(method, test_data):

img = interpolate_to_points(obs_points, z, test_points, interp_type=method, **extra_kw)

with get_test_data('{0}_test.npz'.format(method)) as fobj:
with get_test_data('{}_test.npz'.format(method)) as fobj:
truth = np.load(fobj)['img'].reshape(-1)

assert_array_almost_equal(truth, img)
8 changes: 4 additions & 4 deletions tests/plots/test_skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def test_skewt_barb_unit_conversion_exception(u, v):
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
def test_hodograph_plot_layers():
"""Test hodograph colored height layers with interpolation."""
u = np.zeros((6)) * units.knots
u = np.zeros(6) * units.knots
v = np.array([0, 10, 20, 30, 40, 50]) * units.knots
heights = np.array([0, 1000, 2000, 3000, 4000, 5000]) * units.m
intervals = np.array([500, 1500, 2500, 3500, 4500]) * units.m
Expand All @@ -358,7 +358,7 @@ def test_hodograph_plot_layers():
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
def test_hodograph_plot_layers_different_units():
"""Test hodograph colored height layers with interpolation and different units."""
u = np.zeros((6)) * units.knots
u = np.zeros(6) * units.knots
v = np.array([0, 10, 20, 30, 40, 50]) * units.knots
heights = np.array([0, 1, 2, 3, 4, 5]) * units.km
intervals = np.array([500, 1500, 2500, 3500, 4500]) * units.m
Expand All @@ -376,7 +376,7 @@ def test_hodograph_plot_layers_different_units():
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
def test_hodograph_plot_layers_bound_units():
"""Test hodograph colored height layers with interpolation and different units."""
u = np.zeros((6)) * units.knots
u = np.zeros(6) * units.knots
v = np.array([0, 10, 20, 30, 40, 50]) * units.knots
heights = np.array([0, 1000, 2000, 3000, 4000, 5000]) * units.m
intervals = np.array([0.5, 1.5, 2.5, 3.5, 4.5]) * units.km
Expand Down Expand Up @@ -432,7 +432,7 @@ def test_united_hodograph_range():
@check_and_silence_deprecation
def test_plot_colormapped_bounds_deprecation():
"""Test deprecation of bounds kwarg in `plot_colormapped`."""
u = np.zeros((6)) * units.knots
u = np.zeros(6) * units.knots
v = np.array([0, 10, 20, 30, 40, 50]) * units.knots
heights = np.array([0, 1000, 2000, 3000, 4000, 5000]) * units.m
intervals = np.array([500, 1500, 2500, 3500, 4500]) * units.m
Expand Down
10 changes: 5 additions & 5 deletions tests/plots/test_wx_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
def test_mapper():
"""Test for symbol mapping functionality."""
assert current_weather(0) == ''
assert current_weather(4) == u'\ue9a2'
assert current_weather(7) == u'\ue9a5'
assert current_weather(65) == u'\ue9e1'
assert current_weather(4) == '\ue9a2'
assert current_weather(7) == '\ue9a5'
assert current_weather(65) == '\ue9e1'


def test_alt_char():
"""Test alternate character functionality for mapper."""
assert current_weather.alt_char(7, 1) == u'\ue9a6'
assert current_weather.alt_char(7, 2) == u'\ue9a7'
assert current_weather.alt_char(7, 1) == '\ue9a6'
assert current_weather.alt_char(7, 2) == '\ue9a7'


def test_mapper_len():
Expand Down

0 comments on commit 5fe6f23

Please sign in to comment.