Skip to content

Commit b2960cf

Browse files

File tree

9 files changed

+28
-497
lines changed

9 files changed

+28
-497
lines changed

packages/db-dtypes/docs/usage.rst

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ in pandas.
77
Construct a date :class:`~pandas.Series` with strings in ``YYYY-MM-DD`` format
88
or :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
2123
time 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
3030
equivalent 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`
3938
values 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
5150
Construct a time :class:`~pandas.Series` with strings in ``HH:MM:SS.fraction``
5251
24-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
7368
Combine a date :class:`~pandas.Series` with a time :class:`~pandas.Series` to
7469
create 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

packages/db-dtypes/samples/__init__.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/db-dtypes/samples/pytest.ini

Whitespace-only changes.

packages/db-dtypes/samples/snippets/__init__.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)