Skip to content

Commit 9dfda59

Browse files
committed
Merge pull request #252 from rgommers/ticket-2103-cython-warning
Fix some test warnings
2 parents 0679842 + 12fe3d1 commit 9dfda59

2 files changed

Lines changed: 46 additions & 34 deletions

File tree

‎numpy/core/tests/test_datetime.py‎

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
from numpy.compat import asbytes
66
import datetime
77

8+
# Use pytz to test out various time zones if available
9+
try:
10+
from pytz import timezone as tz
11+
_has_pytz = True
12+
except ImportError:
13+
_has_pytz = False
14+
15+
816
class TestDateTime(TestCase):
917
def test_datetime_dtype_creation(self):
1018
for unit in ['Y', 'M', 'W', 'D',
@@ -1276,6 +1284,7 @@ def test_datetime_as_string(self):
12761284
unit='auto'),
12771285
'2032-01-01')
12781286

1287+
@dec.skipif(not _has_pytz, "The pytz module is not available.")
12791288
def test_datetime_as_string_timezone(self):
12801289
# timezone='local' vs 'UTC'
12811290
a = np.datetime64('2010-03-15T06:30Z', 'm')
@@ -1284,39 +1293,32 @@ def test_datetime_as_string_timezone(self):
12841293
assert_(np.datetime_as_string(a, timezone='local') !=
12851294
'2010-03-15T06:30Z')
12861295

1287-
# Use pytz to test out various time zones
1288-
try:
1289-
from pytz import timezone as tz
1290-
1291-
b = np.datetime64('2010-02-15T06:30Z', 'm')
1292-
1293-
assert_equal(np.datetime_as_string(a, timezone=tz('US/Central')),
1294-
'2010-03-15T01:30-0500')
1295-
assert_equal(np.datetime_as_string(a, timezone=tz('US/Eastern')),
1296-
'2010-03-15T02:30-0400')
1297-
assert_equal(np.datetime_as_string(a, timezone=tz('US/Pacific')),
1298-
'2010-03-14T23:30-0700')
1299-
1300-
assert_equal(np.datetime_as_string(b, timezone=tz('US/Central')),
1301-
'2010-02-15T00:30-0600')
1302-
assert_equal(np.datetime_as_string(b, timezone=tz('US/Eastern')),
1303-
'2010-02-15T01:30-0500')
1304-
assert_equal(np.datetime_as_string(b, timezone=tz('US/Pacific')),
1305-
'2010-02-14T22:30-0800')
1306-
1307-
# Dates to strings with a timezone attached is disabled by default
1308-
assert_raises(TypeError, np.datetime_as_string, a, unit='D',
1309-
timezone=tz('US/Pacific'))
1310-
# Check that we can print out the date in the specified time zone
1311-
assert_equal(np.datetime_as_string(a, unit='D',
1312-
timezone=tz('US/Pacific'), casting='unsafe'),
1313-
'2010-03-14')
1314-
assert_equal(np.datetime_as_string(b, unit='D',
1315-
timezone=tz('US/Central'), casting='unsafe'),
1316-
'2010-02-15')
1317-
except ImportError:
1318-
import warnings
1319-
warnings.warn("pytz not found, pytz compatibility tests skipped")
1296+
b = np.datetime64('2010-02-15T06:30Z', 'm')
1297+
1298+
assert_equal(np.datetime_as_string(a, timezone=tz('US/Central')),
1299+
'2010-03-15T01:30-0500')
1300+
assert_equal(np.datetime_as_string(a, timezone=tz('US/Eastern')),
1301+
'2010-03-15T02:30-0400')
1302+
assert_equal(np.datetime_as_string(a, timezone=tz('US/Pacific')),
1303+
'2010-03-14T23:30-0700')
1304+
1305+
assert_equal(np.datetime_as_string(b, timezone=tz('US/Central')),
1306+
'2010-02-15T00:30-0600')
1307+
assert_equal(np.datetime_as_string(b, timezone=tz('US/Eastern')),
1308+
'2010-02-15T01:30-0500')
1309+
assert_equal(np.datetime_as_string(b, timezone=tz('US/Pacific')),
1310+
'2010-02-14T22:30-0800')
1311+
1312+
# Dates to strings with a timezone attached is disabled by default
1313+
assert_raises(TypeError, np.datetime_as_string, a, unit='D',
1314+
timezone=tz('US/Pacific'))
1315+
# Check that we can print out the date in the specified time zone
1316+
assert_equal(np.datetime_as_string(a, unit='D',
1317+
timezone=tz('US/Pacific'), casting='unsafe'),
1318+
'2010-03-14')
1319+
assert_equal(np.datetime_as_string(b, unit='D',
1320+
timezone=tz('US/Central'), casting='unsafe'),
1321+
'2010-02-15')
13201322

13211323
def test_datetime_arange(self):
13221324
# With two datetimes provided as strings

‎numpy/random/__init__.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,17 @@
8888
"""
8989
# To get sub-modules
9090
from info import __doc__, __all__
91-
from mtrand import *
91+
92+
import warnings
93+
from numpy.testing.utils import WarningManager
94+
95+
warn_ctx = WarningManager()
96+
warn_ctx.__enter__()
97+
try:
98+
warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
99+
from mtrand import *
100+
finally:
101+
warn_ctx.__exit__()
92102

93103
# Some aliases:
94104
ranf = random = sample = random_sample

0 commit comments

Comments
 (0)