JMP19 - 数据帧交换协议弃用警告最近在我的 JSL 日志中看到了这个,jmp19 是否已经进行了其他调整?这个功能最终会被淘汰。我之前在 jmp18 中使用自定义函数将 jmp 表格转换为 pandas 数据帧,但这个方法在 jmp19 中不起作用。那么,现在有什么方法可以实现同样的功能呢?
我在 JSL 脚本中运行我的 Python 代码。
Python Send(o28k_raw);<BR />Python Submit(<BR />raw_data = pd.api.interchange.from_dataframe(o28k_raw)<BR />);
此警告:
:18: Pandas4Warning: The Dataframe Interchange Protocol is deprecated.
For dataframe-agnostic code, you may want to look into:
- Arrow PyCapsule Interface: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
- Narwhals: https://github.com/narwhals-dev/narwhals
自动化和脚本编写数据融合与清理回复:JMP19 - 数据帧交换协议弃用警告您是否看过JMP 用户社区发布的“在 JMP 19 中进一步使用 Python” ?
在 JMP 19 中,使用新函数jmp.from_dataframe() 可以更轻松地处理 Pandas 数据帧。
回复:JMP19 - 数据帧交换协议弃用警告我从同一个链接中找到了下面提到的代码,但是查询语句与我提到的有所不同。
pd.api.interchange.from_dataframe()
回复:JMP19 - 数据帧交换协议弃用警告有趣的是,当我运行以下Python脚本时,没有看到任何警告:
import jmp
import pandas as pd
dt = jmp.open(jmp.SAMPLE_DATA + "Big Class.jmp")
pandas_df = (pd.api.interchange.from_dataframe(dt))
print(pandas_df)
请检查一下,从 JMP 的 Python 编辑器运行 Python 时是否会出现此错误,还是只有使用 Python Submit 执行 Python 时才会出现此错误?
我还尝试了以下操作,但没有出现错误:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt );
Python Submit( "pandas_df = (pd.api.interchange.from_dataframe(dt))" );
Python Submit( "dt2 = jmp.from_dataframe(pandas_df)" );
Python Get(dt2);
您能否测试一下这些脚本,看看它们是否也会在您那边发出同样的警告?
回复:JMP19 - 数据帧交换协议弃用警告我使用 Python Submit 运行 Python 代码时,以及从 JMP 的 Python 编辑器运行 Python 脚本时,都会看到此警告。
pandas_df = (pd.api.interchange.from_dataframe(dt))
/*:
<STRING>
:1: Pandas4Warning: The Dataframe Interchange Protocol is deprecated. For dataframe-agnostic code, you may want to look into: - Arrow PyCapsule Interface: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html - Narwhals: https://github.com/narwhals-dev/narwhals
</STRING>
//:*/
import jmp
import pandas as pd
dt = jmp.open(jmp.SAMPLE_DATA + "Big Class.jmp")
pandas_df = (pd.api.interchange.from_dataframe(dt))
print(pandas_df)
/*:
:5: Pandas4Warning: The Dataframe Interchange Protocol is deprecated.
For dataframe-agnostic code, you may want to look into:
- Arrow PyCapsule Interface: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
- Narwhals: https://github.com/narwhals-dev/narwhals
回复:JMP19 - 数据帧交换协议弃用警告谢谢回复。上面的 Python 代码片段来自脚本索引,所以通常运行没有问题。
如果您当前使用的JMP版本不是最新版本(19.1.2),建议您更新后再试一次。如果您已经是最新版本,则建议您联系JMP技术支持(support@jmp.com )。
回复:JMP19 - 数据帧交换协议弃用警告警告来自 pandas 本身。
我们已在内部完成更新,以使用 PyCapsule 接口。具体发布时间将取决于稳定性测试结果。此次更新还将添加 jmp.from_arrow() 函数,并扩展 jmp.DataTable 对象以支持 Arrow 接口的要求。jmp.from_dataframe() 函数也已在内部进行重构,以利用新功能。
import pandas as pd
dt = jmp.open(jmp.SAMPLE_DATA + "Big Class.jmp")
pandas_df = pd.DataFrame.from_arrow(dt)
print(pandas_df)
回复:JMP19 - 数据帧交换协议弃用警告此警告在 pandas 3.0 及更高版本中出现。
回复:JMP19 - 数据帧交换协议弃用警告谢谢你的解释。
据我了解,当前的弃用警告源自 Pandas 而非 JMP,未来的 JMP 版本将直接支持 Arrow/PyCapsule 接口,从而支持以下工作流程:
dt = jmp.open(...)
pandas_df = pd.DataFrame.from_arrow(dt)
无需依赖数据帧交换协议。
与此同时,我正在尝试确定维护跨 JMP 版本部署的生产脚本的最佳方法。
在 JMP 18 中,我一直以来都依赖于自定义转换函数:
def jmp_to_pandas(jmp_table):
data = {}
for col in jmp_table:
data[col.name] = list(col)
return pd.DataFrame(data)
升级到 JMP 19 后,我切换到了:
<SPAN>pd.api.interchange.from_dataframe(...)</SPAN>
虽然可以运行,但现在会生成 Pandas 弃用警告。
您的建议是继续使用交换 API,直到 Arrow 支持发布,届时我需要重新审视已部署的生产脚本,还是建议恢复使用自定义的 DataTable 到 DataFrame 转换,以便生产代码能够在 Pandas 和 JMP 版本更新中保持稳定?
此外,对于即将推出的 Arrow 实现,将会<SPAN>蓑蓑</SPAN>Arrow 接口是否是必需的依赖项,还是会通过 JMP 公开,而无需用户安装额外的软件包?
感谢您提供的补充信息。
回复:JMP19 - 数据帧交换协议弃用警告通常情况下,我们建议继续使用更现代的 DataFrame 转换方法,例如交换协议,因为它们性能更佳。如果脚本确实需要访问控制台输出,那么抑制警告可能有所帮助,但通常不建议这样做:
import warnings
warnings.simplefilter(action='ignore', category=DeprecationWarning)
就稳定性而言,此弃用已标记为 Pandas4Warning,这意味着这些警告将在 pandas 4.0 中强制执行(参见更新后的弃用策略)。历史上,pandas 大约每 3 年发布一次主要版本,但据我所知,他们并未公布预计发布日期。我们仍然相信,Arrow PyCapsule 接口将在 pandas 4.0 中集成到 JMP 中。
在不了解工作流所依赖的具体 JMP/pandas 版本的情况下,自定义 DataTable 转换可能更适合此用例。此外,值得注意的是, `jmp.from_dataframe_using_csv` 函数也可用,并且在 pandas 的主要版本更新中(已使用 2.3.3 和 3.0.0 进行测试)没有显著差异。该函数在 JMP 19 中可用,并将继续在 JMP 20 中可用。
就目前的实现而言,当使用 pandas.DataFrame 调用`jmp.from_dataframe()`时,它会在内部调用 Arrow PyCapsule 接口( `jmp.from_arrow` )以保持向后兼容性,因此脚本本身无需进行任何调整。但是,关于您的下一个问题,pandas 使用这些方法时需要 pyarrow 作为依赖项,因此您可能需要重新检查执行环境以安装 pyarrow。据我们所知,这似乎是 pandas 特有的问题,因为 polars 不需要额外的 pyarrow 依赖项。
我们很乐意为您解答有关 Python 或 DataFrame 转换的任何其他问题,请随时提问。