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..f80f6d8bb72 100644 --- a/python/cudf/cudf/tests/indexes/test_interval.py +++ b/python/cudf/cudf/tests/indexes/test_interval.py @@ -1 +1,18 @@ # 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_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() + assert_eq(expect, got)