Skip to content

Commit 623038e

Browse files
committed
More plumbing
1 parent 67e476f commit 623038e

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

pandas/core/indexes/base.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -3983,7 +3983,8 @@ def _join_multi(self, other, how, return_indexers=True):
39833983

39843984
def _join_non_unique(self, other, how='left', return_indexers=False):
39853985
from pandas.core.reshape.merge import _get_join_indexers
3986-
3986+
tolerance = self._choose_tolerance([other])
3987+
# FIXME: intolerant
39873988
left_idx, right_idx = _get_join_indexers([self._ndarray_values],
39883989
[other._ndarray_values],
39893990
how=how,
@@ -3996,7 +3997,7 @@ def _join_non_unique(self, other, how='left', return_indexers=False):
39963997
mask = left_idx == -1
39973998
np.putmask(join_index, mask, other._ndarray_values.take(right_idx))
39983999

3999-
join_index = self._wrap_joined_index(join_index, other)
4000+
join_index = self._wrap_joined_index(join_index, other, tolerance)
40004001

40014002
if return_indexers:
40024003
return join_index, left_idx, right_idx
@@ -4133,9 +4134,12 @@ def _get_leaf_sorter(labels):
41334134
else:
41344135
return join_index
41354136

4136-
def _join_monotonic(self, other, how='left', return_indexers=False):
4137-
if self.equals(other):
4137+
def _join_monotonic(self, other, how='left', return_indexers=False,
4138+
tolerance=None):
4139+
tolerance = self._choose_tolerance([other], tolerance=tolerance)
4140+
if self.equals(other, tolerance=tolerance):
41384141
ret_index = other if how == 'right' else self
4142+
# FIXME: intolerant, need to set the used tolerance
41394143
if return_indexers:
41404144
return ret_index, None, None
41414145
else:
@@ -4145,6 +4149,7 @@ def _join_monotonic(self, other, how='left', return_indexers=False):
41454149
ov = other._ndarray_values
41464150

41474151
if self.is_unique and other.is_unique:
4152+
# FIXME: intolerant
41484153
# We can perform much better than the general case
41494154
if how == 'left':
41504155
join_index = self
@@ -4156,11 +4161,14 @@ def _join_monotonic(self, other, how='left', return_indexers=False):
41564161
ridx = None
41574162
elif how == 'inner':
41584163
join_index, lidx, ridx = self._inner_indexer(sv, ov)
4159-
join_index = self._wrap_joined_index(join_index, other)
4164+
join_index = self._wrap_joined_index(join_index, other,
4165+
tolerance)
41604166
elif how == 'outer':
41614167
join_index, lidx, ridx = self._outer_indexer(sv, ov)
4162-
join_index = self._wrap_joined_index(join_index, other)
4168+
join_index = self._wrap_joined_index(join_index, other,
4169+
tolerance)
41634170
else:
4171+
# FIXME: intolerant
41644172
if how == 'left':
41654173
join_index, lidx, ridx = self._left_indexer(sv, ov)
41664174
elif how == 'right':
@@ -4169,7 +4177,7 @@ def _join_monotonic(self, other, how='left', return_indexers=False):
41694177
join_index, lidx, ridx = self._inner_indexer(sv, ov)
41704178
elif how == 'outer':
41714179
join_index, lidx, ridx = self._outer_indexer(sv, ov)
4172-
join_index = self._wrap_joined_index(join_index, other)
4180+
join_index = self._wrap_joined_index(join_index, other, tolerance)
41734181

41744182
if return_indexers:
41754183
lidx = None if lidx is None else ensure_platform_int(lidx)
@@ -4178,9 +4186,9 @@ def _join_monotonic(self, other, how='left', return_indexers=False):
41784186
else:
41794187
return join_index
41804188

4181-
def _wrap_joined_index(self, joined, other):
4189+
def _wrap_joined_index(self, joined, other, tolerance):
41824190
name = self.name if self.name == other.name else None
4183-
return Index(joined, name=name)
4191+
return Index(joined, name=name, tolerance=tolerance)
41844192

41854193
def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
41864194
# this is for partial string indexing,

pandas/core/indexes/interval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def get_loc(self, key, method=None, tolerance=None):
650650
>>> overlapping_index.get_loc(1.5)
651651
array([0, 1], dtype=int64)
652652
"""
653-
# FIXME: mostly intolerant
653+
# FIXME: intolerant
654654
self._check_method(method)
655655

656656
original_key = key
@@ -660,7 +660,7 @@ def get_loc(self, key, method=None, tolerance=None):
660660
if isinstance(key, Interval):
661661
left = self._maybe_cast_slice_bound(key.left, 'left', None)
662662
right = self._maybe_cast_slice_bound(key.right, 'right', None)
663-
key = Interval(left, right, key.closed, tolerance=tolerance)
663+
key = Interval(left, right, key.closed)
664664
else:
665665
key = self._maybe_cast_slice_bound(key, 'left', None)
666666

pandas/core/indexes/multi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2892,9 +2892,9 @@ def _bounds(self):
28922892

28932893
return self.__bounds
28942894

2895-
def _wrap_joined_index(self, joined, other):
2895+
def _wrap_joined_index(self, joined, other, tolerance):
28962896
names = self.names if self.names == other.names else None
2897-
return MultiIndex.from_tuples(joined, names=names)
2897+
return MultiIndex.from_tuples(joined, names=names, tolerance=tolerance)
28982898

28992899
@Appender(Index.isin.__doc__)
29002900
def isin(self, values, level=None):

pandas/core/indexes/numeric.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def _convert_scalar_indexer(self, key, kind=None):
186186
return (super(Int64Index, self)
187187
._convert_scalar_indexer(key, kind=kind))
188188

189-
def _wrap_joined_index(self, joined, other):
189+
def _wrap_joined_index(self, joined, other, tolerance):
190190
name = self.name if self.name == other.name else None
191-
return Int64Index(joined, name=name)
191+
return Int64Index(joined, name=name, tolerance=tolerance)
192192

193193
@classmethod
194194
def _assert_safe_casting(cls, data, subarr):
@@ -263,9 +263,9 @@ def _convert_index_indexer(self, keyarr):
263263
return keyarr.astype(np.uint64)
264264
return keyarr
265265

266-
def _wrap_joined_index(self, joined, other):
266+
def _wrap_joined_index(self, joined, other, tolerance):
267267
name = self.name if self.name == other.name else None
268-
return UInt64Index(joined, name=name)
268+
return UInt64Index(joined, name=name, tolerance=tolerance)
269269

270270
@classmethod
271271
def _assert_safe_casting(cls, data, subarr):

pandas/core/indexes/range.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def equals(self, other, tolerance=None):
330330

331331
return super(RangeIndex, self).equals(other, tolerance=tolerance)
332332

333-
def intersection(self, other):
333+
def intersection(self, other, tolerance=None):
334334
"""
335335
Form the intersection of two Index objects. Sortedness of the result is
336336
not guaranteed
@@ -343,22 +343,25 @@ def intersection(self, other):
343343
-------
344344
intersection : Index
345345
"""
346-
# FIXME: intolerant
347346
if not isinstance(other, RangeIndex):
348-
return super(RangeIndex, self).intersection(other)
347+
return super(RangeIndex, self).intersection(other,
348+
tolerance=tolerance)
349349

350+
tolerance = self._choose_tolerance([other], tolerance=tolerance)
350351
if not len(self) or not len(other):
351-
return RangeIndex._simple_new(None)
352+
return RangeIndex._simple_new(None, tolerance=tolerance)
352353

353354
first = self[::-1] if self._step < 0 else self
354355
second = other[::-1] if other._step < 0 else other
355356

357+
# FIXME: intolerant
358+
356359
# check whether intervals intersect
357360
# deals with in- and decreasing ranges
358361
int_low = max(first._start, second._start)
359362
int_high = min(first._stop, second._stop)
360363
if int_high <= int_low:
361-
return RangeIndex._simple_new(None)
364+
return RangeIndex._simple_new(None, tolerance=tolerance)
362365

363366
# Method hint: linear Diophantine equation
364367
# solve intersection problem
@@ -368,14 +371,15 @@ def intersection(self, other):
368371

369372
# check whether element sets intersect
370373
if (first._start - second._start) % gcd:
371-
return RangeIndex._simple_new(None)
374+
return RangeIndex._simple_new(None, tolerance=tolerance)
372375

373376
# calculate parameters for the RangeIndex describing the
374377
# intersection disregarding the lower bounds
375378
tmp_start = first._start + (second._start - first._start) * \
376379
first._step // gcd * s
377380
new_step = first._step * second._step // gcd
378-
new_index = RangeIndex(tmp_start, int_high, new_step, fastpath=True)
381+
new_index = RangeIndex(tmp_start, int_high, new_step, fastpath=True,
382+
tolerance=tolerance)
379383

380384
# adjust index to limiting interval
381385
new_index._start = new_index._min_fitting_element(int_low)
@@ -423,7 +427,6 @@ def union(self, other, tolerance=None):
423427
-------
424428
union : Index
425429
"""
426-
# FIXME: intolerant
427430
self._assert_can_do_setop(other)
428431
tolerance = self._choose_tolerance([other], tolerance=tolerance)
429432
if len(other) == 0 or self.equals(other, tolerance=tolerance):

0 commit comments

Comments
 (0)