@@ -184,7 +184,7 @@ def write(
184
184
from_pandas_kwargs : dict [str , Any ] = {"schema" : kwargs .pop ("schema" , None )}
185
185
if index is not None :
186
186
from_pandas_kwargs ["preserve_index" ] = index
187
-
187
+ #ekleme yaptığım yer.
188
188
table = self .api .Table .from_pandas (df , ** from_pandas_kwargs )
189
189
if any (isinstance (dtype ,pd .StringDtype ) for dtype in df .dtype ):
190
190
string_dtype = {
@@ -267,23 +267,35 @@ def read(
267
267
mode = "rb" ,
268
268
)
269
269
try :
270
- pa_table = self .api .parquet .read_table (
271
- metadata = pa_table .schema .metadata
272
- string_dtypes = {}
273
- if metadata :
274
- for key , value in metadata .items ():
275
- if key .startswith (b"pandas_string_dtype_" ):
276
- col_name = key .replace (b"pandas_string_dtype_" , b"" ).decode ()
277
- string_dtypes [col_name ] = value .decode ()
278
-
279
-
280
-
270
+ pa_table = self .api .parquet .read_table (
281
271
path_or_handle ,
282
272
columns = columns ,
283
273
filesystem = filesystem ,
284
274
filters = filters ,
285
275
** kwargs ,
286
276
)
277
+
278
+ #eklediğim bölüm pandas_string_dtype_* metadata'larını oku
279
+ string_dtypes = {}
280
+ metadata = pa_table .schema .metadata
281
+ if metadata :
282
+ for key , value in metadata .items ():
283
+ if key .startswith (b"pandas_string_dtype_" ):
284
+ col_name = key .replace (b"pandas_string_dtype_" , b"" ).decode ()
285
+ string_dtypes [col_name ] = value .decode ()
286
+
287
+ # Eklediğim bölüm: types_mapper fonksiyonu
288
+ def types_mapper (pa_type ):
289
+ for field in pa_table .schema :
290
+ if field .type == pa_type :
291
+ colname = field .name
292
+ if colname in string_dtypes :
293
+ return pd .StringDtype (storage = string_dtypes [colname ])
294
+ return None # fallback to default mapper
295
+
296
+ if to_pandas_kwargs is None :
297
+ to_pandas_kwargs = {}
298
+ to_pandas_kwargs ["types_mapper" ] = types_mapper
287
299
with catch_warnings ():
288
300
filterwarnings (
289
301
"ignore" ,
0 commit comments