@@ -879,37 +879,36 @@ def test_expand_user(self, df_compat, monkeypatch):
879
879
with pytest .raises (OSError , match = r".*TestingUser.*" ):
880
880
df_compat .to_parquet ("~/file.parquet" )
881
881
882
- def test_partition_cols_supported (self , pa , df_full ):
882
+ def test_partition_cols_supported (self , tmp_path , pa , df_full ):
883
883
# GH #23283
884
884
partition_cols = ["bool" , "int" ]
885
885
df = df_full
886
- with tm .ensure_clean_dir () as path :
887
- df .to_parquet (path , partition_cols = partition_cols , compression = None )
888
- check_partition_names (path , partition_cols )
889
- assert read_parquet (path ).shape == df .shape
886
+ df .to_parquet (tmp_path , partition_cols = partition_cols , compression = None )
887
+ check_partition_names (tmp_path , partition_cols )
888
+ assert read_parquet (tmp_path ).shape == df .shape
890
889
891
- def test_partition_cols_string (self , pa , df_full ):
890
+ def test_partition_cols_string (self , tmp_path , pa , df_full ):
892
891
# GH #27117
893
892
partition_cols = "bool"
894
893
partition_cols_list = [partition_cols ]
895
894
df = df_full
896
- with tm .ensure_clean_dir () as path :
897
- df .to_parquet (path , partition_cols = partition_cols , compression = None )
898
- check_partition_names (path , partition_cols_list )
899
- assert read_parquet (path ).shape == df .shape
895
+ df .to_parquet (tmp_path , partition_cols = partition_cols , compression = None )
896
+ check_partition_names (tmp_path , partition_cols_list )
897
+ assert read_parquet (tmp_path ).shape == df .shape
900
898
901
- @pytest .mark .parametrize ("path_type" , [str , pathlib .Path ])
902
- def test_partition_cols_pathlib (self , pa , df_compat , path_type ):
899
+ @pytest .mark .parametrize (
900
+ "path_type" , [str , lambda x : x ], ids = ["string" , "pathlib.Path" ]
901
+ )
902
+ def test_partition_cols_pathlib (self , tmp_path , pa , df_compat , path_type ):
903
903
# GH 35902
904
904
905
905
partition_cols = "B"
906
906
partition_cols_list = [partition_cols ]
907
907
df = df_compat
908
908
909
- with tm .ensure_clean_dir () as path_str :
910
- path = path_type (path_str )
911
- df .to_parquet (path , partition_cols = partition_cols_list )
912
- assert read_parquet (path ).shape == df .shape
909
+ path = path_type (tmp_path )
910
+ df .to_parquet (path , partition_cols = partition_cols_list )
911
+ assert read_parquet (path ).shape == df .shape
913
912
914
913
def test_empty_dataframe (self , pa ):
915
914
# GH #27339
@@ -1082,58 +1081,57 @@ def test_s3_roundtrip(self, df_compat, s3_resource, fp, s3so):
1082
1081
write_kwargs = {"compression" : None , "storage_options" : s3so },
1083
1082
)
1084
1083
1085
- def test_partition_cols_supported (self , fp , df_full ):
1084
+ def test_partition_cols_supported (self , tmp_path , fp , df_full ):
1086
1085
# GH #23283
1087
1086
partition_cols = ["bool" , "int" ]
1088
1087
df = df_full
1089
- with tm .ensure_clean_dir () as path :
1090
- df .to_parquet (
1091
- path ,
1092
- engine = "fastparquet" ,
1093
- partition_cols = partition_cols ,
1094
- compression = None ,
1095
- )
1096
- assert os .path .exists (path )
1097
- import fastparquet
1088
+ df .to_parquet (
1089
+ tmp_path ,
1090
+ engine = "fastparquet" ,
1091
+ partition_cols = partition_cols ,
1092
+ compression = None ,
1093
+ )
1094
+ assert os .path .exists (tmp_path )
1095
+ import fastparquet
1098
1096
1099
- actual_partition_cols = fastparquet .ParquetFile (path , False ).cats
1100
- assert len (actual_partition_cols ) == 2
1097
+ actual_partition_cols = fastparquet .ParquetFile (str ( tmp_path ) , False ).cats
1098
+ assert len (actual_partition_cols ) == 2
1101
1099
1102
- def test_partition_cols_string (self , fp , df_full ):
1100
+ def test_partition_cols_string (self , tmp_path , fp , df_full ):
1103
1101
# GH #27117
1104
1102
partition_cols = "bool"
1105
1103
df = df_full
1106
- with tm .ensure_clean_dir () as path :
1107
- df .to_parquet (
1108
- path ,
1109
- engine = "fastparquet" ,
1110
- partition_cols = partition_cols ,
1111
- compression = None ,
1112
- )
1113
- assert os .path .exists (path )
1114
- import fastparquet
1104
+ df .to_parquet (
1105
+ tmp_path ,
1106
+ engine = "fastparquet" ,
1107
+ partition_cols = partition_cols ,
1108
+ compression = None ,
1109
+ )
1110
+ assert os .path .exists (tmp_path )
1111
+ import fastparquet
1115
1112
1116
- actual_partition_cols = fastparquet .ParquetFile (path , False ).cats
1117
- assert len (actual_partition_cols ) == 1
1113
+ actual_partition_cols = fastparquet .ParquetFile (str ( tmp_path ) , False ).cats
1114
+ assert len (actual_partition_cols ) == 1
1118
1115
1119
- def test_partition_on_supported (self , fp , df_full ):
1116
+ def test_partition_on_supported (self , tmp_path , fp , df_full ):
1120
1117
# GH #23283
1121
1118
partition_cols = ["bool" , "int" ]
1122
1119
df = df_full
1123
- with tm .ensure_clean_dir () as path :
1124
- df .to_parquet (
1125
- path ,
1126
- engine = "fastparquet" ,
1127
- compression = None ,
1128
- partition_on = partition_cols ,
1129
- )
1130
- assert os .path .exists (path )
1131
- import fastparquet
1120
+ df .to_parquet (
1121
+ tmp_path ,
1122
+ engine = "fastparquet" ,
1123
+ compression = None ,
1124
+ partition_on = partition_cols ,
1125
+ )
1126
+ assert os .path .exists (tmp_path )
1127
+ import fastparquet
1132
1128
1133
- actual_partition_cols = fastparquet .ParquetFile (path , False ).cats
1134
- assert len (actual_partition_cols ) == 2
1129
+ actual_partition_cols = fastparquet .ParquetFile (str ( tmp_path ) , False ).cats
1130
+ assert len (actual_partition_cols ) == 2
1135
1131
1136
- def test_error_on_using_partition_cols_and_partition_on (self , fp , df_full ):
1132
+ def test_error_on_using_partition_cols_and_partition_on (
1133
+ self , tmp_path , fp , df_full
1134
+ ):
1137
1135
# GH #23283
1138
1136
partition_cols = ["bool" , "int" ]
1139
1137
df = df_full
@@ -1142,14 +1140,13 @@ def test_error_on_using_partition_cols_and_partition_on(self, fp, df_full):
1142
1140
"partitioning data"
1143
1141
)
1144
1142
with pytest .raises (ValueError , match = msg ):
1145
- with tm .ensure_clean_dir () as path :
1146
- df .to_parquet (
1147
- path ,
1148
- engine = "fastparquet" ,
1149
- compression = None ,
1150
- partition_on = partition_cols ,
1151
- partition_cols = partition_cols ,
1152
- )
1143
+ df .to_parquet (
1144
+ tmp_path ,
1145
+ engine = "fastparquet" ,
1146
+ compression = None ,
1147
+ partition_on = partition_cols ,
1148
+ partition_cols = partition_cols ,
1149
+ )
1153
1150
1154
1151
def test_empty_dataframe (self , fp ):
1155
1152
# GH #27339
0 commit comments