-
-
Notifications
You must be signed in to change notification settings - Fork 144
Support an ExtensionDtype and ExtensionArray #554
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
Changes from 3 commits
4bae5e7
011af56
2edb805
fb1c15b
fb9a7ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
from enum import Enum | ||
from typing import ( | ||
Final, | ||
Literal, | ||
) | ||
|
||
import numpy as np | ||
from pandas import Interval | ||
from typing_extensions import ( | ||
TypeAlias, | ||
TypeGuard, | ||
) | ||
|
||
class _NoDefault(Enum): | ||
no_default = ... | ||
|
||
no_default: Final = _NoDefault.no_default | ||
NoDefault: TypeAlias = Literal[_NoDefault.no_default] | ||
|
||
def infer_dtype(value: object, skipna: bool = ...) -> str: ... | ||
def is_iterator(obj: object) -> bool: ... | ||
def is_scalar(val: object) -> bool: ... | ||
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ... | ||
def is_interval(val: object) -> bool: ... | ||
def is_complex(val: object) -> bool: ... | ||
def is_bool(val: object) -> bool: ... | ||
def is_integer(val: object) -> bool: ... | ||
def is_float(val: object) -> bool: ... | ||
def is_interval(val: object) -> TypeGuard[Interval]: ... | ||
def is_complex(val: object) -> TypeGuard[complex]: ... | ||
def is_bool(val: object) -> TypeGuard[bool | np.bool_]: ... | ||
def is_integer(val: object) -> TypeGuard[int | np.integer]: ... | ||
def is_float(val: object) -> TypeGuard[float]: ... | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,8 @@ class WriteExcelBuffer(WriteBuffer[bytes], Protocol): | |
|
||
FilePath: TypeAlias = str | PathLike[str] | ||
|
||
Axis: TypeAlias = str | int | ||
AxisInt: TypeAlias = Literal[0, 1] | ||
Axis: TypeAlias = AxisInt | Literal["index", "columns", "rows"] | ||
Comment on lines
-169
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @twoertwein @Dr-Irv While I understand the intention, this one causes a problem with the following types from Pandas:
The order parameter expects a sequence of ints or strings - with this change this is forbidden. From my code:
PS: Sorry for not creating an issue (yet). I am short on time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When you do have the time, please create an issue with a full code sample. This has picked up that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we go: #560 |
||
IndexLabel: TypeAlias = Hashable | Sequence[Hashable] | ||
Label: TypeAlias = Hashable | None | ||
Level: TypeAlias = Hashable | int | ||
|
@@ -293,6 +294,8 @@ IntervalT = TypeVar( | |
) | ||
IntervalClosedType: TypeAlias = Literal["left", "right", "both", "neither"] | ||
|
||
TakeIndexer: TypeAlias = Sequence[int] | Sequence[np.integer] | npt.NDArray[np.integer] | ||
|
||
IgnoreRaiseCoerce: TypeAlias = Literal["ignore", "raise", "coerce"] | ||
|
||
# Shared by functions such as drop and astype | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
from typing import Literal | ||
from typing import ( | ||
Any, | ||
Literal, | ||
) | ||
|
||
from pandas.core.arrays import ExtensionArray | ||
|
||
from pandas._libs import NaTType | ||
from pandas._libs.missing import NAType | ||
from pandas._typing import type_t | ||
|
||
class ExtensionDtype: | ||
@property | ||
def na_value(self) -> NAType | NaTType: ... | ||
@property | ||
def type(self) -> type_t: ... | ||
type: type_t | ||
na_value: Any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it turns out while pandas implements them as properties, from a typing perspective, they are really class variables, so I annotated them that way in the next commit. Throughout pandas, we just set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't be surpsrised if they are used inconsistently within pandas :( in some places as properties, in some as normal attributes and in some as class variables. I just grepped through pandas/core/dtypes, I didn't find a single line that assigns a value to a class variable If they are class variables, can you add a quick If the pandas tests set it for simplicity/laziness to a class varaible (which is fine with me), we can just add an ignore to them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Take a look at I believe it's declared as a property in For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wounder why mypy/pyright didn't catch that. Maybe because a parent class re-declares There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was wondering the same thing. In reality, |
||
name: str | ||
|
||
@property | ||
def kind( | ||
self, | ||
) -> Literal["b", "i", "u", "f", "c", "m", "M", "O", "S", "U", "V"]: ... | ||
@property | ||
def name(self) -> str: ... | ||
@property | ||
def names(self) -> list[str] | None: ... | ||
def empty(self, size: int | tuple[int, ...]) -> type_t[ExtensionArray]: ... | ||
@classmethod | ||
|
Uh oh!
There was an error while loading. Please reload this page.