Skip to content

Commit

Permalink
Fixing issue AllenDowney#13
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenDowney committed Dec 23, 2014
1 parent 6f9cc8f commit d757805
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/thinkstats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ def ReadStataDct(dct_file, **options):

# fill in the end column by shifting the start column
variables['end'] = variables.start.shift(-1)
variables['end'][len(variables)-1] = 0
variables.loc[len(variables)-1, 'end'] = 0

dct = FixedWidthVariables(variables, index_base=1)
return dct
Expand Down
6 changes: 6 additions & 0 deletions code/thinkstats2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ def testCov(self):
self.assertAlmostEqual(thinkstats2.SpearmanCorr(t, -a), -1)
self.assertAlmostEqual(thinkstats2.SpearmanCorr(t, t2), -0.1878787878)

def testReadStataDct(self):
dct = thinkstats2.ReadStataDct('2002FemPreg.dct')
self.assertEqual(len(dct.variables), 243)
self.assertEqual(len(dct.colspecs), 243)
self.assertEqual(len(dct.names), 243)
self.assertEqual(dct.colspecs[-1][1], -1)

if __name__ == "__main__":
unittest.main()

0 comments on commit d757805

Please sign in to comment.