Skip to content

Use errors='replace' in decoding bytes data in Py3 - #6145

Merged
taldcroft merged 2 commits into
astropy:masterfrom
taldcroft:table-sandwich-replace
Jun 2, 2017
Merged

taldcroft merged 2 commits into
astropy:masterfrom
taldcroft:table-sandwich-replace

Conversation

@taldcroft

@taldcroft taldcroft commented May 31, 2017 •

Copy link
Copy Markdown
Member

This fixes the current test failure in master caused by the interaction of #5700 and #6117, except now I need to back out #6142.

Closes #6121

@taldcroft
taldcroft requested a review from mhvk May 31, 2017 17:30
@taldcroft

Copy link
Copy Markdown
Member Author

Canceling the travis build to rebase this on the very latest master.

cc: @mhvk

@mhvk

mhvk commented May 31, 2017

Copy link
Copy Markdown
Contributor

Sorry for the extra work. I'm OK with this approach -- in the end, the choice is to treat S dtype as a utf-8 string, so it seems OK to replace stuff to ensure one always gets the same result. It does imply that equality tests will now pass for more than one corrupted value, but that seems a reasonable price to pay.

@pllim

pllim commented May 31, 2017

Copy link
Copy Markdown
Member

Does this affect dev or release?

@taldcroft taldcroft added the Affects-dev PRs and issues that do not impact an existing Astropy release label May 31, 2017
@pllim pllim added this to the v2.0.0 milestone May 31, 2017
@taldcroft
taldcroft force-pushed the table-sandwich-replace branch from 11d2c6f to e8ba4a3 Compare May 31, 2017 17:37
@bsipocz

bsipocz commented May 31, 2017

Copy link
Copy Markdown
Member

I guess this is getting to be merged asap, so I've cancelled the master build of #6142 to clear up a tiny bit of the backlog.

@taldcroft

Copy link
Copy Markdown
Member Author

@mhvk - true...

In [8]: t2 = Table([[b'Z\xf1']])

In [9]: t1 = Table([[b'Z\xf0']])

In [10]: t1['col0'] == t2['col0']  # Bytes get compared
Out[10]: array([False], dtype=bool)

In [11]: t1['col0'][0] == t2['col0'][0]  # Unicode gets compared
Out[11]: True

Using an encoding which is subject to decode errors is basis of the problem. Hence all the discussion on numpy-dev related to latin-1, and my original implementation using latin-1. Yes, it is arbitrary and not actually the correct encoding most of the time, BUT it would give False in Out[11].

@mhvk

mhvk commented May 31, 2017

Copy link
Copy Markdown
Contributor

I fear there is no really good solution to this -- maybe I need to get to work to implement setting the decoding after all... Anyway, for now, I think we'll have to live with this annoyance.

@saimn

saimn commented May 31, 2017

Copy link
Copy Markdown
Contributor

One issue I think is that the data can be modified silently (which is different from #6117 where the data was modified but only for printing if I'm correct ?). What would you think about doing the replace in a try/except which would allow to issue a warning ?

@taldcroft

Copy link
Copy Markdown
Member Author

@saimn - maybe I'm not understanding, but I don't see how the decode operation can in any way leak back to modify table data. This is the internal version of __getitem__ and the decode makes a completely new reference that gets returned.

@saimn

saimn commented Jun 1, 2017

Copy link
Copy Markdown
Contributor

@taldcroft - Ah sorry, I was thinking about the case of a new table created via slicing, but I missed the fact that the decode is done only for scalar values (not value.shape). (And only chararray has a .decode method anyway, I got confused with the io.fits code).

@taldcroft
taldcroft merged commit 12b242f into astropy:master Jun 2, 2017
@taldcroft
taldcroft deleted the table-sandwich-replace branch June 2, 2017 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release Bug table

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table unicode sandwich follow-up: use replace for decoding errors?

5 participants