Skip to content

Commit 70514ce

Browse files
committed
revert edits to be pure cut/paste
1 parent 0a94cca commit 70514ce

File tree

2 files changed

+35
-49
lines changed

2 files changed

+35
-49
lines changed

pandas/_libs/internals.pyx

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
cimport cython
44
from cython cimport Py_ssize_t
55

6-
from cpython cimport PyObject, PyInt_Check
7-
from cpython.slice cimport PySlice_Check
6+
cdef extern from "Python.h":
7+
Py_ssize_t PY_SSIZE_T_MAX
88

99
import numpy as np
1010
cimport numpy as np
1111
from numpy cimport int64_t
1212

13-
cdef extern from "Python.h":
14-
Py_ssize_t PY_SSIZE_T_MAX
15-
1613
cdef extern from "compat_helper.h":
1714
cdef int slice_get_indices(PyObject* s, Py_ssize_t length,
1815
Py_ssize_t *start, Py_ssize_t *stop,
@@ -22,19 +19,18 @@ cdef extern from "compat_helper.h":
2219

2320
cdef class BlockPlacement:
2421
# __slots__ = '_as_slice', '_as_array', '_len'
25-
cdef:
26-
slice _as_slice
27-
object _as_array
28-
bint _has_slice, _has_array, _is_known_slice_like
22+
cdef slice _as_slice
23+
cdef object _as_array
24+
25+
cdef bint _has_slice, _has_array, _is_known_slice_like
2926

3027
def __init__(self, val):
31-
cdef:
32-
slice slc
28+
cdef slice slc
3329

3430
self._has_slice = False
3531
self._has_array = False
3632

37-
if PySlice_Check(val):
33+
if isinstance(val, slice):
3834
slc = slice_canonize(val)
3935

4036
if slc.start != slc.stop:
@@ -52,8 +48,7 @@ cdef class BlockPlacement:
5248
self._has_array = True
5349

5450
def __str__(self):
55-
cdef:
56-
slice s = self._ensure_has_slice()
51+
cdef slice s = self._ensure_has_slice()
5752
if s is not None:
5853
v = self._as_slice
5954
else:
@@ -64,17 +59,15 @@ cdef class BlockPlacement:
6459
__repr__ = __str__
6560

6661
def __len__(self):
67-
cdef:
68-
slice s = self._ensure_has_slice()
62+
cdef slice s = self._ensure_has_slice()
6963
if s is not None:
7064
return slice_len(s)
7165
else:
7266
return len(self._as_array)
7367

7468
def __iter__(self):
75-
cdef:
76-
slice s = self._ensure_has_slice()
77-
Py_ssize_t start, stop, step, _
69+
cdef slice s = self._ensure_has_slice()
70+
cdef Py_ssize_t start, stop, step, _
7871
if s is not None:
7972
start, stop, step, _ = slice_get_indices_ex(s)
8073
return iter(range(start, stop, step))
@@ -83,17 +76,15 @@ cdef class BlockPlacement:
8376

8477
@property
8578
def as_slice(self):
86-
cdef:
87-
slice s = self._ensure_has_slice()
79+
cdef slice s = self._ensure_has_slice()
8880
if s is None:
8981
raise TypeError('Not slice-like')
9082
else:
9183
return s
9284

9385
@property
9486
def indexer(self):
95-
cdef:
96-
slice s = self._ensure_has_slice()
87+
cdef slice s = self._ensure_has_slice()
9788
if s is not None:
9889
return s
9990
else:
@@ -105,8 +96,7 @@ cdef class BlockPlacement:
10596

10697
@property
10798
def as_array(self):
108-
cdef:
109-
Py_ssize_t start, stop, end, _
99+
cdef Py_ssize_t start, stop, end, _
110100
if not self._has_array:
111101
start, stop, step, _ = slice_get_indices_ex(self._as_slice)
112102
self._as_array = np.arange(start, stop, step,
@@ -116,19 +106,17 @@ cdef class BlockPlacement:
116106

117107
@property
118108
def is_slice_like(self):
119-
cdef:
120-
slice s = self._ensure_has_slice()
109+
cdef slice s = self._ensure_has_slice()
121110
return s is not None
122111

123112
def __getitem__(self, loc):
124-
cdef:
125-
slice s = self._ensure_has_slice()
113+
cdef slice s = self._ensure_has_slice()
126114
if s is not None:
127115
val = slice_getitem(s, loc)
128116
else:
129117
val = self._as_array[loc]
130118

131-
if not PySlice_Check(val) and val.ndim == 0:
119+
if not isinstance(val, slice) and val.ndim == 0:
132120
return val
133121

134122
return BlockPlacement(val)
@@ -144,11 +132,10 @@ cdef class BlockPlacement:
144132
[o.as_array for o in others]))
145133

146134
cdef iadd(self, other):
147-
cdef:
148-
slice s = self._ensure_has_slice()
149-
Py_ssize_t other_int, start, stop, step, l
135+
cdef slice s = self._ensure_has_slice()
136+
cdef Py_ssize_t other_int, start, stop, step, l
150137

151-
if PyInt_Check(other) and s is not None:
138+
if isinstance(other, int) and s is not None:
152139
other_int = <Py_ssize_t>other
153140

154141
if other_int == 0:
@@ -182,8 +169,7 @@ cdef class BlockPlacement:
182169
return self
183170

184171
cdef BlockPlacement copy(self):
185-
cdef:
186-
slice s = self._ensure_has_slice()
172+
cdef slice s = self._ensure_has_slice()
187173
if s is not None:
188174
return BlockPlacement(s)
189175
else:
@@ -202,7 +188,7 @@ cdef class BlockPlacement:
202188
return self._as_slice
203189

204190

205-
cdef slice_canonize(slice s):
191+
cpdef slice_canonize(slice s):
206192
"""
207193
Convert slice to canonical bounded form.
208194
"""
@@ -248,8 +234,8 @@ cdef slice_canonize(slice s):
248234
return slice(start, stop, step)
249235

250236

251-
cpdef Py_ssize_t slice_len(slice slc,
252-
Py_ssize_t objlen=PY_SSIZE_T_MAX) except -1:
237+
cpdef Py_ssize_t slice_len(
238+
slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX) except -1:
253239
"""
254240
Get length of a bounded slice.
255241
@@ -293,14 +279,14 @@ cpdef slice_get_indices_ex(slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX):
293279
return start, stop, step, length
294280

295281

296-
cdef slice_getitem(slice slc, ind):
282+
def slice_getitem(slice slc not None, ind):
297283
cdef:
298284
Py_ssize_t s_start, s_stop, s_step, s_len
299285
Py_ssize_t ind_start, ind_stop, ind_step, ind_len
300286

301287
s_start, s_stop, s_step, s_len = slice_get_indices_ex(slc)
302288

303-
if PySlice_Check(ind):
289+
if isinstance(ind, slice):
304290
ind_start, ind_stop, ind_step, ind_len = slice_get_indices_ex(ind,
305291
s_len)
306292

@@ -402,7 +388,7 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
402388
start = 0
403389
cur_blkno = blknos[start]
404390

405-
if group is False:
391+
if group == False:
406392
for i in range(1, n):
407393
if blknos[i] != cur_blkno:
408394
yield cur_blkno, slice(start, i)
@@ -447,4 +433,4 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
447433
res_view[i] = diff
448434
i += 1
449435

450-
yield blkno, result
436+
yield blkno, result

pandas/tests/internals/test_internals.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def mgr():
3939
def assert_block_equal(left, right):
4040
tm.assert_numpy_array_equal(left.values, right.values)
4141
assert left.dtype == right.dtype
42-
assert isinstance(left.mgr_locs, lib.BlockPlacement)
43-
assert isinstance(right.mgr_locs, lib.BlockPlacement)
42+
assert isinstance(left.mgr_locs, BlockPlacement)
43+
assert isinstance(right.mgr_locs, BlockPlacement)
4444
tm.assert_numpy_array_equal(left.mgr_locs.as_array,
4545
right.mgr_locs.as_array)
4646

@@ -222,7 +222,7 @@ def _check(blk):
222222
_check(self.bool_block)
223223

224224
def test_mgr_locs(self):
225-
assert isinstance(self.fblock.mgr_locs, lib.BlockPlacement)
225+
assert isinstance(self.fblock.mgr_locs, BlockPlacement)
226226
tm.assert_numpy_array_equal(self.fblock.mgr_locs.as_array,
227227
np.array([0, 2, 4], dtype=np.int64))
228228

@@ -264,14 +264,14 @@ def test_insert(self):
264264
def test_delete(self):
265265
newb = self.fblock.copy()
266266
newb.delete(0)
267-
assert isinstance(newb.mgr_locs, lib.BlockPlacement)
267+
assert isinstance(newb.mgr_locs, BlockPlacement)
268268
tm.assert_numpy_array_equal(newb.mgr_locs.as_array,
269269
np.array([2, 4], dtype=np.int64))
270270
assert (newb.values[0] == 1).all()
271271

272272
newb = self.fblock.copy()
273273
newb.delete(1)
274-
assert isinstance(newb.mgr_locs, lib.BlockPlacement)
274+
assert isinstance(newb.mgr_locs, BlockPlacement)
275275
tm.assert_numpy_array_equal(newb.mgr_locs.as_array,
276276
np.array([0, 4], dtype=np.int64))
277277
assert (newb.values[1] == 2).all()
@@ -679,7 +679,7 @@ def test_consolidate_ordering_issues(self, mgr):
679679
assert cons.nblocks == 4
680680
cons = mgr.consolidate().get_numeric_data()
681681
assert cons.nblocks == 1
682-
assert isinstance(cons.blocks[0].mgr_locs, lib.BlockPlacement)
682+
assert isinstance(cons.blocks[0].mgr_locs, BlockPlacement)
683683
tm.assert_numpy_array_equal(cons.blocks[0].mgr_locs.as_array,
684684
np.arange(len(cons.items), dtype=np.int64))
685685

0 commit comments

Comments
 (0)