(
self,
df: DataFrame,
path: FilePath | WriteBuffer[bytes],
compression: ParquetCompressionOptions = "snappy",
index: bool | None = None,
storage_options: StorageOptions | None = None,
partition_cols: list[str] | None = None,
filesystem=None,
**kwargs,
)
| 172 | self.api = pyarrow |
| 173 | |
| 174 | def write( |
| 175 | self, |
| 176 | df: DataFrame, |
| 177 | path: FilePath | WriteBuffer[bytes], |
| 178 | compression: ParquetCompressionOptions = "snappy", |
| 179 | index: bool | None = None, |
| 180 | storage_options: StorageOptions | None = None, |
| 181 | partition_cols: list[str] | None = None, |
| 182 | filesystem=None, |
| 183 | **kwargs, |
| 184 | ) -> None: |
| 185 | self.validate_dataframe(df) |
| 186 | |
| 187 | from_pandas_kwargs: dict[str, Any] = {"schema": kwargs.pop("schema", None)} |
| 188 | if index is not None: |
| 189 | from_pandas_kwargs["preserve_index"] = index |
| 190 | |
| 191 | table = self.api.Table.from_pandas(df, **from_pandas_kwargs) |
| 192 | |
| 193 | if df.attrs: |
| 194 | df_metadata = {"PANDAS_ATTRS": json.dumps(df.attrs)} |
| 195 | existing_metadata = table.schema.metadata |
| 196 | merged_metadata = {**existing_metadata, **df_metadata} |
| 197 | table = table.replace_schema_metadata(merged_metadata) |
| 198 | |
| 199 | path_or_handle, handles, filesystem = _get_path_or_handle( |
| 200 | path, |
| 201 | filesystem, |
| 202 | storage_options=storage_options, |
| 203 | mode="wb", |
| 204 | is_dir=partition_cols is not None, |
| 205 | ) |
| 206 | if ( |
| 207 | isinstance(path_or_handle, io.BufferedWriter) |
| 208 | and hasattr(path_or_handle, "name") |
| 209 | and isinstance(path_or_handle.name, (str, bytes)) |
| 210 | ): |
| 211 | if isinstance(path_or_handle.name, bytes): |
| 212 | path_or_handle = path_or_handle.name.decode() |
| 213 | else: |
| 214 | path_or_handle = path_or_handle.name |
| 215 | |
| 216 | try: |
| 217 | if partition_cols is not None: |
| 218 | # writes to multiple files under the given path |
| 219 | self.api.parquet.write_to_dataset( |
| 220 | table, |
| 221 | path_or_handle, |
| 222 | compression=compression, |
| 223 | partition_cols=partition_cols, |
| 224 | filesystem=filesystem, |
| 225 | **kwargs, |
| 226 | ) |
| 227 | else: |
| 228 | # write to single output file |
| 229 | self.api.parquet.write_table( |
| 230 | table, |
| 231 | path_or_handle, |
nothing calls this directly
no test coverage detected