See merge.__doc__ with how='cross'
(
left: DataFrame,
right: DataFrame,
on: IndexLabel | AnyArrayLike | None = None,
left_on: IndexLabel | AnyArrayLike | None = None,
right_on: IndexLabel | AnyArrayLike | None = None,
left_index: bool = False,
right_index: bool = False,
sort: bool = False,
suffixes: Suffixes = ("_x", "_y"),
indicator: str | bool = False,
validate: str | None = None,
)
| 400 | |
| 401 | |
| 402 | def _cross_merge( |
| 403 | left: DataFrame, |
| 404 | right: DataFrame, |
| 405 | on: IndexLabel | AnyArrayLike | None = None, |
| 406 | left_on: IndexLabel | AnyArrayLike | None = None, |
| 407 | right_on: IndexLabel | AnyArrayLike | None = None, |
| 408 | left_index: bool = False, |
| 409 | right_index: bool = False, |
| 410 | sort: bool = False, |
| 411 | suffixes: Suffixes = ("_x", "_y"), |
| 412 | indicator: str | bool = False, |
| 413 | validate: str | None = None, |
| 414 | ) -> DataFrame: |
| 415 | """ |
| 416 | See merge.__doc__ with how='cross' |
| 417 | """ |
| 418 | |
| 419 | if ( |
| 420 | left_index |
| 421 | or right_index |
| 422 | or right_on is not None |
| 423 | or left_on is not None |
| 424 | or on is not None |
| 425 | ): |
| 426 | raise MergeError( |
| 427 | "Can not pass on, right_on, left_on or set right_index=True or " |
| 428 | "left_index=True" |
| 429 | ) |
| 430 | |
| 431 | cross_col = f"_cross_{uuid.uuid4()}" |
| 432 | left = left.assign(**{cross_col: 1}) |
| 433 | right = right.assign(**{cross_col: 1}) |
| 434 | |
| 435 | left_on = right_on = [cross_col] |
| 436 | |
| 437 | res = merge( |
| 438 | left, |
| 439 | right, |
| 440 | how="inner", |
| 441 | on=on, |
| 442 | left_on=left_on, |
| 443 | right_on=right_on, |
| 444 | left_index=left_index, |
| 445 | right_index=right_index, |
| 446 | sort=sort, |
| 447 | suffixes=suffixes, |
| 448 | indicator=indicator, |
| 449 | validate=validate, |
| 450 | ) |
| 451 | del res[cross_col] |
| 452 | return res |
| 453 | |
| 454 | |
| 455 | def _groupby_and_merge( |
no test coverage detected