Skip to content

ENH: Add support for float hex format to loadtxt. #5504

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 3 commits into from
Feb 13, 2015

Conversation

charris
Copy link
Member

@charris charris commented Jan 25, 2015

Add _floatconv to npyio.py as a default floating point converter. This
uses float() as a type conversion with a fallback on (ValueError) to
float.fromhex().

Closes #2517.

Cleanup of #133.

@charris
Copy link
Member Author

charris commented Jan 25, 2015

Needed python > 2.5, so open for discussion.

return float(x)
except ValueError:
pass
return float.fromhex(x)
Copy link
Contributor

Choose a reason for hiding this comment

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

the pass should not be needed, you can return from the except clause

@juliantaylor
Copy link
Contributor

2.5 should not be a concern anymore, we (or probably you ;) ) removed 2.5 compat code a while ago and we say since 1.8 >= 2.6

@charris
Copy link
Member Author

charris commented Jan 25, 2015

Yeah, also needs a test.

@Nodd
Copy link
Contributor

Nodd commented Jan 26, 2015

If I understand correctly, that means that "A0" will be treated as hex while "10" will be treatead as base 10. So if a column contains hex values without prefix, some will be treated as base 10 and others as base 16 ?
Looks like explicitely checking for a 0x prefix is necessary.

@charris
Copy link
Member Author

charris commented Jan 26, 2015

@Nodd Good point. I'm thinking this PR is too limited, maybe is it better to check x for the prefixes 0X, 0x, 0o, and 0O up front and convert it to the correct integer before any other conversions.

@charris
Copy link
Member Author

charris commented Jan 26, 2015

Now with new improved implementation.

@charris charris force-pushed the cleanup-gh-133 branch 2 times, most recently from 58207ad to 368822f Compare February 12, 2015 21:38
claumann and others added 3 commits February 13, 2015 10:47
Add _floatconv to npyio.py as a default floating point converter. This
uses float() as a type conversion with a fallback on (ValueError) to
float.fromhex().

Closes numpy#2517.
The strings must be produced by the python float.hex method.
charris added a commit that referenced this pull request Feb 13, 2015
ENH: Add support for float hex format to loadtxt.
@charris charris merged commit c5b90eb into numpy:master Feb 13, 2015
@charris charris deleted the cleanup-gh-133 branch February 13, 2015 18:22
@charris
Copy link
Member Author

charris commented Feb 13, 2015

Not sure this is worth the trouble, but merging anyway.

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.

Support floating point hex representation in loadtxt (Trac #1924)
4 participants