diff options
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/include/numpy/npy_common.h | 2 | ||||
-rw-r--r-- | numpy/core/include/numpy/ufuncobject.h | 38 | ||||
-rw-r--r-- | numpy/core/setup.py | 6 | ||||
-rw-r--r-- | numpy/core/src/common/numpyos.c (renamed from numpy/core/src/multiarray/numpyos.c) | 28 | ||||
-rw-r--r-- | numpy/core/src/common/numpyos.h (renamed from numpy/core/src/multiarray/numpyos.h) | 7 | ||||
-rw-r--r-- | numpy/core/src/common/wrapper.c | 33 | ||||
-rw-r--r-- | numpy/core/src/common/wrapper.h | 13 | ||||
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 5 | ||||
-rw-r--r-- | numpy/core/src/umath/_umath_tests.c.src | 26 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 41 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 46 | ||||
-rw-r--r-- | numpy/core/tests/test_datetime.py | 67 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 2 |
13 files changed, 129 insertions, 185 deletions
diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h index 5faff4385..64aaaacff 100644 --- a/numpy/core/include/numpy/npy_common.h +++ b/numpy/core/include/numpy/npy_common.h @@ -14,7 +14,7 @@ * using static inline modifiers when defining npy_math functions * allows the compiler to make optimizations when possible */ -#if NPY_INTERNAL_BUILD +#if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD #ifndef NPY_INLINE_MATH #define NPY_INLINE_MATH 1 #endif diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index f04de088f..430c1873e 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -111,6 +111,24 @@ typedef int (PyUFunc_MaskedInnerLoopSelectionFunc)( NpyAuxData **out_innerloopdata, int *out_needs_api); +typedef struct _ufunc_extension { + /* New in PyUFuncObject version 1 and above */ + + /* + * for each core_num_dim_ix distinct dimension names, + * the possible "frozen" size (-1 if not frozen). + */ + npy_intp *core_dim_sizes; + + /* + * for each distinct core dimension, a set of flags OR'd together + * e.g., UFUNC_CORE_DIM_CAN_IGNORE if signature has ? + * UFUNC_CORE_DIM_SIZE_UNSET for non-frozen dimensions. + */ + npy_uint32 *core_dim_flags; + +} ufunc_extension; + typedef struct _tagPyUFuncObject { PyObject_HEAD /* @@ -188,9 +206,10 @@ typedef struct _tagPyUFuncObject { /* * This was blocked off to be the "new" inner loop selector in 1.7, * but this was never implemented. (This is also why the above - * selector is called the "legacy" selector.) + * selector is called the "legacy" selector.) Repurposed in 1.16 to + * point to s_extension */ - void *reserved2; + ufunc_extension * extension; /* * A function which returns a masked inner loop for the ufunc. */ @@ -210,20 +229,7 @@ typedef struct _tagPyUFuncObject { */ npy_uint32 iter_flags; - /* New in version 1 and above */ - - /* - * for each core_num_dim_ix distinct dimension names, - * the possible "frozen" size (-1 if not frozen). - */ - npy_intp *core_dim_sizes; - - /* - * for each distinct core dimension, a set of flags OR'd together - * e.g., UFUNC_CORE_DIM_CAN_IGNORE if signature has ? - * UFUNC_CORE_DIM_SIZE_UNSET for non-frozen dimensions. - */ - npy_uint32 *core_dim_flags; + ufunc_extension s_extension; } PyUFuncObject; diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 986e40007..c15dee5b9 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -737,7 +737,7 @@ def configuration(parent_package='',top_path=None): join('src', 'common', 'ucsnarrow.h'), join('src', 'common', 'ufunc_override.h'), join('src', 'common', 'umathmodule.h'), - join('src', 'common', 'wrapper.h'), + join('src', 'common', 'numpyos.h'), ] common_src = [ @@ -747,7 +747,7 @@ def configuration(parent_package='',top_path=None): join('src', 'common', 'templ_common.h.src'), join('src', 'common', 'ucsnarrow.c'), join('src', 'common', 'ufunc_override.c'), - join('src', 'common', 'wrapper.c'), + join('src', 'common', 'numpyos.c'), ] blas_info = get_info('blas_opt', 0) @@ -787,7 +787,6 @@ def configuration(parent_package='',top_path=None): join('src', 'multiarray', 'multiarraymodule.h'), join('src', 'multiarray', 'nditer_impl.h'), join('src', 'multiarray', 'number.h'), - join('src', 'multiarray', 'numpyos.h'), join('src', 'multiarray', 'refcount.h'), join('src', 'multiarray', 'scalartypes.h'), join('src', 'multiarray', 'sequence.h'), @@ -853,7 +852,6 @@ def configuration(parent_package='',top_path=None): join('src', 'multiarray', 'nditer_constr.c'), join('src', 'multiarray', 'nditer_pywrap.c'), join('src', 'multiarray', 'number.c'), - join('src', 'multiarray', 'numpyos.c'), join('src', 'multiarray', 'refcount.c'), join('src', 'multiarray', 'sequence.c'), join('src', 'multiarray', 'shape.c'), diff --git a/numpy/core/src/multiarray/numpyos.c b/numpy/core/src/common/numpyos.c index 52dcbf3c8..d60b1ca17 100644 --- a/numpy/core/src/multiarray/numpyos.c +++ b/numpy/core/src/common/numpyos.c @@ -769,3 +769,31 @@ NumPyOS_ascii_ftoLf(FILE *fp, long double *value) } return r; } + +NPY_NO_EXPORT npy_longlong +NumPyOS_strtoll(const char *str, char **endptr, int base) +{ +#if defined HAVE_STRTOLL + return strtoll(str, endptr, base); +#elif defined _MSC_VER + return _strtoi64(str, endptr, base); +#else + /* ok on 64 bit posix */ + return PyOS_strtol(str, endptr, base); +#endif +} + +NPY_NO_EXPORT npy_ulonglong +NumPyOS_strtoull(const char *str, char **endptr, int base) +{ +#if defined HAVE_STRTOULL + return strtoull(str, endptr, base); +#elif defined _MSC_VER + return _strtoui64(str, endptr, base); +#else + /* ok on 64 bit posix */ + return PyOS_strtoul(str, endptr, base); +#endif +} + + diff --git a/numpy/core/src/multiarray/numpyos.h b/numpy/core/src/common/numpyos.h index 7ca795a6f..4deed8400 100644 --- a/numpy/core/src/multiarray/numpyos.h +++ b/numpy/core/src/common/numpyos.h @@ -31,4 +31,11 @@ NumPyOS_ascii_ftoLf(FILE *fp, long double *value); NPY_NO_EXPORT int NumPyOS_ascii_isspace(int c); +/* Convert a string to an int in an arbitrary base */ +NPY_NO_EXPORT npy_longlong +NumPyOS_strtoll(const char *str, char **endptr, int base); + +/* Convert a string to an int in an arbitrary base */ +NPY_NO_EXPORT npy_ulonglong +NumPyOS_strtoull(const char *str, char **endptr, int base); #endif diff --git a/numpy/core/src/common/wrapper.c b/numpy/core/src/common/wrapper.c deleted file mode 100644 index 43b7064fc..000000000 --- a/numpy/core/src/common/wrapper.c +++ /dev/null @@ -1,33 +0,0 @@ -#define NPY_NO_DEPRECATED_API NPY_API_VERSION -#define _MULTIARRAYMODULE -#include <Python.h> -#include <numpy/arrayobject.h> -#include "wrapper.h" - -NPY_NO_EXPORT npy_longlong -npy_strtoll(const char *str, char **endptr, int base) -{ -#if defined HAVE_STRTOLL - return strtoll(str, endptr, base); -#elif defined _MSC_VER - return _strtoi64(str, endptr, base); -#else - /* ok on 64 bit posix */ - return PyOS_strtol(str, endptr, base); -#endif -} - -NPY_NO_EXPORT npy_ulonglong -npy_strtoull(const char *str, char **endptr, int base) -{ -#if defined HAVE_STRTOULL - return strtoull(str, endptr, base); -#elif defined _MSC_VER - return _strtoui64(str, endptr, base); -#else - /* ok on 64 bit posix */ - return PyOS_strtoul(str, endptr, base); -#endif -} - - diff --git a/numpy/core/src/common/wrapper.h b/numpy/core/src/common/wrapper.h deleted file mode 100644 index 3c0686d92..000000000 --- a/numpy/core/src/common/wrapper.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _COMMON_WRAPPER_H -#define _COMMON_WRAPPER_H - - -/* Convert a string to an int in an arbitrary base */ -NPY_NO_EXPORT npy_longlong -npy_strtoll(const char *str, char **endptr, int base); - -/* Convert a string to an int in an arbitrary base */ -NPY_NO_EXPORT npy_ulonglong -npy_strtoull(const char *str, char **endptr, int base); - -#endif diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 31d69b5f5..db5fa2586 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -34,7 +34,6 @@ #include "cblasfuncs.h" #include "npy_cblas.h" -#include "wrapper.h" #include <limits.h> #include <assert.h> @@ -1767,8 +1766,8 @@ BOOL_scan(FILE *fp, npy_bool *ip, void *NPY_UNUSED(ignore), * #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint, * npy_long, npy_ulong, npy_longlong, npy_ulonglong, * npy_datetime, npy_timedelta# - * #func = (PyOS_strtol, PyOS_strtoul)*4, npy_strtoll, npy_strtoull, - * npy_strtoll*2# + * #func = (PyOS_strtol, PyOS_strtoul)*4, NumPyOS_strtoll, NumPyOS_strtoull, + * NumPyOS_strtoll*2# * #btype = (npy_long, npy_ulong)*4, npy_longlong, npy_ulonglong, * npy_longlong*2# */ diff --git a/numpy/core/src/umath/_umath_tests.c.src b/numpy/core/src/umath/_umath_tests.c.src index 36f2d52d6..e03ab12ec 100644 --- a/numpy/core/src/umath/_umath_tests.c.src +++ b/numpy/core/src/umath/_umath_tests.c.src @@ -217,16 +217,20 @@ static void INIT_OUTER_LOOP_3 npy_intp is1=steps[0], is2=steps[1], os = steps[2]; BEGIN_OUTER_LOOP_3 - char *ip1=args[0], *ip2=args[1], *op=args[2]; + @typ@ i1_x = *(@typ@ *)(args[0] + 0*is1); + @typ@ i1_y = *(@typ@ *)(args[0] + 1*is1); + @typ@ i1_z = *(@typ@ *)(args[0] + 2*is1); + + @typ@ i2_x = *(@typ@ *)(args[1] + 0*is2); + @typ@ i2_y = *(@typ@ *)(args[1] + 1*is2); + @typ@ i2_z = *(@typ@ *)(args[1] + 2*is2); + char *op = args[2]; - *(@typ@ *)op = *(@typ@ *)(ip1 + is1) * *(@typ@ *)(ip2 + 2*is2) - - *(@typ@ *)(ip1 + 2*is1) * *(@typ@ *)(ip2 + is2); + *(@typ@ *)op = i1_y * i2_z - i1_z * i2_y; op += os; - *(@typ@ *)op = *(@typ@ *)(ip1 + 2*is1) * *(@typ@ *)ip2 - - *(@typ@ *)ip1 * *(@typ@ *)(ip2 + 2*is2); + *(@typ@ *)op = i1_z * i2_x - i1_x * i2_z; op += os; - *(@typ@ *)op = *(@typ@ *)ip1 * *(@typ@ *)(ip2 + is2) - - *(@typ@ *)(ip1 + is1) * *(@typ@ *)ip2; + *(@typ@ *)op = i1_x * i2_y - i1_y * i2_x; END_OUTER_LOOP } @@ -531,13 +535,13 @@ UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args) Py_INCREF(Py_None); core_dim_ixs = Py_None; } - if (f->core_dim_flags != NULL) { + if (f->extension->core_dim_flags != NULL) { core_dim_flags = PyTuple_New(f->core_num_dim_ix); if (core_dim_flags == NULL) { goto fail; } for (i = 0; i < f->core_num_dim_ix; i++) { - PyObject * val = PyLong_FromLong(f->core_dim_flags[i]); + PyObject * val = PyLong_FromLong(f->extension->core_dim_flags[i]); PyTuple_SET_ITEM(core_dim_flags, i, val); } } @@ -545,13 +549,13 @@ UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args) Py_INCREF(Py_None); core_dim_flags = Py_None; } - if (f->core_dim_sizes != NULL) { + if (f->extension->core_dim_sizes != NULL) { core_dim_sizes = PyTuple_New(f->core_num_dim_ix); if (core_dim_sizes == NULL) { goto fail; } for (i = 0; i < f->core_num_dim_ix; i++) { - PyObject * val = PyLong_FromLong(f->core_dim_sizes[i]); + PyObject * val = PyLong_FromLong(f->extension->core_dim_sizes[i]); PyTuple_SET_ITEM(core_dim_sizes, i, val); } } diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 66b69f555..e62942efd 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -1327,27 +1327,12 @@ NPY_NO_EXPORT void NPY_NO_EXPORT void @TYPE@_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { - npy_bool give_future_warning = 0; BINARY_LOOP { const @type@ in1 = *(@type@ *)ip1; const @type@ in2 = *(@type@ *)ip2; - const npy_bool res = in1 @OP@ in2; - *((npy_bool *)op1) = res; - - if ((in1 == NPY_DATETIME_NAT || in2 == NPY_DATETIME_NAT) && res) { - give_future_warning = 1; - } - } - if (give_future_warning) { - NPY_ALLOW_C_API_DEF - NPY_ALLOW_C_API; - /* 2016-01-18, 1.11 */ - if (DEPRECATE_FUTUREWARNING( - "In the future, 'NAT @OP@ x' and 'x @OP@ NAT' " - "will always be False.") < 0) { - /* nothing to do, we return anyway */ - } - NPY_DISABLE_C_API; + *((npy_bool *)op1) = (in1 @OP@ in2 && + in1 != NPY_DATETIME_NAT && + in2 != NPY_DATETIME_NAT); } } /**end repeat1**/ @@ -1355,26 +1340,12 @@ NPY_NO_EXPORT void NPY_NO_EXPORT void @TYPE@_not_equal(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { - npy_bool give_future_warning = 0; BINARY_LOOP { const @type@ in1 = *(@type@ *)ip1; const @type@ in2 = *(@type@ *)ip2; - *((npy_bool *)op1) = in1 != in2; - - if (in1 == NPY_DATETIME_NAT && in2 == NPY_DATETIME_NAT) { - give_future_warning = 1; - } - } - if (give_future_warning) { - NPY_ALLOW_C_API_DEF - NPY_ALLOW_C_API; - /* 2016-01-18, 1.11 */ - if (DEPRECATE_FUTUREWARNING( - "In the future, NAT != NAT will be True " - "rather than False.") < 0) { - /* nothing to do, we return anyway */ - } - NPY_DISABLE_C_API; + *((npy_bool *)op1) = (in1 != in2 || + in1 == NPY_DATETIME_NAT || + in2 == NPY_DATETIME_NAT); } } diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 8f792ef31..9f2bb3fb6 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -46,7 +46,7 @@ #include "npy_import.h" #include "extobj.h" #include "common.h" -#include "wrapper.h" +#include "numpyos.h" /********** PRINTF DEBUG TRACING **************/ #define NPY_UF_DBG_TRACING 0 @@ -487,7 +487,7 @@ static npy_int _get_size(const char* str) { char *stop; - npy_longlong size = npy_strtoll(str, &stop, 10); + npy_longlong size = NumPyOS_strtoll(str, &stop, 10); if (stop == str || _is_alpha_underscore(*stop)) { /* not a well formed number */ @@ -572,17 +572,18 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature) ufunc->core_offsets = PyArray_malloc(sizeof(int) * ufunc->nargs); /* The next three items will be shrunk later */ ufunc->core_dim_ixs = PyArray_malloc(sizeof(int) * len); - ufunc->core_dim_flags = PyArray_malloc(sizeof(npy_uint32) * len); - ufunc->core_dim_sizes = PyArray_malloc(sizeof(npy_intp) * len); + ufunc->extension->core_dim_sizes = PyArray_malloc(sizeof(npy_intp) * len); + ufunc->extension->core_dim_flags = PyArray_malloc(sizeof(npy_uint32) * len); if (ufunc->core_num_dims == NULL || ufunc->core_dim_ixs == NULL || - ufunc->core_offsets == NULL || ufunc->core_dim_flags == NULL || - ufunc->core_dim_sizes == NULL) { + ufunc->core_offsets == NULL || + ufunc->extension->core_dim_sizes == NULL || + ufunc->extension->core_dim_flags == NULL) { PyErr_NoMemory(); goto fail; } for (i = 0; i < len; i++) { - ufunc->core_dim_flags[i] = 0; + ufunc->extension->core_dim_flags[i] = 0; } i = _next_non_white_space(signature, 0); @@ -638,7 +639,7 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature) */ for(ix = 0; ix < ufunc->core_num_dim_ix; ix++) { if (frozen_size > 0 ? - frozen_size == ufunc->core_dim_sizes[ix] : + frozen_size == ufunc->extension->core_dim_sizes[ix] : _is_same_name(signature + i, var_names[ix])) { break; } @@ -649,20 +650,20 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature) if (ix == ufunc->core_num_dim_ix) { ufunc->core_num_dim_ix++; var_names[ix] = signature + i; - ufunc->core_dim_sizes[ix] = frozen_size; + ufunc->extension->core_dim_sizes[ix] = frozen_size; if (frozen_size < 0) { - ufunc->core_dim_flags[ix] |= UFUNC_CORE_DIM_SIZE_UNSET; + ufunc->extension->core_dim_flags[ix] |= UFUNC_CORE_DIM_SIZE_UNSET; } if (can_ignore) { - ufunc->core_dim_flags[ix] |= UFUNC_CORE_DIM_CAN_IGNORE; + ufunc->extension->core_dim_flags[ix] |= UFUNC_CORE_DIM_CAN_IGNORE; } } else { - if (can_ignore && !(ufunc->core_dim_flags[ix] & + if (can_ignore && !(ufunc->extension->core_dim_flags[ix] & UFUNC_CORE_DIM_CAN_IGNORE)) { parse_error = "? cannot be used, name already seen without ?"; goto fail; } - if (!can_ignore && (ufunc->core_dim_flags[ix] & + if (!can_ignore && (ufunc->extension->core_dim_flags[ix] & UFUNC_CORE_DIM_CAN_IGNORE)) { parse_error = "? must be used, name already seen with ?"; goto fail; @@ -709,9 +710,11 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature) } ufunc->core_dim_ixs = PyArray_realloc(ufunc->core_dim_ixs, sizeof(int) * cur_core_dim); - ufunc->core_dim_sizes = PyArray_realloc(ufunc->core_dim_sizes, + ufunc->extension->core_dim_sizes = PyArray_realloc( + ufunc->extension->core_dim_sizes, sizeof(npy_intp) * ufunc->core_num_dim_ix); - ufunc->core_dim_flags = PyArray_realloc(ufunc->core_dim_flags, + ufunc->extension->core_dim_flags = PyArray_realloc( + ufunc->extension->core_dim_flags, sizeof(npy_uint32) * ufunc->core_num_dim_ix); /* check for trivial core-signature, e.g. "(),()->()" */ @@ -2489,10 +2492,10 @@ _initialize_variable_parts(PyUFuncObject *ufunc, for (i = 0; i < ufunc->nargs; i++) { op_core_num_dims[i] = ufunc->core_num_dims[i]; } - if (ufunc->version == 1) { + if (ufunc->version == 1 && ufunc->extension != NULL) { for (i = 0; i < ufunc->core_num_dim_ix; i++) { - core_dim_sizes[i] = ufunc->core_dim_sizes[i]; - core_dim_flags[i] = ufunc->core_dim_flags[i]; + core_dim_sizes[i] = ufunc->extension->core_dim_sizes[i]; + core_dim_flags[i] = ufunc->extension->core_dim_flags[i]; } } else if (ufunc->version == 0) { @@ -2503,7 +2506,7 @@ _initialize_variable_parts(PyUFuncObject *ufunc, } else { PyErr_Format(PyExc_TypeError, - "'%s': unrecognized version number %d.", + "'%s': unrecognized version number %d or corrupted data.", ufunc_get_name_cstr(ufunc), ufunc->version); return -1; } @@ -4870,6 +4873,7 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, memset(ufunc, 0, sizeof(PyUFuncObject)); *((int*)&ufunc->version) = UFUNC_VERSION; PyObject_Init((PyObject *)ufunc, &PyUFunc_Type); + ufunc->extension = &ufunc->s_extension; ufunc->nin = nin; ufunc->nout = nout; @@ -5246,8 +5250,8 @@ ufunc_dealloc(PyUFuncObject *ufunc) { PyArray_free(ufunc->core_num_dims); PyArray_free(ufunc->core_dim_ixs); - PyArray_free(ufunc->core_dim_flags); - PyArray_free(ufunc->core_dim_sizes); + PyArray_free(ufunc->extension->core_dim_sizes); + PyArray_free(ufunc->extension->core_dim_flags); PyArray_free(ufunc->core_offsets); PyArray_free(ufunc->core_signature); PyArray_free(ufunc->ptr); diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py index a5e1f73ce..c4918f955 100644 --- a/numpy/core/tests/test_datetime.py +++ b/numpy/core/tests/test_datetime.py @@ -7,7 +7,7 @@ import numpy as np import datetime import pytest from numpy.testing import ( - assert_, assert_equal, assert_raises, assert_warns, suppress_warnings + assert_, assert_equal, assert_raises, assert_warns, suppress_warnings, ) # Use pytz to test out various time zones if available @@ -130,13 +130,10 @@ class TestDateTime(object): def test_compare_generic_nat(self): # regression tests for gh-6452 - assert_equal(np.datetime64('NaT'), - np.datetime64('2000') + np.timedelta64('NaT')) - # nb. we may want to make NaT != NaT true in the future - with suppress_warnings() as sup: - sup.filter(FutureWarning, ".*NAT ==") - assert_(np.datetime64('NaT') == np.datetime64('NaT', 'us')) - assert_(np.datetime64('NaT', 'us') == np.datetime64('NaT')) + assert_(np.datetime64('NaT') != + np.datetime64('2000') + np.timedelta64('NaT')) + assert_(np.datetime64('NaT') != np.datetime64('NaT', 'us')) + assert_(np.datetime64('NaT', 'us') != np.datetime64('NaT')) def test_datetime_scalar_construction(self): # Construct with different units @@ -1154,47 +1151,23 @@ class TestDateTime(object): td_nat = np.timedelta64('NaT', 'h') td_other = np.timedelta64(1, 'h') - with suppress_warnings() as sup: - # The assert warns contexts will again see the warning: - sup.filter(FutureWarning, ".*NAT") - - for op in [np.equal, np.less, np.less_equal, - np.greater, np.greater_equal]: - if op(dt_nat, dt_nat): - assert_warns(FutureWarning, op, dt_nat, dt_nat) - if op(dt_nat, dt_other): - assert_warns(FutureWarning, op, dt_nat, dt_other) - if op(dt_other, dt_nat): - assert_warns(FutureWarning, op, dt_other, dt_nat) - if op(td_nat, td_nat): - assert_warns(FutureWarning, op, td_nat, td_nat) - if op(td_nat, td_other): - assert_warns(FutureWarning, op, td_nat, td_other) - if op(td_other, td_nat): - assert_warns(FutureWarning, op, td_other, td_nat) - - assert_warns(FutureWarning, np.not_equal, dt_nat, dt_nat) - assert_warns(FutureWarning, np.not_equal, td_nat, td_nat) - - with suppress_warnings() as sup: - sup.record(FutureWarning) - assert_(np.not_equal(dt_nat, dt_other)) - assert_(np.not_equal(dt_other, dt_nat)) - assert_(np.not_equal(td_nat, td_other)) - assert_(np.not_equal(td_other, td_nat)) - assert_equal(len(sup.log), 0) - - def test_datetime_futurewarning_once_nat(self): - # Test that the futurewarning is only given once per inner loop - arr1 = np.array(['NaT', 'NaT', '2000-01-01'] * 2, dtype='M8[s]') - arr2 = np.array(['NaT', '2000-01-01', 'NaT'] * 2, dtype='M8[s]') - # All except less, because for less it can't be wrong (NaT is min) for op in [np.equal, np.less, np.less_equal, np.greater, np.greater_equal]: - with suppress_warnings() as sup: - rec = sup.record(FutureWarning, ".*NAT") - op(arr1, arr2) - assert_(len(rec) == 1, "failed for {}".format(op)) + assert_(not op(dt_nat, dt_nat)) + assert_(not op(dt_nat, dt_other)) + assert_(not op(dt_other, dt_nat)) + + assert_(not op(td_nat, td_nat)) + assert_(not op(td_nat, td_other)) + assert_(not op(td_other, td_nat)) + + assert_(np.not_equal(dt_nat, dt_nat)) + assert_(np.not_equal(dt_nat, dt_other)) + assert_(np.not_equal(dt_other, dt_nat)) + + assert_(np.not_equal(td_nat, td_nat)) + assert_(np.not_equal(td_nat, td_other)) + assert_(np.not_equal(td_other, td_nat)) def test_datetime_minmax(self): # The metadata of the result should become the GCD diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 14185ad0e..c0cca9e56 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -286,10 +286,10 @@ class TestUfunc(object): """ pass + # from include/numpy/ufuncobject.h size_unset = 2 can_ignore = 4 def test_signature0(self): - # from include/numpy/ufuncobject.h # the arguments to test_signature are: nin, nout, core_signature enabled, num_dims, ixs, flags, sizes = umt.test_signature( 2, 1, "(i),(i)->()") |