Return the given values as a numpy array, or as an individual item if it's a 0d datetime64 or timedelta64 array. Importantly, this function does not copy data if it is already an ndarray - otherwise, it will not be possible to update Variable values in place. This function mostly e
(data)
| 319 | |
| 320 | |
| 321 | def _as_array_or_item(data): |
| 322 | """Return the given values as a numpy array, or as an individual item if |
| 323 | it's a 0d datetime64 or timedelta64 array. |
| 324 | |
| 325 | Importantly, this function does not copy data if it is already an ndarray - |
| 326 | otherwise, it will not be possible to update Variable values in place. |
| 327 | |
| 328 | This function mostly exists because 0-dimensional ndarrays with |
| 329 | dtype=datetime64 are broken :( |
| 330 | https://github.com/numpy/numpy/issues/4337 |
| 331 | https://github.com/numpy/numpy/issues/7619 |
| 332 | |
| 333 | TODO: remove this (replace with np.asarray) once these issues are fixed |
| 334 | """ |
| 335 | data = np.asarray(data) |
| 336 | if data.ndim == 0: |
| 337 | kind = data.dtype.kind |
| 338 | if kind in "mM": |
| 339 | unit, _ = np.datetime_data(data.dtype) |
| 340 | if kind == "M": |
| 341 | data = np.datetime64(data, unit) |
| 342 | elif kind == "m": |
| 343 | data = np.timedelta64(data, unit) |
| 344 | return data |
| 345 | |
| 346 | |
| 347 | class Variable(NamedArray, AbstractArray, VariableArithmetic): |
no outgoing calls
no test coverage detected
searching dependent graphs…