MCPcopy
hub / github.com/pandas-dev/pandas / write

Method write

pandas/io/parquet.py:298–349  ·  view source on GitHub ↗
(
        self,
        df: DataFrame,
        path,
        compression: Literal["snappy", "gzip", "brotli"] | None = "snappy",
        index=None,
        partition_cols=None,
        storage_options: StorageOptions | None = None,
        filesystem=None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

296 self.api = fastparquet
297
298 def write(
299 self,
300 df: DataFrame,
301 path,
302 compression: Literal["snappy", "gzip", "brotli"] | None = "snappy",
303 index=None,
304 partition_cols=None,
305 storage_options: StorageOptions | None = None,
306 filesystem=None,
307 **kwargs,
308 ) -> None:
309 self.validate_dataframe(df)
310
311 if "partition_on" in kwargs and partition_cols is not None:
312 raise ValueError(
313 "Cannot use both partition_on and "
314 "partition_cols. Use partition_cols for partitioning data"
315 )
316 if "partition_on" in kwargs:
317 partition_cols = kwargs.pop("partition_on")
318
319 if partition_cols is not None:
320 kwargs["file_scheme"] = "hive"
321
322 if filesystem is not None:
323 raise NotImplementedError(
324 "filesystem is not implemented for the fastparquet engine."
325 )
326
327 # cannot use get_handle as write() does not accept file buffers
328 path = stringify_path(path)
329 if is_fsspec_url(path):
330 fsspec = import_optional_dependency("fsspec")
331
332 # if filesystem is provided by fsspec, file must be opened in 'wb' mode.
333 kwargs["open_with"] = lambda path, _: fsspec.open(
334 path, "wb", **(storage_options or {})
335 ).open()
336 elif storage_options:
337 raise ValueError(
338 "storage_options passed with file object or non-fsspec file path"
339 )
340
341 with catch_warnings(record=True):
342 self.api.write(
343 path,
344 df,
345 compression=compression,
346 write_index=index,
347 partition_on=partition_cols,
348 **kwargs,
349 )
350
351 def read(
352 self,

Callers

nothing calls this directly

Calls 7

stringify_pathFunction · 0.90
is_fsspec_urlFunction · 0.90
validate_dataframeMethod · 0.80
popMethod · 0.45
openMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected