-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from lincc-frameworks/dtype-reimpl
Dtype reimplementation
- Loading branch information
Showing
9 changed files
with
332 additions
and
76 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Missing value for NestedDtype | ||
It i something between pandas' NA and NaN | ||
""" | ||
|
||
__all__ = ["NAType", "NA"] | ||
|
||
|
||
class _NAType: | ||
pass | ||
|
||
|
||
class NAType: | ||
"""Singleton class representing missing value for NestedDtype. | ||
It doesn't implement most of the arithmetics and boolean logic operations, | ||
because they are ambiguous for missing values. | ||
The implementation is inspired both by pandas' NA and float number NaN. | ||
`NA` is a singleton instance of this class. | ||
""" | ||
|
||
_instance = None | ||
|
||
def __new__(cls, *args, **kwargs): | ||
"""Create a new instance of NAType.""" | ||
if cls._instance is None: | ||
cls._instance = super().__new__(cls) | ||
return cls._instance | ||
|
||
def __repr__(self) -> str: | ||
return "<NA>" | ||
|
||
def __format__(self, format_spec) -> str: | ||
try: | ||
return self.__repr__().__format__(format_spec) | ||
except ValueError: | ||
return self.__repr__() | ||
|
||
def __bool__(self): | ||
raise TypeError("boolean value of NA is ambiguous") | ||
|
||
def __eq__(self, other): | ||
return False | ||
|
||
def __ne__(self, other): | ||
return True | ||
|
||
def __hash__(self): | ||
return 0 | ||
|
||
|
||
NA = NAType() | ||
"""Missed value for NestedDtype, a singleton instance of `NAType` class.""" |
Oops, something went wrong.