|
| 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 bigframes import operations as ops |
| 16 | +from bigframes import series |
| 17 | + |
| 18 | + |
| 19 | +def unix_seconds(input: series.Series) -> series.Series: |
| 20 | + """Converts a timestmap series to unix epoch seconds |
| 21 | +
|
| 22 | + **Examples:** |
| 23 | +
|
| 24 | + >>> import pandas as pd |
| 25 | + >>> import bigframes.pandas as bpd |
| 26 | + >>> import bigframes.bigquery as bbq |
| 27 | + >>> bpd.options.display.progress_bar = None |
| 28 | +
|
| 29 | + >>> s = bpd.Series([pd.Timestamp("1970-01-02", tz="UTC"), pd.Timestamp("1970-01-03", tz="UTC")]) |
| 30 | + >>> bbq.unix_seconds(s) |
| 31 | + 0 86400 |
| 32 | + 1 172800 |
| 33 | + dtype: Int64 |
| 34 | +
|
| 35 | + Args: |
| 36 | + input (bigframes.pandas.Series): |
| 37 | + A timestamp series. |
| 38 | +
|
| 39 | + Returns: |
| 40 | + bigframes.pandas.Series: A new series of unix epoch in seconds. |
| 41 | +
|
| 42 | + """ |
| 43 | + return input._apply_unary_op(ops.UnixSeconds()) |
| 44 | + |
| 45 | + |
| 46 | +def unix_millis(input: series.Series) -> series.Series: |
| 47 | + """Converts a timestmap series to unix epoch milliseconds |
| 48 | +
|
| 49 | + **Examples:** |
| 50 | +
|
| 51 | + >>> import pandas as pd |
| 52 | + >>> import bigframes.pandas as bpd |
| 53 | + >>> import bigframes.bigquery as bbq |
| 54 | + >>> bpd.options.display.progress_bar = None |
| 55 | +
|
| 56 | + >>> s = bpd.Series([pd.Timestamp("1970-01-02", tz="UTC"), pd.Timestamp("1970-01-03", tz="UTC")]) |
| 57 | + >>> bbq.unix_millis(s) |
| 58 | + 0 86400000 |
| 59 | + 1 172800000 |
| 60 | + dtype: Int64 |
| 61 | +
|
| 62 | + Args: |
| 63 | + input (bigframes.pandas.Series): |
| 64 | + A timestamp series. |
| 65 | +
|
| 66 | + Returns: |
| 67 | + bigframes.pandas.Series: A new series of unix epoch in milliseconds. |
| 68 | +
|
| 69 | + """ |
| 70 | + return input._apply_unary_op(ops.UnixMillis()) |
| 71 | + |
| 72 | + |
| 73 | +def unix_micros(input: series.Series) -> series.Series: |
| 74 | + """Converts a timestmap series to unix epoch microseconds |
| 75 | +
|
| 76 | + **Examples:** |
| 77 | +
|
| 78 | + >>> import pandas as pd |
| 79 | + >>> import bigframes.pandas as bpd |
| 80 | + >>> import bigframes.bigquery as bbq |
| 81 | + >>> bpd.options.display.progress_bar = None |
| 82 | +
|
| 83 | + >>> s = bpd.Series([pd.Timestamp("1970-01-02", tz="UTC"), pd.Timestamp("1970-01-03", tz="UTC")]) |
| 84 | + >>> bbq.unix_micros(s) |
| 85 | + 0 86400000000 |
| 86 | + 1 172800000000 |
| 87 | + dtype: Int64 |
| 88 | +
|
| 89 | + Args: |
| 90 | + input (bigframes.pandas.Series): |
| 91 | + A timestamp series. |
| 92 | +
|
| 93 | + Returns: |
| 94 | + bigframes.pandas.Series: A new series of unix epoch in microseconds. |
| 95 | +
|
| 96 | + """ |
| 97 | + return input._apply_unary_op(ops.UnixMicros()) |
0 commit comments