summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/scalarapi.c6
-rw-r--r--numpy/core/src/multiarray/ucsnarrow.c16
-rw-r--r--numpy/core/tests/test_datetime.py68
-rw-r--r--numpy/random/__init__.py12
4 files changed, 50 insertions, 52 deletions
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 5afa61a1c..e43e0dbe8 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -707,11 +707,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
#endif
/* Need an extra slot and need to use Python memory manager */
uni->str = NULL;
-#if PY_VERSION_HEX >= 0x02070000
- destptr = PyObject_MALLOC(sizeof(Py_UNICODE) * (length + 1));
-#else
- destptr = PyMem_NEW(Py_UNICODE, length + 1);
-#endif
+ destptr = PyMem_NEW(Py_UNICODE,length+1);
if (destptr == NULL) {
Py_DECREF(obj);
return PyErr_NoMemory();
diff --git a/numpy/core/src/multiarray/ucsnarrow.c b/numpy/core/src/multiarray/ucsnarrow.c
index 850d734f4..2deab106a 100644
--- a/numpy/core/src/multiarray/ucsnarrow.c
+++ b/numpy/core/src/multiarray/ucsnarrow.c
@@ -92,14 +92,8 @@ MyPyUnicode_New(int length)
{
PyUnicodeObject *unicode;
unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
- if (unicode == NULL) {
- return NULL;
- }
-#if PY_VERSION_HEX >= 0x02070000
- unicode->str = PyObject_MALLOC(sizeof(Py_UNICODE) * (length + 1));
-#else
- unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
-#endif
+ if (unicode == NULL) return NULL;
+ unicode->str = PyMem_NEW(Py_UNICODE, length+1);
if (!unicode->str) {
_Py_ForgetReference((PyObject *)unicode);
PyObject_Del(unicode);
@@ -122,11 +116,7 @@ MyPyUnicode_Resize(PyUnicodeObject *uni, int length)
void *oldstr;
oldstr = uni->str;
-#if PY_VERSION_HEX >= 0x02070000
- PyObject_REALLOC(uni->str, sizeof(Py_UNICODE) * (length + 1));
-#else
- PyMem_RESIZE(uni->str, Py_UNICODE, length + 1);
-#endif
+ PyMem_RESIZE(uni->str, Py_UNICODE, length+1);
if (!uni->str) {
uni->str = oldstr;
PyErr_NoMemory();
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index a0519612e..842bb9bc4 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -5,6 +5,14 @@ from numpy.testing import *
from numpy.compat import asbytes
import datetime
+# Use pytz to test out various time zones if available
+try:
+ from pytz import timezone as tz
+ _has_pytz = True
+except ImportError:
+ _has_pytz = False
+
+
class TestDateTime(TestCase):
def test_datetime_dtype_creation(self):
for unit in ['Y', 'M', 'W', 'D',
@@ -1276,6 +1284,7 @@ class TestDateTime(TestCase):
unit='auto'),
'2032-01-01')
+ @dec.skipif(not _has_pytz, "The pytz module is not available.")
def test_datetime_as_string_timezone(self):
# timezone='local' vs 'UTC'
a = np.datetime64('2010-03-15T06:30Z', 'm')
@@ -1284,39 +1293,32 @@ class TestDateTime(TestCase):
assert_(np.datetime_as_string(a, timezone='local') !=
'2010-03-15T06:30Z')
- # Use pytz to test out various time zones
- try:
- from pytz import timezone as tz
-
- b = np.datetime64('2010-02-15T06:30Z', 'm')
-
- assert_equal(np.datetime_as_string(a, timezone=tz('US/Central')),
- '2010-03-15T01:30-0500')
- assert_equal(np.datetime_as_string(a, timezone=tz('US/Eastern')),
- '2010-03-15T02:30-0400')
- assert_equal(np.datetime_as_string(a, timezone=tz('US/Pacific')),
- '2010-03-14T23:30-0700')
-
- assert_equal(np.datetime_as_string(b, timezone=tz('US/Central')),
- '2010-02-15T00:30-0600')
- assert_equal(np.datetime_as_string(b, timezone=tz('US/Eastern')),
- '2010-02-15T01:30-0500')
- assert_equal(np.datetime_as_string(b, timezone=tz('US/Pacific')),
- '2010-02-14T22:30-0800')
-
- # Dates to strings with a timezone attached is disabled by default
- assert_raises(TypeError, np.datetime_as_string, a, unit='D',
- timezone=tz('US/Pacific'))
- # Check that we can print out the date in the specified time zone
- assert_equal(np.datetime_as_string(a, unit='D',
- timezone=tz('US/Pacific'), casting='unsafe'),
- '2010-03-14')
- assert_equal(np.datetime_as_string(b, unit='D',
- timezone=tz('US/Central'), casting='unsafe'),
- '2010-02-15')
- except ImportError:
- import warnings
- warnings.warn("pytz not found, pytz compatibility tests skipped")
+ b = np.datetime64('2010-02-15T06:30Z', 'm')
+
+ assert_equal(np.datetime_as_string(a, timezone=tz('US/Central')),
+ '2010-03-15T01:30-0500')
+ assert_equal(np.datetime_as_string(a, timezone=tz('US/Eastern')),
+ '2010-03-15T02:30-0400')
+ assert_equal(np.datetime_as_string(a, timezone=tz('US/Pacific')),
+ '2010-03-14T23:30-0700')
+
+ assert_equal(np.datetime_as_string(b, timezone=tz('US/Central')),
+ '2010-02-15T00:30-0600')
+ assert_equal(np.datetime_as_string(b, timezone=tz('US/Eastern')),
+ '2010-02-15T01:30-0500')
+ assert_equal(np.datetime_as_string(b, timezone=tz('US/Pacific')),
+ '2010-02-14T22:30-0800')
+
+ # Dates to strings with a timezone attached is disabled by default
+ assert_raises(TypeError, np.datetime_as_string, a, unit='D',
+ timezone=tz('US/Pacific'))
+ # Check that we can print out the date in the specified time zone
+ assert_equal(np.datetime_as_string(a, unit='D',
+ timezone=tz('US/Pacific'), casting='unsafe'),
+ '2010-03-14')
+ assert_equal(np.datetime_as_string(b, unit='D',
+ timezone=tz('US/Central'), casting='unsafe'),
+ '2010-02-15')
def test_datetime_arange(self):
# With two datetimes provided as strings
diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py
index 73b5fdabc..34e57ba2c 100644
--- a/numpy/random/__init__.py
+++ b/numpy/random/__init__.py
@@ -88,7 +88,17 @@ set_state Set state of generator.
"""
# To get sub-modules
from info import __doc__, __all__
-from mtrand import *
+
+import warnings
+from numpy.testing.utils import WarningManager
+
+warn_ctx = WarningManager()
+warn_ctx.__enter__()
+try:
+ warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
+ from mtrand import *
+finally:
+ warn_ctx.__exit__()
# Some aliases:
ranf = random = sample = random_sample