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

Function test_metadata_compat_missing_field_name

python/pyarrow/tests/test_pandas.py:4858–4906  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4856
4857
4858def test_metadata_compat_missing_field_name():
4859 # Combination of missing field name but with index column as metadata.
4860 # This combo occurs in the latest versions of fastparquet (0.3.2), but not
4861 # in pyarrow itself (since field_name was added in 0.8, index as metadata
4862 # only added later)
4863
4864 a_values = [1, 2, 3, 4]
4865 b_values = ['a', 'b', 'c', 'd']
4866 a_arrow = pa.array(a_values, type='int64')
4867 b_arrow = pa.array(b_values, type='utf8')
4868
4869 expected = pd.DataFrame({
4870 'a': a_values,
4871 'b': b_values,
4872 }, index=pd.RangeIndex(0, 8, step=2, name='qux'))
4873 table = pa.table({'a': a_arrow, 'b': b_arrow})
4874
4875 # metadata generated by fastparquet 0.3.2 with missing field_names
4876 table = table.replace_schema_metadata({
4877 b'pandas': json.dumps({
4878 'column_indexes': [
4879 {'field_name': None,
4880 'metadata': None,
4881 'name': None,
4882 'numpy_type': 'object',
4883 'pandas_type': 'mixed-integer'}
4884 ],
4885 'columns': [
4886 {'metadata': None,
4887 'name': 'a',
4888 'numpy_type': 'int64',
4889 'pandas_type': 'int64'},
4890 {'metadata': None,
4891 'name': 'b',
4892 'numpy_type': 'object',
4893 'pandas_type': 'unicode'}
4894 ],
4895 'index_columns': [
4896 {'kind': 'range',
4897 'name': 'qux',
4898 'start': 0,
4899 'step': 2,
4900 'stop': 8}
4901 ],
4902 'pandas_version': '0.25.0'}
4903
4904 )})
4905 result = table.to_pandas()
4906 tm.assert_frame_equal(result, expected)
4907
4908
4909def test_metadata_index_name_not_json_serializable():

Callers

nothing calls this directly

Calls 2

dumpsMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected