执行并获取结果#
延迟执行#
MaxFrame 使用延迟执行来利用全局优化。也就是说,除非客户端本地需要执行结果,否则MaxFrame 表达式在手动执行前不会被执行。例如,
>>> df.head(3)
DataFrame <op=DataFrameILoc, key=182b756be8a9f15c937a04223f11ffba>
不会被执行,而
>>> df.head(3).execute()
0 1 2
0 0.167771 0.568741 0.877450
1 0.037518 0.796745 0.072169
2 0.052900 0.936048 0.307194
将触发执行。以下列出了一些会触发执行的条件。
直接调用``execute()``。
DataFrame 和 Series 的所有绘图函数,包括
maxframe.dataframe.DataFrame.plot()、maxframe.dataframe.DataFrame.plot.bar()等。
异步执行#
指定 wait=False 可以使执行异步进行。将返回一个 Future 对象 。
>>> fut = df.head(3).execute(wait=False)
>>> fut.wait()
>>> fut.result()
0 1 2
0 0.167771 0.568741 0.877450
1 0.037518 0.796745 0.072169
2 0.052900 0.936048 0.307194
获取结果#
您可以使用 fetch() 函数从已执行的对象中获取执行结果。获取的数据是一个本地Python对象(即pandas对象或numpy数组),可以由本地Python库处理。
>>> df.execute().fetch()
0 1 2
0 0.167771 0.568741 0.877450
1 0.037518 0.796745 0.072169
2 0.052900 0.936048 0.307194
请注意,fetch() 将获取MaxFrame对象背后的所有数据。如果您只需要预览几条数据,只需在IPython或JupyterLab等交互式Python环境中调用``execute()``方法或简单地调用``execute()``方法。MaxFrame将简单地查看第一行和最后一行。
>>> repr(df.execute()) # or simply df.execute() if in an interactive environment
0 1 2
0 0.167771 0.568741 0.877450
1 0.037518 0.796745 0.072169
2 0.052900 0.936048 0.307194
...
97 0.167771 0.568741 0.877450
98 0.037518 0.796745 0.072169
99 0.052900 0.936048 0.307194