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
from functools import total_ordering | |
from math import sqrt | |
@total_ordering | |
class Vector(object): | |
""" | |
Simple class to represent a 2D vector with X and Y components. | |
Could extend with more useful methods etc | |
""" | |
def __init__(self, x, y): |
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 | |
""" |
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
class VectorArray(ExtensionScalarOpsMixin, ExtensionArray): | |
""" | |
Custom Extension Array type for an array of Vectors | |
Needs to define: | |
- Associated Dtype it is used with | |
- How to construct array from sequence of scalars | |
- How data is stored and accessed | |
- Any custom array methods | |
""" |