-
Notifications
You must be signed in to change notification settings - Fork 915
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
[FEA] How to read hex as int using cudf #1925
Comments
If the numbers start with "0x" they will be interpreted as hexadecimal numbers. This was added in #973. |
We have datasets where For eg: We have numbers like |
I see. That is currently not supported. One option could be to add a hex datatype that can be specified in dtype. Or we could perhaps automatically treat [0-9a-f] as "digits". |
FWIW, I like the first option of adding a hex datatype. Automatically treating [0-9a-f] as "digits" makes it inconsistent with |
@VibhuJawa For adding a If you have |
I would prefer a more explicit I also do not sure know how to get , x = int("9512c20b", 16)
print(x) Output
@randerzander Thoughts ? |
I believe >>> import pandas as pd
>>> df = pd.DataFrame([int('9512c20b', 16)], dtype='int32')
>>> print(df)
0
0 -1793932789
>>> df = pd.DataFrame([int('9512c20b', 16)], dtype='int64')
>>> print(df)
0
0 2501034507 |
Aah, got it. I think with We may even want to look at supporting bigger import numpy as np
num = int('9512c20b', 16)
i32 = np.iinfo(np.int32)
i64 = np.iinfo(np.int64)
print(i32.max<num)
print(i64.max<num)
print(np.int32(num))
print(np.int64(num))
|
So I decided on adding Let me know what you think... |
I agree with this approach . I think alias will make it intuitive for the user . Thanks a lot for your work on this. |
This PR silences warnings in `test_csv.py`. (I am working through one test file at a time so we can enable `-Werr` in the future.) The only warning in this file is related to integer overflow in pandas. Currently, the test data is as follows: https://github.com/rapidsai/cudf/blob/21325e8348f33b28e434d08d687a28f251c38f67/python/cudf/cudf/tests/test_csv.py#L1313-L1319 First, I note that this "hex" dtype is not part of the pandas API. It is a cuDF addition (#1925, #2149). Note that there are dtypes for `int32` / `hex32`, and the test data contains both a negative value `-0x1000` and a value `9512c20b`. The negative value `-0x1000` has a sensible interpretation if the results are meant to be signed, but then the value `9512c20b` is out of range (the maximum signed 32-bit value would be `0x7FFFFFFF` and the minimum signed 32-bit value would be `0x80000000`, using the big-endian convention of the parser). Recognizing this, pandas throws a `FutureWarning` when parsing the data `9512c20b` as `int32`, and unsafely wraps it to a negative value. This behavior will eventually be replaced by an `OverflowError`. In the future, we may need to decide if cuDF should raise an `OverflowError` when exceeding `0x7FFFFFFF` for consistency with pandas, or decide to use unsigned integers when parsing "hex" dtypes and compare to pandas' unsigned types in this test. Authors: - Bradley Dice (https://github.com/bdice) Approvers: - Vukasin Milovanovic (https://github.com/vuule) - https://github.com/brandon-b-miller URL: #10362
What is your question?
What is the
cudf
equivalent way to read hex as int columns using cudf.Example of doing this in pandas.
Output
The text was updated successfully, but these errors were encountered: