Skip to content

Commit 8ad7f07

Browse files
committed
TST: round out test coverage in pandas.core
1 parent b5ce934 commit 8ad7f07

File tree

10 files changed

+74
-14
lines changed

10 files changed

+74
-14
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
144144
mgr = mgr.copy()
145145
elif dtype is not None:
146146
# no choice but to copy
147-
mgr = mgr.cast(dtype)
147+
mgr = mgr.astype(dtype)
148148
elif isinstance(data, dict):
149149
mgr = self._init_dict(data, index, columns, dtype=dtype)
150150
elif isinstance(data, np.ndarray):

pandas/core/generic.py

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def drop(self, labels, axis=0):
163163

164164
class NDFrame(PandasObject):
165165
"""
166+
N-dimensional analogue of DataFrame. Store multi-dimensional in a
167+
size-mutable, labeled data structure
166168
167169
Parameters
168170
----------
@@ -174,6 +176,9 @@ class NDFrame(PandasObject):
174176
_default_stat_axis = 0
175177

176178
def __init__(self, data, axes=None, copy=False, dtype=None):
179+
if dtype is not None:
180+
data = data.astype(dtype)
181+
177182
self._data = data
178183

179184
def astype(self, dtype):

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _verify_integrity(self):
320320
tot_items = sum(len(x.items) for x in self.blocks)
321321
assert(len(self.items) == tot_items)
322322

323-
def cast(self, dtype):
323+
def astype(self, dtype):
324324
new_blocks = []
325325
for block in self.blocks:
326326
newb = make_block(block.values.astype(dtype), block.items,

pandas/core/panel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(self, data, items=None, major_axis=None, minor_axis=None,
143143
mgr = mgr.copy()
144144
elif dtype is not None:
145145
# no choice but to copy
146-
mgr = mgr.cast(dtype)
146+
mgr = mgr.astype(dtype)
147147
elif isinstance(data, dict):
148148
mgr = self._init_dict(data, passed_axes, dtype=dtype)
149149
elif isinstance(data, (np.ndarray, list)):
@@ -464,7 +464,7 @@ def reindex(self, major=None, items=None, minor=None, method=None,
464464
if items is not None:
465465
result = result._reindex_axis(items, method, 0, copy)
466466

467-
if result is self:
467+
if result is self and copy:
468468
raise ValueError('Must specify at least one axis')
469469

470470
return result

pandas/core/sparse.py

+6
Original file line numberDiff line numberDiff line change
@@ -1463,9 +1463,15 @@ def to_long(self, filter_observations=True):
14631463
def reindex(self, major=None, items=None, minor=None, major_axis=None,
14641464
minor_axis=None, copy=False):
14651465
"""
1466+
Conform / reshape panel axis labels to new input labels
14661467
14671468
Parameters
14681469
----------
1470+
major : array-like, default None
1471+
items : array-like, default None
1472+
minor : array-like, default None
1473+
copy : boolean, default False
1474+
Copy underlying SparseDataFrame objects
14691475
14701476
Returns
14711477
-------

pandas/io/pytables.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,12 @@ class HDFStore(object):
8282
and if the file does not exist it is created.
8383
``'r+'``
8484
It is similar to ``'a'``, but the file must already exist.
85-
8685
complevel : int, 1-9, default 0
8786
If a complib is specified compression will be applied
8887
where possible
89-
9088
complib : {'zlib', 'bzip2', 'lzo', 'blosc', None}, default None
9189
If complevel is > 0 apply compression to objects written
9290
in the store wherever possible
93-
9491
fletcher32 : bool, default False
9592
If applying compression use the fletcher32 checksum
9693
@@ -101,7 +98,8 @@ class HDFStore(object):
10198
>>> bar = store['foo'] # retrieve
10299
>>> store.close()
103100
"""
104-
def __init__(self, path, mode='a', complevel=0, complib=None, fletcher32=False):
101+
def __init__(self, path, mode='a', complevel=0, complib=None,
102+
fletcher32=False):
105103
try:
106104
import tables as _
107105
except ImportError: # pragma: no cover

pandas/io/tests/test_pytables.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,15 @@ def test_frame(self):
159159
self._check_roundtrip_table(df, tm.assert_frame_equal)
160160
self._check_roundtrip(df, tm.assert_frame_equal)
161161

162+
self._check_roundtrip_table(df, tm.assert_frame_equal,
163+
compression=True)
164+
self._check_roundtrip(df, tm.assert_frame_equal,
165+
compression=True)
166+
162167
tdf = tm.makeTimeDataFrame()
163168
self._check_roundtrip(tdf, tm.assert_frame_equal)
169+
self._check_roundtrip(tdf, tm.assert_frame_equal,
170+
compression=True)
164171

165172
def test_store_mixed(self):
166173
def _make_one():
@@ -283,8 +290,13 @@ def test_select_filter_corner(self):
283290
result = self.store.select('frame', [crit])
284291
tm.assert_frame_equal(result, df.ix[:, df.columns[:75]])
285292

286-
def _check_roundtrip(self, obj, comparator):
287-
store = HDFStore(self.scratchpath, 'w')
293+
def _check_roundtrip(self, obj, comparator, compression=False):
294+
options = {}
295+
if compression:
296+
options['complevel'] = 9
297+
options['complib'] = 'blosc'
298+
299+
store = HDFStore(self.scratchpath, 'w', **options)
288300
try:
289301
store['obj'] = obj
290302
retrieved = store['obj']
@@ -293,8 +305,13 @@ def _check_roundtrip(self, obj, comparator):
293305
store.close()
294306
os.remove(self.scratchpath)
295307

296-
def _check_roundtrip_table(self, obj, comparator):
297-
store = HDFStore(self.scratchpath, 'w')
308+
def _check_roundtrip_table(self, obj, comparator, compression=False):
309+
options = {}
310+
if compression:
311+
options['complevel'] = 9
312+
options['complib'] = 'blosc'
313+
314+
store = HDFStore(self.scratchpath, 'w', **options)
298315
try:
299316
store.put('obj', obj, table=True)
300317
retrieved = store['obj']

pandas/tests/test_functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pandas import Index, isnull
2-
import pandas.core.functions as fns
2+
import pandas.sandbox.functions as fns
33
import numpy as np
44
import unittest
55
import numpy as np

pandas/tests/test_ndframe.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import unittest
2+
3+
import numpy as np
4+
5+
from pandas.core.generic import NDFrame
6+
import pandas.util.testing as t
7+
8+
class TestNDFrame(unittest.TestCase):
9+
10+
def setUp(self):
11+
tdf = t.makeTimeDataFrame()
12+
self.ndf = NDFrame(tdf._data)
13+
14+
def test_constructor(self):
15+
# with cast
16+
ndf = NDFrame(self.ndf._data, dtype=int)
17+
self.assert_(ndf.values.dtype == np.int_)
18+
19+
def test_ndim(self):
20+
self.assertEquals(self.ndf.ndim, 2)
21+
22+
def test_astype(self):
23+
casted = self.ndf.astype(int)
24+
self.assert_(casted.values.dtype == np.int_)
25+
26+
if __name__ == '__main__':
27+
import nose
28+
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
29+
exit=False)
30+

pandas/tests/test_panel.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,12 @@ def test_reindex(self):
522522
assert_frame_equal(larger.major_xs(self.panel.major_axis[1]),
523523
smaller.major_xs(smaller_major[0]))
524524

525-
# reindex_like
525+
# don't necessarily copy
526+
result = self.panel.reindex(major=self.panel.major_axis, copy=False)
527+
self.assert_(result is self.panel)
526528

529+
def test_reindex_like(self):
530+
# reindex_like
527531
smaller = self.panel.reindex(items=self.panel.items[:-1],
528532
major=self.panel.major_axis[:-1],
529533
minor=self.panel.minor_axis[:-1])

0 commit comments

Comments
 (0)