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

[BUG] Support casting with Pandas dtype aliases #8904

Closed
sarahyurick opened this issue Jul 29, 2021 · 2 comments · Fixed by #8920
Closed

[BUG] Support casting with Pandas dtype aliases #8904

sarahyurick opened this issue Jul 29, 2021 · 2 comments · Fixed by #8920
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@sarahyurick
Copy link
Contributor

sarahyurick commented Jul 29, 2021

Related to #8885.

I am able to cast to Pandas' boolean dtype with:

import cudf
import pandas as pd

s = cudf.Series([1, 2, 0])
s.astype(pd.BooleanDtype())
0     True
1     True
2    False
dtype: bool

However, the string name "boolean" for the BooleanDtype is not supported:

s.astype("boolean")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_26633/182000827.py in <module>
      4 s = cudf.Series([1, 2, 3])
      5 s.astype(pd.BooleanDtype())
----> 6 s.astype("boolean")

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/series.py in astype(self, dtype, copy, errors)
   3114         except Exception as e:
   3115             if errors == "raise":
-> 3116                 raise e
   3117             elif errors == "warn":
   3118                 import traceback

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/series.py in astype(self, dtype, copy, errors)
   3106         try:
   3107             print(dtype)
-> 3108             data = self._column.astype(dtype)
   3109 
   3110             return self._copy_construct(

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/column/column.py in astype(self, dtype, **kwargs)
    884         dtype = pandas_dtypes_to_cudf_dtypes.get(dtype, dtype)
    885         if _is_non_decimal_numeric_dtype(dtype):
--> 886             return self.as_numerical_column(dtype, **kwargs)
    887         elif is_categorical_dtype(dtype):
    888             return self.as_categorical_column(dtype, **kwargs)

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/column/numerical.py in as_numerical_column(self, dtype, **kwargs)
    254 
    255     def as_numerical_column(self, dtype: Dtype, **kwargs) -> NumericalColumn:
--> 256         dtype = np.dtype(dtype)
    257         if dtype == self.dtype:
    258             return self

TypeError: data type 'boolean' not understood
@sarahyurick sarahyurick added bug Something isn't working Needs Triage Need team to review and classify labels Jul 29, 2021
@shwina shwina added the Python Affects Python cuDF API. label Jul 29, 2021
@sarahyurick sarahyurick removed the Needs Triage Need team to review and classify label Jul 30, 2021
@sarahyurick
Copy link
Contributor Author

sarahyurick commented Jul 30, 2021

Similar to #8915.

@sarahyurick sarahyurick reopened this Jul 30, 2021
@sarahyurick sarahyurick changed the title [BUG] Support casting to Pandas types with dtype aliases [BUG] Support casting with Pandas dtype aliases Aug 2, 2021
@sarahyurick sarahyurick self-assigned this Aug 2, 2021
rapids-bot bot pushed a commit that referenced this issue Aug 2, 2021
Addressing #8904. Note that it does not include the "string" alias because we already have `as_string_column`.

Authors:
  - Sarah Yurick (https://github.com/sarahyurick)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #8920
@galipremsagar
Copy link
Contributor

Fixed by #8920

@galipremsagar galipremsagar linked a pull request Aug 2, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants