(self)
| 414 | |
| 415 | @ignore_skipped |
| 416 | def test_method(self): |
| 417 | common.verbosePrint("* Condition is ``%s``." % cond) |
| 418 | # Replace bitwise operators with their logical counterparts. |
| 419 | pycond = cond |
| 420 | for ptop, pyop in [("&", "and"), ("|", "or"), ("~", "not")]: |
| 421 | pycond = pycond.replace(ptop, pyop) |
| 422 | pycond = compile(pycond, "<string>", "eval") |
| 423 | |
| 424 | table = self.table |
| 425 | self.create_indexes(colname, ncolname, "c_idxextra") |
| 426 | |
| 427 | table_slice = dict(start=1, stop=table.nrows - 5, step=3) |
| 428 | rownos, fvalues = None, None |
| 429 | # Test that both simple and nested columns work as expected. |
| 430 | # Knowing how the table is filled, results must be the same. |
| 431 | for acolname in [colname, ncolname]: |
| 432 | # First the reference Python version. |
| 433 | pyrownos, pyfvalues, pyvars = [], [], condvars.copy() |
| 434 | for row in table.iterrows(**table_slice): |
| 435 | pyvars[colname] = row[acolname] |
| 436 | pyvars["c_extra"] = row["c_extra"] |
| 437 | pyvars["c_idxextra"] = row["c_idxextra"] |
| 438 | try: |
| 439 | with warnings.catch_warnings(): |
| 440 | warnings.filterwarnings( |
| 441 | "ignore", |
| 442 | "invalid value encountered in arc(cos|sin)", |
| 443 | RuntimeWarning, |
| 444 | ) |
| 445 | isvalidrow = eval(pycond, func_info, pyvars) |
| 446 | except TypeError: |
| 447 | raise SilentlySkipTest( |
| 448 | "The Python type does not support the operation." |
| 449 | ) |
| 450 | if isvalidrow: |
| 451 | pyrownos.append(row.nrow) |
| 452 | pyfvalues.append(row[acolname]) |
| 453 | pyrownos = np.array(pyrownos) # row numbers already sorted |
| 454 | pyfvalues = np.array(pyfvalues, dtype=sctype) |
| 455 | pyfvalues.sort() |
| 456 | common.verbosePrint( |
| 457 | f"* {len(pyrownos)} rows selected by Python " |
| 458 | f"from ``{acolname}``." |
| 459 | ) |
| 460 | if rownos is None: |
| 461 | rownos = pyrownos # initialise reference results |
| 462 | fvalues = pyfvalues |
| 463 | else: |
| 464 | self.assertTrue(np.all(pyrownos == rownos)) # check |
| 465 | self.assertTrue(np.all(pyfvalues == fvalues)) |
| 466 | |
| 467 | # Then the in-kernel or indexed version. |
| 468 | ptvars = condvars.copy() |
| 469 | ptvars[colname] = table.colinstances[acolname] |
| 470 | ptvars["c_extra"] = table.colinstances["c_extra"] |
| 471 | ptvars["c_idxextra"] = table.colinstances["c_idxextra"] |
| 472 | try: |
| 473 | isidxq = table.will_query_use_indexing(cond, ptvars) |
nothing calls this directly
no test coverage detected