8000 Merge pull request #6047 from charris/pep8-pyflakes-numpy.core.tests · numpy/numpy@9918d35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9918d35

Browse files
committed
Merge pull request #6047 from charris/pep8-pyflakes-numpy.core.tests
PEP8 and pyflakes fixups for numpy/core/tests/*.py
2 parents c3f04c7 + 730adaa commit 9918d35

30 files changed

+2032
-1989
lines changed

numpy/core/tests/test_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from __future__ import division, absolute_import, print_function
22

33
import sys
4-
import warnings
54

65
import numpy as np
7-
from numpy.testing import *
86
from numpy.compat import sixu
7+
from numpy.testing import (
8+
run_module_suite, assert_, assert_equal, assert_array_equal,
9+
assert_raises
10+
)
911

1012
# Switch between new behaviour when NPY_RELAXED_STRIDES_CHECKING is set.
1113
NPY_RELAXED_STRIDES_CHECKING = np.ones((10, 1), order='C').flags.f_contiguous
1214

1315

1416
def test_array_array():
15-
obj = object()
1617
tobj = type(object)
1718
ones11 = np.ones((1, 1), np.float64)
1819
tndarray = type(ones11)
19-
# Test is_ndarary
20+
# Test is_ndarray
2021
assert_equal(np.array(ones11, dtype=np.float64), ones11)
2122
old_refcount = sys.getrefcount(tndarray)
2223
np.array(ones11)

numpy/core/tests/test_arrayprint.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from __future__ import division, absolute_import, print_function
44

55
import sys
6+
67
import numpy as np
7-
from numpy.testing import *
88
from numpy.compat import sixu
9+
from numpy.testing import (
10+
TestCase, run_module_suite, assert_, assert_equal
11+
)
912

1013
class TestArrayRepr(object):
1114
def test_nan_inf(self):
@@ -81,37 +84,39 @@ def _format_function(x):
8184
return 'o'
8285
else:
8386
return 'O'
87+
8488
x = np.arange(3)
8589
if sys.version_info[0] >= 3:
8690
x_hex = "[0x0 0x1 0x2]"
8791
x_oct = "[0o0 0o1 0o2]"
8892
else:
8993
x_hex = "[0x0L 0x1L 0x2L]"
9094
x_oct = "[0L 01L 02L]"
91-
assert_(np.array2string(x, formatter={'all':_format_function}) == \
95+
assert_(np.array2string(x, formatter={'all':_format_function}) ==
9296
"[. o O]")
93-
assert_(np.array2string(x, formatter={'int_kind':_format_function}) ==\
97+
assert_(np.array2string(x, formatter={'int_kind':_format_function}) ==
9498
"[. o O]")
95-
assert_(np.array2string(x, fo F438 rmatter={'all':lambda x: "%.4f" % x}) == \
99+
assert_(np.array2string(x, formatter={'all':lambda x: "%.4f" % x}) ==
96100
"[0.0000 1.0000 2.0000]")
97-
assert_equal(np.array2string(x, formatter={'int':lambda x: hex(x)}), \
101+
assert_equal(np.array2string(x, formatter={'int':lambda x: hex(x)}),
98102
x_hex)
99-
assert_equal(np.array2string(x, formatter={'int':lambda x: oct(x)}), \
103+
assert_equal(np.array2string(x, formatter={'int':lambda x: oct(x)}),
100104
x_oct)
101105

102106
x = np.arange(3.)
103-
assert_(np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) == \
107+
assert_(np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) ==
104108
"[0.00 1.00 2.00]")
105-
assert_(np.array2string(x, formatter={'float':lambda x: "%.2f" % x}) == \
109+
assert_(np.array2string(x, formatter={'float':lambda x: "%.2f" % x}) ==
106110
"[0.00 1.00 2.00]")
107111

108112
s = np.array(['abc', 'def'])
109-
assert_(np.array2string(s, formatter={'numpystr':lambda s: s*2}) == \
110-
'[abcabc defdef]')
113+
assert_(np.array2string(s, formatter={'numpystr':lambda s: s*2}) ==
114+
'[abcabc defdef]')
111115

112116

113117
class TestPrintOptions:
114118
"""Test getting and setting global print options."""
119+
115120
def setUp(self):
116121
self.oldopts = np.get_printoptions()
117122

@@ -162,6 +167,5 @@ def test_unicode_object_array():
162167
assert_equal(repr(x), expected)
163168

164169

165-
166170
if __name__ == "__main__":
167171
run_module_suite()

numpy/core/tests/test_datetime.py

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
10000
@@ -1,11 +1,15 @@
11
from __future__ import division, absolute_import, print_function
22

3-
import os, pickle
3+
import pickle
4+
45
import numpy
56
import numpy as np
6-
from numpy.testing import *
7-
from numpy.compat import asbytes
87
import datetime
8+
from numpy.compat import asbytes
9+
from numpy.testing import (
10+
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
11+
dec
12+
)
913

1014
# Use pytz to test out various time zones if available
1115
try:
@@ -20,7 +24,7 @@ def test_datetime_dtype_creation(self):
2024
for unit in ['Y', 'M', 'W', 'D',
2125
'h', 'm', 's', 'ms', 'us',
2226
'ns', 'ps', 'fs', 'as']:
23-
dt1 = np.dtype('M8[750%s]'%unit)
27+
dt1 = np.dtype('M8[750%s]' % unit)
2428
assert_(dt1 == np.dtype('datetime64[750%s]' % unit))
2529
dt2 = np.dtype('m8[%s]' % unit)
2630
assert_(dt2 == np.dtype('timedelta64[%s]' % unit))
@@ -522,7 +526,7 @@ def test_datetime_array_str(self):
522526

523527
a = np.array(['2011-03-16T13:55Z', '1920-01-01T03:12Z'], dtype='M')
524528
assert_equal(np.array2string(a, separator=', ',
525-
formatter={'datetime': lambda x :
529+
formatter={'datetime': lambda x:
526530
"'%s'" % np.datetime_as_string(x, timezone='UTC')}),
527531
"['2011-03-16T13:55Z', '1920-01-01T03:12Z']")
528532

@@ -608,11 +612,11 @@ def test_cast_overflow(self):
608612
def cast():
609613
numpy.datetime64("1971-01-01 00:00:00.000000000000000").astype("<M8[D]")
610614
assert_raises(OverflowError, cast)
615+
611616
def cast2():
612617
numpy.datetime64("2014").astype("<M8[fs]")
613618
assert_raises(OverflowError, cast2)
614619

615-
616620
def test_pyobject_roundtrip(self):
617621
# All datetime types should be able to roundtrip through object
618622
a = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1080,7 +1084,7 @@ def test_datetime_minmax(self):
10801084
def test_hours(self):
10811085
t = np.ones(3, dtype='M8[s]')
10821086
t[0] = 60*60*24 + 60*60*10
1083-
assert_(t[0].item().hour == 10 )
1087+
assert_(t[0].item().hour == 10)
10841088

10851089
def test_divisor_conversion_year(self):
10861090
assert_(np.dtype('M8[Y/4]') == np.dtype('M8[3M]'))
@@ -1116,10 +1120,10 @@ def test_divisor_conversion_second(self):
11161120

11171121
def test_divisor_conversion_fs(self):
11181122
assert_(np.dtype('M8[fs/100]') == np.dtype('M8[10as]'))
1119-
self.assertRaises(ValueError, lambda : np.dtype('M8[3fs/10000]'))
1123+
self.assertRaises(ValueError, lambda: np.dtype('M8[3fs/10000]'))
11201124

11211125
def test_divisor_conversion_as(self):
1122-
self.assertRaises(ValueError, lambda : np.dtype('M8[as/10]'))
1126+
self.assertRaises(ValueError, lambda: np.dtype('M8[as/10]'))
11231127

11241128
def test_string_parser_variants(self):
11251129
# Allow space instead of 'T' between date and time
@@ -1141,7 +1145,6 @@ def test_string_parser_variants(self):
11411145
assert_equal(np.datetime64('1977-03-02T12:30-0230'),
11421146
np.datetime64('1977-03-02T15:00Z'))
11431147

1144-
11451148
def test_string_parser_error_check(self):
11461149
# Arbitrary bad string
11471150
assert_raises(ValueError, np.array, ['badvalue'], np.dtype('M8[us]'))
@@ -1220,7 +1223,6 @@ def test_string_parser_error_check(self):
12201223
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00-25:00'],
12211224
np.dtype('M8[us]'))
12221225

1223-
12241226
def test_creation_overflow(self):
12251227
date = '1980-03-23 20:00:00Z'
12261228
timesteps = np.array([date], dtype='datetime64[s]')[0].astype(np.int64)
@@ -1312,39 +1314,31 @@ def test_datetime_as_string(self):
13121314

13131315
# unit='auto' parameter
13141316
assert_equal(np.datetime_as_string(
1315-
np.datetime64('2032-07-18T12:23:34.123456Z', 'us'),
1316-
unit='auto'),
1317-
'2032-07-18T12:23:34.123456Z')
1317+
np.datetime64('2032-07-18T12:23:34.123456Z', 'us'), unit='auto'),
1318+
'2032-07-18T12:23:34.123456Z')
13181319
assert_equal(np.datetime_as_string(
1319-
np.datetime64('2032-07-18T12:23:34.12Z', 'us'),
1320-
unit='auto'),
1321-
'2032-07-18T12:23:34.120Z')
1320+
np.datetime64('2032-07-18T12:23:34.12Z', 'us'), unit='auto'),
1321+
'2032-07-18T12:23:34.120Z')
13221322
assert_equal(np.datetime_as_string(
1323-
np.datetime64('2032-07-18T12:23:34Z', 'us'),
1324-
unit='auto'),
1325-
'2032-07-18T12:23:34Z')
1323+
np.datetime64('2032-07-18T12:23:34Z', 'us'), unit='auto'),
1324+
'2032-07-18T12:23:34Z')
13261325
assert_equal(np.datetime_as_string(
1327-
np.datetime64('2032-07-18T12:23:00Z', 'us'),
1328-
unit='auto'),
1329-
'2032-07-18T12:23Z')
1326+
np.datetime64('2032-07-18T12:23:00Z', 'us'), unit='auto'),
1327+
'2032-07-18T12:23Z')
13301328
# 'auto' doesn't split up hour and minute
13311329
assert_equal(np.datetime_as_string(
1332-
np.datetime64('2032-07-18T12:00:00Z', 'us'),
1333-
unit='auto'),
1334-
'2032-07-18T12:00Z')
1330+
np.datetime64('2032-07-18T12:00:00Z', 'us'), unit='auto'),
1331+
'2032-07-18T12:00Z')
13351332
assert_equal(np.datetime_as_string(
1336-
np.datetime64('2032-07-18T00:00:00Z', 'us'),
1337-
unit='auto'),
1338-
'2032-07-18')
1333+
np.datetime64('2032-07-18T00:00:00Z', 'us'), unit='auto'),
1334+
'2032-07-18')
13391335
# 'auto' doesn't split up the date
13401336
assert_equal(np.datetime_as_string(
1341-
np.datetime64('2032-07-01T00:00:00Z', 'us'),
1342-
unit='auto'),
1343-
'2032-07-01')
1337+
np.datetime64('2032-07-01T00:00:00Z', 'us'), unit='auto'),
1338+
'2032-07-01')
13441339
assert_equal(np.datetime_as_string(
1345-
np.datetime64('2032-01-01T00:00:00Z', 'us'),
1346-
unit='auto'),
1347-
'2032-01-01')
1340+
np.datetime64('2032-01-01T00:00:00Z', 'us'), unit='auto'),
1341+
'2032-01-01')
13481342

13491343
@dec.skipif(not _has_pytz, "The pytz module is not available.")
13501344
def test_datetime_as_string_timezone(self):
@@ -1610,7 +1604,7 @@ def test_datetime_busday_holidays_offset(self):
16101604
np.datetime64('2011-11-10'))
16111605

16121606
# A bigger forward jump across more than one week/holiday
1613-
holidays=['2011-10-10', '2011-11-11', '2011-11-24',
1607+
holidays = ['2011-10-10', '2011-11-11', '2011-11-24',
16141608
'2011-12-25', '2011-05-30', '2011-02-21',
16151609
'2011-12-26', '2012-01-02']
16161610
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)
@@ -1712,10 +1706,10 @@ def test_datetime_busday_holidays_offset(self):
17121706
np.datetime64('2012-03-08'))
17131707

17141708
def test_datetime_busday_holidays_count(self):
1715-
holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
1716-
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
1717-
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
1718-
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10']
1709+
holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
1710+
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
1711+
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
1712+
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10']
17191713
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)
17201714

17211715
# Validate against busday_offset broadcast against
@@ -1748,11 +1742,11 @@ def test_datetime_busday_holidays_count(self):
17481742
assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
17491743

17501744
def test_datetime_is_busday(self):
1751-
holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
1752-
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
1753-
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
1754-
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10',
1755-
'NaT']
1745+
holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
1746+
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
1747+
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
1748+
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10',
1749+
'NaT']
17561750
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)
17571751

17581752
# Weekend/weekday tests

0 commit comments

Comments
 (0)
0