Skip to content

Commit 2ebade0

Browse files
committed
few more unit tests
git-svn-id: http://pandas.googlecode.com/svn/trunk@85 d5231056-7de3-11de-ac95-d976489f1ece
1 parent 04aac90 commit 2ebade0

File tree

5 files changed

+82
-18
lines changed

5 files changed

+82
-18
lines changed

Diff for: examples/regressions.py

+2
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ def makeSeries():
4444

4545
panelModel = ols(y=Y, x=data, window=50)
4646

47+
model = ols(y=Y, x=data)
48+
4749
print panelModel

Diff for: pandas/core/frame.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, data=None, index=None):
8282
elif index is not None:
8383
self.index = index
8484
else:
85-
raise Exception('DataFrame constructor not properly called!')
85+
self.index = NULL_INDEX
8686

8787
def _set_index(self, index):
8888
if isinstance(index, Index):
@@ -141,7 +141,6 @@ def fromDict(cls, inputDict=None, castFloat=True, **kwds):
141141
index = inputDict.values()[0].keys()
142142
if not isinstance(index, Index):
143143
index = Index(sorted(index))
144-
145144
else:
146145
# GET set of indices
147146
indices = set([])
@@ -175,12 +174,7 @@ def toDict(self):
175174
------
176175
nested dict mapping: {column -> index -> value}
177176
"""
178-
tree = {}
179-
for col, series in self.iteritems():
180-
tree[col] = branch = {}
181-
for i in self.index:
182-
branch[i] = series[i]
183-
return tree
177+
return dict((k, v.toDict()) for k, v in self.iteritems())
184178

185179
@classmethod
186180
def fromRecords(cls, data, indexField=None):

Diff for: pandas/core/tests/test_frame.py

+47-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas.core.api import DateRange, DataFrame, Index, Series
1111
from pandas.core.datetools import bday
1212

13-
from pandas.core.tests.common import assert_almost_equal
13+
from pandas.core.tests.common import assert_almost_equal, randn
1414
import pandas.core.tests.common as common
1515

1616
#-------------------------------------------------------------------------------
@@ -42,8 +42,8 @@ def setUp(self):
4242
}
4343

4444
def test_constructor(self):
45-
46-
self.assertRaises(Exception, DataFrame)
45+
df = DataFrame()
46+
self.assert_(len(df.index) == 0)
4747

4848
def test_constructor_mixed(self):
4949
index, data = common.getMixedTypeDict()
@@ -75,7 +75,7 @@ def test_fromDict(self):
7575
# can't cast to float
7676
test_data = {
7777
'A' : dict(zip(range(20), common.makeDateIndex(20))),
78-
'B' : dict(zip(range(15), common.randn(15)))
78+
'B' : dict(zip(range(15), randn(15)))
7979
}
8080
frame = self.klass.fromDict(test_data)
8181
self.assertEqual(len(frame), 20)
@@ -87,9 +87,21 @@ def test_fromDict(self):
8787
self.assertEqual(len(self.klass.fromDict()), 0)
8888
self.assertRaises(Exception, self.klass.fromDict, [self.ts1, self.ts2])
8989

90+
# Length-one dict micro-optimization
91+
frame = self.klass.fromDict({'A' : {'1' : 1, '2' : 2}})
92+
self.assert_(np.array_equal(frame.index, ['1', '2']))
93+
9094
def test_toDict(self):
91-
pass
95+
test_data = {
96+
'A' : {'1' : 1, '2' : 2},
97+
'B' : {'1' : '1', '2' : '2', '3' : '3'},
98+
}
99+
recons_data = self.klass.fromDict(test_data, castFloat=False).toDict()
92100

101+
for k, v in test_data.iteritems():
102+
for k2, v2 in v.iteritems():
103+
self.assertEqual(v2, recons_data[k][k2])
104+
93105
def test_fromRecords(self):
94106
# from numpy documentation
95107
arr = np.zeros((2,),dtype=('i4,f4,a10'))
@@ -118,8 +130,12 @@ def test_fromMatrix(self):
118130
mat, ['A', 'B'], [1, 2])
119131

120132
def test_nonzero(self):
121-
pass
133+
empty = DataFrame({})
134+
135+
self.assertFalse(empty)
122136

137+
self.assert_(self.frame)
138+
123139
def test_repr(self):
124140
# small one
125141
foo = repr(self.frame)
@@ -133,7 +149,7 @@ def test_repr(self):
133149
foo = repr(self.mixed_frame)
134150

135151
# big mixed
136-
biggie = self.klass({'A' : common.randn(1000),
152+
biggie = self.klass({'A' : randn(1000),
137153
'B' : common.makeStringIndex(1000)},
138154
index=range(1000))
139155
foo = repr(biggie)
@@ -187,7 +203,12 @@ def test_setitem(self):
187203
assert((self.frame['col8'] == 'foo').all())
188204

189205
self.assertRaises(Exception, self.frame.__setitem__,
190-
common.randn(len(self.frame) + 1))
206+
randn(len(self.frame) + 1))
207+
208+
# set ndarray
209+
arr = randn(len(self.frame))
210+
self.frame['col9'] = arr
211+
self.assert_((self.frame['col9'] == arr).all())
191212

192213
def test_delitem(self):
193214
del self.frame['A']
@@ -349,6 +370,7 @@ def test_pivot(self):
349370

350371
def test_reindex(self):
351372
newFrame = self.frame.reindex(self.ts1.index)
373+
352374
for col in newFrame.cols():
353375
for idx, val in newFrame[col].iteritems():
354376
if idx in self.frame.index:
@@ -358,12 +380,15 @@ def test_reindex(self):
358380
self.assertEqual(val, self.frame[col][idx])
359381
else:
360382
self.assert_(np.isnan(val))
383+
361384
for col, series in newFrame.iteritems():
362385
self.assert_(common.equalContents(series.index, newFrame.index))
363386
emptyFrame = self.frame.reindex(Index([]))
364387
self.assert_(len(emptyFrame.index) == 0)
365388

389+
# Cython code should be unit-tested directly
366390
nonContigFrame = self.frame.reindex(self.ts1.index[::2])
391+
367392
for col in nonContigFrame.cols():
368393
for idx, val in nonContigFrame[col].iteritems():
369394
if idx in self.frame.index:
@@ -373,9 +398,23 @@ def test_reindex(self):
373398
self.assertEqual(val, self.frame[col][idx])
374399
else:
375400
self.assert_(np.isnan(val))
401+
376402
for col, series in nonContigFrame.iteritems():
377403
self.assert_(common.equalContents(series.index, nonContigFrame.index))
378404

405+
# corner cases
406+
407+
# Same index, copies values
408+
newFrame = self.frame.reindex(self.frame.index)
409+
self.assert_(newFrame.index is self.frame.index)
410+
411+
# length zero
412+
newFrame = self.frame.reindex([])
413+
self.assert_(not newFrame)
414+
415+
def test_reindex_mixed(self):
416+
pass
417+
379418
def test_transpose(self):
380419
frame = self.frame
381420
dft = frame.T

Diff for: pandas/lib/tests/test_tseries.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
3+
import numpy as np
4+
5+
class TestTseriesUtil(unittest.TestCase):
6+
7+
def test_combineFunc(self):
8+
pass
9+
10+
def test_reindex(self):
11+
pass
12+
13+
def test_isnull(self):
14+
pass
15+
16+
def test_groupby(self):
17+
pass
18+
19+
def test_groupby_withnull(self):
20+
pass
21+
22+
def test_getMergeVec(self):
23+
pass
24+
25+
def test_getFillVec(self):
26+
pass
27+
28+
class TestMoments(unittest.TestCase):
29+
pass

Diff for: setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
URL = "pandas.googlecode.com"
2121
DOWNLOAD_URL = ''
2222
CLASSIFIERS = [
23-
'Development Status :: 3 - Alpha',
23+
'Development Status :: 4 - Beta',
2424
'Environment :: Console',
2525
'Operating System :: OS Independent',
2626
'Intended Audience :: Science/Research',
@@ -83,7 +83,7 @@ def configuration(parent_package='', top_path=None, package_name=DISTNAME):
8383
setup(configuration=configuration,
8484
packages=setuptools.find_packages(),
8585
classifiers=CLASSIFIERS,
86-
requires=['numpy', 'scikits.statsmodels', 'dateutil'],
86+
requires=['numpy', 'scipy', 'scikits.statsmodels', 'dateutil'],
8787
platforms='any',
8888
test_suite='nose.collector',
8989
zip_safe=False)

0 commit comments

Comments
 (0)