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

Refactor numpy array input in as_column #14651

Merged
merged 35 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
aac2c1e
Refactor numpy array input in as_column
mroeschke Dec 19, 2023
5afd82c
Merge remote-tracking branch 'upstream/branch-24.02' into ref/np_arra…
mroeschke Dec 19, 2023
18be5c0
make bool and int data go through arrow
mroeschke Dec 19, 2023
1eb5cf0
Merge remote-tracking branch 'upstream/branch-24.02' into ref/np_arra…
mroeschke Dec 19, 2023
ac403ca
Fix typo, just build buffer again for datelike types
mroeschke Dec 19, 2023
2655e26
Merge remote-tracking branch 'upstream/branch-24.02' into ref/np_arra…
mroeschke Dec 20, 2023
e192238
Fix ==
mroeschke Dec 20, 2023
8778e29
Treat NAs in np array as NULL with arrow
mroeschke Dec 20, 2023
dbca8d4
Merge remote-tracking branch 'upstream/branch-24.02' into ref/np_arra…
mroeschke Dec 29, 2023
2013017
Merge remote-tracking branch 'upstream/branch-24.02' into ref/np_arra…
mroeschke Jan 11, 2024
e75893a
Reuse is_nat
mroeschke Jan 11, 2024
bdb8da0
Add comments about NaT behavior
mroeschke Jan 11, 2024
b39a75e
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Jan 31, 2024
94baa34
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Feb 6, 2024
edd2080
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Feb 21, 2024
66d4403
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Feb 24, 2024
ba963ad
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Feb 26, 2024
192f376
Trigger CI
mroeschke Feb 26, 2024
1c923b4
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Feb 28, 2024
1917103
Fix some tests
mroeschke Feb 28, 2024
99c1419
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Feb 29, 2024
a969b84
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Mar 7, 2024
92856de
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Mar 12, 2024
147ba2b
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Mar 14, 2024
ef56817
fix some concat tests
mroeschke Mar 14, 2024
ab5d10f
Dont create mask if no NAs
mroeschke Mar 14, 2024
e2fb5b4
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Mar 15, 2024
96f1491
Fix test, add error for unitless datetlike
mroeschke Mar 15, 2024
912e5b9
Merge remote-tracking branch 'upstream/branch-24.04' into ref/np_arra…
mroeschke Mar 15, 2024
95ae6b2
Merge remote-tracking branch 'upstream/branch-24.06' into ref/np_arra…
mroeschke Mar 18, 2024
bee6c91
Merge remote-tracking branch 'upstream/branch-24.06' into ref/np_arra…
mroeschke Apr 4, 2024
2c64990
Address review
mroeschke Apr 5, 2024
4d57148
Merge remote-tracking branch 'upstream/branch-24.06' into ref/np_arra…
mroeschke Apr 5, 2024
3ffd9e6
Remove carveout for np array of cupy objects
mroeschke Apr 5, 2024
15fff60
Merge remote-tracking branch 'upstream/branch-24.06' into ref/np_arra…
mroeschke Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dont create mask if no NAs
  • Loading branch information
mroeschke committed Mar 14, 2024
commit ab5d10fc13ffb534f5dace5fff899e4139d6e518
39 changes: 19 additions & 20 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2078,26 +2078,25 @@ def as_column(
arbitrary = arbitrary.astype(new_type)

is_nat = np.isnat(arbitrary)
if (nan_as_null is None or nan_as_null) and is_nat.any():
# Convert NaT to NA, which pyarrow does by default
return as_column(
pa.array(arbitrary),
dtype=dtype,
nan_as_null=nan_as_null,
)
else:
buffer = as_buffer(arbitrary.view("|u1"))
# Consider NaT as NA in the mask
# but maintain NaT as a value
bool_mask = as_column(~is_nat)
mask = as_buffer(bools_to_mask(bool_mask))
col = build_column(
data=buffer, mask=mask, dtype=arbitrary.dtype
)

if dtype:
col = col.astype(dtype)
return col
mask = None
if is_nat.any():
if nan_as_null is None or nan_as_null:
# Convert NaT to NA, which pyarrow does by default
return as_column(
pa.array(arbitrary),
dtype=dtype,
nan_as_null=nan_as_null,
)
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

Superfluous else since we're returning above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Removed

# Consider NaT as NA in the mask
# but maintain NaT as a value
bool_mask = as_column(~is_nat)
mask = as_buffer(bools_to_mask(bool_mask))
buffer = as_buffer(arbitrary.view("|u1"))
col = build_column(data=buffer, mask=mask, dtype=arbitrary.dtype)
if dtype:
col = col.astype(dtype)
return col
else:
raise NotImplementedError(f"{arbitrary.dtype} not supported")
elif (view := as_memoryview(arbitrary)) is not None:
Expand Down
10 changes: 2 additions & 8 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,14 +1350,8 @@ def __repr__(self):

output = output.replace("nan", str(cudf.NA))
elif preprocess._values.nullable:
# TODO: Should we be checking presence of a base_mask or if there are NAs
# in general?
if isinstance(self._values, (StringColumn, DatetimeColumn)):
output = repr(
self.to_pandas(
nullable=isinstance(self._values, StringColumn)
)
)
if isinstance(self._values, StringColumn):
output = repr(self.to_pandas(nullable=True))
else:
output = repr(self._clean_nulls_from_index().to_pandas())
# We should remove all the single quotes
Expand Down
Loading