|
| 1 | +========================= |
| 2 | +NumPy 1.7.0 Release Notes |
| 3 | +========================= |
| 4 | + |
| 5 | +This release includes several new features as well as numerous bug fixes and |
| 6 | +refactorings. It supports Python 2.4 - 2.7 and 3.1 - 3.2. |
| 7 | + |
| 8 | +Highlights |
| 9 | +========== |
| 10 | + |
| 11 | +* ``where=`` parameter to ufuncs (allows the use of boolean arrays to choose |
| 12 | + where a computation should be done) |
| 13 | +* ``vectorize`` improvements (added 'excluded' and 'cache' keyword, general |
| 14 | + cleanup and bug fixes) |
| 15 | +* ``numpy.random.choice`` (random sample generating function) |
| 16 | + |
| 17 | + |
| 18 | +Compatibility notes |
| 19 | +=================== |
| 20 | + |
| 21 | +In a future version of numpy, the functions np.diag, np.diagonal, and |
| 22 | +the diagonal method of ndarrays will return a view onto the original |
| 23 | +array, instead of producing a copy as they do now. This makes a |
| 24 | +difference if you write to the array returned by any of these |
| 25 | +functions. To facilitate this transition, numpy 1.7 produces a |
| 26 | +DeprecationWarning if it detects that you may be attempting to write |
| 27 | +to such an array. See the documentation for np.diagonal for details. |
| 28 | + |
| 29 | +The default casting rule for UFunc out= parameters has been changed from |
| 30 | +'unsafe' to 'same_kind'. Most usages which violate the 'same_kind' |
| 31 | +rule are likely bugs, so this change may expose previously undetected |
| 32 | +errors in projects that depend on NumPy. |
| 33 | + |
| 34 | +Full-array boolean indexing has been optimized to use a different, |
| 35 | +optimized code path. This code path should produce the same results, |
| 36 | +but any feedback about changes to your code would be appreciated. |
| 37 | + |
| 38 | +Attempting to write to a read-only array (one with |
| 39 | +``arr.flags.writeable`` set to ``False``) used to raise either a |
| 40 | +RuntimeError, ValueError, or TypeError inconsistently, depending on |
| 41 | +which code path was taken. It now consistently raises a ValueError. |
<
8000
td data-grid-cell-id="diff-fe5af5965c7aee100dcc9f1c94b5bd559da54afa79d1d751f3b3e4d02ba58d08-empty-42-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
42 | + |
| 43 | +The <ufunc>.reduce functions evaluate some reductions in a different |
| 44 | +order than in previous versions of NumPy, generally providing higher |
| 45 | +performance. Because of the nature of floating-point arithmetic, this |
| 46 | +may subtly change some results, just as linking NumPy to a different |
| 47 | +BLAS implementations such as MKL can. |
| 48 | + |
| 49 | +If upgrading from 1.5, then generally in 1.6 and 1.7 there have been |
| 50 | +substantial code added and some code paths altered, particularly in |
| 51 | +the areas of type resolution and buffered iteration over universal |
| 52 | +functions. This might have an impact on your code particularly if |
| 53 | +you relied on accidental behavior in the past. |
| 54 | + |
| 55 | +New features |
| 56 | +============ |
| 57 | + |
| 58 | +Mask-based NA missing values |
| 59 | +---------------------------- |
| 60 | + |
| 61 | +Preliminary support for NA missing values similar to those in R has |
| 62 | +been implemented. This was done by adding optional NA masks to the core |
| 63 | +array object. |
| 64 | + |
| 65 | +.. note:: The NA API is *experimental*, and may undergo changes in future |
| 66 | + versions of NumPy. The current implementation based on masks will likely be |
| 67 | + supplemented by a second one based on bit-patterns, and it is possible that |
| 68 | + a difference will be made between missing and ignored data. |
| 69 | + |
| 70 | +While a significant amount of the NumPy functionality has been extended to |
| 71 | +support NA masks, not everything is yet supported. Here is an (incomplete) |
| 72 | +list of things that do and do not work with NA values: |
| 73 | + |
| 74 | +What works with NA: |
| 75 | + * Basic indexing and slicing, as well as full boolean mask indexing. |
| 76 | + * All element-wise ufuncs. |
| 77 | + * All UFunc.reduce methods, with a new skipna parameter. |
| 78 | + * np.all and np.any satisfy the rules NA | True == True and |
| 79 | + NA & False == False |
| 80 | + * The nditer object. |
| 81 | + * Array methods: |
| 82 | + + ndarray.clip, ndarray.min, ndarray.max, ndarray.sum, ndarray.prod, |
| 83 | + ndarray.conjugate, ndarray.diagonal, ndarray.flatten |
| 84 | + + numpy.concatenate, numpy.column_stack, numpy.hstack, |
| 85 | + numpy.vstack, numpy.dstack, numpy.squeeze, numpy.mean, numpy.std, |
| 86 | + numpy.var |
| 87 | + |
| 88 | +What doesn't work with NA: |
| 89 | + * Fancy indexing, such as with lists and partial boolean masks. |
| 90 | + * ndarray.flat and any other methods that use the old iterator |
| 91 | + mechanism instead of the newer nditer. |
| 92 | + * Struct dtypes, which will have corresponding struct masks with |
| 93 | + one mask value per primitive field of the struct dtype. |
| 94 | + * UFunc.accumulate, UFunc.reduceat. |
| 95 | + * Ufunc calls with both NA masks and a where= mask at the same time. |
| 96 | + * File I/O has not been extended to support NA-masks. |
| 97 | + * np.logical_and and np.logical_or don't satisfy the |
| 98 | + rules NA | True == True and NA & False == False yet. |
| 99 | + * Array methods: |
| 100 | + + ndarray.argmax, ndarray.argmin, |
| 101 | + + numpy.repeat, numpy.delete (relies on fancy indexing), |
| 102 | + numpy.append, numpy.insert (relies on fancy indexing), |
| 103 | + numpy.where, |
| 104 | + |
| 105 | +Differences with R: |
| 106 | + * R's parameter rm.na=T is spelled skipna=True in NumPy. |
| 107 | + * np.isna(nan) is False, but R's is.na(nan) is TRUE. This is because |
| 108 | + NumPy's NA is treated independently of the underlying data type. |
| 109 | + * Boolean indexing, where the result is compressed to just |
| 110 | + the elements with true in the mask, raises if the boolean mask |
| 111 | + has an NA value in it. This is because that value could be either |
| 112 | + True or False, meaning the count of the output array is actually |
| 113 | + NA. R treats this case in a manner inconsistent with the NA model, |
| 114 | + returning NA values in the spots where the boolean index has NA. |
| 115 | + This may have a practical advantage in spite of violating the |
| 116 | + NA theoretical model, so NumPy could adopt the behavior if necessary |
| 117 | + |
| 118 | +For more information, see `doc/neps/missing-data.rst <https://github.com/numpy/numpy/blob/maintenance/1.7.x/doc/neps/missing-data.rst>`_. |
| 119 | + |
| 120 | +Reduction UFuncs Generalize axis= Parameter |
| 121 | +------------------------------------------- |
| 122 | + |
| 123 | +Any ufunc.reduce function call, as well as other reductions like |
| 124 | +sum, prod, any, all, max and min support the ability to choose |
| 125 | +a subset of the axes to reduce over. Previously, one could say |
| 126 | +axis=None to mean all the axes or axis=# to pick a single axis. |
| 127 | +Now, one can also say axis=(#,#) to pick a list of axes for reduction. |
| 128 | + |
| 129 | +Reduction UFuncs New keepdims= Parameter |
| 130 | +---------------------------------------- |
| 131 | + |
| 132 | +There is a new keepdims= parameter, which if set to True, doesn't |
| 133 | +throw away the reduction axes but instead sets them to have size one. |
| 134 | +When this option is set, the reduction result will broadcast correctly |
| 135 | +to the original operand which was reduced. |
| 136 | + |
| 137 | +Datetime support |
| 138 | +---------------- |
| 139 | + |
| 140 | +.. note:: The datetime API is *experimental* in 1.7.0, and may undergo changes |
| 141 | + in future versions of NumPy. |
| 142 | + |
| 143 | +There have been a lot of fixes and enhancements to datetime64 compared |
| 144 | +to NumPy 1.6: |
| 145 | + |
| 146 | +* the parser is quite strict about only accepting ISO 8601 dates, with a few |
| 147 | + convenience extensions |
| 148 | +* converts between units correctly |
| 149 | +* datetime arithmetic works correctly |
| 150 | +* business day functionality (allows the datetime to be used in contexts where |
| 151 | + only certain days of the week are valid) |
| 152 | + |
| 153 | +The notes in `doc/source/reference/arrays.datetime.rst <https://github.com/numpy/numpy/blob/maintenance/1.7.x/doc/source/reference/arrays.datetime.rst>`_ |
| 154 | +(also available in the online docs at `arrays.datetime.html |
| 155 | +<http://docs.scipy.org/doc/numpy/reference/arrays.datetime.html>`_) should be |
| 156 | +consulted for more details. |
| 157 | + |
| 158 | +Custom formatter for printing arrays |
| 159 | +------------------------------------ |
| 160 | + |
| 161 | +See the new ``formatter`` parameter of the ``numpy.set_printoptions`` |
| 162 | +function. |
| 163 | + |
| 164 | +New function numpy.random.choice |
| 165 | +--------------------------------- |
| 166 | + |
| 167 | +A generic sampling function has been added which will generate samples from |
| 168 | +a given array-like. The samples can be with or without replacement, and |
| 169 | +with uniform or given non-uniform probabilities. |
| 170 | + |
| 171 | +New function isclose |
| 172 | +-------------------- |
| 173 | + |
| 174 | +Returns a boolean array where two arrays are element-wise equal within a |
| 175 | +tolerance. Both relative and absolute tolerance can be specified. The |
| 176 | +function is NA aware. |
| 177 | + |
| 178 | +Preliminary multi-dimensional support in the polynomial package |
| 179 | +--------------------------------------------------------------- |
| 180 | + |
| 181 | +Axis keywords have been added to the integration and differentiation |
| 182 | +functions and a tensor keyword was added to the evaluation functions. |
| 183 | +These additions allow multi-dimensional coefficient arrays to be used in |
| 184 | +those functions. New functions for evaluating 2-D and 3-D coefficient |
| 185 | +arrays on grids or sets of points were added together with 2-D and 3-D |
| 186 | +pseudo-Vandermonde matrices that can be used for fitting. |
| 187 | + |
| 188 | +Support for mask-based NA values in the polynomial package fits |
| 189 | +--------------------------------------------------------------- |
| 190 | + |
| 191 | +The fitting functions recognize and remove masked data from the fit. |
| 192 | + |
| 193 | +Ability to pad rank-n arrays |
| 194 | +---------------------------- |
| 195 | + |
| 196 | +A pad module containing functions for padding n-dimensional arrays has |
| 197 | +been added. The various private padding functions are exposed as options to |
| 198 | +a public 'pad' function. Example:: |
| 199 | + |
| 200 | + pad(a, 5, mode='mean') |
| 201 | + |
| 202 | +Current modes are ``constant``, ``edge``, ``linear_ramp``, ``maximum``, |
| 203 | +``mean``, ``median``, ``minimum``, ``reflect``, ``symmetric``, ``wrap``, and |
| 204 | +``<function>``. |
| 205 | + |
| 206 | + |
| 207 | +New argument to searchsorted |
| 208 | +---------------------------- |
| 209 | + |
| 210 | +The function searchsorted now accepts a 'sorter' argument that is a |
| 211 | +permuation array that sorts the array to search. |
| 212 | + |
| 213 | +C API |
| 214 | +----- |
| 215 | + |
| 216 | +New function ``PyArray_RequireWriteable`` provides a consistent |
| 217 | +interface for checking array writeability -- any C code which works |
| 218 | +with arrays whose WRITEABLE flag is not known to be True a priori, |
| 219 | +should make sure to call this function before writing. |
| 220 | + |
| 221 | +NumPy C Style Guide added (``doc/C_STYLE_GUIDE.rst.txt``). |
| 222 | + |
| 223 | +Changes |
| 224 | +======= |
| 225 | + |
| 226 | +General |
| 227 | +------- |
| 228 | + |
| 229 | +The function np.concatenate tries to match the layout of its input |
| 230 | +arrays. Previously, the layout did not follow any particular reason, |
| 231 | +and depended in an undesirable way on the particular axis chosen for |
| 232 | +concatenation. A bug was also fixed which silently allowed out of bounds |
| 233 | +axis arguments. |
| 234 | + |
| 235 | +The ufuncs logical_or, logical_and, and logical_not now follow Python's |
| 236 | +behavior with object arrays, instead of trying to call methods on the |
| 237 | +objects. For example the expression (3 and 'test') produces the string |
| 238 | +'test', and now np.logical_and(np.array(3, 'O'), np.array('test', 'O')) |
| 239 | +produces 'test' as well. |
| 240 | + |
| 241 | +C-API |
| 242 | +----- |
| 243 | + |
| 244 | +The following macros now require trailing semicolons:: |
| 245 | + |
| 246 | + NPY_BEGIN_THREADS_DEF |
| 247 | + NPY_BEGIN_THREADS |
| 248 | + NPY_ALLOW_C_API |
| 249 | + NPY_ALLOW_C_API_DEF |
| 250 | + NPY_DISABLE_C_API |
| 251 | + |
| 252 | + |
| 253 | +Deprecations |
| 254 | +============ |
| 255 | + |
| 256 | +General |
| 257 | +------- |
| 258 | + |
| 259 | +Specifying a custom string formatter with a `_format` array attribute is |
| 260 | +deprecated. The new `formatter` keyword in ``numpy.set_printoptions`` or |
| 261 | +``numpy.array2string`` can be used instead. |
| 262 | + |
| 263 | +The deprecated imports in the polynomial package have been removed. |
| 264 | + |
| 265 | +C-API |
| 266 | +----- |
| 267 | + |
| 268 | +Direct access to the fields of PyArrayObject* has been deprecated. Direct |
| 269 | +access has been recommended against for many releases. Expect similar |
| 270 | +deprecations for PyArray_Descr* and other core objects in the future as |
| 271 | +preparation for NumPy 2.0. |
| 272 | + |
| 273 | +The macros in old_defines.h are deprecated and will be removed in the next |
| 274 | +minor release (>= 1.8). The sed script tools/replace_old_macros.sed can |
| 275 | +be used to replace these macros with the newer versions. |
| 276 | + |
| 277 | +You can test your code against the deprecated C API by #defining |
| 278 | +NPY_NO_DEPRECATED_API to the target version number, for example |
| 279 | +NPY_1_7_API_VERSION, before including any NumPy headers. |
0 commit comments