Skip to content

BUG: Fix bug in pd.read_clipboard on windows with PY3 (GH4561); not decoding properly #4571

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

Merged
merged 1 commit into from
Aug 15, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Aug 14, 2013

closes #4561

try:
encoding = kwargs.get('encoding')
if encoding is None:
encoding = 'UTF-8'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this maybe be get_option('display.encoding')?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could even do

encoding = kwargs.get('encoding', get_option('display.encoding'))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@jreback
Copy link
Contributor Author

jreback commented Aug 14, 2013

this is a windows encoding, could use sys.getsystemencoding()?

on side note:
cc @jtratner

in pandas/compat.py

    def bytes_to_str(b, encoding='utf-8'):
        return b.decode(encoding)

shouldn't this be:

    def bytes_to_str(b, encoding=None):
        if encoding is None:
             encoding='utf-8'
        return b.decode(encoding)

@cpcloud
Copy link
Member

cpcloud commented Aug 14, 2013

why? strings are immutable so even if it's appended to in the function it won't be seen in the caller

@cpcloud
Copy link
Member

cpcloud commented Aug 14, 2013

similar to if you increment an int parameter

def f(x):
    x += 1
y = 1
f(y)
print(y) # prints 1

@cpcloud
Copy link
Member

cpcloud commented Aug 14, 2013

also i think it's sys.getfilesystemencoding()

@jtratner
Copy link
Contributor

@jreback how about:

    def bytes_to_str(b, encoding='utf-8'):
        return b.decode(encoding or 'utf-8')

For the other one, you can just wrap in an or instead - clearer and doesn't execute get_option if not needed

encoding = kwargs.get('encoding') or get_option('display.encoding')

@cpcloud
Copy link
Member

cpcloud commented Aug 14, 2013

What's with all of you green icon folk? 😄

@jreback
Copy link
Contributor Author

jreback commented Aug 14, 2013

they must have changed the default, I don't have a pic up

@jreback
Copy link
Contributor Author

jreback commented Aug 14, 2013

https://travis-ci.org/jreback/pandas/jobs/10216546

I guess pyperclip acts differently on windows and linux under py3.......

@cpcloud
Copy link
Member

cpcloud commented Aug 14, 2013

it's annoying that all string types in python2 have decode and encode methods while only bytes types in python3 have decode and str types have only encode

@jreback
Copy link
Contributor Author

jreback commented Aug 14, 2013

you could monkey-patch strings at runtime to make it a noop! but pretty I guess the error means you are not doing something right

jreback added a commit that referenced this pull request Aug 15, 2013
BUG: Fix bug in pd.read_clipboard on windows with PY3 (GH4561); not decoding properly
@jreback jreback merged commit b5ee28b into pandas-dev:master Aug 15, 2013
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

Successfully merging this pull request may close these issues.

BUG: read_clipboard fails on Windows since pandas 0.12
3 participants