(
self,
df: DataFrame,
path,
compression: Literal["snappy", "gzip", "brotli"] | None = "snappy",
index=None,
partition_cols=None,
storage_options: StorageOptions | None = None,
filesystem=None,
**kwargs,
)
| 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, |
nothing calls this directly
no test coverage detected