-
Notifications
You must be signed in to change notification settings - Fork 6.7k
chore: migrate code from googleapis/python-db-dtypes-pandas #13776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+212
−0
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
b4040c6
feat: add `time` and `date` dtypes
tswast 2393641
chore: add license headers to __init__.py files
tswast 8f7fe00
chore: fail samples nox session if python version is missing (#17)
gcf-owl-bot[bot] e104b89
chore(python): Add kokoro configs for python 3.10 samples testing (#26)
gcf-owl-bot[bot] fc653d2
feat: rename dbtime and dbdate dtypes to avoid future conflicts with …
tswast a604e56
docs: add how-to guide and include API reference (#33)
tswast e5c6019
chore(samples): Add check for tests in directory (#54)
gcf-owl-bot[bot] 0ea0a03
chore(python): Noxfile recognizes that tests can live in a folder (#58)
gcf-owl-bot[bot] 366f815
chore(deps): update all dependencies (#68)
renovate-bot 0a5d994
chore: Adding support for pytest-xdist and pytest-parallel (#76)
gcf-owl-bot[bot] 12f870d
chore(deps): update dependency pytest to v7.1.0 (#80)
renovate-bot 0f63bdb
chore(deps): update dependency pytest to v7.1.1 (#83)
renovate-bot b625a30
chore(python): use black==22.3.0 (#96)
gcf-owl-bot[bot] 39f17f8
chore(python): add nox session to sort python imports (#102)
gcf-owl-bot[bot] 0bf2571
chore(deps): update dependency pytest to v7.1.2 (#105)
renovate-bot 805981d
fix: require python 3.7+ (#125)
gcf-owl-bot[bot] b052c0d
chore(deps): update dependency pytest to v7.1.3 (#144)
renovate-bot f7d60e3
chore: detect samples tests in nested directories (#146)
gcf-owl-bot[bot] 272fe91
chore(deps): update dependency pytest to v7.2.0 (#151)
renovate-bot b42c336
chore(python): drop flake8-import-order in samples noxfile (#156)
gcf-owl-bot[bot] 37543c1
chore(python): add support for python 3.11 (#168)
gcf-owl-bot[bot] ff1923d
chore(deps): update dependency pytest to v7.2.1 (#170)
renovate-bot 1bea21e
chore(deps): update dependency pytest to v7.2.2 (#174)
renovate-bot fd04398
chore(deps): update dependency pytest to v7.3.1 (#184)
renovate-bot 6733c57
chore(deps): update dependency pytest to v7.3.2 (#188)
renovate-bot d7cfa6f
chore(deps): update dependency pytest to v7.4.0 (#191)
renovate-bot d40c13e
chore(deps): update all dependencies (#209)
renovate-bot 373d223
chore(deps): update all dependencies (#221)
renovate-bot c60e59d
feat: Add support for Python 3.12 (#223)
gcf-owl-bot[bot] 507757b
chore(deps): update dependency pytest to v7.4.4 (#235)
renovate-bot 91b5d72
chore(deps): update dependency pytest to v8 (#239)
renovate-bot 16e3db9
chore(deps): update dependency pytest to v8.0.1 (#243)
renovate-bot 95ec38c
chore(deps): update dependency pytest to v8.0.2 (#247)
renovate-bot bad7998
chore(deps): update dependency pytest to v8.1.1 (#251)
renovate-bot 31b47a7
testing: use arbitrary equality for pinned pytest version (#262)
Linchin f851905
chore: format code files with nox (#281)
chelsea-lin c23bc24
chore(deps): update all dependencies (#290)
renovate-bot c454c0d
build: use multiScm for Kokoro release builds (#294)
gcf-owl-bot[bot] 74d18b5
deps!: Drop support for Python 3.7 and 3.8 (AI Experiment) (#337)
chalmerlowe 5336318
test: updates python versions and sets owlbot excludes (#367)
chalmerlowe 34baee3
chore(deps): update dependency pytest to v8.4.1 (#368)
renovate-bot eb61401
chore(deps): update all dependencies (#373)
renovate-bot 43f7f5c
feat: Add support for Python 3.14 (#380)
daniel-sanche 7999039
Merge remote-tracking branch 'migration/main' into python-db-dtypes-p…
Linchin 63a4fbc
correct header
Linchin d4eb1bb
add noxconfig.py
Linchin 79e8aff
delete noxfile.py
Linchin 7ac946e
add
Linchin 365c40a
lint
Linchin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Default TEST_CONFIG_OVERRIDE for python repos. | ||
|
|
||
| # You can copy this file into your directory, then it will be imported from | ||
| # the noxfile.py. | ||
|
|
||
| # The source of truth: | ||
| # https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py | ||
|
|
||
| TEST_CONFIG_OVERRIDE = { | ||
| # You can opt out from the test for specific Python versions. | ||
| "ignored_versions": ["2.7", "3.7", "3.8"], | ||
| # Old samples are opted out of enforcing Python type hints | ||
| # All new samples should feature them | ||
| "enforce_type_hints": True, | ||
| # An envvar key for determining the project id to use. Change it | ||
| # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a | ||
| # build specific Cloud project. You can also use your own string | ||
| # to use your own Cloud project. | ||
| "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", | ||
| # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', | ||
| # If you need to use a specific version of pip, | ||
| # change pip_version_override to the string representation | ||
| # of the version number, for example, "20.2.4" | ||
| "pip_version_override": None, | ||
| # A dictionary you want to inject into your test. Don't put any | ||
| # secrets here. These values will override predefined values. | ||
| "envs": {}, | ||
| } |
79 changes: 79 additions & 0 deletions
79
bigquery/python-db-dtypes-pandas/snippets/pandas_date_and_time.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| def pandas_date_and_time(): | ||
| # [START bigquery_pandas_date_create] | ||
|
|
||
| import datetime | ||
|
|
||
| import pandas as pd | ||
|
|
||
| import db_dtypes # noqa import to register dtypes | ||
|
|
||
| dates = pd.Series([datetime.date(2021, 9, 17), "2021-9-18"], dtype="dbdate") | ||
|
|
||
| # [END bigquery_pandas_date_create] | ||
| # [START bigquery_pandas_date_as_datetime] | ||
|
|
||
| datetimes = dates.astype("datetime64") | ||
|
|
||
| # [END bigquery_pandas_date_as_datetime] | ||
| # [START bigquery_pandas_date_sub] | ||
|
|
||
| dates2 = pd.Series(["2021-1-1", "2021-1-2"], dtype="dbdate") | ||
| diffs = dates - dates2 | ||
|
|
||
| # [END bigquery_pandas_date_sub] | ||
| # [START bigquery_pandas_date_add_offset] | ||
|
|
||
| do = pd.DateOffset(days=1) | ||
| after = dates + do | ||
| before = dates - do | ||
|
|
||
| # [END bigquery_pandas_date_add_offset] | ||
| # [START bigquery_pandas_time_create] | ||
|
|
||
| times = pd.Series([datetime.time(1, 2, 3, 456789), "12:00:00.6"], dtype="dbtime") | ||
|
|
||
| # [END bigquery_pandas_time_create] | ||
| # [START bigquery_pandas_time_as_timedelta] | ||
|
|
||
| timedeltas = times.astype("timedelta64") | ||
|
|
||
| # [END bigquery_pandas_time_as_timedelta] | ||
|
|
||
| # Combine datetime64 and timedelta64 to confirm adding dates and times are | ||
| # equivalent. | ||
| combined0 = datetimes + timedeltas | ||
|
|
||
| # [START bigquery_pandas_combine_date_time] | ||
|
|
||
| combined = dates + times | ||
|
|
||
| # [END bigquery_pandas_combine_date_time] | ||
|
|
||
| return ( | ||
| dates, | ||
| datetimes, | ||
| dates2, | ||
| diffs, | ||
| do, | ||
| after, | ||
| before, | ||
| times, | ||
| timedeltas, | ||
| combined, | ||
| combined0, | ||
| ) |
60 changes: 60 additions & 0 deletions
60
bigquery/python-db-dtypes-pandas/snippets/pandas_date_and_time_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import datetime | ||
|
|
||
| import numpy as np | ||
| from pandas import Timestamp | ||
|
|
||
|
|
||
| def test_pandas_date_and_time(): | ||
| from .pandas_date_and_time import pandas_date_and_time | ||
|
|
||
| ( | ||
| dates, | ||
| _, | ||
| dates2, | ||
| diffs, | ||
| do, | ||
| after, | ||
| before, | ||
| times, | ||
| _, | ||
| combined, | ||
| combined0, | ||
| ) = pandas_date_and_time() | ||
|
|
||
| assert str(dates.dtype) == "dbdate" | ||
| assert list(dates) == [datetime.date(2021, 9, 17), datetime.date(2021, 9, 18)] | ||
|
|
||
| assert np.array_equal( | ||
| diffs, | ||
| dates.astype("datetime64") - dates2.astype("datetime64"), | ||
| ) | ||
|
|
||
| assert np.array_equal(after, dates.astype("object") + do) | ||
| assert np.array_equal(before, dates.astype("object") - do) | ||
|
|
||
| assert str(times.dtype) == "dbtime" | ||
| assert list(times) == [ | ||
| datetime.time(1, 2, 3, 456789), | ||
| datetime.time(12, 0, 0, 600000), | ||
| ] | ||
|
|
||
| for c in combined0, combined: | ||
| assert str(c.dtype) == "datetime64[ns]" | ||
| assert list(c) == [ | ||
| Timestamp("2021-09-17 01:02:03.456789"), | ||
| Timestamp("2021-09-18 12:00:00.600000"), | ||
| ] |
1 change: 1 addition & 0 deletions
1
bigquery/python-db-dtypes-pandas/snippets/requirements-test.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pytest==8.4.2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| db-dtypes | ||
| numpy | ||
| pandas | ||
| pyarrow |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinning
pytestto an exact patch version (8.4.2) can be overly restrictive. It's generally recommended to use a more flexible version specifier (e.g.,pytest>=8.4.2,<9orpytest~=8.4.2) to allow for minor bug fixes and security updates without requiring manual intervention, unless there's a specific compatibility issue that necessitates this exact pin.