Skip to content

Commit d330c5f

Browse files
authored
Write and read function is updated in parquet.py By Gül
1 parent 5295edb commit d330c5f

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

pandas/io/parquet.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def write(
184184
from_pandas_kwargs: dict[str, Any] = {"schema": kwargs.pop("schema", None)}
185185
if index is not None:
186186
from_pandas_kwargs["preserve_index"] = index
187-
187+
#ekleme yaptığım yer.
188188
table = self.api.Table.from_pandas(df, **from_pandas_kwargs)
189189
if any(isinstance(dtype,pd.StringDtype) for dtype in df.dtype):
190190
string_dtype={
@@ -267,23 +267,35 @@ def read(
267267
mode="rb",
268268
)
269269
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(
281271
path_or_handle,
282272
columns=columns,
283273
filesystem=filesystem,
284274
filters=filters,
285275
**kwargs,
286276
)
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
287299
with catch_warnings():
288300
filterwarnings(
289301
"ignore",

0 commit comments

Comments
 (0)