3
3
from datetime import datetime
4
4
import os
5
5
import unittest
6
- import sys
7
6
import warnings
8
7
import nose
9
8
10
9
import numpy as np
11
10
12
- from pandas .core .frame import DataFrame
11
+ from pandas .core .frame import DataFrame , Series
13
12
from pandas .io .parsers import read_csv
14
13
from pandas .io .stata import read_stata , StataReader , StataWriter
15
14
import pandas .util .testing as tm
16
15
from pandas .util .testing import ensure_clean
17
16
from pandas .util .misc import is_little_endian
18
17
18
+
19
19
class StataTests (unittest .TestCase ):
20
20
21
21
def setUp (self ):
@@ -35,6 +35,7 @@ def setUp(self):
35
35
self .csv8 = os .path .join (self .dirpath , 'tbl19-3.csv' )
36
36
self .dta9 = os .path .join (self .dirpath , 'lbw.dta' )
37
37
self .csv9 = os .path .join (self .dirpath , 'lbw.csv' )
38
+ self .dta10 = os .path .join (self .dirpath , 'stata10.dta' )
38
39
39
40
def read_dta (self , file ):
40
41
return read_stata (file , convert_dates = True )
@@ -189,9 +190,24 @@ def test_read_dta9(self):
189
190
decimal = 3
190
191
)
191
192
193
+ def test_read_dta10 (self ):
194
+ original = DataFrame (
195
+ data =
196
+ [
197
+ ["string" , "object" , 1 , 1.1 , np .datetime64 ('2003-12-25' )]
198
+ ],
199
+ columns = ['string' , 'object' , 'integer' , 'float' , 'datetime' ])
200
+ original ["object" ] = Series (original ["object" ], dtype = object )
201
+ original .index .name = 'index'
202
+
203
+ with ensure_clean (self .dta10 ) as path :
204
+ original .to_stata (path , {'datetime' : 'tc' }, False )
205
+ written_and_read_again = self .read_dta (path )
206
+ tm .assert_frame_equal (written_and_read_again .set_index ('index' ), original )
207
+
192
208
def test_stata_doc_examples (self ):
193
209
with ensure_clean (self .dta5 ) as path :
194
- df = DataFrame (np .random .randn (10 ,2 ),columns = list ('AB' ))
210
+ df = DataFrame (np .random .randn (10 , 2 ), columns = list ('AB' ))
195
211
df .to_stata (path )
196
212
197
213
if __name__ == '__main__' :
0 commit comments