8000 PEP8 and pyflakes fixups for numpy/core/tests/*.py by charris · Pull Request #6047 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

PEP8 and pyflakes fixups for numpy/core/tests/*.py #6047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions numpy/core/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from __future__ import division, absolute_import, print_function

import sys
import warnings

import numpy as np
from numpy.testing import *
from numpy.compat import sixu
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_array_equal,
assert_raises
)

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


def test_array_array():
obj = object()
tobj = type(object)
ones11 = np.ones((1, 1), np.float64)
tndarray = type(ones11)
# Test is_ndarary
# Test is_ndarray
assert_equal(np.array(ones11, dtype=np.float64), ones11)
old_refcount = sys.getrefcount(tndarray)
np.array(ones11)
Expand Down
26 changes: 15 additions & 11 deletions numpy/core/tests/test_arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
from __future__ import division, absolute_import, print_function

import sys

import numpy as np
from numpy.testing import *
from numpy.compat import sixu
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal
)

class TestArrayRepr(object):
def test_nan_inf(self):
Expand Down Expand Up @@ -81,37 +84,39 @@ def _format_function(x):
return 'o'
else:
return 'O'

x = np.arange(3)
if sys.version_info[0] >= 3:
x_hex = "[0x0 0x1 0x2]"
x_oct = "[0o0 0o1 0o2]"
else:
x_hex = "[0x0L 0x1L 0x2L]"
x_oct = "[0L 01L 02L]"
assert_(np.array2string(x, formatter={'all':_format_function}) == \
assert_(np.array2string(x, formatter={'all':_format_function}) ==
"[. o O]")
assert_(np.array2string(x, formatter={'int_kind':_format_function}) ==\
assert_(np.array2string(x, formatter={'int_kind':_format_function}) ==
"[. o O]")
assert_(np.array2string(x, formatter={'all':lambda x: "%.4f" % x}) == \
assert_(np.array2string(x, formatter={'all':lambda x: "%.4f" % x}) ==
"[0.0000 1.0000 2.0000]")
assert_equal(np.array2string(x, formatter={'int':lambda x: hex(x)}), \
assert_equal(np.array2string(x, formatter={'int':lambda x: hex(x)}),
x_hex)
assert_equal(np.array2string(x, formatter={'int':lambda x: oct(x)}), \
assert_equal(np.array2string(x, formatter={'int':lambda x: oct(x)}),
x_oct)

x = np.arange(3.)
assert_(np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) == \
assert_(np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) ==
"[0.00 1.00 2.00]")
assert_(np.array2string(x, formatter={'float':lambda x: "%.2f" % x}) == \
assert_(np.array2string(x, formatter={'float':lambda x: "%.2f" % x}) ==
"[0.00 1.00 2.00]")

s = np.array(['abc', 'def'])
assert_(np.array2string(s, formatter={'numpystr':lambda s: s*2}) == \
'[abcabc defdef]')
assert_(np.array2string(s, formatter={'numpystr':lambda s: s*2}) ==
'[abcabc defdef]')


class TestPrintOptions:
"""Test getting and setting global print options."""

def setUp(self):
self.oldopts = np.get_printoptions()

Expand Down Expand Up @@ -162,6 +167,5 @@ def test_unicode_object_array():
assert_equal(repr(x), expected)



if __name__ == "__main__":
run_module_suite()
84 changes: 39 additions & 45 deletions numpy/core/tests/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from __future__ import division, absolute_import, print_function

import os, pickle
import pickle

import numpy
import numpy as np
from numpy.testing import *
from numpy.compat import asbytes
import datetime
from numpy.compat import asbytes
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
dec
)

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

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

Expand Down Expand Up @@ -608,11 +612,11 @@ def test_cast_overflow(self):
def cast():
numpy.datetime64("1971-01-01 00:00:00.000000000000000").astype("<M8[D]")
assert_raises(OverflowError, cast)

def cast2():
numpy.datetime64("2014").astype("<M8[fs]")
assert_raises(OverflowError, cast2)


def test_pyobject_roundtrip(self):
# All datetime types should be able to roundtrip through object
a = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down Expand Up @@ -1080,7 +1084,7 @@ def test_datetime_minmax(self):
def test_hours(self):
t = np.ones(3, dtype='M8[s]')
t[0] = 60*60*24 + 60*60*10
assert_(t[0].item().hour == 10 )
assert_(t[0].item().hour == 10)

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

def test_divisor_conversion_fs(self):
assert_(np.dtype('M8[fs/100]') == np.dtype('M8[10as]'))
self.assertRaises(ValueError, lambda : np.dtype('M8[3fs/10000]'))
self.assertRaises(ValueError, lambda: np.dtype('M8[3fs/10000]'))

def test_divisor_conversion_as(self):
self.assertRaises(ValueError, lambda : np.dtype('M8[as/10]'))
self.assertRaises(ValueError, lambda: np.dtype('M8[as/10]'))

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


def test_string_parser_error_check(self):
# Arbitrary bad string
assert_raises(ValueError, np.array, ['badvalue'], np.dtype('M8[us]'))
Expand Down Expand Up @@ -1220,7 +1223,6 @@ def test_string_parser_error_check(self):
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00-25:00'],
np.dtype('M8[us]'))


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

# unit='auto' parameter
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:34.123456Z', 'us'),
unit='auto'),
'2032-07-18T12:23:34.123456Z')
np.datetime64('2032-07-18T12:23:34.123456Z', 'us'), unit='auto'),
'2032-07-18T12:23:34.123456Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:34.12Z', 'us'),
unit='auto'),
'2032-07-18T12:23:34.120Z')
np.datetime64('2032-07-18T12:23:34.12Z', 'us'), unit='auto'),
'2032-07-18T12:23:34.120Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:34Z', 'us'),
unit='auto'),
'2032-07-18T12:23:34Z')
np.datetime64('2032-07-18T12:23:34Z', 'us'), unit='auto'),
'2032-07-18T12:23:34Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:00Z', 'us'),
unit='auto'),
'2032-07-18T12:23Z')
np.datetime64('2032-07-18T12:23:00Z', 'us'), unit='auto'),
'2032-07-18T12:23Z')
# 'auto' doesn't split up hour and minute
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:00:00Z', 'us'),
unit='auto'),
'2032-07-18T12:00Z')
np.datetime64('2032-07-18T12:00:00Z', 'us'), unit='auto'),
'2032-07-18T12:00Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T00:00:00Z', 'us'),
unit='auto'),
'2032-07-18')
np.datetime64('2032-07-18T00:00:00Z', 'us'), unit='auto'),
'2032-07-18')
# 'auto' doesn't split up the date
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-01T00:00:00Z', 'us'),
unit='auto'),
'2032-07-01')
np.datetime64('2032-07-01T00:00:00Z', 'us'), unit='auto'),
'2032-07-01')
assert_equal(np.datetime_as_string(
np.datetime64('2032-01-01T00:00:00Z', 'us'),
unit='auto'),
'2032-01-01')
np.datetime64('2032-01-01T00:00:00Z', 'us'), unit='auto'),
'2032-01-01')

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

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

def test_datetime_busday_holidays_count(self):
holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10']
holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10']
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)

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

def test_datetime_is_busday(self):
holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10',
'NaT']
holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10',
'NaT']
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)

# Weekend/weekday tests
Expand Down
Loading
0