Skip to content

Instantly share code, notes, and snippets.

@Finndersen
Created December 30, 2022 20:52
Show Gist options
  • Save Finndersen/49c16975740b93981c24d1428bab097c to your computer and use it in GitHub Desktop.
Save Finndersen/49c16975740b93981c24d1428bab097c to your computer and use it in GitHub Desktop.
VectorDtype definition for Pandas Extension Types example
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