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

Function multisourcefs

python/pyarrow/tests/test_dataset.py:220–268  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

218
219@pytest.fixture(scope='module')
220def multisourcefs(request):
221 request.config.pyarrow.requires('pandas')
222 request.config.pyarrow.requires('parquet')
223
224 df = _generate_data(1000)
225 mockfs = fs._MockFileSystem()
226
227 # simply split the dataframe into four chunks to construct a data source
228 # from each chunk into its own directory
229 n = len(df)
230 df_a, df_b, df_c, df_d = [df.iloc[i:i+n//4] for i in range(0, n, n//4)]
231
232 # create a directory containing a flat sequence of parquet files without
233 # any partitioning involved
234 mockfs.create_dir('plain')
235 n = len(df_a)
236 for i, chunk in enumerate([df_a.iloc[i:i+n//10] for i in range(0, n, n//10)]):
237 path = f'plain/chunk-{i}.parquet'
238 with mockfs.open_output_stream(path) as out:
239 pq.write_table(_table_from_pandas(chunk), out)
240
241 # create one with schema partitioning by weekday and color
242 mockfs.create_dir('schema')
243 for part, chunk in df_b.groupby([df_b.date.dt.dayofweek, df_b.color]):
244 folder = f'schema/{part[0]}/{part[1]}'
245 path = f'{folder}/chunk.parquet'
246 mockfs.create_dir(folder)
247 with mockfs.open_output_stream(path) as out:
248 pq.write_table(_table_from_pandas(chunk), out)
249
250 # create one with hive partitioning by year and month
251 mockfs.create_dir('hive')
252 for part, chunk in df_c.groupby([df_c.date.dt.year, df_c.date.dt.month]):
253 folder = f'hive/year={part[0]}/month={part[1]}'
254 path = f'{folder}/chunk.parquet'
255 mockfs.create_dir(folder)
256 with mockfs.open_output_stream(path) as out:
257 pq.write_table(_table_from_pandas(chunk), out)
258
259 # create one with hive partitioning by color
260 mockfs.create_dir('hive_color')
261 for part, chunk in df_d.groupby("color"):
262 folder = f'hive_color/color={part}'
263 path = f'{folder}/chunk.parquet'
264 mockfs.create_dir(folder)
265 with mockfs.open_output_stream(path) as out:
266 pq.write_table(_table_from_pandas(chunk), out)
267
268 return mockfs
269
270
271@pytest.fixture

Callers

nothing calls this directly

Calls 7

_generate_dataFunction · 0.85
lenFunction · 0.85
_table_from_pandasFunction · 0.85
requiresMethod · 0.80
create_dirMethod · 0.45
open_output_streamMethod · 0.45
write_tableMethod · 0.45

Tested by

no test coverage detected