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