Better cell magic by removing some of the syntax limitations
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- jupyter-notebook, python
调研方向
该 issue 提议对 cell-magic 语法进行五项相关更改,包括表达式放置、块终止、参数、line-magic 回退和续行。未指定任何实现文件、解析器入口点或测试;首先定位 cell-magic 的解析和转换代码,然后为每项提议分别建立兼容性测试,并定义接受哪些语法。
由索引模型根据 Issue 内容生成。
描述
Below, I'm making suggestions (A)-(E) how I think cell magic could be made even better.
If people generally think these are good ideas, I'd try and make a PR.
First, however, I wanted to see if there are any syntax or compatibility issues I'm missing.
As far as I can tell, each of my suggestions
(1) extends the set of legal cell contents
and all but (B) and (E)
(2) gives the same results on the previous set of legal cell contents
where the only reason that (B) and (E) do not give the same results on previous contents is that nested magic would trip (which I actually use quite frequently)
If I required triple-% for the new functionality, I think all my suggestions would satisfy both (1) and (2).
(A) Just about any cell magic I've ever used would have been better if it was possible to assign output via
df = %%sql
<SOME QUERY>
similar to how it's already possible to do
df = %sql <SOME QUERY>.
More generally, I think it should simply be allowed to start %%-magic anywhere in a cell.
Most cell magic I know instead implement awkward workarounds like
%%sql -o df
<SOME QUERY>
but since every cell magic uses its own syntax and most don't support things like assigning to dictionaries, this is a major hassle.
(B) Extending on the previous item, it'd be great if we could also have code after %%-magic, e.g.,
df = %%sql
<SOME QUERY>
%%
i.e., be able to close a cell magic block by %% (see intro: maybe best to just use triple-%)
(C) Just about any cell magic I've ever used would have been better if it was possible to do
%%sql(connection=a, flag=b)
<SOME QUERY>
and have this be translated to a regular function-call of the function registered as part of the cell-magic registration, the result of which would then do the actual cell-magic.
Most cell magic I know instead implements awkward workarounds like sql -f -conn conn but since every cell magic uses its own syntax and most don't support things like indexing dictionaries, this is a major hassle.
For example, the sql magic above could be implemented by registering
def sql_cell_magic_wrapper(connection: Conn = None, flag: bool = None) -> Func[str, Any]:
def cell_magic(cell: str) -> Any:
return sql_client.execute(cell)
with Jupyter; and a simple %%sql without arguments could simply be translated to a call of sql_cell_magic_wrapper without arguments, i.e., sql_cell_magic_wrapper()(<cell>)
(D) Cell magic should be allowed to fall back to line magic:
%%sql <SOME QUERY>
It's annoying to always have to remove/add % just because you're changing your mind whether you need an entire cell or not.
(E) Further to (D), it should be legal to terminate a single-line %%-magic and continue the line non-magically, e.g.
df = (%%sql <SOME QUERY> %%).sum()
(A-E): In combination, it would be possible to do
import pandas as pd
import numpy as np
import my_magic
df = pd.DataFrame({'i': np.arange(13), 'v': np.random.rand(13)})
agg = %%sql(progress_bar=False)
SELECT
i, v
FROM df
WHERE i % 2 == 0
%%
agg.plot(x='i', y='v')
or, if one so prefers,
import pandas as pd
import numpy as np
import my_magic
df = pd.DataFrame({'i': np.arange(13), 'v': np.random.rand(13)})
%%sql(progress_bar=False) SELECT i, v FROM df WHERE i % 2 == 0 %%.plot(x='i', y='v')
- 主要语言
- Python
- 星标
- 734
- 派生
- 411
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 9
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ipython/ipykernel 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 1/5 1 小时以内 新手友好度 72/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 68/100
查看 ipython/ipykernel 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·