-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address distinction between DataType and DataType() (#3857)
- Loading branch information
1 parent
3b4ea61
commit 95f4683
Showing
3 changed files
with
42 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import inspect | ||
|
||
import polars as pl | ||
import polars.datatypes as datatypes | ||
|
||
|
||
def test_dtype_init_equivalence() -> None: | ||
# check "DataType.__new__" behaviour for all datatypes | ||
all_datatypes = set( | ||
dtype | ||
for dtype in (getattr(datatypes, attr) for attr in dir(datatypes)) | ||
if inspect.isclass(dtype) and issubclass(dtype, datatypes.DataType) | ||
) | ||
for dtype in all_datatypes: | ||
assert dtype == dtype() | ||
|
||
|
||
def test_dtype_temporal_units() -> None: | ||
# check (in)equality behaviour of temporal types that take units | ||
for tu in datatypes.DTYPE_TEMPORAL_UNITS: | ||
assert pl.Datetime == pl.Datetime(tu) | ||
assert pl.Duration == pl.Duration(tu) | ||
|
||
assert pl.Datetime(tu) == pl.Datetime() # type: ignore[operator] | ||
assert pl.Duration(tu) == pl.Duration() # type: ignore[operator] | ||
|
||
assert pl.Datetime("ms") != pl.Datetime("ns") | ||
assert pl.Duration("ns") != pl.Duration("us") |