| 282 | } |
| 283 | |
| 284 | Status Observe(PyArray_Descr* descr) { |
| 285 | int dtype = fix_numpy_type_num(descr->type_num); |
| 286 | |
| 287 | if (current_type_num_ == -1) { |
| 288 | current_dtype_ = descr; |
| 289 | current_type_num_ = dtype; |
| 290 | return Status::OK(); |
| 291 | } else if (current_type_num_ == dtype) { |
| 292 | // Same type, but for datetime we still need to check units match |
| 293 | if (dtype == NPY_DATETIME) { |
| 294 | int action = Observe_DATETIME(descr); |
| 295 | if (action == INVALID) { |
| 296 | return InvalidDatetimeUnitMix(descr); |
| 297 | } |
| 298 | } |
| 299 | return Status::OK(); |
| 300 | } |
| 301 | |
| 302 | #define OBSERVE_CASE(DTYPE) \ |
| 303 | case NPY_##DTYPE: \ |
| 304 | action = Observe_##DTYPE(descr, dtype); \ |
| 305 | break; |
| 306 | |
| 307 | int action = OK; |
| 308 | switch (current_type_num_) { |
| 309 | OBSERVE_CASE(BOOL); |
| 310 | OBSERVE_CASE(INT8); |
| 311 | OBSERVE_CASE(INT16); |
| 312 | OBSERVE_CASE(INT32); |
| 313 | OBSERVE_CASE(INT64); |
| 314 | OBSERVE_CASE(UINT8); |
| 315 | OBSERVE_CASE(UINT16); |
| 316 | OBSERVE_CASE(UINT32); |
| 317 | OBSERVE_CASE(UINT64); |
| 318 | OBSERVE_CASE(FLOAT16); |
| 319 | OBSERVE_CASE(FLOAT32); |
| 320 | OBSERVE_CASE(FLOAT64); |
| 321 | case NPY_DATETIME: |
| 322 | action = Observe_DATETIME(descr); |
| 323 | break; |
| 324 | default: |
| 325 | return Status::NotImplemented("Unsupported numpy type ", GetNumPyTypeName(dtype)); |
| 326 | } |
| 327 | |
| 328 | if (action == INVALID) { |
| 329 | return InvalidMix(dtype); |
| 330 | } |
| 331 | return Status::OK(); |
| 332 | } |
| 333 | |
| 334 | bool dtype_was_observed() const { return current_type_num_ != -1; } |
| 335 |
no test coverage detected