File tree 3 files changed +13
-2
lines changed
3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ Bug Fixes
66
66
67
67
- Bug in ``scatter_matrix`` draws unexpected axis ticklabels (:issue:`5662`)
68
68
69
-
69
+ - Fixed bug in ``StataWriter`` resulting in changes to input ``DataFrame`` upon save (:issue:`9795`).
70
70
71
71
72
72
- Bug in ``transform`` causing length mismatch when null entries were present and a fast aggregator was being used (:issue:`9697`)
Original file line number Diff line number Diff line change @@ -1885,6 +1885,8 @@ def _prepare_pandas(self, data):
1885
1885
#NOTE: we might need a different API / class for pandas objects so
1886
1886
# we can set different semantics - handle this with a PR to pandas.io
1887
1887
1888
+ data = data .copy ()
1889
+
1888
1890
if self ._write_index :
1889
1891
data = data .reset_index ()
1890
1892
@@ -2013,7 +2015,7 @@ def _write_variable_labels(self, labels=None):
2013
2015
self ._write (_pad_bytes ("" , 81 ))
2014
2016
2015
2017
def _prepare_data (self ):
2016
- data = self .data . copy ()
2018
+ data = self .data
2017
2019
typlist = self .typlist
2018
2020
convert_dates = self ._convert_dates
2019
2021
# 1. Convert dates
Original file line number Diff line number Diff line change @@ -290,6 +290,15 @@ def test_stata_doc_examples(self):
290
290
df = DataFrame (np .random .randn (10 , 2 ), columns = list ('AB' ))
291
291
df .to_stata (path )
292
292
293
+ def test_write_preserves_original (self ):
294
+ # 9795
295
+ np .random .seed (423 )
296
+ df = pd .DataFrame (np .random .randn (5 ,4 ), columns = list ('abcd' ))
297
+ df .ix [2 , 'a' :'c' ] = np .nan
298
+ df_copy = df .copy ()
299
+ df .to_stata ('test.dta' , write_index = False )
300
+ tm .assert_frame_equal (df , df_copy )
301
+
293
302
def test_encoding (self ):
294
303
295
304
# GH 4626, proper encoding handling
You can’t perform that action at this time.
0 commit comments