MCPcopy Create free account
hub / github.com/apache/arrow / write_feather

Function write_feather

python/pyarrow/feather.py:115–195  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

113
114
115def 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")

Callers 15

_check_pandas_roundtripFunction · 0.90
_check_arrow_roundtripFunction · 0.90
fFunction · 0.90
test_datasetFunction · 0.90
test_read_tableFunction · 0.90
test_use_threadsFunction · 0.90
test_overwritten_fileFunction · 0.90
test_filelike_objectsFunction · 0.90
test_v2_set_chunksizeFunction · 0.90

Calls 2

check_chunked_overflowFunction · 0.85
lenFunction · 0.85

Tested by 15

_check_pandas_roundtripFunction · 0.72
_check_arrow_roundtripFunction · 0.72
fFunction · 0.72
test_datasetFunction · 0.72
test_read_tableFunction · 0.72
test_use_threadsFunction · 0.72
test_overwritten_fileFunction · 0.72
test_filelike_objectsFunction · 0.72
test_v2_set_chunksizeFunction · 0.72