Skip to content

Commit

Permalink
Don't override to_pandas for Datelike columns (#15167)
Browse files Browse the repository at this point in the history
`pandas.Series(pyarrow.array)` is first interpreted as an object data type since pandas doesn't know how to handle pyarrow arrays yet which is bad. Additionally if pyarrow becomes required in pandas this may have different behavior in the future.

I think the linked issues might be outdated and we can rely on pyarrow's `to_pandas`

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)

URL: #15167
  • Loading branch information
mroeschke authored Mar 7, 2024
1 parent 188d7cb commit c2bb860
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
27 changes: 0 additions & 27 deletions python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,33 +313,6 @@ def dayofyear(self) -> ColumnBase:
def day_of_year(self) -> ColumnBase:
return self.get_dt_field("day_of_year")

def to_pandas(
self,
*,
index: Optional[pd.Index] = None,
nullable: bool = False,
arrow_type: bool = False,
) -> pd.Series:
if arrow_type and nullable:
raise ValueError(
f"{arrow_type=} and {nullable=} cannot both be set."
)
elif nullable:
raise NotImplementedError(f"{nullable=} is not implemented.")
elif arrow_type:
return pd.Series(
pd.arrays.ArrowExtensionArray(self.to_arrow()), index=index
)
else:
# `copy=True` workaround until following issue is fixed:
# https://issues.apache.org/jira/browse/ARROW-9772
return pd.Series(
self.to_arrow(),
copy=True,
dtype=self.dtype,
index=index,
)

@property
def values(self):
"""
Expand Down
27 changes: 0 additions & 27 deletions python/cudf/cudf/core/column/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,6 @@ def to_arrow(self) -> pa.Array:
null_count=self.null_count,
)

def to_pandas(
self,
*,
index: Optional[pd.Index] = None,
nullable: bool = False,
arrow_type: bool = False,
) -> pd.Series:
# `copy=True` workaround until following issue is fixed:
# https://issues.apache.org/jira/browse/ARROW-9772
if arrow_type and nullable:
raise ValueError(
f"{arrow_type=} and {nullable=} cannot both be set."
)
elif nullable:
raise NotImplementedError(f"{nullable=} is not implemented.")
elif arrow_type:
return pd.Series(
pd.arrays.ArrowExtensionArray(self.to_arrow()), index=index
)
else:
return pd.Series(
self.to_arrow(),
copy=True,
dtype=self.dtype,
index=index,
)

def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
reflect, op = self._check_reflected_op(op)
other = self._wrap_binop_normalization(other)
Expand Down

0 comments on commit c2bb860

Please sign in to comment.