Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): Update BytecodeParser for upcoming Python 3.13 #18677

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions py-polars/polars/_utils/udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ def op(inst: Instruction) -> str:
return "replace_strict"
else:
msg = (
"unrecognized opname"
"\n\nPlease report a bug to https://github.com/pola-rs/polars/issues"
" with the content of function you were passing to `map` and the"
f" following instruction object:\n{inst!r}"
f"unexpected or unrecognised op name ({inst.opname})\n\n"
"Please report a bug to https://github.com/pola-rs/polars/issues "
"with the content of function you were passing to the `map` "
f"expressions and the following instruction object:\n{inst!r}"
)
raise AssertionError(msg)

Expand Down Expand Up @@ -751,7 +751,7 @@ def __init__(
self._original_instructions = list(instructions)
self._rewritten_instructions = self._rewrite(
self._upgrade_instruction(inst)
for inst in self._original_instructions
for inst in self._unpack_superinstructions(self._original_instructions)
if inst.opname not in self._ignored_ops
)

Expand Down Expand Up @@ -1018,6 +1018,22 @@ def _rewrite_methods(

return len(matching_instructions)

@staticmethod
def _unpack_superinstructions(
instructions: list[Instruction],
) -> Iterator[Instruction]:
"""Expand known 'superinstructions' into their component parts."""
for inst in instructions:
if inst.opname == "LOAD_FAST_LOAD_FAST":
for idx in (0, 1):
yield inst._replace(
opname="LOAD_FAST",
argval=inst.argval[idx],
argrepr=inst.argval[idx],
)
else:
yield inst

@staticmethod
def _upgrade_instruction(inst: Instruction) -> Instruction:
"""Rewrite any older binary opcodes using py 3.11 'BINARY_OP' instead."""
Expand Down