From c2ab939f292e0816d624c80407df7893b20bb529 Mon Sep 17 00:00:00 2001 From: makbigc Date: Tue, 7 May 2019 17:15:00 +0800 Subject: [PATCH 01/18] Use new repr and fix docstring --- pandas/core/arrays/interval.py | 45 ++++++++++++++++++++++---------- pandas/core/indexes/interval.py | 46 ++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 94b9dc8ebab55..34c586df9f2d5 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -116,9 +116,9 @@ ``Interval`` objects: >>> pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]) - IntervalArray([(0, 1], (1, 5]], - closed='right', - dtype='interval[int64]') + + [(0, 1], (1, 5]] + Length: 2, closed: right, dtype: interval[int64] It may also be constructed using one of the constructor methods: :meth:`IntervalArray.from_arrays`, @@ -842,15 +842,31 @@ def _format_data(self): return summary + #def __repr__(self): + # tpl = textwrap.dedent("""\ + # {cls}({data}, + # {lead}closed='{closed}', + # {lead}dtype='{dtype}')""") + # return tpl.format(cls=self.__class__.__name__, + # data=self._format_data(), + # lead=' ' * len(self.__class__.__name__) + ' ', + # closed=self.closed, dtype=self.dtype) + def __repr__(self): - tpl = textwrap.dedent("""\ - {cls}({data}, - {lead}closed='{closed}', - {lead}dtype='{dtype}')""") - return tpl.format(cls=self.__class__.__name__, - data=self._format_data(), - lead=' ' * len(self.__class__.__name__) + ' ', - closed=self.closed, dtype=self.dtype) + template = ( + '{class_name}' + '{data}\n' + 'Length: {length}, closed: {closed}, dtype: {dtype}' + ) + # the short repr has no trailing newline, while the truncated + # repr does. So we include a newline in our template, and strip + # any trailing newlines from format_object_summary + data = self._format_data() + class_name = '<{}>\n'.format(self.__class__.__name__) + return template.format(class_name=class_name, data=data, + length=len(self), + closed=self.closed, + dtype=self.dtype) def _format_space(self): space = ' ' * (len(self.__class__.__name__) + 1) @@ -1049,9 +1065,10 @@ def repeat(self, repeats, axis=None): -------- >>> intervals = pd.%(qualname)s.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals - %(klass)s([(0, 1], (1, 3], (2, 4]], - closed='right', - dtype='interval[int64]') + <%(klass)s> + [(0, 1], (1, 3], (2, 4]] + Length: 3, closed: right, dtype: interval[int64] + >>> intervals.overlaps(pd.Interval(0.5, 1.5)) array([ True, True, False]) diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index a3dbf2e03957b..f6e64a490c6a7 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1086,8 +1086,52 @@ def equals(self, other): self.right.equals(other.right) and self.closed == other.closed) - @Appender(_interval_shared_docs['overlaps'] % _index_doc_kwargs) def overlaps(self, other): + """ + Check elementwise if an Interval overlaps the values in the + IntervalIndex. + + Two intervals overlap if they share a common point, including closed + endpoints. Intervals that only have an open endpoint in common do not + overlap. + + .. versionadded:: 0.24.0 + + Parameters + ---------- + other : Interval + Interval to check against for an overlap. + + Returns + ------- + ndarray + Boolean array positionally indicating where an overlap occurs. + + See Also + -------- + Interval.overlaps : Check whether two Interval objects overlap. + + Examples + -------- + >>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) + >>> intervals + IntervalIndex([(0, 1], (1, 3], (2, 4]], + closed='right', + dtype='interval[int64]') + + >>> intervals.overlaps(pd.Interval(0.5, 1.5)) + array([ True, True, False]) + + Intervals that share closed endpoints overlap: + + >>> intervals.overlaps(pd.Interval(1, 3, closed='left')) + array([ True, True, True]) + + Intervals that only have an open endpoint in common do not overlap: + + >>> intervals.overlaps(pd.Interval(1, 2, closed='right')) + array([False, True, False]) + """ return self._data.overlaps(other) def _setop(op_name, sort=None): From f9740c7ce43b4d3f81c393ab257305ec53aba854 Mon Sep 17 00:00:00 2001 From: makbigc Date: Tue, 7 May 2019 17:15:13 +0800 Subject: [PATCH 02/18] Delete one test --- pandas/tests/arrays/interval/test_interval.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index 34de36b4f6665..a04e5831766ac 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -58,10 +58,3 @@ def test_set_na(self, left_right_dtypes): expected = IntervalArray.from_arrays(expected_left, expected_right) tm.assert_extension_array_equal(result, expected) - - -def test_repr_matches(): - idx = IntervalIndex.from_breaks([1, 2, 3]) - a = repr(idx) - b = repr(idx.values) - assert a.replace("Index", "Array") == b From 54bc56b6e77e50dd79a70f7b18f753cc4d793df0 Mon Sep 17 00:00:00 2001 From: makbigc Date: Wed, 8 May 2019 19:53:43 +0800 Subject: [PATCH 03/18] Remove relundant code --- pandas/core/arrays/interval.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 34c586df9f2d5..605c5c6cf2e2a 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -842,16 +842,6 @@ def _format_data(self): return summary - #def __repr__(self): - # tpl = textwrap.dedent("""\ - # {cls}({data}, - # {lead}closed='{closed}', - # {lead}dtype='{dtype}')""") - # return tpl.format(cls=self.__class__.__name__, - # data=self._format_data(), - # lead=' ' * len(self.__class__.__name__) + ' ', - # closed=self.closed, dtype=self.dtype) - def __repr__(self): template = ( '{class_name}' From 95c012ad7e7b79e16a5d7e6fafdf7e646ddf1952 Mon Sep 17 00:00:00 2001 From: makbigc Date: Wed, 8 May 2019 20:28:46 +0800 Subject: [PATCH 04/18] Remove relundant import --- pandas/tests/arrays/interval/test_interval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index a04e5831766ac..634a6af2cb5f9 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -2,7 +2,7 @@ import pytest import pandas as pd -from pandas import Index, Interval, IntervalIndex, date_range, timedelta_range +from pandas import Index, Interval, date_range, timedelta_range from pandas.core.arrays import IntervalArray import pandas.util.testing as tm From cc25182839c4a199365a03305d6c1a89755f6b02 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 21 Jun 2019 00:03:07 +0800 Subject: [PATCH 05/18] Separate the example section from _interval_shared_docs --- pandas/core/arrays/interval.py | 118 +++++++++++++++++++------------- pandas/core/indexes/interval.py | 100 +++++++++++++++------------ 2 files changed, 127 insertions(+), 91 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index ac0c3e61b0323..66718ee0eeb9d 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -222,7 +222,7 @@ def _from_factorized(cls, values, original): values = values.astype(original.dtype.subtype) return cls(values, closed=original.closed) - _interval_shared_docs['from_breaks'] = """ + _interval_shared_docs['from_breaks'] = textwrap.dedent("""\ Construct an %(klass)s from an array of splits. Parameters @@ -249,23 +249,28 @@ def _from_factorized(cls, values, original): %(klass)s.from_arrays : Construct from a left and right array. %(klass)s.from_tuples : Construct from a sequence of tuples. - Examples - -------- - >>> pd.%(qualname)s.from_breaks([0, 1, 2, 3]) - %(klass)s([(0, 1], (1, 2], (2, 3]], - closed='right', - dtype='interval[int64]') - """ + %(examples)s\ + """) @classmethod - @Appender(_interval_shared_docs['from_breaks'] % _shared_docs_kwargs) + @Appender(_interval_shared_docs['from_breaks'] % dict( + klass='IntervalArray', + examples=textwrap.dedent("""\ + Examples + -------- + >>> pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3]) + + [(0, 1], (1, 2], (2, 3]] + Length: 3, closed: right, dtype: interval[int64] + """), + )) def from_breaks(cls, breaks, closed='right', copy=False, dtype=None): breaks = maybe_convert_platform_interval(breaks) return cls.from_arrays(breaks[:-1], breaks[1:], closed, copy=copy, dtype=dtype) - _interval_shared_docs['from_arrays'] = """ + _interval_shared_docs['from_arrays'] = textwrap.dedent(""" Construct from two arrays defining the left and right bounds. Parameters @@ -311,16 +316,19 @@ def from_breaks(cls, breaks, closed='right', copy=False, dtype=None): using an unsupported type for `left` or `right`. At the moment, 'category', 'object', and 'string' subtypes are not supported. - Examples - -------- - >>> %(klass)s.from_arrays([0, 1, 2], [1, 2, 3]) - %(klass)s([(0, 1], (1, 2], (2, 3]], - closed='right', - dtype='interval[int64]') - """ + %(examples)s\ + """) @classmethod - @Appender(_interval_shared_docs['from_arrays'] % _shared_docs_kwargs) + @Appender(_interval_shared_docs['from_arrays'] % dict( + klass='IntervalArray', + examples=textwrap.dedent("""\ + >>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3]) + + [(0, 1], (1, 2], (2, 3]] + Length: 3, closed: right, dtype: interval[int64] + """), + )) def from_arrays(cls, left, right, closed='right', copy=False, dtype=None): left = maybe_convert_platform_interval(left) right = maybe_convert_platform_interval(right) @@ -370,7 +378,7 @@ def from_arrays(cls, left, right, closed='right', copy=False, dtype=None): closed='right', dtype='interval[int64]') """ - _interval_shared_docs['from_tuples'] = """ + _interval_shared_docs['from_tuples'] = textwrap.dedent("""\ Construct an %(klass)s from an array-like of tuples Parameters @@ -399,15 +407,21 @@ def from_arrays(cls, left, right, closed='right', copy=False, dtype=None): %(klass)s.from_breaks : Construct an %(klass)s from an array of splits. - Examples - -------- - >>> pd.%(qualname)s.from_tuples([(0, 1), (1, 2)]) - %(klass)s([(0, 1], (1, 2]], - closed='right', dtype='interval[int64]') - """ + %(examples)s\ + """) @classmethod - @Appender(_interval_shared_docs['from_tuples'] % _shared_docs_kwargs) + @Appender(_interval_shared_docs['from_tuples'] % dict( + klass='IntervalArray', + examples=textwrap.dedent("""\ + Examples + -------- + >>> pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)]) + + [(0, 1], (1, 2]] + Length: 2, closed: right, dtype: interval[int64] + """), + )) def from_tuples(cls, data, closed='right', copy=False, dtype=None): if len(data): left, right = [], [] @@ -886,7 +900,7 @@ def closed(self): """ return self._closed - _interval_shared_docs['set_closed'] = """ + _interval_shared_docs['set_closed'] = textwrap.dedent("""\ Return an %(klass)s identical to the current one, but closed on the specified side @@ -902,20 +916,25 @@ def closed(self): ------- new_index : %(klass)s + %(examples)s\ + """) + + @Appender(_interval_shared_docs['set_closed'] % dict( + klass='IntervalArray', + examples=textwrap.dedent("""\ Examples -------- - >>> index = pd.interval_range(0, 3) + >>> index = pd.arrays.IntervalArray.from_breaks(range(4)) >>> index - IntervalIndex([(0, 1], (1, 2], (2, 3]], - closed='right', - dtype='interval[int64]') + + [(0, 1], (1, 2], (2, 3]] + Length: 3, closed: right, dtype: interval[int64] >>> index.set_closed('both') - IntervalIndex([[0, 1], [1, 2], [2, 3]], - closed='both', - dtype='interval[int64]') - """ - - @Appender(_interval_shared_docs['set_closed'] % _shared_docs_kwargs) + + [[0, 1], [1, 2], [2, 3]] + Length: 3, closed: both, dtype: interval[int64] + """), + )) def set_closed(self, closed): if closed not in _VALID_CLOSED: msg = "invalid option for 'closed': {closed}" @@ -1028,7 +1047,7 @@ def repeat(self, repeats, axis=None): right_repeat = self.right.repeat(repeats) return self._shallow_copy(left=left_repeat, right=right_repeat) - _interval_shared_docs['overlaps'] = """ + _interval_shared_docs['overlaps'] = textwrap.dedent(""" Check elementwise if an Interval overlaps the values in the %(klass)s. Two intervals overlap if they share a common point, including closed @@ -1039,7 +1058,7 @@ def repeat(self, repeats, axis=None): Parameters ---------- - other : Interval + other : %(klass)s Interval to check against for an overlap. Returns @@ -1053,11 +1072,7 @@ def repeat(self, repeats, axis=None): Examples -------- - >>> intervals = pd.%(qualname)s.from_tuples([(0, 1), (1, 3), (2, 4)]) - >>> intervals - <%(klass)s> - [(0, 1], (1, 3], (2, 4]] - Length: 3, closed: right, dtype: interval[int64] + %(examples)s >>> intervals.overlaps(pd.Interval(0.5, 1.5)) array([ True, True, False]) @@ -1071,9 +1086,20 @@ def repeat(self, repeats, axis=None): >>> intervals.overlaps(pd.Interval(1, 2, closed='right')) array([False, True, False]) - """ - @Appender(_interval_shared_docs['overlaps'] % _shared_docs_kwargs) + """) + + @Appender(_interval_shared_docs['overlaps'] % dict( + klass='IntervalArray', + examples=textwrap.dedent("""\ + >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3),\ + (2, 4)]) + >>> intervals + + [(0, 1], (1, 3], (2, 4]] + Length: 3, closed: right, dtype: interval[int64] + """), + )) def overlaps(self, other): if isinstance(other, (IntervalArray, ABCIntervalIndex)): raise NotImplementedError diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 52e5ed8a7666d..889a64b77080b 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -206,7 +206,17 @@ def _simple_new(cls, array, name, closed=None): return result @classmethod - @Appender(_interval_shared_docs['from_breaks'] % _index_doc_kwargs) + @Appender(_interval_shared_docs['from_breaks'] % dict( + klass='IntervalIndex', + examples=textwrap.dedent("""\ + Examples + -------- + >>> pd.IntervalIndex.from_breaks([0, 1, 2, 3]) + IntervalIndex([(0, 1], (1, 2], (2, 3]], + closed='right', + dtype='interval[int64]') + """), + )) def from_breaks(cls, breaks, closed='right', name=None, copy=False, dtype=None): with rewrite_exception("IntervalArray", cls.__name__): @@ -215,7 +225,17 @@ def from_breaks(cls, breaks, closed='right', name=None, copy=False, return cls._simple_new(array, name=name) @classmethod - @Appender(_interval_shared_docs['from_arrays'] % _index_doc_kwargs) + @Appender(_interval_shared_docs['from_arrays'] % dict( + klass='IntervalIndex', + examples=textwrap.dedent("""\ + Examples + -------- + >>> pd.IntervalIndex.from_arrays([0, 1, 2], [1, 2, 3]) + IntervalIndex([(0, 1], (1, 2], (2, 3]], + closed='right', + dtype='interval[int64]') + """), + )) def from_arrays(cls, left, right, closed='right', name=None, copy=False, dtype=None): with rewrite_exception("IntervalArray", cls.__name__): @@ -239,7 +259,17 @@ def from_intervals(cls, data, closed=None, name=None, copy=False, return cls._simple_new(array, name=name) @classmethod - @Appender(_interval_shared_docs['from_tuples'] % _index_doc_kwargs) + @Appender(_interval_shared_docs['from_tuples'] % dict( + klass='IntervalIndex', + examples=textwrap.dedent("""\ + Examples + -------- + >>> pd.IntervalIndex.from_tuples([(0, 1), (1, 2)]) + IntervalIndex([(0, 1], (1, 2]], + closed='right', + dtype='interval[int64]') + """), + )) def from_tuples(cls, data, closed='right', name=None, copy=False, dtype=None): with rewrite_exception("IntervalArray", cls.__name__): @@ -356,7 +386,22 @@ def closed(self): """ return self._data._closed - @Appender(_interval_shared_docs['set_closed'] % _index_doc_kwargs) + @Appender(_interval_shared_docs['set_closed'] % dict( + klass='IntervalIndex', + examples=textwrap.dedent("""\ + Examples + -------- + >>> index = pd.interval_range(0, 3) + >>> index + IntervalIndex([(0, 1], (1, 2], (2, 3]], + closed='right', + dtype='interval[int64]') + >>> index.set_closed('both') + IntervalIndex([[0, 1], [1, 2], [2, 3]], + closed='both', + dtype='interval[int64]') + """), + )) def set_closed(self, closed): if closed not in _VALID_CLOSED: msg = "invalid option for 'closed': {closed}" @@ -1134,52 +1179,17 @@ def equals(self, other): self.right.equals(other.right) and self.closed == other.closed) - def overlaps(self, other): - """ - Check elementwise if an Interval overlaps the values in the - IntervalIndex. - - Two intervals overlap if they share a common point, including closed - endpoints. Intervals that only have an open endpoint in common do not - overlap. - - .. versionadded:: 0.24.0 - - Parameters - ---------- - other : Interval - Interval to check against for an overlap. - - Returns - ------- - ndarray - Boolean array positionally indicating where an overlap occurs. - - See Also - -------- - Interval.overlaps : Check whether two Interval objects overlap. - - Examples - -------- + @Appender(_interval_shared_docs['overlaps'] % dict( + klass='IntervalIndex', + examples=textwrap.dedent("""\ >>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals IntervalIndex([(0, 1], (1, 3], (2, 4]], closed='right', dtype='interval[int64]') - - >>> intervals.overlaps(pd.Interval(0.5, 1.5)) - array([ True, True, False]) - - Intervals that share closed endpoints overlap: - - >>> intervals.overlaps(pd.Interval(1, 3, closed='left')) - array([ True, True, True]) - - Intervals that only have an open endpoint in common do not overlap: - - >>> intervals.overlaps(pd.Interval(1, 2, closed='right')) - array([False, True, False]) - """ + """), + )) + def overlaps(self, other): return self._data.overlaps(other) @Appender(_index_shared_docs['intersection']) From 4c86f53cd2caf3bb450f86efca33ffdd4a7618d7 Mon Sep 17 00:00:00 2001 From: makbigc Date: Sat, 22 Jun 2019 18:13:08 +0800 Subject: [PATCH 06/18] Fix docstring error --- pandas/core/arrays/interval.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 66718ee0eeb9d..345abea775770 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1073,7 +1073,6 @@ def repeat(self, repeats, axis=None): Examples -------- %(examples)s - >>> intervals.overlaps(pd.Interval(0.5, 1.5)) array([ True, True, False]) @@ -1086,14 +1085,13 @@ def repeat(self, repeats, axis=None): >>> intervals.overlaps(pd.Interval(1, 2, closed='right')) array([False, True, False]) - """) @Appender(_interval_shared_docs['overlaps'] % dict( klass='IntervalArray', examples=textwrap.dedent("""\ - >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3),\ - (2, 4)]) + >>> data = [(0, 1), (1, 3), (2, 4)] + >>> intervals = pd.arrays.IntervalArray.from_tuples(data) >>> intervals [(0, 1], (1, 3], (2, 4]] From 0e0747429cb57f25dde6086ce6e549ceb47f556d Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 19 Jul 2019 16:39:24 +0800 Subject: [PATCH 07/18] Fix the example in contain method --- pandas/core/arrays/interval.py | 22 +++++++++++++--------- pandas/core/indexes/interval.py | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 6ea87fdb727bf..7a812cc4e5634 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1101,10 +1101,9 @@ def repeat(self, repeats, axis=None): right_repeat = self.right.repeat(repeats) return self._shallow_copy(left=left_repeat, right=right_repeat) - _interval_shared_docs[ "contains" - ] = """ + ] = textwrap.dedent(""" Check elementwise if the Intervals contain the value. Return a boolean mask whether the value is contained in the Intervals @@ -1129,16 +1128,21 @@ def repeat(self, repeats, axis=None): Examples -------- - >>> intervals = pd.%(qualname)s.from_tuples([(0, 1), (1, 3), (2, 4)]) + %(examples)s + """) + + @Appender(_interval_shared_docs["contains"] % dict( + klass="IntervalArray", + examples=textwrap.dedent(""" + >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals - %(klass)s([(0, 1], (1, 3], (2, 4]], - closed='right', - dtype='interval[int64]') + + [(0, 1], (1, 3], (2, 4]] + Length: 3, closed: right, dtype: interval[int64] >>> intervals.contains(0.5) array([ True, False, False]) - """ - - @Appender(_interval_shared_docs["contains"] % _shared_docs_kwargs) + """), + )) def contains(self, other): if isinstance(other, Interval): raise NotImplementedError("contains not implemented for two intervals") diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 810d7b462b5fd..cefc5d49e9d66 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1230,12 +1230,23 @@ def equals(self, other): and self.closed == other.closed ) - @Appender(_interval_shared_docs["contains"] % _index_doc_kwargs) + @Appender(_interval_shared_docs["contains"] % dict( + klass="IntervalIndex", + examples=textwrap.dedent("""\ + >>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) + >>> intervals + IntervalIndex([(0, 1], (1, 3], (2, 4]], + closed='right', + dtype='interval[int64]') + >>> intervals.contains(0.5) + array([ True, False, False]) + """), + )) def contains(self, other): return self._data.contains(other) @Appender(_interval_shared_docs["overlaps"] % dict( - klass='IntervalIndex', + klass="IntervalIndex", examples=textwrap.dedent("""\ >>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals From 55f701a878fd396ddf03003a39ce06bc69ada804 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 19 Jul 2019 17:44:26 +0800 Subject: [PATCH 08/18] Fix the black format --- pandas/core/arrays/interval.py | 148 +++++++++++++++++++------------- pandas/core/indexes/interval.py | 90 ++++++++++++------- 2 files changed, 149 insertions(+), 89 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 7a812cc4e5634..930fb72dfed51 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -246,9 +246,8 @@ def _from_factorized(cls, values, original): values = values.astype(original.dtype.subtype) return cls(values, closed=original.closed) - _interval_shared_docs[ - "from_breaks" - ] = textwrap.dedent(""" + _interval_shared_docs["from_breaks"] = textwrap.dedent( + """ Construct an %(klass)s from an array of splits. Parameters @@ -276,28 +275,33 @@ def _from_factorized(cls, values, original): %(klass)s.from_tuples : Construct from a sequence of tuples. %(examples)s\ - """) + """ + ) @classmethod - @Appender(_interval_shared_docs["from_breaks"] % dict( - klass='IntervalArray', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["from_breaks"] + % dict( + klass="IntervalArray", + examples=textwrap.dedent( + """\ Examples -------- >>> pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3]) [(0, 1], (1, 2], (2, 3]] Length: 3, closed: right, dtype: interval[int64] - """), - )) + """ + ), + ) + ) def from_breaks(cls, breaks, closed="right", copy=False, dtype=None): breaks = maybe_convert_platform_interval(breaks) return cls.from_arrays(breaks[:-1], breaks[1:], closed, copy=copy, dtype=dtype) - _interval_shared_docs[ - "from_arrays" - ] = textwrap.dedent(""" + _interval_shared_docs["from_arrays"] = textwrap.dedent( + """ Construct from two arrays defining the left and right bounds. Parameters @@ -344,18 +348,24 @@ def from_breaks(cls, breaks, closed="right", copy=False, dtype=None): 'category', 'object', and 'string' subtypes are not supported. %(examples)s\ - """) + """ + ) @classmethod - @Appender(_interval_shared_docs["from_arrays"] % dict( - klass='IntervalArray', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["from_arrays"] + % dict( + klass="IntervalArray", + examples=textwrap.dedent( + """\ >>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3]) [(0, 1], (1, 2], (2, 3]] Length: 3, closed: right, dtype: interval[int64] - """), - )) + """ + ), + ) + ) def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): left = maybe_convert_platform_interval(left) right = maybe_convert_platform_interval(right) @@ -408,9 +418,8 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): closed='right', dtype='interval[int64]') """ - _interval_shared_docs[ - "from_tuples" - ] = textwrap.dedent(""" + _interval_shared_docs["from_tuples"] = textwrap.dedent( + """ Construct an %(klass)s from an array-like of tuples Parameters @@ -440,20 +449,26 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): splits. %(examples)s\ - """) + """ + ) @classmethod - @Appender(_interval_shared_docs["from_tuples"] % dict( - klass='IntervalArray', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["from_tuples"] + % dict( + klass="IntervalArray", + examples=textwrap.dedent( + """\ Examples -------- >>> pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)]) [(0, 1], (1, 2]] Length: 2, closed: right, dtype: interval[int64] - """), - )) + """ + ), + ) + ) def from_tuples(cls, data, closed="right", copy=False, dtype=None): if len(data): left, right = [], [] @@ -897,21 +912,21 @@ def _format_data(self): def __repr__(self): template = ( - '{class_name}' - '{data}\n' - 'Length: {length}, closed: {closed}, dtype: {dtype}' + "{class_name}" + "{data}\n" + "Length: {length}, closed: {closed}, dtype: {dtype}" ) # the short repr has no trailing newline, while the truncated # repr does. So we include a newline in our template, and strip # any trailing newlines from format_object_summary data = self._format_data() - class_name = '<{}>\n'.format(self.__class__.__name__) + class_name = "<{}>\n".format(self.__class__.__name__) return template.format( class_name=class_name, data=data, length=len(self), closed=self.closed, - dtype=self.dtype + dtype=self.dtype, ) def _format_space(self): @@ -942,9 +957,8 @@ def closed(self): """ return self._closed - _interval_shared_docs[ - "set_closed" - ] = textwrap.dedent(""" + _interval_shared_docs["set_closed"] = textwrap.dedent( + """ Return an %(klass)s identical to the current one, but closed on the specified side @@ -961,11 +975,15 @@ def closed(self): new_index : %(klass)s %(examples)s\ - """) + """ + ) - @Appender(_interval_shared_docs["set_closed"] % dict( - klass='IntervalArray', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["set_closed"] + % dict( + klass="IntervalArray", + examples=textwrap.dedent( + """\ Examples -------- >>> index = pd.arrays.IntervalArray.from_breaks(range(4)) @@ -977,8 +995,10 @@ def closed(self): [[0, 1], [1, 2], [2, 3]] Length: 3, closed: both, dtype: interval[int64] - """), - )) + """ + ), + ) + ) def set_closed(self, closed): if closed not in _VALID_CLOSED: msg = "invalid option for 'closed': {closed}" @@ -1101,9 +1121,8 @@ def repeat(self, repeats, axis=None): right_repeat = self.right.repeat(repeats) return self._shallow_copy(left=left_repeat, right=right_repeat) - _interval_shared_docs[ - "contains" - ] = textwrap.dedent(""" + _interval_shared_docs["contains"] = textwrap.dedent( + """ Check elementwise if the Intervals contain the value. Return a boolean mask whether the value is contained in the Intervals @@ -1129,11 +1148,15 @@ def repeat(self, repeats, axis=None): Examples -------- %(examples)s - """) + """ + ) - @Appender(_interval_shared_docs["contains"] % dict( - klass="IntervalArray", - examples=textwrap.dedent(""" + @Appender( + _interval_shared_docs["contains"] + % dict( + klass="IntervalArray", + examples=textwrap.dedent( + """ >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals @@ -1141,8 +1164,10 @@ def repeat(self, repeats, axis=None): Length: 3, closed: right, dtype: interval[int64] >>> intervals.contains(0.5) array([ True, False, False]) - """), - )) + """ + ), + ) + ) def contains(self, other): if isinstance(other, Interval): raise NotImplementedError("contains not implemented for two intervals") @@ -1151,9 +1176,8 @@ def contains(self, other): other < self.right if self.open_right else other <= self.right ) - _interval_shared_docs[ - "overlaps" - ] = textwrap.dedent(""" + _interval_shared_docs["overlaps"] = textwrap.dedent( + """ Check elementwise if an Interval overlaps the values in the %(klass)s. Two intervals overlap if they share a common point, including closed @@ -1191,19 +1215,25 @@ def contains(self, other): >>> intervals.overlaps(pd.Interval(1, 2, closed='right')) array([False, True, False]) - """) + """ + ) - @Appender(_interval_shared_docs["overlaps"] % dict( - klass='IntervalArray', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["overlaps"] + % dict( + klass="IntervalArray", + examples=textwrap.dedent( + """\ >>> data = [(0, 1), (1, 3), (2, 4)] >>> intervals = pd.arrays.IntervalArray.from_tuples(data) >>> intervals [(0, 1], (1, 3], (2, 4]] Length: 3, closed: right, dtype: interval[int64] - """), - )) + """ + ), + ) + ) def overlaps(self, other): if isinstance(other, (IntervalArray, ABCIntervalIndex)): raise NotImplementedError diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index a4cdb4137e31e..f2c20500fa9bc 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -250,17 +250,22 @@ def _simple_new(cls, array, name, closed=None): return result @classmethod - @Appender(_interval_shared_docs["from_breaks"] % dict( - klass='IntervalIndex', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["from_breaks"] + % dict( + klass="IntervalIndex", + examples=textwrap.dedent( + """\ Examples -------- >>> pd.IntervalIndex.from_breaks([0, 1, 2, 3]) IntervalIndex([(0, 1], (1, 2], (2, 3]], closed='right', dtype='interval[int64]') - """), - )) + """ + ), + ) + ) def from_breaks(cls, breaks, closed="right", name=None, copy=False, dtype=None): with rewrite_exception("IntervalArray", cls.__name__): array = IntervalArray.from_breaks( @@ -269,17 +274,22 @@ def from_breaks(cls, breaks, closed="right", name=None, copy=False, dtype=None): return cls._simple_new(array, name=name) @classmethod - @Appender(_interval_shared_docs["from_arrays"] % dict( - klass='IntervalIndex', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["from_arrays"] + % dict( + klass="IntervalIndex", + examples=textwrap.dedent( + """\ Examples -------- >>> pd.IntervalIndex.from_arrays([0, 1, 2], [1, 2, 3]) IntervalIndex([(0, 1], (1, 2], (2, 3]], closed='right', dtype='interval[int64]') - """), - )) + """ + ), + ) + ) def from_arrays( cls, left, right, closed="right", name=None, copy=False, dtype=None ): @@ -306,17 +316,22 @@ def from_intervals(cls, data, closed=None, name=None, copy=False, dtype=None): return cls._simple_new(array, name=name) @classmethod - @Appender(_interval_shared_docs["from_tuples"] % dict( - klass='IntervalIndex', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["from_tuples"] + % dict( + klass="IntervalIndex", + examples=textwrap.dedent( + """\ Examples -------- >>> pd.IntervalIndex.from_tuples([(0, 1), (1, 2)]) IntervalIndex([(0, 1], (1, 2]], closed='right', dtype='interval[int64]') - """), - )) + """ + ), + ) + ) def from_tuples(cls, data, closed="right", name=None, copy=False, dtype=None): with rewrite_exception("IntervalArray", cls.__name__): arr = IntervalArray.from_tuples(data, closed=closed, copy=copy, dtype=dtype) @@ -412,9 +427,12 @@ def closed(self): """ return self._data._closed - @Appender(_interval_shared_docs["set_closed"] % dict( - klass='IntervalIndex', - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["set_closed"] + % dict( + klass="IntervalIndex", + examples=textwrap.dedent( + """\ Examples -------- >>> index = pd.interval_range(0, 3) @@ -426,8 +444,10 @@ def closed(self): IntervalIndex([[0, 1], [1, 2], [2, 3]], closed='both', dtype='interval[int64]') - """), - )) + """ + ), + ) + ) def set_closed(self, closed): if closed not in _VALID_CLOSED: msg = "invalid option for 'closed': {closed}" @@ -1225,9 +1245,12 @@ def equals(self, other): and self.closed == other.closed ) - @Appender(_interval_shared_docs["contains"] % dict( - klass="IntervalIndex", - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["contains"] + % dict( + klass="IntervalIndex", + examples=textwrap.dedent( + """\ >>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals IntervalIndex([(0, 1], (1, 3], (2, 4]], @@ -1235,21 +1258,28 @@ def equals(self, other): dtype='interval[int64]') >>> intervals.contains(0.5) array([ True, False, False]) - """), - )) + """ + ), + ) + ) def contains(self, other): return self._data.contains(other) - @Appender(_interval_shared_docs["overlaps"] % dict( - klass="IntervalIndex", - examples=textwrap.dedent("""\ + @Appender( + _interval_shared_docs["overlaps"] + % dict( + klass="IntervalIndex", + examples=textwrap.dedent( + """\ >>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals IntervalIndex([(0, 1], (1, 3], (2, 4]], closed='right', dtype='interval[int64]') - """), - )) + """ + ), + ) + ) def overlaps(self, other): return self._data.overlaps(other) From 480d780f22edd30b9c13fdfae1a5d97f173bac77 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 19 Jul 2019 19:52:31 +0800 Subject: [PATCH 09/18] Fix docstring error --- pandas/core/arrays/interval.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 930fb72dfed51..9462947e9a376 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1148,6 +1148,8 @@ def repeat(self, repeats, axis=None): Examples -------- %(examples)s + >>> intervals.contains(0.5) + array([ True, False, False]) """ ) @@ -1156,14 +1158,12 @@ def repeat(self, repeats, axis=None): % dict( klass="IntervalArray", examples=textwrap.dedent( - """ + """\ >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)]) >>> intervals [(0, 1], (1, 3], (2, 4]] Length: 3, closed: right, dtype: interval[int64] - >>> intervals.contains(0.5) - array([ True, False, False]) """ ), ) From 3c367196b057291a07c3125e4a9c47c13e1fa9cb Mon Sep 17 00:00:00 2001 From: makbigc Date: Mon, 19 Aug 2019 13:44:59 +0800 Subject: [PATCH 10/18] Add whatsnew entry in v1.0 --- doc/source/whatsnew/v1.0.0.rst | 23 ++++++++++++++++++++++- pandas/core/arrays/interval.py | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 0be4ebc627b30..7162ee67099cb 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -38,7 +38,28 @@ Backwards incompatible API changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :class:`pandas.core.groupby.GroupBy.transform` now raises on invalid operation names (:issue:`27489`). -- +- :class:`pandas.core.arrays.IntervalArray` adopts a new ``__repr__`` in accordance with other array classes (:issue:`25022`) + +*pandas 0.25.x* + +.. code-block:: ipython + + In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[1]: + IntervalArray([(0, 1], (2, 3]], + closed='right', + dtype='interval[int64]') + +*pandas 1.0.0* + +.. ipython:: python + + In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[2]: + + [(0, 1], (2, 3]] + Length: 2, closed: right, dtype: interval[int64] + .. _whatsnew_1000.api.other: diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 88ae045c9768a..a877b67b6a2d5 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -378,7 +378,7 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): _interval_shared_docs[ "from_tuples" - ] = """ + ] = textwrap.dedent(""" Construct an %(klass)s from an array-like of tuples Parameters @@ -408,7 +408,7 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): splits. %(examples)s\ - """ + """) @classmethod @Appender( From 0a62694916257593a4133807fbe12d6c8e847ac0 Mon Sep 17 00:00:00 2001 From: makbigc Date: Mon, 19 Aug 2019 17:04:54 +0800 Subject: [PATCH 11/18] Fix lint error --- doc/source/whatsnew/v1.0.0.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 7162ee67099cb..1ec3f191eed12 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -44,8 +44,8 @@ Backwards incompatible API changes .. code-block:: ipython - In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[1]: + In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[1]: IntervalArray([(0, 1], (2, 3]], closed='right', dtype='interval[int64]') @@ -54,8 +54,8 @@ Backwards incompatible API changes .. ipython:: python - In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[2]: + In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[2]: [(0, 1], (2, 3]] Length: 2, closed: right, dtype: interval[int64] From f6d4f03ef45b2021cffdc9236c490ec4c03033bc Mon Sep 17 00:00:00 2001 From: makbigc Date: Mon, 19 Aug 2019 18:26:23 +0800 Subject: [PATCH 12/18] Fix black error --- pandas/core/arrays/interval.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index a877b67b6a2d5..e85c6bdcf292b 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -376,9 +376,8 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): left, right, closed, copy=copy, dtype=dtype, verify_integrity=True ) - _interval_shared_docs[ - "from_tuples" - ] = textwrap.dedent(""" + _interval_shared_docs["from_tuples"] = textwrap.dedent( + """ Construct an %(klass)s from an array-like of tuples Parameters @@ -408,7 +407,8 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): splits. %(examples)s\ - """) + """ + ) @classmethod @Appender( From 32ddfa9f96d346a72294ef3bf9e1586ea0304573 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 30 Aug 2019 12:31:24 +0800 Subject: [PATCH 13/18] Fix doc format error and add test_repr --- doc/source/whatsnew/v1.0.0.rst | 10 +++++----- pandas/tests/arrays/interval/test_interval.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 1ec3f191eed12..b4a47f0ca34e2 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -42,10 +42,10 @@ Backwards incompatible API changes *pandas 0.25.x* -.. code-block:: ipython +.. code-block:: python - In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[1]: + arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + arr IntervalArray([(0, 1], (2, 3]], closed='right', dtype='interval[int64]') @@ -54,8 +54,8 @@ Backwards incompatible API changes .. ipython:: python - In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[2]: + arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + arr [(0, 1], (2, 3]] Length: 2, closed: right, dtype: interval[int64] diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index be315dc2eb0c7..655a6e717119b 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -91,3 +91,15 @@ def test_set_na(self, left_right_dtypes): expected = IntervalArray.from_arrays(expected_left, expected_right) tm.assert_extension_array_equal(result, expected) + + +def test_repr(): + # GH 25022 + arr = IntervalArray.from_tuples([(0, 1), (1, 2)]) + result = repr(arr) + expected = ( + "\n" + "[(0, 1], (1, 2]]\n" + "Length: 2, closed: right, dtype: interval[int64]" + ) + assert result == expected From 5a16fa7e942213932d99e4f8fbd4619ffa136308 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 30 Aug 2019 14:12:27 +0800 Subject: [PATCH 14/18] Fix format error --- doc/source/whatsnew/v1.0.0.rst | 18 +++++++++--------- pandas/core/arrays/interval.py | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 348fce5ef0ab5..da0e4613073c8 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -42,23 +42,23 @@ Backwards incompatible API changes *pandas 0.25.x* -.. code-block:: python +.. code-block:: ipython - arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - arr + In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[1]: IntervalArray([(0, 1], (2, 3]], closed='right', dtype='interval[int64]') *pandas 1.0.0* -.. ipython:: python +.. code-block:: ipython - arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - arr - - [(0, 1], (2, 3]] - Length: 2, closed: right, dtype: interval[int64] + In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[2]: + IntervalArray([(0, 1], (2, 3]], + closed='right', + dtype='interval[int64]') .. _whatsnew_1000.api.other: diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 176269c91294c..1f4b76a259f00 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -376,9 +376,8 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): left, right, closed, copy=copy, dtype=dtype, verify_integrity=True ) - _interval_shared_docs[ - "from_tuples" - ] = """ + _interval_shared_docs["from_tuples"] = textwrap.dedent( + """ Construct an %(klass)s from an array-like of tuples. Parameters @@ -409,6 +408,7 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None): %(examples)s\ """ + ) @classmethod @Appender( From 64889eca9fd10c26f2b0627c82b6214326742e46 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 30 Aug 2019 15:18:28 +0800 Subject: [PATCH 15/18] Remove tailing space in v1.0 rst --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index da0e4613073c8..46e3e2b204158 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -55,7 +55,7 @@ Backwards incompatible API changes .. code-block:: ipython In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[2]: + Out[2]: IntervalArray([(0, 1], (2, 3]], closed='right', dtype='interval[int64]') From 5ab6ae9724c682dc031dac6bf5151efe1134afaf Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 6 Sep 2019 21:49:15 +0800 Subject: [PATCH 16/18] Fix v1.0.0.rst --- doc/source/whatsnew/v1.0.0.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 46e3e2b204158..9ff12a3595b02 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -42,20 +42,20 @@ Backwards incompatible API changes *pandas 0.25.x* -.. code-block:: ipython +.. code-block:: python - In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[1]: + intv_arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + intv_arr IntervalArray([(0, 1], (2, 3]], closed='right', dtype='interval[int64]') *pandas 1.0.0* -.. code-block:: ipython +.. code-block:: python - In [2]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - Out[2]: + intv_arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + intv_arr IntervalArray([(0, 1], (2, 3]], closed='right', dtype='interval[int64]') From 5f31bca3813b2ed71363a9d40518f217d2b546d6 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 6 Sep 2019 23:28:16 +0800 Subject: [PATCH 17/18] remove the output in v1.0 --- doc/source/whatsnew/v1.0.0.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 9ff12a3595b02..040e5480a06f4 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -46,9 +46,6 @@ Backwards incompatible API changes intv_arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) intv_arr - IntervalArray([(0, 1], (2, 3]], - closed='right', - dtype='interval[int64]') *pandas 1.0.0* @@ -56,9 +53,6 @@ Backwards incompatible API changes intv_arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) intv_arr - IntervalArray([(0, 1], (2, 3]], - closed='right', - dtype='interval[int64]') .. _whatsnew_1000.api.other: From 6bbee48ae8b6a3612c161e8fde178d27141ed7d8 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 6 Sep 2019 23:58:41 +0800 Subject: [PATCH 18/18] Fix v1 --- doc/source/whatsnew/v1.0.0.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 040e5480a06f4..3c4625401b243 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -42,17 +42,20 @@ Backwards incompatible API changes *pandas 0.25.x* -.. code-block:: python +.. code-block:: ipython + + In [1]: pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) + Out[2]: + IntervalArray([(0, 1], (2, 3]], + closed='right', + dtype='interval[int64]') - intv_arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - intv_arr *pandas 1.0.0* -.. code-block:: python +.. ipython:: python - intv_arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) - intv_arr + pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)]) .. _whatsnew_1000.api.other: