|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | + |
| 16 | +import datetime |
| 17 | + |
| 18 | +import pandas as pd |
15 | 19 | import pandas.testing |
16 | 20 |
|
17 | 21 | from bigframes import dtypes |
18 | 22 |
|
19 | 23 |
|
| 24 | +def test_date_diff_between_series(session): |
| 25 | + pd_df = pd.DataFrame( |
| 26 | + { |
| 27 | + "col_1": [datetime.date(2025, 1, 2), datetime.date(2025, 2, 1)], |
| 28 | + "col_2": [datetime.date(2024, 1, 2), datetime.date(2026, 1, 30)], |
| 29 | + } |
| 30 | + ).astype(dtypes.DATE_DTYPE) |
| 31 | + bf_df = session.read_pandas(pd_df) |
| 32 | + |
| 33 | + actual_result = (bf_df["col_1"] - bf_df["col_2"]).to_pandas() |
| 34 | + |
| 35 | + expected_result = (pd_df["col_1"] - pd_df["col_2"]).astype(dtypes.TIMEDELTA_DTYPE) |
| 36 | + pandas.testing.assert_series_equal( |
| 37 | + actual_result, expected_result, check_index_type=False |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +def test_date_diff_literal_sub_series(scalars_dfs): |
| 42 | + bf_df, pd_df = scalars_dfs |
| 43 | + literal = datetime.date(2030, 5, 20) |
| 44 | + |
| 45 | + actual_result = (literal - bf_df["date_col"]).to_pandas() |
| 46 | + |
| 47 | + expected_result = (literal - pd_df["date_col"]).astype(dtypes.TIMEDELTA_DTYPE) |
| 48 | + pandas.testing.assert_series_equal( |
| 49 | + actual_result, expected_result, check_index_type=False |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | +def test_date_diff_series_sub_literal(scalars_dfs): |
| 54 | + bf_df, pd_df = scalars_dfs |
| 55 | + literal = datetime.date(1980, 5, 20) |
| 56 | + |
| 57 | + actual_result = (bf_df["date_col"] - literal).to_pandas() |
| 58 | + |
| 59 | + expected_result = (pd_df["date_col"] - literal).astype(dtypes.TIMEDELTA_DTYPE) |
| 60 | + pandas.testing.assert_series_equal( |
| 61 | + actual_result, expected_result, check_index_type=False |
| 62 | + ) |
| 63 | + |
| 64 | + |
20 | 65 | def test_date_series_diff_agg(scalars_dfs): |
21 | 66 | bf_df, pd_df = scalars_dfs |
22 | 67 |
|
|
0 commit comments