-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: EA._can_hold_na -> EDtype.can_hold_na #41654
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
API: EA._can_hold_na -> EDtype.can_hold_na #41654
Conversation
jbrockmendel
commented
May 24, 2021
- closes API: EA._can_hold_na should be a dtype attribute, not EA #40574
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
pandas/core/arrays/datetimelike.py
Outdated
@@ -158,6 +158,9 @@ class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray): | |||
_is_recognized_dtype: Callable[[DtypeObj], bool] | |||
_recognized_scalars: tuple[type, ...] | |||
_ndarray: np.ndarray | |||
# Incompatible types in assignment (expression has type "bool", base class | |||
# "ExtensionArray" defined the type as "Callable[[ExtensionArray], bool]") | |||
_can_hold_na = True # type: ignore[assignment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if u make this a property (like u do below) then can avoid the typing issue
# (previously declared in base class "Block") | ||
_can_hold_na = False # type: ignore[misc] | ||
# Incompatible types in assignment (expression has type "bool", base class | ||
# "Block" defined the type as "Callable[[Block], bool]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @jorisvandenbossche if any comments
actually this is failing precommit |
pre-commit fixed |
pandas/core/dtypes/base.py
Outdated
@@ -367,6 +367,13 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None: | |||
else: | |||
return None | |||
|
|||
@property | |||
def can_hold_na(self) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be public?
I know this is an existing property on the ExtensionArray, but do we actually support (or want to support) an extension array that cannot hold missing values? (I don't think we currently have one, so this is also not really tested?) |
Except for PandasArray, I assume (but since that's not actually stored in practice, that's a bit a special case anyhow) |
I think |
i've added blocker since I don't think we should change this during the rc. so we either get it in for 1.3.0rc or move to 1.4/2.0 |
is the public/private question (and a rebase) the only outstanding issue? im happy to make this private |
Also the question whether we should have this at all, IMO. And if we have that property, what does it mean? (what's the behaviour for operations like setitem or reindexing that can introduce missing values?) |
I'm open to having this discussion, but I think it can be done separately from the "where should this attribute live" discussion given that it already exists on EA. |
But if we are not yet sure if and how such property would be used, we can also leave it where it is for now? (or what problem is this PR fixing?) If moving it, let's at least make it private and document it that way (as an internal property that no EA author should change, as that is undefined behaviour) |
The corner cases I want to rule out are where can_hold_na is values-dependent and potentially non-constant, e.g. (xref #40574)
|
this lgtm, i agree this should be on the dtype. |
@jorisvandenbossche ok here? |
doc/source/whatsnew/v1.3.0.rst
Outdated
@@ -644,6 +644,7 @@ Other API changes | |||
- Accessing ``_constructor_expanddim`` on a :class:`DataFrame` and ``_constructor_sliced`` on a :class:`Series` now raise an ``AttributeError``. Previously a ``NotImplementedError`` was raised (:issue:`38782`) | |||
- Added new ``engine`` and ``**engine_kwargs`` parameters to :meth:`DataFrame.to_sql` to support other future "SQL engines". Currently we still only use ``SQLAlchemy`` under the hood, but more engines are planned to be supported such as ``turbodbc`` (:issue:`36893`) | |||
- Removed redundant ``freq`` from :class:`PeriodIndex` string representation (:issue:`41653`) | |||
- :attr:`ExtensionArray._can_hold_na` should now be implemented on the :class:`ExtensionDtype` subclass as ``_can_hold_na`` (:issue:`40574`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this mention, if we are not yet clear on the intended semantics of it.
Yeah, I won't object moving it. Just a tiny comment on the whatsnew. |
whatsnew removed + greenish |
Thanks @jbrockmendel |