-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REF: implement get_unit_from_dtype (#46410)
* REF: implement get_unit_from_dtype * avoid cpplint complaint
- Loading branch information
1 parent
fa7e31b
commit 55d1aca
Showing
7 changed files
with
89 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
import numpy as np | ||
|
||
class OutOfBoundsDatetime(ValueError): ... | ||
|
||
# only exposed for testing | ||
def py_get_unit_from_dtype(dtype: np.dtype): ... |
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,37 @@ | ||
import numpy as np | ||
|
||
from pandas._libs.tslibs.np_datetime import py_get_unit_from_dtype | ||
|
||
|
||
def test_get_unit_from_dtype(): | ||
# datetime64 | ||
assert py_get_unit_from_dtype(np.dtype("M8[Y]")) == 0 | ||
assert py_get_unit_from_dtype(np.dtype("M8[M]")) == 1 | ||
assert py_get_unit_from_dtype(np.dtype("M8[W]")) == 2 | ||
# B has been deprecated and removed -> no 3 | ||
assert py_get_unit_from_dtype(np.dtype("M8[D]")) == 4 | ||
assert py_get_unit_from_dtype(np.dtype("M8[h]")) == 5 | ||
assert py_get_unit_from_dtype(np.dtype("M8[m]")) == 6 | ||
assert py_get_unit_from_dtype(np.dtype("M8[s]")) == 7 | ||
assert py_get_unit_from_dtype(np.dtype("M8[ms]")) == 8 | ||
assert py_get_unit_from_dtype(np.dtype("M8[us]")) == 9 | ||
assert py_get_unit_from_dtype(np.dtype("M8[ns]")) == 10 | ||
assert py_get_unit_from_dtype(np.dtype("M8[ps]")) == 11 | ||
assert py_get_unit_from_dtype(np.dtype("M8[fs]")) == 12 | ||
assert py_get_unit_from_dtype(np.dtype("M8[as]")) == 13 | ||
|
||
# timedelta64 | ||
assert py_get_unit_from_dtype(np.dtype("m8[Y]")) == 0 | ||
assert py_get_unit_from_dtype(np.dtype("m8[M]")) == 1 | ||
assert py_get_unit_from_dtype(np.dtype("m8[W]")) == 2 | ||
# B has been deprecated and removed -> no 3 | ||
assert py_get_unit_from_dtype(np.dtype("m8[D]")) == 4 | ||
assert py_get_unit_from_dtype(np.dtype("m8[h]")) == 5 | ||
assert py_get_unit_from_dtype(np.dtype("m8[m]")) == 6 | ||
assert py_get_unit_from_dtype(np.dtype("m8[s]")) == 7 | ||
assert py_get_unit_from_dtype(np.dtype("m8[ms]")) == 8 | ||
assert py_get_unit_from_dtype(np.dtype("m8[us]")) == 9 | ||
assert py_get_unit_from_dtype(np.dtype("m8[ns]")) == 10 | ||
assert py_get_unit_from_dtype(np.dtype("m8[ps]")) == 11 | ||
assert py_get_unit_from_dtype(np.dtype("m8[fs]")) == 12 | ||
assert py_get_unit_from_dtype(np.dtype("m8[as]")) == 13 |