|
1 | | -from typing import Optional, Union |
| 1 | +from typing import Any, Optional, Union |
2 | 2 |
|
3 | 3 | import pandas as pd |
4 | 4 |
|
| 5 | + |
| 6 | +def _cudf_mask_none(result: Any, mask: Any) -> Any: |
| 7 | + result_pd = result.to_pandas().astype('object') |
| 8 | + result_pd.iloc[mask] = None |
| 9 | + return result_pd |
| 10 | + |
5 | 11 | from .ASTPredicate import ASTPredicate |
6 | 12 | from graphistry.compute.typing import SeriesT |
7 | 13 |
|
@@ -178,9 +184,8 @@ def __call__(self, s: SeriesT) -> SeriesT: |
178 | 184 | has_na: bool = bool(s.isna().any()) |
179 | 185 | if has_na: |
180 | 186 | # Convert to object dtype and apply mask to preserve None values |
181 | | - na_mask: pd.Series = s.to_pandas().isna() |
182 | | - result_pd = result.to_pandas().astype('object').where(~na_mask, None) |
183 | | - result = cudf.from_pandas(result_pd) |
| 187 | + na_mask_arr = s.to_pandas().isna().to_numpy() |
| 188 | + result = cudf.from_pandas(_cudf_mask_none(result, na_mask_arr)) |
184 | 189 | else: |
185 | 190 | if not self.case: |
186 | 191 | s_modified = s.str.lower() |
@@ -346,9 +351,8 @@ def __call__(self, s: SeriesT) -> SeriesT: |
346 | 351 | has_na: bool = bool(s.isna().any()) |
347 | 352 | if has_na: |
348 | 353 | # Convert to object dtype and apply mask to preserve None values |
349 | | - na_mask: pd.Series = s.to_pandas().isna() |
350 | | - result_pd = result.to_pandas().astype('object').where(~na_mask, None) |
351 | | - result = cudf.from_pandas(result_pd) |
| 354 | + na_mask_arr = s.to_pandas().isna().to_numpy() |
| 355 | + result = cudf.from_pandas(_cudf_mask_none(result, na_mask_arr)) |
352 | 356 | else: |
353 | 357 | if not self.case: |
354 | 358 | s_modified = s.str.lower() |
|
0 commit comments