Skip to content

Commit

Permalink
MAINT: Mark deprecation warning with a date and Numpy version.
Browse files Browse the repository at this point in the history
This is to make it easier to find and remove deprecated features.
It would be a good idea if all deprecations were made with similar
comments.
  • Loading branch information
charris committed Jun 21, 2015
1 parent f686192 commit 505b0f4
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions numpy/_import_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def __call__(self,*packages, **options):
when True, don't load packages [default: False]
"""
# 2014-10-29, 1.10
warnings.warn('pkgload and PackageLoader are obsolete '
'and will be removed in a future version of numpy',
DeprecationWarning)
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ',
msg = "The `_format` attribute is deprecated in Numpy 2.0 and " \
"will be removed in 2.1. Use the `formatter` kw instead."
import warnings
# 2011-04-03, RemoveMe
warnings.warn(msg, DeprecationWarning)
except AttributeError:
# find the right formatting function for the array
Expand Down Expand Up @@ -446,6 +447,7 @@ def array2string(a, max_line_width=None, precision=None,
"2.0 and will be removed in 2.1. Use the " \
"`formatter` kw instead."
import warnings
# 2012-05-11, RemoveMe
warnings.warn(msg, DeprecationWarning)
except AttributeError:
if isinstance(x, tuple):
Expand Down
1 change: 1 addition & 0 deletions numpy/core/fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2624,6 +2624,7 @@ def rank(a):
0
"""
# 2014-04-12, 1.9
warnings.warn(
"`rank` is deprecated; use the `ndim` attribute or function instead. "
"To find the rank of a matrix see `numpy.linalg.matrix_rank`.",
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ def correlate(a, v, mode='valid', old_behavior=False):
# the old behavior should be made available under a different name, see thread
# http://thread.gmane.org/gmane.comp.python.numeric.general/12609/focus=12630
if old_behavior:
# 2009-07-18 RemoveMe
warnings.warn("""
The old behavior of correlate was deprecated for 1.4.0, and will be completely removed
for NumPy 2.0.
Expand Down Expand Up @@ -1114,6 +1115,7 @@ def alterdot():
restoredot : `restoredot` undoes the effects of `alterdot`.
"""
# 2014-08-13, 1.10
warnings.warn("alterdot no longer does anything.", DeprecationWarning)


Expand All @@ -1137,6 +1139,7 @@ def restoredot():
alterdot : `restoredot` undoes the effects of `alterdot`.
"""
# 2014-08-13, 1.10
warnings.warn("restoredot no longer does anything.", DeprecationWarning)


Expand Down
9 changes: 9 additions & 0 deletions numpy/core/src/multiarray/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ array_might_be_written(PyArrayObject *obj)
"The quick fix is to make an explicit copy (e.g., do\n"
"arr.diagonal().copy() or arr[['f0','f1']].copy()).";
if (PyArray_FLAGS(obj) & NPY_ARRAY_WARN_ON_WRITE) {
/* 2012-07-17, 1.7 */
if (DEPRECATE_FUTUREWARNING(msg) < 0) {
return -1;
}
Expand Down Expand Up @@ -1345,6 +1346,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
break;
case Py_EQ:
if (other == Py_None) {
/* 2013-07-25, 1.7 */
if (DEPRECATE_FUTUREWARNING("comparison to `None` will result in "
"an elementwise object comparison in the future.") < 0) {
return NULL;
Expand All @@ -1368,6 +1370,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
* this way.
*/
if (array_other == NULL) {
/* 2015-05-07, 1.10 */
PyErr_Clear();
if (DEPRECATE(
"elementwise == comparison failed and returning scalar "
Expand All @@ -1382,6 +1385,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
PyArray_DESCR(array_other),
NPY_EQUIV_CASTING);
if (_res == 0) {
/* 2015-05-07, 1.10 */
Py_DECREF(array_other);
if (DEPRECATE_FUTUREWARNING(
"elementwise == comparison failed and returning scalar "
Expand Down Expand Up @@ -1417,6 +1421,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
* Comparisons should raise errors when element-wise comparison
* is not possible.
*/
/* 2015-05-14, 1.10 */
PyErr_Clear();
if (DEPRECATE("elementwise == comparison failed; "
"this will raise an error in the future.") < 0) {
Expand All @@ -1429,6 +1434,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
break;
case Py_NE:
if (other == Py_None) {
/* 2013-07-25, 1.8 */
if (DEPRECATE_FUTUREWARNING("comparison to `None` will result in "
"an elementwise object comparison in the future.") < 0) {
return NULL;
Expand All @@ -1452,6 +1458,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
* this way.
*/
if (array_other == NULL) {
/* 2015-05-07, 1.10 */
PyErr_Clear();
if (DEPRECATE(
"elementwise != comparison failed and returning scalar "
Expand All @@ -1466,6 +1473,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
PyArray_DESCR(array_other),
NPY_EQUIV_CASTING);
if (_res == 0) {
/* 2015-05-07, 1.10 */
Py_DECREF(array_other);
if (DEPRECATE_FUTUREWARNING(
"elementwise != comparison failed and returning scalar "
Expand Down Expand Up @@ -1495,6 +1503,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
* Comparisons should raise errors when element-wise comparison
* is not possible.
*/
/* 2015-05-14, 1.10 */
PyErr_Clear();
if (DEPRECATE("elementwise != comparison failed; "
"this will raise an error in the future.") < 0) {
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/conversion_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)

/* Be a bit stricter and not allow bools, np.bool_ is handled later */
if (PyBool_Check(o)) {
/* 2013-04-13, 1.8 */
if (DEPRECATE("using a boolean instead of an integer"
" will result in an error in the future") < 0) {
return -1;
Expand Down Expand Up @@ -817,6 +818,7 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)

/* Disallow numpy.bool_. Boolean arrays do not currently support index. */
if (PyArray_IsScalar(o, Bool)) {
/* 2013-06-09, 1.8 */
if (DEPRECATE("using a boolean instead of an integer"
" will result in an error in the future") < 0) {
return -1;
Expand Down Expand Up @@ -884,6 +886,7 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)
}
/* Give a deprecation warning, unless there was already an error */
if (!error_converting(long_value)) {
/* 2013-04-13, 1.8 */
if (DEPRECATE("using a non-integer number instead of an integer"
" will result in an error in the future") < 0) {
return -1;
Expand Down Expand Up @@ -1139,6 +1142,7 @@ PyArray_TypestrConvert(int itemsize, int gentype)
if (itemsize == 4 || itemsize == 8) {
int ret = 0;
if (evil_global_disable_warn_O4O8_flag) {
/* 2012-02-04, 1.7, not sure when this can be removed */
ret = DEPRECATE("DType strings 'O4' and 'O8' are "
"deprecated because they are platform "
"specific. Use 'O' instead");
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,7 @@ PyArray_FromDimsAndDataAndDescr(int nd, int *d,
char msg[] = "PyArray_FromDimsAndDataAndDescr: use PyArray_NewFromDescr.";

if (DEPRECATE(msg) < 0) {
/* 2009-04-30, 1.5 */
return NULL;
}
if (!PyArray_ISNBO(descr->byteorder))
Expand All @@ -2476,6 +2477,7 @@ PyArray_FromDims(int nd, int *d, int type)
char msg[] = "PyArray_FromDims: use PyArray_SimpleNew.";

if (DEPRECATE(msg) < 0) {
/* 2009-04-30, 1.5 */
return NULL;
}
ret = (PyArrayObject *)PyArray_FromDimsAndDataAndDescr(nd, d,
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,8 @@ arraydescr_names_set(PyArray_Descr *self, PyObject *val)
}

/*
* FIXME
*
* This deprecation has been temporarily removed for the NumPy 1.7
* release. It should be re-added after the 1.7 branch is done,
* and a convenience API to replace the typical use-cases for
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ partition_prep_kth_array(PyArrayObject * ktharray,
npy_intp nkth, i;

if (!PyArray_CanCastSafely(PyArray_TYPE(ktharray), NPY_INTP)) {
/* 2013-05-18, 1.8 */
if (DEPRECATE("Calling partition with a non integer index"
" will result in an error in the future") < 0) {
return NULL;
Expand Down
8 changes: 7 additions & 1 deletion numpy/core/src/multiarray/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
* replaced with a slice.
*/
if (index_type & HAS_ELLIPSIS) {
/* 2013-04-14, 1.8 */
if (DEPRECATE(
"an index can only have a single Ellipsis (`...`); "
"replace all but one with slices (`:`).") < 0) {
Expand Down Expand Up @@ -433,6 +434,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
* later just like a normal array.
*/
if (PyArray_ISBOOL(tmp_arr)) {
/* 2013-04-14, 1.8 */
if (DEPRECATE_FUTUREWARNING(
"in the future, boolean array-likes will be "
"handled as a boolean array index") < 0) {
Expand Down Expand Up @@ -465,6 +467,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
else if (!PyArray_ISINTEGER(tmp_arr)) {
if (PyArray_NDIM(tmp_arr) == 0) {
/* match integer deprecation warning */
/* 2013-09-25, 1.8 */
if (DEPRECATE(
"using a non-integer number instead of an "
"integer will result in an error in the "
Expand All @@ -480,6 +483,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
}
}
else {
/* 2013-09-25, 1.8 */
if (DEPRECATE(
"non integer (and non boolean) array-likes "
"will not be accepted as indices in the "
Expand Down Expand Up @@ -1727,10 +1731,11 @@ attempt_1d_fallback(PyArrayObject *self, PyObject *ind, PyObject *op)
if (iter_ass_subscript(self_iter, ind, op) < 0) {
goto fail;
}

Py_XDECREF((PyObject *)self_iter);
Py_DECREF(err);

/* 2014-06-12, 1.9 */
if (DEPRECATE(
"assignment will raise an error in the future, most likely "
"because your index result shape does not match the value array "
Expand All @@ -1744,6 +1749,7 @@ attempt_1d_fallback(PyArrayObject *self, PyObject *ind, PyObject *op)
if (!PyErr_ExceptionMatches(err)) {
PyObject *err, *val, *tb;
PyErr_Fetch(&err, &val, &tb);
/* 2014-06-12, 1.9 */
DEPRECATE_FUTUREWARNING(
"assignment exception type will change in the future");
PyErr_Restore(err, val, tb);
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode)
PyArray_Descr *descr;
static const char msg[] = "PyArray_As1D: use PyArray_AsCArray.";

/* 2008-07-14, 1.5 */
if (DEPRECATE(msg) < 0) {
return -1;
}
Expand All @@ -278,6 +279,7 @@ PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
PyArray_Descr *descr;
static const char msg[] = "PyArray_As1D: use PyArray_AsCArray.";

/* 2008-07-14, 1.5 */
if (DEPRECATE(msg) < 0) {
return -1;
}
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/nditer_constr.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32 flags,
"deprecated. Use `oa_ndim == -1` or the MultiNew "
"iterator for NumPy <1.8 compatibility";
if (DEPRECATE(mesg) < 0) {
/* 2013-02-23, 1.8 */
return NULL;
}
oa_ndim = -1;
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/number.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ array_index(PyArrayObject *v)
return NULL;
}
if (PyArray_NDIM(v) != 0) {
/* 2013-04-20, 1.8 */
if (DEPRECATE("converting an array with ndim > 0 to an index"
" will result in an error in the future") < 0) {
return NULL;
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/src/umath/loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,7 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
if (ret_obj == NULL) {
#if @identity@ != -1
if (in1 == in2) {
/* 2014-01-26, 1.9 */
PyErr_Clear();
if (DEPRECATE("numpy @kind@ will not check object identity "
"in the future. The comparison error will "
Expand All @@ -2591,6 +2592,7 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
if (ret == -1) {
#if @identity@ != -1
if (in1 == in2) {
/* 2014-01-26, 1.9 */
PyErr_Clear();
if (DEPRECATE("numpy @kind@ will not check object identity "
"in the future. The error trying to get the "
Expand All @@ -2606,6 +2608,7 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
}
#if @identity@ != -1
if ((in1 == in2) && ((npy_bool)ret != @identity@)) {
/* 2014-01-26, 1.9 */
if (DEPRECATE_FUTUREWARNING(
"numpy @kind@ will not check object identity "
"in the future. The comparison did not return the "
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/src/umath/ufunc_type_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ PyUFunc_NegativeTypeResolver(PyUFuncObject *ufunc,

/* The type resolver would have upcast already */
if (out_dtypes[0]->type_num == NPY_BOOL) {
/* 2013-12-05, 1.9 */
if (DEPRECATE("numpy boolean negative (the unary `-` operator) is "
"deprecated, use the bitwise_xor (the `^` operator) "
"or the logical_xor function instead.") < 0) {
Expand Down Expand Up @@ -799,6 +800,7 @@ PyUFunc_SubtractionTypeResolver(PyUFuncObject *ufunc,

/* The type resolver would have upcast already */
if (out_dtypes[0]->type_num == NPY_BOOL) {
/* 2013-12-05, 1.9 */
if (DEPRECATE("numpy boolean subtract (the binary `-` operator) is "
"deprecated, use the bitwise_xor (the `^` operator) "
"or the logical_xor function instead.") < 0) {
Expand Down
2 changes: 2 additions & 0 deletions numpy/distutils/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def initialize_options(self):

def try_run(self, body, headers=None, include_dirs=None,
libraries=None, library_dirs=None, lang="c"):
# 2008-11-16, RemoveMe
warnings.warn("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n" \
"Usage of try_run is deprecated: please do not \n" \
"use it anymore, and avoid configuration checks \n" \
Expand Down Expand Up @@ -435,6 +436,7 @@ def get_output(self, body, headers=None, include_dirs=None,
built from 'body' and 'headers'. Returns the exit status code
of the program and its output.
"""
# 2008-11-16, RemoveMe
warnings.warn("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n" \
"Usage of get_output is deprecated: please do not \n" \
"use it anymore, and avoid configuration checks \n" \
Expand Down
1 change: 1 addition & 0 deletions numpy/distutils/exec_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_pythonexe():

def splitcmdline(line):
import warnings
# 2007-12-26 RemoveMe
warnings.warn('splitcmdline is deprecated; use shlex.split',
DeprecationWarning)
return shlex.split(line)
Expand Down
Loading

0 comments on commit 505b0f4

Please sign in to comment.