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

Function get_column_metadata

python/pyarrow/pandas_compat.py:150–194  ·  view source on GitHub ↗

Construct the metadata for a given column Parameters ---------- column : pandas.Series or pandas.Index name : str arrow_type : pyarrow.DataType field_name : str Equivalent to `name` when `column` is a `Series`, otherwise if `column` is a pandas Index then `fi

(column, name, arrow_type, field_name)

Source from the content-addressed store, hash-verified

148
149
150def get_column_metadata(column, name, arrow_type, field_name):
151 """Construct the metadata for a given column
152
153 Parameters
154 ----------
155 column : pandas.Series or pandas.Index
156 name : str
157 arrow_type : pyarrow.DataType
158 field_name : str
159 Equivalent to `name` when `column` is a `Series`, otherwise if `column`
160 is a pandas Index then `field_name` will not be the same as `name`.
161 This is the name of the field in the arrow Table's schema.
162
163 Returns
164 -------
165 dict
166 """
167 logical_type = get_logical_type(arrow_type)
168
169 string_dtype, extra_metadata = get_extension_dtype_info(column)
170 if logical_type == 'decimal':
171 extra_metadata = {
172 'precision': arrow_type.precision,
173 'scale': arrow_type.scale,
174 }
175 string_dtype = 'object'
176
177 if (
178 name is not None
179 and not (isinstance(name, float) and np.isnan(name))
180 and not isinstance(name, str)
181 ):
182 raise TypeError(
183 f"Column name must be a string. Got column {name} of type "
184 f"{type(name).__name__}"
185 )
186
187 assert isinstance(field_name, str), str(type(field_name))
188 return {
189 'name': name,
190 'field_name': field_name,
191 'pandas_type': logical_type,
192 'numpy_type': string_dtype,
193 'metadata': extra_metadata,
194 }
195
196
197def construct_metadata(columns_to_convert, df, column_names, index_levels,

Callers 1

construct_metadataFunction · 0.85

Calls 4

get_extension_dtype_infoFunction · 0.85
get_logical_typeFunction · 0.70
TypeErrorFunction · 0.50
typeEnum · 0.50

Tested by

no test coverage detected