Write a pandas.DataFrame to Feather format. Parameters ---------- df : pandas.DataFrame or pyarrow.Table Data to write out as Feather format. dest : str Local destination path. compression : string, default None Can be one of {"zstd", "lz4", "uncompr
(df, dest, compression=None, compression_level=None,
chunksize=None, version=2)
| 113 | |
| 114 | |
| 115 | def write_feather(df, dest, compression=None, compression_level=None, |
| 116 | chunksize=None, version=2): |
| 117 | """ |
| 118 | Write a pandas.DataFrame to Feather format. |
| 119 | |
| 120 | Parameters |
| 121 | ---------- |
| 122 | df : pandas.DataFrame or pyarrow.Table |
| 123 | Data to write out as Feather format. |
| 124 | dest : str |
| 125 | Local destination path. |
| 126 | compression : string, default None |
| 127 | Can be one of {"zstd", "lz4", "uncompressed"}. The default of None uses |
| 128 | LZ4 for V2 files if it is available, otherwise uncompressed. |
| 129 | compression_level : int, default None |
| 130 | Use a compression level particular to the chosen compressor. If None |
| 131 | use the default compression level |
| 132 | chunksize : int, default None |
| 133 | For V2 files, the internal maximum size of Arrow RecordBatch chunks |
| 134 | when writing the Arrow IPC file format. None means use the default, |
| 135 | which is currently 64K |
| 136 | version : int, default 2 |
| 137 | Feather file version. Version 2 is the current. Version 1 is the more |
| 138 | limited legacy format |
| 139 | """ |
| 140 | if _pandas_api.have_pandas: |
| 141 | if (_pandas_api.has_sparse and |
| 142 | isinstance(df, _pandas_api.pd.SparseDataFrame)): |
| 143 | df = df.to_dense() |
| 144 | |
| 145 | if _pandas_api.is_data_frame(df): |
| 146 | # Feather v1 creates a new column in the resultant Table to |
| 147 | # store index information if index type is not RangeIndex |
| 148 | |
| 149 | if version == 1: |
| 150 | preserve_index = False |
| 151 | elif version == 2: |
| 152 | preserve_index = None |
| 153 | else: |
| 154 | raise ValueError("Version value should either be 1 or 2") |
| 155 | |
| 156 | table = Table.from_pandas(df, preserve_index=preserve_index) |
| 157 | |
| 158 | if version == 1: |
| 159 | # Version 1 does not chunking |
| 160 | for i, name in enumerate(table.schema.names): |
| 161 | col = table[i] |
| 162 | check_chunked_overflow(name, col) |
| 163 | else: |
| 164 | table = df |
| 165 | |
| 166 | if version == 1: |
| 167 | if len(table.column_names) > len(set(table.column_names)): |
| 168 | raise ValueError("cannot serialize duplicate column names") |
| 169 | |
| 170 | if compression is not None: |
| 171 | raise ValueError("Feather V1 files do not support compression " |
| 172 | "option") |