|
79 | 79 | from_arrays
|
80 | 80 | from_tuples
|
81 | 81 | from_breaks
|
| 82 | +contains |
82 | 83 | overlaps
|
83 | 84 | set_closed
|
84 | 85 | to_tuples
|
@@ -1017,6 +1018,52 @@ def repeat(self, repeats, axis=None):
|
1017 | 1018 | right_repeat = self.right.repeat(repeats)
|
1018 | 1019 | return self._shallow_copy(left=left_repeat, right=right_repeat)
|
1019 | 1020 |
|
| 1021 | + _interval_shared_docs['contains'] = """ |
| 1022 | + Check elementwise if the Intervals contain the value. |
| 1023 | +
|
| 1024 | + Return a boolean mask whether the value is contained in the Intervals |
| 1025 | + of the %(klass)s. |
| 1026 | +
|
| 1027 | + .. versionadded:: 0.25.0 |
| 1028 | +
|
| 1029 | + Parameters |
| 1030 | + ---------- |
| 1031 | + other : scalar |
| 1032 | + The value to check whether it is contained in the Intervals. |
| 1033 | +
|
| 1034 | + Returns |
| 1035 | + ------- |
| 1036 | + boolean array |
| 1037 | +
|
| 1038 | + See Also |
| 1039 | + -------- |
| 1040 | + Interval.contains : Check whether Interval object contains value. |
| 1041 | + %(klass)s.overlaps : Check if an Interval overlaps the values in the |
| 1042 | + %(klass)s. |
| 1043 | +
|
| 1044 | + Examples |
| 1045 | + -------- |
| 1046 | + >>> intervals = pd.%(qualname)s.from_tuples([(0, 1), (1, 3), (2, 4)]) |
| 1047 | + >>> intervals |
| 1048 | + %(klass)s([(0, 1], (1, 3], (2, 4]], |
| 1049 | + closed='right', |
| 1050 | + dtype='interval[int64]') |
| 1051 | + >>> intervals.contains(0.5) |
| 1052 | + array([ True, False, False]) |
| 1053 | + """ |
| 1054 | + |
| 1055 | + @Appender(_interval_shared_docs['contains'] % _shared_docs_kwargs) |
| 1056 | + def contains(self, other): |
| 1057 | + if isinstance(other, Interval): |
| 1058 | + raise NotImplementedError( |
| 1059 | + 'contains not implemented for two intervals' |
| 1060 | + ) |
| 1061 | + |
| 1062 | + return ( |
| 1063 | + (self.left < other if self.open_left else self.left <= other) & |
| 1064 | + (other < self.right if self.open_right else other <= self.right) |
| 1065 | + ) |
| 1066 | + |
1020 | 1067 | _interval_shared_docs['overlaps'] = """
|
1021 | 1068 | Check elementwise if an Interval overlaps the values in the %(klass)s.
|
1022 | 1069 |
|
|
0 commit comments