From 383c3cfe4232ace46273a85da97a26d6acc5220e Mon Sep 17 00:00:00 2001 From: Ashwin Srinath <3190405+shwina@users.noreply.github.com> Date: Mon, 22 May 2023 11:58:29 -0400 Subject: [PATCH] Default to closed="right" in `IntervalIndex` constructor (#13394) Closes #13393 Authors: - Ashwin Srinath (https://github.com/shwina) Approvers: - https://github.com/brandon-b-miller - GALI PREM SAGAR (https://github.com/galipremsagar) URL: https://github.com/rapidsai/cudf/pull/13394 --- python/cudf/cudf/core/index.py | 4 ++++ python/cudf/cudf/tests/indexes/test_interval.py | 17 +++++++++++++++++ 2 files changed, 21 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..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)