Closed sparshbhawsar closed 4 years ago
Thanks for reporting this.
This seems to be related:
def _read_wtq_table(input_dir: Text, wtq_table_id: Text) -> pd.DataFrame:
"""Reads table file as pandas frame."""
table_path = os.path.join(input_dir, wtq_table_id)
with tf.io.gfile.GFile(table_path, 'r') as table_in:
return pd.read_csv(
table_in,
delimiter=',',
escapechar='\\',
encoding='utf-8',
dtype='str',
)
This is the problematic code.
I can reproduce the issue with this:
import tensorflow.compat.v1 as tf
import pandas as pd
from typing import Text
import os
import csv
tf.get_logger().setLevel('ERROR')
def _read_wtq_table(input_dir: Text, wtq_table_id: Text) -> pd.DataFrame:
"""Reads table file as pandas frame."""
table_path = os.path.join(input_dir, wtq_table_id)
with tf.io.gfile.GFile(table_path) as table_in:
return pd.read_csv(
table_in,
delimiter=',',
escapechar='\\',
encoding='utf-8',
dtype='str',
)
with open("/tmp/test.csv", "w") as output_file:
writer = csv.writer(output_file)
writer.writerow(["a", "b", "c"])
writer.writerow(["1", "2", "3"])
print(_read_wtq_table("/tmp", "test.csv"))
The problem is cause by pd.read_csv wrapping the GFile object with an TextIOWrapper.
A potential fix is this:
def _read_wtq_table(input_dir: Text, wtq_table_id: Text) -> pd.DataFrame:
"""Reads table file as pandas frame."""
table_path = os.path.join(input_dir, wtq_table_id)
with tf.io.gfile.GFile(table_path) as table_in:
string_io = io.StringIO(table_in.read())
return pd.read_csv(
string_io,
delimiter=',',
escapechar='\\',
encoding='utf-8',
dtype='str',
)
I tried the potential fix it's not working, I got the same error.
That's odd it worked for me. Anyway better fix is to remove encoding='utf-8'
:
def _read_wtq_table(input_dir: Text, wtq_table_id: Text) -> pd.DataFrame:
"""Reads table file as pandas frame."""
table_path = os.path.join(input_dir, wtq_table_id)
with tf.io.gfile.GFile(table_path) as table_in:
return pd.read_csv(
table_in,
delimiter=',',
escapechar='\\',
dtype='str',
)
Can you try that?
(The code will still handle UTF-8 correctly since that's the default for GFile.)
Should be fixed with the latest push. Feel free to reopen if this is still not working for you.
Hey @thomasmueller-google,
Thanks it worked !
Hello,
While model data creation using task WTQ, I got AttributeError: 'GFile' object has no attribute 'readable'
COMMAND USED: ! python tapas/tapas/run_task_main.py \ --task="WTQ" \ --input_dir="{input_dir}" \ --output_dir="{output_dir}" \ --bert_vocab_file="/content/tapas_model/vocab.txt" \ --mode="create_data"
ERROR :