@@ -2591,35 +2591,26 @@ def test_many_strl(temp_file, version):
2591
2591
2592
2592
@pytest .mark .parametrize ("version" , [114 , 117 , 118 , 119 , None ])
2593
2593
def test_convert_dates_key_handling (tmp_path , version ):
2594
- # GH 60536
2594
+
2595
2595
temp_file = tmp_path / "test.dta"
2596
2596
df = DataFrame ({"old_name" : [1 , 2 , 3 ], "some_other_name" : [4 , 5 , 6 ]})
2597
2597
2598
- # Case 1: Key exists in _convert_dates
2598
+ # Case 1: Key exists in convert_dates
2599
2599
convert_dates = {"old_name" : "converted_date" }
2600
- df .rename (columns = {"old_name" : "new_name" }, inplace = True )
2601
- with StataWriter (
2602
- temp_file ,
2603
- df ,
2604
- convert_dates = convert_dates ,
2605
- version = version ,
2606
- ) as writer :
2607
- writer .write_file ()
2600
+ df_renamed = df .rename (columns = {"old_name" : "new_name" }) # Mimic column renaming
2601
+ df_renamed .to_stata (temp_file , convert_dates = convert_dates )
2602
+
2608
2603
result = read_stata (temp_file )
2609
- assert list (result .columns ) == ["new_name" , "some_other_name" ]
2610
- assert "converted_date" in result .columns
2604
+ assert "new_name" in result .columns
2605
+ assert "old_name" not in result .columns
2606
+ assert result ["new_name" ].tolist () == ["converted_date" , "converted_date" , "converted_date" ]
2611
2607
2612
- # Case 2: Key does not exist in _convert_dates
2613
- df = DataFrame ({"old_name" : [1 , 2 , 3 ], "some_other_name" : [4 , 5 , 6 ]})
2608
+ # Case 2: Key does not exist in convert_dates
2614
2609
convert_dates = {"some_other_name" : "converted_date" }
2615
- df .rename (columns = {"old_name" : "new_name" }, inplace = True )
2616
- with StataWriter (
2617
- temp_file ,
2618
- df ,
2619
- convert_dates = convert_dates ,
2620
- version = version ,
2621
- ) as writer :
2622
- writer .write_file ()
2610
+ df_renamed = df .rename (columns = {"old_name" : "new_name" }) # Mimic column renaming
2611
+ df_renamed .to_stata (temp_file , convert_dates = convert_dates )
2612
+
2623
2613
result = read_stata (temp_file )
2624
- assert list (result .columns ) == ["new_name" , "some_other_name" ]
2625
- assert "converted_date" in result .columns
2614
+ assert "new_name" not in result .columns
2615
+ assert "old_name" in result .columns
2616
+ assert result ["some_other_name" ].tolist () == ["converted_date" , "converted_date" , "converted_date" ]
0 commit comments