Join arrays `r1` and `r2` on key `key`. The key should be either a string or a sequence of string corresponding to the fields used to join the array. An exception is raised if the `key` field cannot be found in the two input arrays. Neither `r1` nor `r2` should have any dupli
(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2',
defaults=None, usemask=True, asrecarray=False)
| 1480 | |
| 1481 | @array_function_dispatch(_join_by_dispatcher) |
| 1482 | def join_by(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2', |
| 1483 | defaults=None, usemask=True, asrecarray=False): |
| 1484 | """ |
| 1485 | Join arrays `r1` and `r2` on key `key`. |
| 1486 | |
| 1487 | The key should be either a string or a sequence of string corresponding |
| 1488 | to the fields used to join the array. An exception is raised if the |
| 1489 | `key` field cannot be found in the two input arrays. Neither `r1` nor |
| 1490 | `r2` should have any duplicates along `key`: the presence of duplicates |
| 1491 | will make the output quite unreliable. Note that duplicates are not |
| 1492 | looked for by the algorithm. |
| 1493 | |
| 1494 | Parameters |
| 1495 | ---------- |
| 1496 | key : {string, sequence} |
| 1497 | A string or a sequence of strings corresponding to the fields used |
| 1498 | for comparison. |
| 1499 | r1, r2 : arrays |
| 1500 | Structured arrays. |
| 1501 | jointype : {'inner', 'outer', 'leftouter'}, optional |
| 1502 | If 'inner', returns the elements common to both r1 and r2. |
| 1503 | If 'outer', returns the common elements as well as the elements of |
| 1504 | r1 not in r2 and the elements of not in r2. |
| 1505 | If 'leftouter', returns the common elements and the elements of r1 |
| 1506 | not in r2. |
| 1507 | r1postfix : string, optional |
| 1508 | String appended to the names of the fields of r1 that are present |
| 1509 | in r2 but absent of the key. |
| 1510 | r2postfix : string, optional |
| 1511 | String appended to the names of the fields of r2 that are present |
| 1512 | in r1 but absent of the key. |
| 1513 | defaults : {dictionary}, optional |
| 1514 | Dictionary mapping field names to the corresponding default values. |
| 1515 | usemask : {True, False}, optional |
| 1516 | Whether to return a MaskedArray (or MaskedRecords is |
| 1517 | `asrecarray==True`) or an ndarray. |
| 1518 | asrecarray : {False, True}, optional |
| 1519 | Whether to return a recarray (or MaskedRecords if `usemask==True`) |
| 1520 | or just a flexible-type ndarray. |
| 1521 | |
| 1522 | Notes |
| 1523 | ----- |
| 1524 | * The output is sorted along the key. |
| 1525 | * A temporary array is formed by dropping the fields not in the key for |
| 1526 | the two arrays and concatenating the result. This array is then |
| 1527 | sorted, and the common entries selected. The output is constructed by |
| 1528 | filling the fields with the selected entries. Matching is not |
| 1529 | preserved if there are some duplicates... |
| 1530 | |
| 1531 | """ |
| 1532 | # Check jointype |
| 1533 | if jointype not in ('inner', 'outer', 'leftouter'): |
| 1534 | raise ValueError( |
| 1535 | "The 'jointype' argument should be in 'inner', " |
| 1536 | f"'outer' or 'leftouter' (got '{jointype}' instead)" |
| 1537 | ) |
| 1538 | # If we have a single key, put it in a tuple |
| 1539 | if isinstance(key, str): |
searching dependent graphs…