@@ -7,11 +7,13 @@ in pandas.
77Construct a date :class: `~pandas.Series ` with strings in ``YYYY-MM-DD `` format
88or :class: `datetime.date ` objects.
99
10- .. literalinclude :: samples/snippets/pandas_date_and_time.py
11- :language: python
12- :dedent: 4
13- :start-after: [START bigquery_pandas_date_create]
14- :end-before: [END bigquery_pandas_date_create]
10+ .. code-block :: python
11+
12+ import datetime
13+ import pandas as pd
14+ import db_dtypes # noqa import to register dtypes
15+
16+ dates = pd.Series([datetime.date(2021 , 9 , 17 ), " 2021-9-18" ], dtype = " dbdate" )
1517
1618 Working with dates
1719^^^^^^^^^^^^^^^^^^
@@ -20,29 +22,26 @@ Convert a date :class:`~pandas.Series` to a ``datetime64`` Series with
2022:meth: `~pandas.Series.astype `. The resulting values use midnight as the
2123time part.
2224
23- .. literalinclude :: samples/snippets/pandas_date_and_time.py
24- :language: python
25- :dedent: 4
26- :start-after: [START bigquery_pandas_date_as_datetime]
27- :end-before: [END bigquery_pandas_date_as_datetime]
25+ .. code-block :: python
26+
27+ datetimes = dates.astype(" datetime64" )
2828
2929 Just like ``datetime64 `` values, date values can be subtracted. This is
3030equivalent to first converting to ``datetime64 `` and then subtracting.
3131
32- .. literalinclude :: samples/snippets/pandas_date_and_time.py
33- :language: python
34- :dedent: 4
35- :start-after: [START bigquery_pandas_date_sub]
36- :end-before: [END bigquery_pandas_date_sub]
32+ .. code-block :: python
33+
34+ dates2 = pd.Series([" 2021-1-1" , " 2021-1-2" ], dtype = " dbdate" )
35+ diffs = dates - dates2
3736
3837 Just like ``datetime64 `` values, :class: `~pandas.tseries.offsets.DateOffset `
3938values can be added to them.
4039
41- .. literalinclude :: samples/snippets/pandas_date_and_time.py
42- :language: python
43- :dedent: 4
44- :start- after: [START bigquery_pandas_date_add_offset]
45- :end- before: [END bigquery_pandas_date_add_offset]
40+ .. code-block :: python
41+
42+ do = pd.DateOffset( days = 1 )
43+ after = dates + do
44+ before = dates - do
4645
4746
4847 Working with times
@@ -51,20 +50,16 @@ Working with times
5150Construct a time :class: `~pandas.Series ` with strings in ``HH:MM:SS.fraction ``
525124-hour format or :class: `datetime.time ` objects.
5352
54- .. literalinclude :: samples/snippets/pandas_date_and_time.py
55- :language: python
56- :dedent: 4
57- :start-after: [START bigquery_pandas_time_create]
58- :end-before: [END bigquery_pandas_time_create]
53+ .. code-block :: python
54+
55+ times = pd.Series([datetime.time(1 , 2 , 3 , 456789 ), " 12:00:00.6" ], dtype = " dbtime" )
5956
6057 Convert a time :class: `~pandas.Series ` to a ``timedelta64 `` Series with
6158:meth: `~pandas.Series.astype `.
6259
63- .. literalinclude :: samples/snippets/pandas_date_and_time.py
64- :language: python
65- :dedent: 4
66- :start-after: [START bigquery_pandas_time_as_timedelta]
67- :end-before: [END bigquery_pandas_time_as_timedelta]
60+ .. code-block :: python
61+
62+ timedeltas = times.astype(" timedelta64" )
6863
6964
7065 Combining dates and times
@@ -73,8 +68,6 @@ Combining dates and times
7368Combine a date :class: `~pandas.Series ` with a time :class: `~pandas.Series ` to
7469create a ``datetime64 `` :class: `~pandas.Series `.
7570
76- .. literalinclude :: samples/snippets/pandas_date_and_time.py
77- :language: python
78- :dedent: 4
79- :start-after: [START bigquery_pandas_combine_date_time]
80- :end-before: [END bigquery_pandas_combine_date_time]
71+ .. code-block :: python
72+
73+ combined = dates + times
0 commit comments