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

Function field

python/pyarrow/jvm.py:199–256  ·  view source on GitHub ↗

Construct a Field from a org.apache.arrow.vector.types.pojo.Field instance. Parameters ---------- jvm_field: org.apache.arrow.vector.types.pojo.Field Returns ------- pyarrow.Field

(jvm_field)

Source from the content-addressed store, hash-verified

197
198
199def field(jvm_field):
200 """
201 Construct a Field from a org.apache.arrow.vector.types.pojo.Field
202 instance.
203
204 Parameters
205 ----------
206 jvm_field: org.apache.arrow.vector.types.pojo.Field
207
208 Returns
209 -------
210 pyarrow.Field
211 """
212 name = str(jvm_field.getName())
213 jvm_type = jvm_field.getType()
214
215 typ = None
216 if not jvm_type.isComplex():
217 type_str = jvm_type.getTypeID().toString()
218 if type_str == 'Null':
219 typ = pa.null()
220 elif type_str == 'Int':
221 typ = _from_jvm_int_type(jvm_type)
222 elif type_str == 'FloatingPoint':
223 typ = _from_jvm_float_type(jvm_type)
224 elif type_str == 'Utf8':
225 typ = pa.string()
226 elif type_str == 'Binary':
227 typ = pa.binary()
228 elif type_str == 'FixedSizeBinary':
229 typ = pa.binary(jvm_type.getByteWidth())
230 elif type_str == 'Bool':
231 typ = pa.bool_()
232 elif type_str == 'Time':
233 typ = _from_jvm_time_type(jvm_type)
234 elif type_str == 'Timestamp':
235 typ = _from_jvm_timestamp_type(jvm_type)
236 elif type_str == 'Date':
237 typ = _from_jvm_date_type(jvm_type)
238 elif type_str == 'Decimal':
239 typ = pa.decimal128(jvm_type.getPrecision(), jvm_type.getScale())
240 else:
241 raise NotImplementedError(
242 f"Unsupported JVM type: {type_str}")
243 else:
244 # TODO: The following JVM types are not implemented:
245 # Struct, List, FixedSizeList, Union, Dictionary
246 raise NotImplementedError(
247 "JVM field conversion only implemented for primitive types.")
248
249 nullable = jvm_field.isNullable()
250 jvm_metadata = jvm_field.getMetadata()
251 if jvm_metadata.isEmpty():
252 metadata = None
253 else:
254 metadata = {str(entry.getKey()): str(entry.getValue())
255 for entry in jvm_metadata.entrySet()}
256 return pa.field(name, typ, nullable, metadata)

Callers 12

schemaFunction · 0.70
arrayFunction · 0.70
GetStructTypeMethod · 0.50
TestSessionFunction · 0.50
makeMethod · 0.50
Field__initializeFunction · 0.50
InferSchemaFromDotsFunction · 0.50
Schema__from_listFunction · 0.50

Calls 11

_from_jvm_int_typeFunction · 0.85
_from_jvm_float_typeFunction · 0.85
_from_jvm_time_typeFunction · 0.85
_from_jvm_timestamp_typeFunction · 0.85
_from_jvm_date_typeFunction · 0.85
getNameMethod · 0.80
getTypeIDMethod · 0.80
getTypeMethod · 0.45
toStringMethod · 0.45
stringMethod · 0.45
fieldMethod · 0.45

Tested by 2

TestSessionFunction · 0.40