Polars for Python:读取数据帧时如何消除“确保传递文件路径而不是 python 文件对象”警告?

pab*_*agn 6 python dataframe python-polars

该声明

  • Polars.read_csv()我正在通过 Python 文件处理程序使用方法读取数据集:
 with gzip.open(os.path.join(getParameters()['rdir'], dataset)) as compressed_file:
    df = pl.read_csv(compressed_file, sep = '\t', ignore_errors=True)
Run Code Online (Sandbox Code Playgroud)
  • 不断弹出性能警告:
Polars found a filename. Ensure you pass a path to the file instead of a python file object when possible for best performance.
Run Code Online (Sandbox Code Playgroud)

可能的解决方案

  • 我已经尝试过 Python 警告抑制,但似乎 Polars 实际上只是打印出此语句,而没有任何关联的默认警告。
  • 另一种可能性是使用非处理程序方法进行读取?

任何关于如何摆脱这个恼人的消息的想法将受到高度赞赏。

小智 4

我在从对象打开时遇到了类似的问题ZipFile.read()解决方案是在文件名中添加一个方法。也许同样的方法也适用于你的情况?

 with gzip.open(os.path.join(getParameters()['rdir'], dataset)) as compressed_file:
    df = pl.read_csv(compressed_file.read(), sep = '\t', ignore_errors=True)
Run Code Online (Sandbox Code Playgroud)