Skip to content

Commit

Permalink
BUG: Fix IntervalIndex constructor and copy with non-default closed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jschendel authored and jreback committed Nov 20, 2017
1 parent a172ff9 commit 1915ffc
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 182 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.21.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Bug Fixes
- Bug in ``pd.Series.rolling.skew()`` and ``rolling.kurt()`` with all equal values has floating issue (:issue:`18044`)
- Bug in ``pd.DataFrameGroupBy.count()`` when counting over a datetimelike column (:issue:`13393`)
- Bug in ``pd.concat`` when empty and non-empty DataFrames or Series are concatenated (:issue:`18178` :issue:`18187`)
- Bug in :class:`IntervalIndex` constructor when a list of intervals is passed with non-default ``closed`` (:issue:`18334`)
- Bug in :meth:`IntervalIndex.copy` when copying and ``IntervalIndex`` with non-default ``closed`` (:issue:`18339`)

Conversion
^^^^^^^^^^
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ def __new__(cls, data, closed='right',
if isinstance(data, IntervalIndex):
left = data.left
right = data.right

closed = data.closed
else:

# don't allow scalars
if is_scalar(data):
cls._scalar_data_error(data)

data = IntervalIndex.from_intervals(data, name=name)
left, right = data.left, data.right
left, right, closed = data.left, data.right, data.closed

return cls._simple_new(left, right, closed, name,
copy=copy, verify_integrity=verify_integrity)
Expand Down Expand Up @@ -580,7 +580,8 @@ def copy(self, deep=False, name=None):
left = self.left.copy(deep=True) if deep else self.left
right = self.right.copy(deep=True) if deep else self.right
name = name if name is not None else self.name
return type(self).from_arrays(left, right, name=name)
closed = self.closed
return type(self).from_arrays(left, right, closed=closed, name=name)

@Appender(_index_shared_docs['astype'])
def astype(self, dtype, copy=True):
Expand Down
Loading

0 comments on commit 1915ffc

Please sign in to comment.