Skip to content

Commit 4789a13

Browse files
committed
Merge branch-25.06 into branch-25.08
2 parents 0960231 + f71e181 commit 4789a13

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

ci/test_narwhals.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ rapids-logger "Check narwhals versions"
2626
python -c "import narwhals; print(narwhals.show_versions())"
2727

2828
rapids-logger "Run narwhals tests for cuDF"
29-
python -m pytest \
29+
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest \
3030
--cache-clear \
3131
--junitxml="${RAPIDS_TESTS_DIR}/junit-cudf-narwhals.xml" \
32+
-p xdist \
33+
-p env \
34+
-p no:pytest_benchmark \
3235
-p cudf.testing.narwhals_test_plugin \
3336
--numprocesses=8 \
3437
--dist=worksteal \
@@ -44,9 +47,12 @@ test_nan \
4447
"
4548

4649
rapids-logger "Run narwhals tests for cuDF Polars"
47-
NARWHALS_POLARS_GPU=1 python -m pytest \
50+
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 NARWHALS_POLARS_GPU=1 python -m pytest \
4851
--cache-clear \
4952
--junitxml="${RAPIDS_TESTS_DIR}/junit-cudf-polars-narwhals.xml" \
53+
-p xdist \
54+
-p env \
55+
-p no:pytest_benchmark \
5056
-k "not ( \
5157
${TESTS_THAT_NEED_NARWHALS_FIX_FOR_CUDF_POLARS} \
5258
)" \
@@ -84,10 +90,13 @@ TESTS_THAT_NEED_NARWHALS_FIX_FOR_CUDF_PANDAS=" \
8490
test_dtypes \
8591
"
8692

87-
NARWHALS_DEFAULT_CONSTRUCTORS=pandas python -m pytest \
93+
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 NARWHALS_DEFAULT_CONSTRUCTORS=pandas python -m pytest \
8894
-p cudf.pandas \
8995
--cache-clear \
9096
--junitxml="${RAPIDS_TESTS_DIR}/junit-cudf-pandas-narwhals.xml" \
97+
-p xdist \
98+
-p env \
99+
-p no:pytest_benchmark \
91100
-k "not ( \
92101
${TESTS_THAT_NEED_CUDF_FIX} or \
93102
${TESTS_TO_ALWAYS_SKIP} or \

cpp/src/rolling/detail/rolling.cuh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,16 @@ struct DeviceRolling {
126126

127127
bool output_is_valid = (count >= min_periods);
128128

129-
// store the output value, one per thread
130-
cudf::detail::rolling_store_output_functor<OutputType, op == aggregation::MEAN>{}(
131-
output.element<OutputType>(current_index), val, count);
129+
if (output_is_valid) {
130+
// store the output value, one per thread, but only if the
131+
// output is valid. min_periods is required to be >= 1, and so
132+
// here, count must be nonzero. We need to avoid storing if
133+
// count is zero since this could cause UB in some aggregations,
134+
// which may cause the compiler to deduce nonsense about the loop
135+
// that increments count.
136+
cudf::detail::rolling_store_output_functor<OutputType, op == aggregation::MEAN>{}(
137+
output.element<OutputType>(current_index), val, count);
138+
}
132139

133140
return output_is_valid;
134141
}

cpp/src/rolling/detail/rolling.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,23 @@ struct rolling_store_output_functor {
3535
// Specialization for MEAN
3636
template <typename _T>
3737
struct rolling_store_output_functor<_T, true> {
38-
// SFINAE for non-bool types
38+
// Don't store the output if count is zero since integral division by zero is
39+
// undefined behaviour. The caller must ensure that the relevant row is
40+
// marked as invalid with a null.
41+
42+
// SFINAE for non-bool, non-timestamp types
3943
template <typename T = _T,
4044
std::enable_if_t<!(cudf::is_boolean<T>() || cudf::is_timestamp<T>())>* = nullptr>
4145
CUDF_HOST_DEVICE inline void operator()(T& out, T& val, size_type count)
4246
{
43-
out = val / count;
44-
}
45-
46-
// SFINAE for bool type
47-
template <typename T = _T, std::enable_if_t<cudf::is_boolean<T>()>* = nullptr>
48-
CUDF_HOST_DEVICE inline void operator()(T& out, T& val, size_type count)
49-
{
50-
out = static_cast<int32_t>(val) / count;
47+
if (count > 0) { out = val / count; }
5148
}
5249

5350
// SFINAE for timestamp types
5451
template <typename T = _T, std::enable_if_t<cudf::is_timestamp<T>()>* = nullptr>
5552
CUDF_HOST_DEVICE inline void operator()(T& out, T& val, size_type count)
5653
{
57-
out = static_cast<T>(val.time_since_epoch() / count);
54+
if (count > 0) { out = static_cast<T>(val.time_since_epoch() / count); }
5855
}
5956
};
6057

0 commit comments

Comments
 (0)