Skip to content

Commit

Permalink
Default to closed="right" in IntervalIndex constructor (#13394)
Browse files Browse the repository at this point in the history
  • Loading branch information
shwina authored May 22, 2023
1 parent 209ab6e commit 383c3cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
17 changes: 17 additions & 0 deletions python/cudf/cudf/tests/indexes/test_interval.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 383c3cf

Please sign in to comment.