Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.api.extensions.ExtensionDtype#

classpandas.api.extensions.ExtensionDtype[source]#

A custom data type, to be paired with an ExtensionArray.

See also

extensions.register_extension_dtype

Register an ExtensionType with pandas as class decorator.

extensions.ExtensionArray

Abstract base class for custom 1-D array types.

Notes

The interface includes the following abstract methods that mustbe implemented by subclasses:

  • type

  • name

  • construct_array_type

The following attributes and methods influence the behavior of the dtype inpandas operations

  • _is_numeric

  • _is_boolean

  • _get_common_dtype

Thena_value class attribute can be used to set the default NA valuefor this type.numpy.nan is used by default.

ExtensionDtypes are required to be hashable. The base class providesa default implementation, which relies on the_metadata classattribute._metadata should be a tuple containing the stringsthat define your data type. For example, withPeriodDtype that’sthefreq attribute.

If you have a parametrized dtype you should set the ``_metadata``class property.

Ideally, the attributes in_metadata will match theparameters to yourExtensionDtype.__init__ (if any). If any ofthe attributes in_metadata don’t implement the standard__eq__ or__hash__, the default implementations here will notwork.

Examples

For interaction with Apache Arrow (pyarrow), a__from_arrow__ methodcan be implemented: this method receives a pyarrow Array or ChunkedArrayas only argument and is expected to return the appropriate pandasExtensionArray for this dtype and the passed values:

>>>importpyarrow>>>frompandas.api.extensionsimportExtensionArray>>>classExtensionDtype:...def__from_arrow__(...self,...array:pyarrow.Array|pyarrow.ChunkedArray...)->ExtensionArray:......

This class does not inherit from ‘abc.ABCMeta’ for performance reasons.Methods and properties required by the interface raisepandas.errors.AbstractMethodError and noregister method isprovided for registering virtual subclasses.

Attributes

index_class

The Index subclass to return from Index.__new__ when this dtype is encountered.

kind

A character code (one of 'biufcmMOSUV'), default 'O'

na_value

Default NA value to use for this type.

name

A string identifying the data type.

names

Ordered list of field names, or None if there are no fields.

type

The scalar type for the array, e.g.int.

Methods

construct_array_type()

Return the array type associated with this dtype.

construct_from_string(string)

Construct this type from a string.

empty(shape)

Construct an ExtensionArray of this dtype with the given shape.

is_dtype(dtype)

Check if we match 'dtype'.


[8]ページ先頭

©2009-2025 Movatter.jp