From 5bd6f94864ac714f48455a6471a5845006a9892e Mon Sep 17 00:00:00 2001 From: "Robert (Bobby) Evans" Date: Wed, 3 Mar 2021 09:17:29 -0600 Subject: [PATCH 1/3] Fix JNI deprecation of all, put it on the wrong version before (#7501) A while ago I deprecated the API that I wanted to keep and didn't do the one that should go away. This fixes that. Authors: - Robert (Bobby) Evans (@revans2) Approvers: - Jason Lowe (@jlowe) URL: https://github.com/rapidsai/cudf/pull/7501 --- java/src/main/java/ai/rapids/cudf/ColumnView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/main/java/ai/rapids/cudf/ColumnView.java b/java/src/main/java/ai/rapids/cudf/ColumnView.java index 1dce52f7105..5543f02d6ba 100644 --- a/java/src/main/java/ai/rapids/cudf/ColumnView.java +++ b/java/src/main/java/ai/rapids/cudf/ColumnView.java @@ -1106,9 +1106,7 @@ public Scalar any(DType outType) { * Returns a boolean scalar that is true if all of the elements in * the column are true or non-zero otherwise false. * Null values are skipped. - * @deprecated the only output type supported is BOOL8. */ - @Deprecated public Scalar all() { return all(DType.BOOL8); } @@ -1118,7 +1116,9 @@ public Scalar all() { * if all of the elements in the column are true or non-zero * otherwise false or 0. * Null values are skipped. + * @deprecated the only output type supported is BOOL8. */ + @Deprecated public Scalar all(DType outType) { return reduce(Aggregation.all(), outType); } From c69b6f82adaa821c5201055ce3bd1672978b5704 Mon Sep 17 00:00:00 2001 From: "Robert (Bobby) Evans" Date: Wed, 3 Mar 2021 09:24:19 -0600 Subject: [PATCH 2/3] JNI bit cast (#7493) In #7373 logical_cast is renamed to bit_cast. That breaks JNI, and this fixes it. Authors: - Robert (Bobby) Evans (@revans2) - Nghia Truong (@ttnghia) Approvers: - Raza Jafri (@razajafri) - Jason Lowe (@jlowe) - Alessandro Bellina (@abellina) URL: https://github.com/rapidsai/cudf/pull/7493 --- .../main/java/ai/rapids/cudf/ColumnView.java | 19 +++++++++++++++++-- java/src/main/native/src/ColumnViewJni.cpp | 8 ++++---- .../java/ai/rapids/cudf/ColumnVectorTest.java | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/java/src/main/java/ai/rapids/cudf/ColumnView.java b/java/src/main/java/ai/rapids/cudf/ColumnView.java index 5543f02d6ba..331c5b08764 100644 --- a/java/src/main/java/ai/rapids/cudf/ColumnView.java +++ b/java/src/main/java/ai/rapids/cudf/ColumnView.java @@ -1304,9 +1304,24 @@ public ColumnVector castTo(DType type) { * types must match. * @param type the type you want to go to. * @return a ColumnView that cannot outlive the Column that owns the actual data it points to. + * @deprecated this has changed to bit_cast in C++ so use that name instead */ + @Deprecated public ColumnView logicalCastTo(DType type) { - return new ColumnView(logicalCastTo(getNativeView(), + return bitCastTo(type); + } + + /** + * Zero-copy cast between types with the same underlying length. + * + * Similar to bit_cast in C++. This will take the underlying data and create new metadata + * so it is interpreted as a new type. Not all types are supported the width of the + * types must match. + * @param type the type you want to go to. + * @return a ColumnView that cannot outlive the Column that owns the actual data it points to. + */ + public ColumnView bitCastTo(DType type) { + return new ColumnView(bitCastTo(getNativeView(), type.typeId.getNativeId(), type.getScale())); } @@ -2607,7 +2622,7 @@ private static native long stringReplaceWithBackrefs(long columnView, String pat private static native long castTo(long nativeHandle, int type, int scale); - private static native long logicalCastTo(long nativeHandle, int type, int scale); + private static native long bitCastTo(long nativeHandle, int type, int scale); private static native long byteListCast(long nativeHandle, boolean config); diff --git a/java/src/main/native/src/ColumnViewJni.cpp b/java/src/main/native/src/ColumnViewJni.cpp index 47aa30e5d31..a0613f9b73f 100644 --- a/java/src/main/native/src/ColumnViewJni.cpp +++ b/java/src/main/native/src/ColumnViewJni.cpp @@ -760,16 +760,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_logicalCastTo(JNIEnv *env, jclass, - jlong handle, jint type, - jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitCastTo(JNIEnv *env, jclass, + jlong handle, jint type, + jint scale) { JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); cudf::column_view *column = reinterpret_cast(handle); cudf::data_type n_data_type = cudf::jni::make_data_type(type, scale); std::unique_ptr result = std::make_unique(); - *result = cudf::logical_cast(*column, n_data_type); + *result = cudf::bit_cast(*column, n_data_type); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index 9dba4c4c184..a3500ae86ef 100644 --- a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java +++ b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java @@ -2061,10 +2061,10 @@ void emptyStringColumnFindReplaceAll() { } @Test - void testLogicalCast() { + void testBitCast() { try (ColumnVector cv = ColumnVector.decimalFromLongs(-2, 1L, 2L, 100L, 552L); ColumnVector expected = ColumnVector.fromLongs(1L, 2L, 100L, 552L); - ColumnView casted = cv.logicalCastTo(DType.INT64)) { + ColumnView casted = cv.bitCastTo(DType.INT64)) { assertColumnsAreEqual(expected, casted); } } From 4d0c1608edc2c1f3707445e9f99f67b1261fa32e Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Wed, 3 Mar 2021 17:30:04 -0600 Subject: [PATCH 3/3] xfail failing pytest in pandas 1.2.3 (#7507) Looks like a new patch to the version of `1.2` was released(`1.2.3`) and this breaks one of our pytest. xfailing that pytest for `1.2.3`. Authors: - GALI PREM SAGAR (@galipremsagar) Approvers: - Christopher Harris (@cwharris) - AJ Schmidt (@ajschmidt8) - Keith Kraus (@kkraus14) URL: https://github.com/rapidsai/cudf/pull/7507 --- python/cudf/cudf/core/_compat.py | 1 + python/cudf/cudf/tests/test_setitem.py | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/cudf/cudf/core/_compat.py b/python/cudf/cudf/core/_compat.py index 0fedfcabb46..807e96f2c38 100644 --- a/python/cudf/cudf/core/_compat.py +++ b/python/cudf/cudf/core/_compat.py @@ -7,3 +7,4 @@ PANDAS_GE_100 = PANDAS_VERSION >= version.parse("1.0") PANDAS_GE_110 = PANDAS_VERSION >= version.parse("1.1") PANDAS_GE_120 = PANDAS_VERSION >= version.parse("1.2") +PANDAS_EQ_123 = PANDAS_VERSION == version.parse("1.2.3") diff --git a/python/cudf/cudf/tests/test_setitem.py b/python/cudf/cudf/tests/test_setitem.py index fc885a13808..4d2e2a4b33b 100644 --- a/python/cudf/cudf/tests/test_setitem.py +++ b/python/cudf/cudf/tests/test_setitem.py @@ -5,7 +5,7 @@ import pytest import cudf -from cudf.core._compat import PANDAS_GE_120 +from cudf.core._compat import PANDAS_EQ_123, PANDAS_GE_120 from cudf.tests.utils import assert_eq, assert_exceptions_equal @@ -21,9 +21,8 @@ def test_dataframe_setitem_bool_mask_scaler(df, arg, value): @pytest.mark.xfail( - condition=not PANDAS_GE_120, - reason="pandas incorrectly adds nulls with dataframes " - "but works fine with scalars", + condition=PANDAS_EQ_123 or not PANDAS_GE_120, + reason="https://github.com/pandas-dev/pandas/issues/40204", ) def test_dataframe_setitem_scaler_bool(): df = pd.DataFrame({"a": [1, 2, 3]})