Created
December 30, 2022 20:52
-
-
Save Finndersen/49c16975740b93981c24d1428bab097c to your computer and use it in GitHub Desktop.
VectorDtype definition for Pandas Extension Types example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from pandas.core.dtypes.dtypes import PandasExtensionDtype | |
from pandas.api.extensions import ExtensionArray, ExtensionScalarOpsMixin, register_extension_dtype | |
@register_extension_dtype | |
class VectorDtype(PandasExtensionDtype): | |
""" | |
Class to describe the custom Vector data type | |
""" | |
type = Vector # Scalar type for data | |
name = 'vector' # String identifying the data type name | |
@classmethod | |
def construct_array_type(cls): | |
""" | |
Return array type associated with this dtype | |
""" | |
return VectorArray | |
def __str__(self): | |
return self.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment