@@ -231,6 +231,38 @@ def test_encoding(self):
231231 self .assert_ (result == expected )
232232 self .assert_ (isinstance (result , unicode ))
233233
234+ def test_read_write_dta11 (self ):
235+ original = DataFrame ([(1 , 2 , 3 , 4 )],
236+ columns = ['good' , compat .u ('b\u00E4 d' ), '8number' , 'astringwithmorethan32characters______' ])
237+ formatted = DataFrame ([(1 , 2 , 3 , 4 )],
238+ columns = ['good' , 'b_d' , '_8number' , 'astringwithmorethan32characters_' ])
239+ formatted .index .name = 'index'
240+
241+ with tm .ensure_clean () as path :
242+ with warnings .catch_warnings (record = True ) as w :
243+ original .to_stata (path , None , False )
244+ np .testing .assert_equal (
245+ len (w ), 1 ) # should get a warning for that format.
246+
247+ written_and_read_again = self .read_dta (path )
248+ tm .assert_frame_equal (written_and_read_again .set_index ('index' ), formatted )
249+
250+ def test_read_write_dta12 (self ):
251+ original = DataFrame ([(1 , 2 , 3 , 4 )],
252+ columns = ['astringwithmorethan32characters_1' , 'astringwithmorethan32characters_2' , '+' , '-' ])
253+ formatted = DataFrame ([(1 , 2 , 3 , 4 )],
254+ columns = ['astringwithmorethan32characters_' , '_0astringwithmorethan32character' , '_' , '_1_' ])
255+ formatted .index .name = 'index'
256+
257+ with tm .ensure_clean () as path :
258+ with warnings .catch_warnings (record = True ) as w :
259+ original .to_stata (path , None , False )
260+ np .testing .assert_equal (
261+ len (w ), 1 ) # should get a warning for that format.
262+
263+ written_and_read_again = self .read_dta (path )
264+ tm .assert_frame_equal (written_and_read_again .set_index ('index' ), formatted )
265+
234266if __name__ == '__main__' :
235267 nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
236268 exit = False )
0 commit comments