| 1072 | tm.assert_frame_equal(expected2, conversion) |
| 1073 | |
| 1074 | def test_drop_column(self, datapath): |
| 1075 | expected = self.read_csv(datapath("io", "data", "stata", "stata6.csv")) |
| 1076 | expected["byte_"] = expected["byte_"].astype(np.int8) |
| 1077 | expected["int_"] = expected["int_"].astype(np.int16) |
| 1078 | expected["long_"] = expected["long_"].astype(np.int32) |
| 1079 | expected["float_"] = expected["float_"].astype(np.float32) |
| 1080 | expected["double_"] = expected["double_"].astype(np.float64) |
| 1081 | expected["date_td"] = expected["date_td"].apply( |
| 1082 | datetime.strptime, args=("%Y-%m-%d",) |
| 1083 | ) |
| 1084 | |
| 1085 | columns = ["byte_", "int_", "long_"] |
| 1086 | expected = expected[columns] |
| 1087 | dropped = read_stata( |
| 1088 | datapath("io", "data", "stata", "stata6_117.dta"), |
| 1089 | convert_dates=True, |
| 1090 | columns=columns, |
| 1091 | ) |
| 1092 | |
| 1093 | tm.assert_frame_equal(expected, dropped) |
| 1094 | |
| 1095 | # See PR 10757 |
| 1096 | columns = ["int_", "long_", "byte_"] |
| 1097 | expected = expected[columns] |
| 1098 | reordered = read_stata( |
| 1099 | datapath("io", "data", "stata", "stata6_117.dta"), |
| 1100 | convert_dates=True, |
| 1101 | columns=columns, |
| 1102 | ) |
| 1103 | tm.assert_frame_equal(expected, reordered) |
| 1104 | |
| 1105 | msg = "columns contains duplicate entries" |
| 1106 | with pytest.raises(ValueError, match=msg): |
| 1107 | read_stata( |
| 1108 | datapath("io", "data", "stata", "stata6_117.dta"), |
| 1109 | convert_dates=True, |
| 1110 | columns=["byte_", "byte_"], |
| 1111 | ) |
| 1112 | |
| 1113 | msg = "The following columns were not found in the Stata data set: not_found" |
| 1114 | with pytest.raises(ValueError, match=msg): |
| 1115 | read_stata( |
| 1116 | datapath("io", "data", "stata", "stata6_117.dta"), |
| 1117 | convert_dates=True, |
| 1118 | columns=["byte_", "int_", "long_", "not_found"], |
| 1119 | ) |
| 1120 | |
| 1121 | @pytest.mark.parametrize("version", [114, 117, 118, 119, None]) |
| 1122 | @pytest.mark.filterwarnings( |