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

Function test_partitioning_factory_dictionary

python/pyarrow/tests/test_dataset.py:2002–2031  ·  view source on GitHub ↗
(mockfs, infer_dictionary, pickled,
                                         pickle_module)

Source from the content-addressed store, hash-verified

2000@pytest.mark.parametrize(
2001 "pickled", [lambda x, m: x, lambda x, m: m.loads(m.dumps(x))])
2002def test_partitioning_factory_dictionary(mockfs, infer_dictionary, pickled,
2003 pickle_module):
2004 paths_or_selector = fs.FileSelector('subdir', recursive=True)
2005 format = ds.ParquetFileFormat()
2006 options = ds.FileSystemFactoryOptions('subdir')
2007
2008 partitioning_factory = ds.DirectoryPartitioning.discover(
2009 ['group', 'key'], infer_dictionary=infer_dictionary)
2010 options.partitioning_factory = pickled(partitioning_factory, pickle_module)
2011
2012 factory = ds.FileSystemDatasetFactory(
2013 mockfs, paths_or_selector, format, options)
2014
2015 inferred_schema = factory.inspect()
2016 if infer_dictionary:
2017 expected_type = pa.dictionary(pa.int32(), pa.string())
2018 assert inferred_schema.field('key').type == expected_type
2019
2020 table = factory.finish().to_table().combine_chunks()
2021 actual = table.column('key').chunk(0)
2022 expected = pa.array(['xxx'] * 5 + ['yyy'] * 5).dictionary_encode()
2023 assert actual.equals(expected)
2024
2025 # ARROW-9345 ensure filtering on the partition field works
2026 table = factory.finish().to_table(filter=ds.field('key') == 'xxx')
2027 actual = table.column('key').chunk(0)
2028 expected = expected.slice(0, 5)
2029 assert actual.equals(expected)
2030 else:
2031 assert inferred_schema.field('key').type == pa.string()
2032
2033
2034@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 12

ParquetFileFormatMethod · 0.80
equalsMethod · 0.80
inspectMethod · 0.45
dictionaryMethod · 0.45
stringMethod · 0.45
fieldMethod · 0.45
to_tableMethod · 0.45
finishMethod · 0.45
columnMethod · 0.45
arrayMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected