-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Read CSV using c engine silently swallows useful exceptions #13652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
you have a pretty old version of pandas, current is 0.18.1 and 0.19.0 releasing soon. and you can simply pass in the the I am closing, but if you can provide a copy-pastable example that reproduces a non-obvious error on latest, then pls reopen. |
This should not have been closed. 1 Even though the version I have is old, I think this issue still exists in latest version. 2 The encoding issue was just an example that was easy to produce and should not be dismised because of the existence of the encoding option. If the file handle was a socket and the connection was reset, it would also raise an exception and there would not be a workaround |
I just verified this with same code using newer pandas
|
I do not have permissions to reopen this issue. Can you do so? |
@bdrosen96 then pls show an example which can be copy-pasted. e.g. your file is not there. you need to create it to repro (e.g. write out a test csv file or something), better yet is to use StringIO |
and you are testing on 0.18.1, I am pretty sure these are already fixed on master. |
import pandas
import codecs
import traceback
import sys
import io
# Data in UTF-8
DATA = '''num, text
1,サウロン(Sauron、アイヌアの創造の時 - 第三紀3019年3月25日)は、J・R・R・トールキンの中つ国を舞台とした小説
『ホビットの冒険』『指輪物語』『シルマリルの物語』の登場人物。
2,『ホビットの冒険』に言及のある「死人うらない師」(映画『ホビットシリーズ』の字幕では「死人遣い(ネクロマンサー)」)とは彼のことである。
3,その続編である『指輪物語』においては「一つの指輪(the One Ring)」の作り主、「冥王(Dark Lord)」、「かの者
(the One)[1]」として登場する。前史にあたる『シルマリルの物語』では、初代の冥王モルゴスの最も力ある側近であった。
4,サウロンは元来、アルダ(地球)の創造を担った天使的種族アイヌアの一員であったが、主メルコールの反逆に加担して堕落し、アルダに害をなす存在となった。
5,「サウロン」とはクウェンヤで「身の毛のよだつもの」という意味であり、シンダリンで同様の意味である名前「ゴルサウア」と呼ばれることもある。
6,これらは、サウロンを恐れ、忌み嫌ったエルフによる名であり、『指輪物語』作中においてアラゴルンは「かれ(サウロン)は自分の本当の名は使わないし、それを字に書いたり口に出したりすることも許さない」と発言している。
7,そのほか、第二紀にエルフに対して自称したとされる名に、「アンナタール(物贈る君)」、「アルタノ(高貴な細工師)」、「アウレンディル(アウレの下僕)」がある。
8,第一紀の頃のサウロンは、自在に変身する能力を持っていた。
9,その能力を使えば見目麗しい立派な外見を装うことや、また巨大な狼や吸血こうもりといった怪物に変じることもでき、エルフから恐れられた。
10,第二紀に一つの指輪を作り上げたサウロンは、他の力の指輪で成される事柄やその所有者を支配できるようになった。
11,また、肉体が滅びても指輪がある限り何度でも蘇ることができた。
12,ただしヌーメノール没落の際に美しい肉体を破壊された後は、二度と美しく変身することはできなくなり、その悪意の
具現のような見るも恐ろしい姿しかとれなくなったという。
13,またしばしば「まぶたのない火に縁取られた目」といった心象表現で捉えられた。
'''
pandas.show_versions()
print("Pandas version: {}\n".format(pandas.__version__))
print("Python version: {}\n".format(sys.version_info))
def build_stream():
bytes_data = DATA.encode("shift-jis")
handle = io.BytesIO(bytes_data)
codec = codecs.lookup("utf-8")
utf8 = codecs.lookup('utf-8')
# stream must be binary UTF8
stream = codecs.StreamRecoder(
handle, utf8.encode, utf8.decode, codec.streamreader, codec.streamwriter)
return stream
def test_pandas(use_python):
stream = build_stream()
if use_python:
engine = 'python'
else:
engine = 'c'
df = pandas.read_csv(stream, engine=engine)
print("Showing stream error on read\n")
try:
stream = build_stream()
data = stream.read()
except Exception as exc:
traceback.print_exc(file=sys.stdout)
print("Showing stream error on read_csv (python engine)\n")
try:
stream = test_pandas(True)
except Exception as exc:
traceback.print_exc(file=sys.stdout)
print("Showing missing stream error on read_csv (python c)\n")
try:
stream = test_pandas(False)
except Exception as exc:
traceback.print_exc(file=sys.stdout)
|
I just ran this again on master and got same behavior. Pandas version: 0.18.1+198.g3f6d4bd |
pls show the output from master |
again, using a non-decoded stream is really really odd; this is not supported |
I'll reopen. If you can provide a PR which 'fixes' this I think it will be easier to look/test. cc @gfyoung |
|
|
@bdrosen96 : thanks for pointing this out! You can submit a PR for this and make sure to include a test as well (I would think in |
I cannot submit a PR without creating a fork first (permissions issue) |
Of course. It clearly says that in the documentation for contributing. |
Code Sample, a copy-pastable example if possible
Actual Output
Expected Behavior
The C engine should behave like python engine. This should be possible by using PyErr_Occurred .
The text was updated successfully, but these errors were encountered: