forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix and test incorrect case in delta_to_nanoseconds (pandas-dev#23302)
- Loading branch information
1 parent
f6e5e2b
commit 708e0b1
Showing
5 changed files
with
51 additions
and
13 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
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,40 @@ | ||
# -*- coding: utf-8 -*- | ||
import numpy as np | ||
import pytest | ||
|
||
import pandas as pd | ||
from pandas._libs.tslibs.timedeltas import delta_to_nanoseconds | ||
|
||
|
||
def test_delta_to_nanoseconds(): | ||
obj = np.timedelta64(14, 'D') | ||
result = delta_to_nanoseconds(obj) | ||
assert result == 14 * 24 * 3600 * 1e9 | ||
|
||
obj = pd.Timedelta(minutes=-7) | ||
result = delta_to_nanoseconds(obj) | ||
assert result == -7 * 60 * 1e9 | ||
|
||
obj = pd.Timedelta(minutes=-7).to_pytimedelta() | ||
result = delta_to_nanoseconds(obj) | ||
assert result == -7 * 60 * 1e9 | ||
|
||
obj = pd.offsets.Nano(125) | ||
result = delta_to_nanoseconds(obj) | ||
assert result == 125 | ||
|
||
obj = 1 | ||
result = delta_to_nanoseconds(obj) | ||
assert obj == 1 | ||
|
||
obj = np.int64(2) | ||
result = delta_to_nanoseconds(obj) | ||
assert obj == 2 | ||
|
||
obj = np.int32(3) | ||
result = delta_to_nanoseconds(obj) | ||
assert result == 3 | ||
|
||
obj = np.array([123456789], dtype='m8[ns]') | ||
with pytest.raises(TypeError): | ||
delta_to_nanoseconds(obj) |