|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from typing import cast |
| 16 | +from unittest import mock |
| 17 | + |
| 18 | +import bigframes.core.tools.datetimes |
| 19 | +import bigframes.dtypes |
| 20 | +import bigframes.pandas |
| 21 | +import bigframes.testing.mocks |
| 22 | + |
| 23 | + |
| 24 | +def test_to_datetime_with_series_and_format_doesnt_cache(monkeypatch): |
| 25 | + df = bigframes.testing.mocks.create_dataframe(monkeypatch) |
| 26 | + series = mock.Mock(spec=bigframes.pandas.Series, wraps=df["col"]) |
| 27 | + dt_series = cast( |
| 28 | + bigframes.pandas.Series, |
| 29 | + bigframes.core.tools.datetimes.to_datetime(series, format="%Y%m%d"), |
| 30 | + ) |
| 31 | + series._cached.assert_not_called() |
| 32 | + assert dt_series.dtype == bigframes.dtypes.DATETIME_DTYPE |
| 33 | + |
| 34 | + |
| 35 | +def test_to_datetime_with_series_and_format_utc_doesnt_cache(monkeypatch): |
| 36 | + df = bigframes.testing.mocks.create_dataframe(monkeypatch) |
| 37 | + series = mock.Mock(spec=bigframes.pandas.Series, wraps=df["col"]) |
| 38 | + dt_series = cast( |
| 39 | + bigframes.pandas.Series, |
| 40 | + bigframes.core.tools.datetimes.to_datetime(series, format="%Y%m%d", utc=True), |
| 41 | + ) |
| 42 | + series._cached.assert_not_called() |
| 43 | + assert dt_series.dtype == bigframes.dtypes.TIMESTAMP_DTYPE |
0 commit comments