Skip to content

Commit a07a166

Browse files
committed
cleared up bug with is_monotonic resetting unique
1 parent 109322a commit a07a166

File tree

6 files changed

+56
-86
lines changed

6 files changed

+56
-86
lines changed

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def factorize(values, sort=False, order=None, na_sentinel=-1, size_hint=None):
131131
(hash_klass, vec_klass), vals = _get_data_algo(vals, _hashtables)
132132

133133
table = hash_klass(size_hint or len(vals))
134-
uniques = vec_klass(len(vals))
134+
uniques = vec_klass()
135135
labels = table.get_labels(vals, uniques, 0, na_sentinel)
136136

137137
labels = com._ensure_platform_int(labels)

pandas/core/index.py

+1
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ def union(self, other):
13641364
-------
13651365
union : Index
13661366
"""
1367+
13671368
if not hasattr(other, '__iter__'):
13681369
raise TypeError('Input must be iterable.')
13691370

pandas/hashtable.pyx

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ cdef extern from "Python.h":
3535

3636
cdef size_t _INIT_VEC_CAP = 32
3737

38-
cdef class Vector:
39-
pass
40-
41-
cdef class ObjectVector(Vector):
38+
cdef class ObjectVector:
4239

4340
cdef:
4441
PyObject **data
@@ -130,7 +127,7 @@ cdef void Float64VectorData_append(Float64VectorData *data, float64_t x) nogil:
130127
data.data[data.n] = x
131128
data.n += 1
132129

133-
cdef class Float64Vector(Vector):
130+
cdef class Float64Vector:
134131

135132
cdef:
136133
Float64VectorData *data

pandas/index.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,13 @@ cdef class IndexEngine:
233233
cdef inline _do_monotonic_check(self):
234234
try:
235235
values = self._get_index_values()
236-
self.monotonic_inc, self.monotonic_dec, self.unique = \
236+
self.monotonic_inc, self.monotonic_dec = \
237237
self._call_monotonic(values)
238238
except TypeError:
239239
self.monotonic_inc = 0
240240
self.monotonic_dec = 0
241241

242242
self.monotonic_check = 1
243-
self.unique_check = 1
244243

245244
cdef _get_index_values(self):
246245
return self.vgetter()
@@ -269,7 +268,8 @@ cdef class IndexEngine:
269268

270269
if len(self.mapping) == len(values):
271270
self.unique = 1
272-
self.unique_check = 1
271+
self.unique_check = 1
272+
273273
self.initialized = 1
274274

275275
def clear_mapping(self):

pandas/src/generate_code.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,11 @@ def is_monotonic_%(name)s(ndarray[%(c_type)s] arr, bint timelike):
586586
'''
587587
Returns
588588
-------
589-
is_monotonic_inc, is_monotonic_dec, is_unique
589+
is_monotonic_inc, is_monotonic_dec
590590
'''
591591
cdef:
592592
Py_ssize_t i, n
593593
%(c_type)s prev, cur
594-
bint is_unique = 1
595594
bint is_monotonic_inc = 1
596595
bint is_monotonic_dec = 1
597596
@@ -600,21 +599,20 @@ def is_monotonic_%(name)s(ndarray[%(c_type)s] arr, bint timelike):
600599
if n == 1:
601600
if arr[0] != arr[0] or (timelike and arr[0] == iNaT):
602601
# single value is NaN
603-
return False, False, True
602+
return False, False
604603
else:
605-
return True, True, True
604+
return True, True
606605
elif n < 2:
607-
return True, True, True
606+
return True, True
608607
609608
if timelike and arr[0] == iNaT:
610-
return False, False, None
609+
return False, False
611610
612611
%(nogil)s
613612
%(tab)sprev = arr[0]
614613
%(tab)sfor i in range(1, n):
615614
%(tab)s cur = arr[i]
616615
%(tab)s if timelike and cur == iNaT:
617-
%(tab)s is_unique = 0
618616
%(tab)s is_monotonic_inc = 0
619617
%(tab)s is_monotonic_dec = 0
620618
%(tab)s break
@@ -623,20 +621,18 @@ def is_monotonic_%(name)s(ndarray[%(c_type)s] arr, bint timelike):
623621
%(tab)s elif cur > prev:
624622
%(tab)s is_monotonic_dec = 0
625623
%(tab)s elif cur == prev:
626-
%(tab)s is_unique = 0
624+
%(tab)s pass # is_unique = 0
627625
%(tab)s else:
628626
%(tab)s # cur or prev is NaN
629-
%(tab)s is_unique = 0
630627
%(tab)s is_monotonic_inc = 0
631628
%(tab)s is_monotonic_dec = 0
632629
%(tab)s break
633630
%(tab)s if not is_monotonic_inc and not is_monotonic_dec:
634-
%(tab)s is_unique = 0
635631
%(tab)s is_monotonic_inc = 0
636632
%(tab)s is_monotonic_dec = 0
637633
%(tab)s break
638634
%(tab)s prev = cur
639-
return is_monotonic_inc, is_monotonic_dec, is_unique
635+
return is_monotonic_inc, is_monotonic_dec
640636
"""
641637

642638
map_indices_template = """@cython.wraparound(False)

0 commit comments

Comments
 (0)