Skip to content

Commit 878dce4

Browse files
authored
docs: add how-to guide and include API reference (#33)
* docs: add how-to guide and include API reference * fix indentation * fix types in sample * fix types in sample
1 parent 50ea0f7 commit 878dce4

File tree

8 files changed

+112
-36
lines changed

8 files changed

+112
-36
lines changed

README.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@ Pandas Data Types for SQL systems (BigQuery, Spanner)
1818
.. _Library Documentation: https://googleapis.dev/python/db-dtypes/latest
1919

2020

21-
Quick Start
22-
-----------
23-
24-
In order to use this library, you first need to go through the following steps:
25-
26-
1. `Select or create a Cloud Platform project.`_
27-
2. [Optional] `Enable billing for your project.`_
28-
3. `Enable the BigQuery Storage API.`_
29-
4. `Setup Authentication.`_
30-
31-
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
32-
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
33-
.. _Enable the BigQuery Storage API.: https://console.cloud.google.com/apis/library/bigquery.googleapis.com
34-
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
35-
3621
Installation
3722
------------
3823

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
"grpc": ("https://grpc.github.io/grpc/python/", None),
352352
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
353353
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
354-
"pandas": ("http://pandas.pydata.org/pandas-docs/dev", None),
354+
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
355355
}
356356

357357

docs/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
.. include:: README.rst
22

3+
How-to Guides
4+
-------------
5+
6+
.. toctree::
7+
:maxdepth: 2
8+
9+
usage
10+
11+
312
API Reference
413
-------------
514

docs/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
API Reference
22
^^^^^^^^^^^^^
33

4-
.. automodule:: db_dtypes.version
4+
.. automodule:: db_dtypes

docs/samples

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../samples

docs/usage.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
Using the db-dtypes package
2+
---------------------------
3+
4+
Importing the :mod:`db_dtypes` module registers the extension dtypes for use
5+
in pandas.
6+
7+
Construct a date :class:`~pandas.Series` with strings in ``YYYY-MM-DD`` format
8+
or :class:`datetime.date` objects.
9+
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]
15+
16+
Working with dates
17+
^^^^^^^^^^^^^^^^^^
18+
19+
Convert a date :class:`~pandas.Series` to a ``datetime64`` Series with
20+
:meth:`~pandas.Series.astype`. The resulting values use midnight as the
21+
time part.
22+
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]
28+
29+
Just like ``datetime64`` values, date values can be subtracted. This is
30+
equivalent to first converting to ``datetime64`` and then subtracting.
31+
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]
37+
38+
Just like ``datetime64`` values, :class:`~pandas.tseries.offsets.DateOffset`
39+
values can be added to them.
40+
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]
46+
47+
48+
Working with times
49+
^^^^^^^^^^^^^^^^^^
50+
51+
Construct a time :class:`~pandas.Series` with strings in ``HH:MM:SS.fraction``
52+
24-hour format or :class:`datetime.time` objects.
53+
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]
59+
60+
Convert a time :class:`~pandas.Series` to a ``timedelta64`` Series with
61+
:meth:`~pandas.Series.astype`.
62+
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]
68+
69+
70+
Combining dates and times
71+
^^^^^^^^^^^^^^^^^^^^^^^^^
72+
73+
Combine a date :class:`~pandas.Series` with a time :class:`~pandas.Series` to
74+
create a ``datetime64`` :class:`~pandas.Series`.
75+
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]

owlbot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
unit_test_python_versions=["3.6", "3.7", "3.8", "3.9"],
3232
system_test_python_versions=["3.8"],
3333
cov_level=100,
34-
intersphinx_dependencies={"pandas": "http://pandas.pydata.org/pandas-docs/dev"},
34+
intersphinx_dependencies={
35+
"pandas": "https://pandas.pydata.org/pandas-docs/stable/"
36+
},
3537
)
3638
s.move(templated_files, excludes=["docs/multiprocessing.rst"])
3739

samples/snippets/pandas_date_and_time.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,53 @@
1414

1515

1616
def pandas_date_and_time():
17-
# [START bigquery_date_create]
17+
# [START bigquery_pandas_date_create]
1818

1919
import datetime
2020
import pandas as pd
2121
import db_dtypes # noqa import to register dtypes
2222

2323
dates = pd.Series([datetime.date(2021, 9, 17), "2021-9-18"], dtype="dbdate")
2424

25-
# [END bigquery_date_create]
26-
# [START bigquery_date_as_datetime]
25+
# [END bigquery_pandas_date_create]
26+
# [START bigquery_pandas_date_as_datetime]
2727

2828
datetimes = dates.astype("datetime64")
2929

30-
# [END bigquery_date_as_datetime]
31-
# [START bigquery_date_sub]
30+
# [END bigquery_pandas_date_as_datetime]
31+
# [START bigquery_pandas_date_sub]
3232

3333
dates2 = pd.Series(["2021-1-1", "2021-1-2"], dtype="dbdate")
3434
diffs = dates - dates2
3535

36-
# [END bigquery_date_sub]
37-
# [START bigquery_date_do]
36+
# [END bigquery_pandas_date_sub]
37+
# [START bigquery_pandas_date_add_offset]
3838

3939
do = pd.DateOffset(days=1)
4040
after = dates + do
4141
before = dates - do
4242

43-
# [END bigquery_date_do]
44-
# [START bigquery_time_create]
43+
# [END bigquery_pandas_date_add_offset]
44+
# [START bigquery_pandas_time_create]
4545

4646
times = pd.Series([datetime.time(1, 2, 3, 456789), "12:00:00.6"], dtype="dbtime")
4747

48-
# [END bigquery_time_create]
49-
# [START bigquery_time_as_timedelta]
48+
# [END bigquery_pandas_time_create]
49+
# [START bigquery_pandas_time_as_timedelta]
5050

5151
timedeltas = times.astype("timedelta64")
5252

53-
# [END bigquery_time_as_timedelta]
54-
# [START bigquery_combine_date_time]
53+
# [END bigquery_pandas_time_as_timedelta]
5554

56-
combined = datetimes + timedeltas
55+
# Combine datetime64 and timedelta64 to confirm adding dates and times are
56+
# equivalent.
57+
combined0 = datetimes + timedeltas
5758

58-
# [END bigquery_combine_date_time]
59-
combined0 = combined
60-
# [START bigquery_combine2_date_time]
59+
# [START bigquery_pandas_combine_date_time]
6160

6261
combined = dates + times
6362

64-
# [END bigquery_combine2_date_time]
63+
# [END bigquery_pandas_combine_date_time]
6564

6665
return (
6766
dates,

0 commit comments

Comments
 (0)