Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: move MaskedArray subclass attributes to dtypes #58423

Merged
merged 5 commits into from Apr 29, 2024

Conversation

jbrockmendel
Copy link
Member

Discussed on yesterday's dev call, incremental steps towards merging IntegerArray/FloatingArray/BooleanArray into a single class

_internal_fill_value: Scalar

@property
def truthy_value(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be "private" ie `_truthy_value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are accessed from outside the dtype's methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these raise NotImplementedError as a fallback? The idea is this class can be used for more than just float/integer/bool in the future right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think there's any plans to extend like that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought decided to privatize after all

_internal_fill_value: Scalar

@property
def truthy_value(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these raise NotImplementedError as a fallback? The idea is this class can be used for more than just float/integer/bool in the future right?

values = np.empty(shape, dtype=dtype.type)
values.fill(cls._internal_fill_value)
dtype = cast(BaseMaskedDtype, dtype)
values: np.ndarray = np.empty(shape, dtype=dtype.type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the type declaration required here? I assume mypy would be able to infer this from the right hand side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy complained without this

@@ -155,8 +148,9 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self:
@classmethod
@doc(ExtensionArray._empty)
def _empty(cls, shape: Shape, dtype: ExtensionDtype) -> Self:
values = np.empty(shape, dtype=dtype.type)
values.fill(cls._internal_fill_value)
dtype = cast(BaseMaskedDtype, dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast suspicious - why wouldn't we just change the type of dtype to BaseMaskedType if the _internal_fill_value attribute was required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC mypy complains if we do that, but in practice that is correct that we should only ever get BaseMaskedDtype here

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mroeschke mroeschke added the NA - MaskedArrays Related to pd.NA and nullable extension arrays label Apr 29, 2024
@WillAyd WillAyd merged commit a2bce66 into pandas-dev:main Apr 29, 2024
50 checks passed
@WillAyd
Copy link
Member

WillAyd commented Apr 29, 2024

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the ref-maskeddtype branch April 29, 2024 14:23
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants