Skip to content

Commit 437ecde

Browse files
committed
removed core/setup.py and test coverage for internals
1 parent 8091ded commit 437ecde

File tree

4 files changed

+26
-62
lines changed

4 files changed

+26
-62
lines changed

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _init_dict(self, data, index, columns, dtype=None):
180180
blocks, columns = form_blocks(homogenized, index, columns)
181181

182182
# consolidate for now
183-
mgr = BlockManager(blocks, [columns, index], ndim=2)
183+
mgr = BlockManager(blocks, [columns, index])
184184
return mgr.consolidate()
185185

186186
def _init_matrix(self, values, index, columns, dtype=None,
@@ -203,7 +203,7 @@ def _init_matrix(self, values, index, columns, dtype=None,
203203

204204
columns = _ensure_index(columns)
205205
block = make_block(values.T, columns, columns)
206-
return BlockManager([block], [columns, index], ndim=2)
206+
return BlockManager([block], [columns, index])
207207

208208
def astype(self, dtype):
209209
"""

pandas/core/internals.py

+15-49
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class Block(object):
1717
Index-ignorant; let the container take care of that
1818
"""
1919
def __init__(self, values, items, ref_items, ndim=2):
20-
# values = _convert_if_1d(values)
21-
2220
if issubclass(values.dtype.type, basestring):
2321
values = np.array(values, dtype=object)
2422

@@ -161,12 +159,6 @@ def _cast_if_bool_int(values):
161159
values = values.astype(object)
162160
return values
163161

164-
def _convert_if_1d(values):
165-
if values.ndim == 1:
166-
values = np.atleast_2d(values)
167-
168-
return values
169-
170162
#-------------------------------------------------------------------------------
171163
# Is this even possible?
172164

@@ -224,17 +216,13 @@ class BlockManager(object):
224216
-----
225217
This is *not* a public API class
226218
"""
227-
def __init__(self, blocks, axes, skip_integrity_check=False, ndim=None):
219+
def __init__(self, blocks, axes, skip_integrity_check=False):
228220
self.axes = [_ensure_index(ax) for ax in axes]
229221
self.blocks = blocks
230222

231-
if ndim is None and len(blocks) == 0:
232-
raise ValueError('must specify dimension if no input blocks')
233-
elif ndim is None:
234-
ndim = blocks[0].ndim
235-
else:
236-
for block in blocks:
237-
assert(ndim == block.values.ndim)
223+
ndim = len(axes)
224+
for block in blocks:
225+
assert(ndim == block.values.ndim)
238226

239227
self.ndim = ndim
240228

@@ -325,7 +313,7 @@ def cast(self, dtype):
325313
block.ref_items)
326314
new_blocks.append(newb)
327315

328-
new_mgr = BlockManager(new_blocks, self.axes, ndim=self.ndim)
316+
new_mgr = BlockManager(new_blocks, self.axes)
329317
return new_mgr.consolidate()
330318

331319
def is_consolidated(self):
@@ -340,7 +328,7 @@ def get_slice(self, slice_obj, axis=0):
340328

341329
new_axes = list(self.axes)
342330
new_axes[axis] = new_axes[axis][slice_obj]
343-
return BlockManager(new_blocks, new_axes, ndim=self.ndim)
331+
return BlockManager(new_blocks, new_axes)
344332

345333
def _slice_blocks(self, slice_obj, axis):
346334
new_blocks = []
@@ -364,7 +352,7 @@ def from_blocks(cls, blocks, index):
364352
# also checks for overlap
365353
items = _union_block_items(blocks)
366354
ndim = blocks[0].ndim
367-
return BlockManager(blocks, [items, index], ndim=ndim)
355+
return BlockManager(blocks, [items, index])
368356

369357
def __contains__(self, item):
370358
return item in self.items
@@ -375,7 +363,7 @@ def nblocks(self):
375363

376364
def copy(self):
377365
copy_blocks = [block.copy() for block in self.blocks]
378-
return BlockManager(copy_blocks, self.axes, ndim=self.ndim)
366+
return BlockManager(copy_blocks, self.axes)
379367

380368
def as_matrix(self, items=None):
381369
if len(self.blocks) == 0:
@@ -530,7 +518,7 @@ def reindex_axis(self, new_axis, method=None, axis=0):
530518

531519
new_axes = list(self.axes)
532520
new_axes[axis] = new_axis
533-
return BlockManager(new_blocks, new_axes, ndim=self.ndim)
521+
return BlockManager(new_blocks, new_axes)
534522

535523
def reindex_items(self, new_items):
536524
"""
@@ -566,7 +554,7 @@ def reindex_items(self, new_items):
566554
new_axes = list(self.axes)
567555
new_axes[0] = new_items
568556

569-
return BlockManager(new_blocks, new_axes, ndim=self.ndim)
557+
return BlockManager(new_blocks, new_axes)
570558

571559
def merge(self, other):
572560
assert(self._is_indexed_like(other))
@@ -677,8 +665,6 @@ def form_blocks(data, index, items):
677665

678666
blocks = []
679667

680-
ndim = 2
681-
682668
if len(num_dict) > 0:
683669
num_dtypes = set(v.dtype for v in num_dict.values())
684670
if len(num_dtypes) > 1:
@@ -688,15 +674,15 @@ def form_blocks(data, index, items):
688674

689675
# TODO: find corner cases
690676
# TODO: check type inference
691-
num_block = _simple_blockify(num_dict, items, num_dtype, ndim)
677+
num_block = _simple_blockify(num_dict, items, num_dtype)
692678
blocks.append(num_block)
693679

694680
if len(bool_dict):
695-
bool_block = _simple_blockify(bool_dict, items, np.bool_, ndim)
681+
bool_block = _simple_blockify(bool_dict, items, np.bool_)
696682
blocks.append(bool_block)
697683

698684
if len(object_dict) > 0:
699-
object_block = _simple_blockify(object_dict, items, np.object_, ndim)
685+
object_block = _simple_blockify(object_dict, items, np.object_)
700686
blocks.append(object_block)
701687

702688
if len(extra_items):
@@ -709,10 +695,10 @@ def form_blocks(data, index, items):
709695

710696
return blocks, items
711697

712-
def _simple_blockify(dct, ref_items, dtype, ndim):
698+
def _simple_blockify(dct, ref_items, dtype):
713699
block_items, values = _stack_dict(dct)
714700
# CHECK DTYPE?
715-
if values.dtype != dtype:
701+
if values.dtype != dtype: # pragma: no cover
716702
values = values.astype(dtype)
717703

718704
return make_block(values, block_items, ref_items)
@@ -732,26 +718,6 @@ def _blocks_to_series_dict(blocks, index=None):
732718
series_dict[item] = Series(vec, index=index)
733719
return series_dict
734720

735-
def _interleave(blocks, items):
736-
"""
737-
Return ndarray from blocks with specified item order
738-
Items must be contained in the blocks
739-
"""
740-
dtype = _interleaved_dtype(blocks)
741-
items = _ensure_index(items)
742-
743-
result = np.empty((len(blocks[0]), len(items)), dtype=dtype)
744-
itemmask = np.zeros(len(items), dtype=bool)
745-
746-
# By construction, all of the item should be covered by one of the blocks
747-
for block in blocks:
748-
indexer, mask = items.get_indexer(block.items)
749-
assert(mask.all())
750-
result[:, indexer] = block.values
751-
itemmask[indexer] = 1
752-
assert(itemmask.all())
753-
return result
754-
755721
def _interleaved_dtype(blocks):
756722
have_int = False
757723
have_bool = False

pandas/core/setup.py

-11
This file was deleted.

pandas/tests/test_internals.py

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test_ref_locs(self):
6767
def test_attrs(self):
6868
self.assert_(self.fblock.shape == self.fblock.values.shape)
6969
self.assert_(self.fblock.dtype == self.fblock.values.dtype)
70+
self.assert_(len(self.fblock) == len(self.fblock.values))
7071

7172
def test_merge(self):
7273
avals = randn(2, 10)
@@ -170,6 +171,9 @@ def setUp(self):
170171
get_int_ex()]
171172
self.mgr = BlockManager.from_blocks(self.blocks, np.arange(N))
172173

174+
def test_constructor_corner(self):
175+
pass
176+
173177
def test_attrs(self):
174178
self.assertEquals(self.mgr.nblocks, len(self.mgr.blocks))
175179
self.assertEquals(len(self.mgr), len(self.mgr.items))
@@ -181,6 +185,11 @@ def test_is_mixed_dtype(self):
181185
mgr = BlockManager.from_blocks(blocks, np.arange(N))
182186
self.assert_(not mgr.is_mixed_dtype())
183187

188+
def test_is_indexed_like(self):
189+
self.assert_(self.mgr._is_indexed_like(self.mgr))
190+
mgr2 = self.mgr.reindex_axis(np.arange(N - 1), axis=1)
191+
self.assert_(not self.mgr._is_indexed_like(mgr2))
192+
184193
def test_block_id_vector(self):
185194
expected = [0, 1, 0, 1, 0, 2, 3]
186195
result = self.mgr.block_id_vector

0 commit comments

Comments
 (0)