0

读取从 gcs 传输的 csv 文件 2020 年 3 月 13 日时开始遇到错误。下载后检查ai平台上的文件权限

相关文档:https ://www.tensorflow.org/api_docs/python/tf/io/gfile/GFile (看起来可读属性已被删除......)

命令:

sh.gsutil('cp',GCS_PATH,raw_rating_path)
with tf.io.gfile.GFile(raw_rating_path) as f:
   df = pd.read_csv(f)

已验证文件是本地文件并具有以下权限:

-rw-rw-rw- 1 root root 32617551 Apr  1 20:24 /tmp/placeScores.csv

错误(从原始 AI 平台日志中清理了一点):

File "/root/.local/lib/python3.7/site-packages/pandas/io/parsers.py", line 676, in parser_f
return _read(filepath_or_buffer, kwds)
File "/root/.local/lib/python3.7/site-packages/pandas/io/parsers.py", line 448, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "/root/.local/lib/python3.7/site-packages/pandas/io/parsers.py", line 880, in __init__
self._make_engine(self.engine)
File "/root/.local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1114, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/root/.local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1880, in __init__
src = TextIOWrapper(src, encoding=encoding, newline="")
AttributeError: 'GFile' object has no attribute 'readable'
4

2 回答 2

2

移除了 tf.io.gfile.GFile 线程锁,再次成功读取数据。不清楚 ai 平台上出了什么问题,因为它使用 tf.io.gfile.GFile 在本地运行。这可能是 tf install on ai-platform tensorflow build 2.1 的问题

df = data_io.read_csv(raw_rating_path)
# with tf.io.gfile.GFile(raw_rating_path, 'r') as f:
#   df = pd.read_csv(f)
于 2020-04-03T13:11:50.537 回答
1

阅读 Tensor Flow 文档,您似乎忘记了函数“tf.io.gfile.GFile(raw_rating_path)”中的参数“mode”,根据该文档它应该是“tf.io.gfile.GFile(raw_rating_path,模式='r')"。

于 2020-04-02T02:26:33.780 回答