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

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Sep 11, 2024

Still mildly painful to install/debug under the Python 3.13rc1, but here's another update for the BytecodeParser, building on #16304. Might be the last one needed, but will have to wait on the final release to be sure 🤔

We now recognise specific "superinstructions"1 and unpack them to their underlying component instructions (eg: LOAD_FAST_LOAD_FASTLOAD_FAST+LOAD_FAST).

from polars._utils.udfs import BytecodeParser

bp = BytecodeParser(
    function = lambda x: (x/x) * (x+x),
    map_target = "expr",
)
  • Python 3.11/3.12 bytecode for the example UDF/lambda given above:
    bp.dis()
    # 4    0 RESUME                   0
    #      2 LOAD_FAST                0 (x)
    #      4 LOAD_FAST                0 (x)
    #      6 BINARY_OP               11 (/)
    #     10 LOAD_FAST                0 (x)
    #     12 LOAD_FAST                0 (x)
    #     14 BINARY_OP                0 (+)
    #     18 BINARY_OP                5 (*)
    #     22 RETURN_VALUE
  • Python 3.13 bytecode (note presence of superinstructions):
    bp.dis()
    # 4   RESUME                   0
    #     LOAD_FAST_LOAD_FAST      0 (x, x)
    #     BINARY_OP               11 (/)
    #     LOAD_FAST_LOAD_FAST      0 (x, x)
    #     BINARY_OP                0 (+)
    #     BINARY_OP                5 (*)
    #     RETURN_VALUE             
  • Result (across all Python versions):
    bp.to_expression("x")
    # (pl.col("x") / pl.col("x")) * (pl.col("x") + pl.col("x"))

Footnotes

  1. https://github.com/faster-cpython/ideas/issues/16

@alexander-beedie alexander-beedie changed the title feat(python): BytecodeParser update for upcoming Python 3.13 feat(python): BytecodeParser update for upcoming/new Python release Sep 11, 2024
@alexander-beedie alexander-beedie changed the title feat(python): BytecodeParser update for upcoming/new Python release feat(python): BytecodeParser update for upcoming/new Python 3.13 Sep 11, 2024
@alexander-beedie alexander-beedie changed the title feat(python): BytecodeParser update for upcoming/new Python 3.13 feat(python): Update BytecodeParser for upcoming Python 3.13 Sep 11, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Sep 11, 2024
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Project coverage is 79.93%. Comparing base (149d6b9) to head (1aa0c4a).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
py-polars/polars/_utils/udfs.py 57.14% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18677      +/-   ##
==========================================
+ Coverage   79.91%   79.93%   +0.01%     
==========================================
  Files        1513     1513              
  Lines      203310   203317       +7     
  Branches     2892     2896       +4     
==========================================
+ Hits       162467   162512      +45     
+ Misses      40293    40254      -39     
- Partials      550      551       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 merged commit db1b15f into pola-rs:main Sep 11, 2024
21 checks passed
@alexander-beedie alexander-beedie deleted the py313-bytecode-update branch September 11, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants