Skip to content

Commit 1915ffc

Browse files
jschendeljreback
authored andcommitted
BUG: Fix IntervalIndex constructor and copy with non-default closed (#18340)
1 parent a172ff9 commit 1915ffc

File tree

3 files changed

+267
-182
lines changed

3 files changed

+267
-182
lines changed

doc/source/whatsnew/v0.21.1.txt

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Bug Fixes
6262
- Bug in ``pd.Series.rolling.skew()`` and ``rolling.kurt()`` with all equal values has floating issue (:issue:`18044`)
6363
- Bug in ``pd.DataFrameGroupBy.count()`` when counting over a datetimelike column (:issue:`13393`)
6464
- Bug in ``pd.concat`` when empty and non-empty DataFrames or Series are concatenated (:issue:`18178` :issue:`18187`)
65+
- Bug in :class:`IntervalIndex` constructor when a list of intervals is passed with non-default ``closed`` (:issue:`18334`)
66+
- Bug in :meth:`IntervalIndex.copy` when copying and ``IntervalIndex`` with non-default ``closed`` (:issue:`18339`)
6567

6668
Conversion
6769
^^^^^^^^^^

pandas/core/indexes/interval.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ def __new__(cls, data, closed='right',
190190
if isinstance(data, IntervalIndex):
191191
left = data.left
192192
right = data.right
193-
193+
closed = data.closed
194194
else:
195195

196196
# don't allow scalars
197197
if is_scalar(data):
198198
cls._scalar_data_error(data)
199199

200200
data = IntervalIndex.from_intervals(data, name=name)
201-
left, right = data.left, data.right
201+
left, right, closed = data.left, data.right, data.closed
202202

203203
return cls._simple_new(left, right, closed, name,
204204
copy=copy, verify_integrity=verify_integrity)
@@ -580,7 +580,8 @@ def copy(self, deep=False, name=None):
580580
left = self.left.copy(deep=True) if deep else self.left
581581
right = self.right.copy(deep=True) if deep else self.right
582582
name = name if name is not None else self.name
583-
return type(self).from_arrays(left, right, name=name)
583+
closed = self.closed
584+
return type(self).from_arrays(left, right, closed=closed, name=name)
584585

585586
@Appender(_index_shared_docs['astype'])
586587
def astype(self, dtype, copy=True):

0 commit comments

Comments
 (0)