Skip to content

Commit

Permalink
fix some code lints, use pycodestyle, and skip E226
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf authored and wesleybowman committed Mar 21, 2018
1 parent f69dc76 commit 4654454
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ script:
fi

- if [[ $TEST_TARGET == 'coding_standards' ]]; then
find . -type f -name "*.py" ! -name 'conf.py' | xargs flake8 --ignore=E741 --max-line-length=100 ;
pycodestyle --ignore=E741,E226 --max-line-length=100 tests ;
pycodestyle --ignore=E741,E226 --max-line-length=100 utide ;
fi
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flake8
matplotlib
pandas
pycodestyle
pytest
pytest-cov
pandas
matplotlib
16 changes: 11 additions & 5 deletions tests/test_HNL.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os

import pytest

import numpy as np
from numpy.testing import assert_array_almost_equal, assert_array_equal

import pytest

import utide
from utide.utilities import Bunch, loadbunch, convert_unicode_arrays
from utide.utilities import Bunch, convert_unicode_arrays, loadbunch


thisdir = os.path.dirname(__file__)
datapath = os.path.join(thisdir, 'data')
Expand All @@ -16,8 +17,13 @@

epoch = '1700-01-01'

solve_kw = dict(epoch=epoch, lat=21, constit='auto', method='ols',
conf_int='linear')
solve_kw = {
'epoch': epoch,
'lat': 21,
'constit': 'auto',
'method': 'ols',
'conf_int': 'linear',
}

coef_all = utide.solve(t, h, **solve_kw)

Expand Down
1 change: 1 addition & 0 deletions tests/test_astron.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from __future__ import (absolute_import, division, print_function)

import numpy as np

from utide.astronomy import ut_astron


Expand Down
4 changes: 2 additions & 2 deletions tests/test_harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

from numpy.testing import assert_array_almost_equal

from utide._ut_constants import _base_dir
from utide.harmonics import FUV
from utide.utilities import loadbunch
from utide._ut_constants import _base_dir

fname = os.path.join(_base_dir, 'FUV0.npz')

Expand All @@ -27,7 +27,7 @@ def test_FUV():

for i, flag in enumerate(x.flags):
F, U, V = FUV(x.t, x.t0, x.lind-1, x.lat, flag)
print('i:', i, "ngflgs:", flag)
print('i: {} ngflags: {}'.format(i, flag))

# We use broadcasting instead of replication, so
# we need to test only against the first row of
Expand Down
1 change: 1 addition & 0 deletions tests/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime

import numpy as np

from utide._time_conversion import _normalize_time


Expand Down
7 changes: 4 additions & 3 deletions tests/test_periodogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
from __future__ import (absolute_import, division, print_function)

import numpy as np

import utide.periodogram as pgram


def random_ts(ndays, dt_hours, complex=True):
def random_ts(ndays, dt_hours, is_complex=True):
"""Returns t (time in days) and x (random series)."""
np.random.seed(1)
npts = int(ndays * 24 / dt_hours)
if npts % 2:
npts -= 1
t = np.arange(npts, dtype=float) * dt_hours / 24
if complex:
if is_complex:
x = np.random.randn(npts) + 1j * np.random.randn(npts)
else:
x = np.random.randn(npts)
Expand All @@ -39,7 +40,7 @@ def test_fft_ls_consistency():


def test_uv_consistency():
t, x = random_ts(20, 0.5, complex=False)
t, x = random_ts(20, 0.5, is_complex=False)
xx = x + 1j * x
y_fft = pgram.band_psd(t, xx, [1/12.42], equi=True)
y_ls = pgram.band_psd(t, xx, [1/12.42], equi=False)
Expand Down
78 changes: 41 additions & 37 deletions tests/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

import numpy as np

from utide._ut_constants import ut_constants
from utide import solve
from utide import reconstruct
from utide import solve
from utide._ut_constants import ut_constants
from utide.utilities import Bunch


Expand All @@ -38,14 +38,15 @@ def test_roundtrip():
arg = 2 * np.pi * (time - tref) * freq_cpd[jj] - np.deg2rad(phase)
time_series = amp * np.cos(arg)

opts = dict(constit='auto',
phase='raw',
nodal=False,
trend=False,
method='ols',
conf_int='linear',
Rayleigh_min=0.95,
)
opts = {
'constit': 'auto',
'phase': 'raw',
'nodal': False,
'trend': False,
'method': 'ols',
'conf_int': 'linear',
'Rayleigh_min': 0.95,
}

speed_coef = solve(time, time_series, time_series, lat=lat, **opts)
elev_coef = solve(time, time_series, lat=lat, **opts)
Expand Down Expand Up @@ -100,14 +101,15 @@ def test_masked_input():
arg = 2 * np.pi * (time - tref) * freq_cpd[jj] - np.deg2rad(phase)
time_series = amp * np.cos(arg)

opts = dict(constit='auto',
phase='raw',
nodal=False,
trend=False,
method='ols',
conf_int='linear',
Rayleigh_min=0.95,
)
opts = {
'constit': 'auto',
'phase': 'raw',
'nodal': False,
'trend': False,
'method': 'ols',
'conf_int': 'linear',
'Rayleigh_min': 0.95,
}

t = np.ma.array(time)
t[[10, 15, 20, 21]] = np.ma.masked
Expand Down Expand Up @@ -170,14 +172,15 @@ def test_robust():
time_series[:5] = 10
time_series[-5:] = -10

opts = dict(constit='auto',
phase='raw',
nodal=False,
trend=False,
method='robust',
conf_int='linear',
Rayleigh_min=0.95,
)
opts = {
'constit': 'auto',
'phase': 'raw',
'nodal': False,
'trend': False,
'method': 'robust',
'conf_int': 'linear',
'Rayleigh_min': 0.95,
}

speed_coef = solve(time, time_series, time_series, lat=lat, **opts)
elev_coef = solve(time, time_series, lat=lat, **opts)
Expand Down Expand Up @@ -210,17 +213,18 @@ def test_MC():
np.random.seed(1)
time_series += 0.01 * np.random.randn(len(time_series))

opts = dict(constit='auto',
phase='raw',
nodal=False,
trend=False,
method='ols',
conf_int='MC',
white=False,
Rayleigh_min=0.95,
)

speed_coef = solve(time, time_series, time_series, lat=lat, **opts)
opts = {
'constit': 'auto',
'phase': 'raw',
'nodal': False,
'trend': False,
'method': 'ols',
'conf_int': 'MC',
'white': False,
'Rayleigh_min': 0.95,
}

speed_coef = solve(time, time_series, time_series, lat=lat, **opts)
elev_coef = solve(time, time_series, lat=lat, **opts)

for name, AA, AA_ci, gg, gg_ci in zip(elev_coef.name,
Expand Down
9 changes: 5 additions & 4 deletions tests/test_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
Full example test.
"""
import pytest

from matplotlib.dates import date2num

import numpy as np

from pandas import date_range
from matplotlib.dates import date2num

from utide import solve
from utide import reconstruct
import pytest

from utide import reconstruct, solve
from utide.utilities import Bunch


Expand Down
4 changes: 2 additions & 2 deletions utide/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import numpy as np

from utide.periodogram import band_psd
from utide.ellipse_params import ut_cs2cep
from utide.periodogram import band_psd
from utide.utilities import complex_interp


Expand Down Expand Up @@ -346,7 +346,7 @@ def _confidence(coef, cnstit, opt, t, e, tin, elor, xraw, xmod, W, m, B,
coef.theta_ci[ind] = 1.96 * sig2.imag
ind += 1
else:
raise NotImplementedError("Monte Carlo inference not implemented")
raise NotImplementedError('Monte Carlo inference not implemented')

return coef

Expand Down
3 changes: 1 addition & 2 deletions utide/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ def convert_unicode_arrays(b):
if val.dtype.kind == 'O':
newval = np.empty(shape=val.shape, dtype=val.dtype)
for k, x in enumerate(val):
if (isinstance(x, np.ndarray) and x.dtype.kind == 'U'
and x.size == 1):
if (isinstance(x, np.ndarray) and x.dtype.kind == 'U' and x.size == 1): # noqa
newval[k] = x.item()
else:
newval[k] = x
Expand Down

0 comments on commit 4654454

Please sign in to comment.