From 0632bc5500bd69931cbea4ae10b02db9c545373d Mon Sep 17 00:00:00 2001 From: Ashwin Srinath Date: Fri, 19 May 2023 14:51:37 -0400 Subject: [PATCH 1/2] Add a test for converting interval indexes to arrow --- python/cudf/cudf/core/index.py | 4 ++++ python/cudf/cudf/tests/indexes/test_interval.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index 519b84faea0..8bdf0938dfb 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -3028,6 +3028,10 @@ def __init__( if copy: data = column.as_column(data, dtype=dtype).copy() kwargs = _setdefault_name(data, name=name) + + if closed is None: + closed = "right" + if isinstance(data, IntervalColumn): data = data elif isinstance(data, pd.Series) and (is_interval_dtype(data.dtype)): diff --git a/python/cudf/cudf/tests/indexes/test_interval.py b/python/cudf/cudf/tests/indexes/test_interval.py index 06777c8e6af..b63b95a2419 100644 --- a/python/cudf/cudf/tests/indexes/test_interval.py +++ b/python/cudf/cudf/tests/indexes/test_interval.py @@ -1 +1,12 @@ # Copyright (c) 2023, NVIDIA CORPORATION. +import pandas as pd +import pyarrow as pa + +import cudf +from cudf.testing._utils import assert_eq + + +def test_interval_to_arrow(): + expect = pa.Array.from_pandas(pd.IntervalIndex([pd.Interval(0, 1)])) + got = cudf.IntervalIndex([pd.Interval(0, 1)]).to_arrow() + assert_eq(expect, got) From 299c586cb00ef06ce691c702997d62ba4b8d4459 Mon Sep 17 00:00:00 2001 From: Ashwin Srinath Date: Fri, 19 May 2023 14:56:37 -0400 Subject: [PATCH 2/2] Add a test for the interval constructor --- python/cudf/cudf/tests/indexes/test_interval.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/cudf/cudf/tests/indexes/test_interval.py b/python/cudf/cudf/tests/indexes/test_interval.py index b63b95a2419..f80f6d8bb72 100644 --- a/python/cudf/cudf/tests/indexes/test_interval.py +++ b/python/cudf/cudf/tests/indexes/test_interval.py @@ -6,6 +6,12 @@ from cudf.testing._utils import assert_eq +def test_interval_constructor_default_closed(): + idx = cudf.IntervalIndex([pd.Interval(0, 1)]) + assert idx.closed == "right" + assert idx.dtype.closed == "right" + + def test_interval_to_arrow(): expect = pa.Array.from_pandas(pd.IntervalIndex([pd.Interval(0, 1)])) got = cudf.IntervalIndex([pd.Interval(0, 1)]).to_arrow()