Comments (2)
For now it's a constraint of the implementation it seems. We could improve that '=' check to check after doing quoted string capture groups to get around it. But someone would need to write a fairly good suite of unittests to ensure it works correctly in all cases (harder problem to get right than it may seem).
from papermill.
Hello,
would it be possible to use the built-in ast package to parse the python code?
https://docs.python.org/3/library/ast.html
I saw some comments from ~2020 about this not being compatible with other languages, but I would argue it's a safer approach than the regex version and would catch corner cases that are not yet properly supported by the regex, such as the one shared here or if the type provided contains a "." (cf sample below)
Sample parameter cell
import datetime as dt
string_param: str = ""
equal_param = "./all/date=20240102/ml_flow_run_id=Y/model/"
multi_line_param: str = "test1" + "test2"
date_param: dt.datetime = dt.datetime(2024, 4, 17, 0, 0, 0)
a = b = 2
list_param = []
dict_param = {
"key1": "value",
"key2": [1, 2, 3],
"key3": "=",
}
Sample parsing code:
# param_code is a variable containing the above cell's source code
tree: ast.Module = ast.parse(param_code)
for node in ast.walk(tree):
if isinstance(ann_assign := node, ast.AnnAssign) and isinstance(
name := ann_assign.target, ast.Name
):
print(name.id)
elif isinstance(assign := node, ast.Assign):
for target in assign.targets:
if isinstance(target, ast.Name):
print(target.id)
I get the following output:
string_param
equal_param
multi_line_param
date_param
a
b
list_param
dict_param
@MSeal: if that would be of interest to you, I can propose a PR for this :)
from papermill.
Related Issues (20)
- SparkMagic pyspark kernel magic(%%sql) hangs when running with Papermill. HOT 1
- Metadata of parameters cell not copied (`{'slideshow': {'slide_type': 'skip'}`)
- Enhance the progress bar to display customizable message HOT 1
- AttributeError: kernelspec HOT 3
- Latest release not installable from sdist HOT 1
- Do an audit of requirements files, pyproject.toml, ci config, tox HOT 5
- Stale repo action HOT 3
- Kernel not found with venvs (jupyter_client.kernelspec.NoSuchKernel) HOT 2
- Does tqdm print properly with --log-output? HOT 1
- nbformat 5.1.2 and 5.1.3 cause AttributeError: 'NoneType' object has no attribute 'cells'
- Pandas style has no effect HOT 3
- RuntimeError: Kernel didn't respond in 60 seconds HOT 2
- Make the parameters of progress_bar specifiable by a dictionary
- pip install --no-binary gives "No such file or directory" error
- Cell that starts with %%time does not report errors HOT 2
- PapermillNotebookClient deprecation warning: unrecognized argument input_path HOT 1
- Tuple in the config dictionary changed to string when run a python notebook with papermill HOT 1
- New Release HOT 7
- Missing Notebook linked in docs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from papermill.