Skip to content
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

Decode bytes to str with Pandas reader #57

Open
nirvana-msu opened this issue Nov 21, 2017 · 4 comments
Open

Decode bytes to str with Pandas reader #57

nirvana-msu opened this issue Nov 21, 2017 · 4 comments

Comments

@nirvana-msu
Copy link

It would be nice if there was a setting which allowed to get data as str, rather than bytes, in Python 3 when used with pandas=True. I'm aware of the discussion in #35 and related example of a custom reader here, so it's definitely possible to achieve this. It just seems like there are quite a few things you need to overwrite to handle all the cases, which makes it very easy to do it wrong. If this is not going to be officially supported out of the box, then at least a recipe with QReader implementation which handles all the possible cases would be extremely helpful.

I feel like Python 3 users would prefer to get str over bytes in vast majority of cases, and using pandas DataFrame is essential in most scientific applications. If anything, at first I was naively expecting that passing encoding to QConnection would make it do exactly that. So if you don't pass any encoding it would give you bytes, but if you do pass the encoding it would give you decoded strings.

Thanks!

@seizetheday
Copy link

This is what I exactly need!!

@zjc5415
Copy link

zjc5415 commented May 14, 2018

This is what I exactly need!!

an easy way to do is:
in the file qreader.py, function _read_list:
change
if qtype == QSYMBOL_LIST:
symbols = self.buffer.get_symbols(length)
data = numpy.array(symbols, dtype = numpy.string
)
return qlist(data, qtype = qtype, adjust_dtype = False)
to:
if qtype == QSYMBOL_LIST:
symbols = self._buffer.get_symbols(length)
data = numpy.array(symbols, dtype = str)
return qlist(data, qtype = qtype, adjust_dtype = False)

it works but i don't if there are side effects

@wscsgh59
Copy link

Hello zjc5415,

This hasn't solved the issue for me. I gert an error saying that 'ascii' codec can't decode byte”. Is there another way to do it ?

THnaks

@zjc5415
Copy link

zjc5415 commented Apr 19, 2019

Hello zjc5415,

This hasn't solved the issue for me. I gert an error saying that 'ascii' codec can't decode byte”. Is there another way to do it ?

THnaks

in my case it is python3.6。

you may debug it line by line and check the reason。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants