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

Remove numba JIT kernel usage from dataframe copy tests #13385

Merged
Changes from all commits
Commits
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
42 changes: 14 additions & 28 deletions python/cudf/cudf/tests/test_dataframe_copy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright (c) 2018-2023, NVIDIA CORPORATION.
from copy import copy, deepcopy

import cupy as cp
import numpy as np
import pandas as pd
import pytest
from numba import cuda

from cudf.core.dataframe import DataFrame
from cudf.testing._utils import ALL_TYPES, assert_eq
from cudf.testing._utils import ALL_TYPES, assert_eq, assert_neq

"""
DataFrame copy expectations
Expand Down Expand Up @@ -131,47 +131,33 @@ def test_cudf_dataframe_copy_then_insert(copy_fn, ncols, data_type):
assert not copy_df.to_string().split() == df.to_string().split()


@cuda.jit
def group_mean(data, segments, output):
i = cuda.grid(1)
if i < segments.size:
s = segments[i]
e = segments[i + 1] if (i + 1) < segments.size else data.size
# mean calculation
carry = 0.0
n = e - s
for j in range(s, e):
carry += data[j]
output[i] = carry / n


@cuda.jit
def add_one(data):
i = cuda.grid(1)
if i == 1:
data[i] = data[i] + 1.0


def test_kernel_deep_copy():
def test_deep_copy_write_in_place():
pdf = pd.DataFrame(
[[1, 2, 3], [4, 5, 6], [7, 8, 9]], columns=["a", "b", "c"]
)
gdf = DataFrame.from_pandas(pdf)
cdf = gdf.copy(deep=True)
sr = gdf["b"]

add_one[1, len(sr)](sr._column.data_array_view(mode="write"))
assert not gdf.to_string().split() == cdf.to_string().split()
# Write a value in-place on the deep copy.
# This should only affect the copy and not the original.
cp.asarray(sr._column)[1] = 42
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved

assert_neq(gdf, cdf)
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved

def test_kernel_shallow_copy():

def test_shallow_copy_write_in_place():
pdf = pd.DataFrame(
[[1, 2, 3], [4, 5, 6], [7, 8, 9]], columns=["a", "b", "c"]
)
gdf = DataFrame.from_pandas(pdf)
cdf = gdf.copy(deep=False)
sr = gdf["a"]
add_one[1, len(sr)](sr.to_cupy())

# Write a value in-place on the shallow copy.
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
# This should change the copy and original.
cp.asarray(sr._column)[1] = 42
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved

assert_eq(gdf, cdf)


Expand Down