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

问题描述 投票:0回答:1

声明

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

可能的解决方案

  • 我已经尝试过 Python 警告抑制,但 Polars 似乎只是打印出这个警告而没有任何相关的错误。
  • 另一种可能性是使用非处理程序方法读取?

任何关于如何摆脱这个恼人的消息的想法将不胜感激。

python dataframe python-polars
1个回答
0
投票

我在从

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)
© www.soinside.com 2019 - 2024. All rights reserved.