Skip to content

Commit 3abb831

Browse files
test: Fix prerelease and pandas 3.0 test compat
1 parent 342fa72 commit 3abb831

File tree

10 files changed

+164
-213
lines changed

10 files changed

+164
-213
lines changed

bigframes/testing/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@
1717
These modules are provided for testing the BigQuery DataFrames package. The
1818
interface is not considered stable.
1919
"""
20+
from bigframes.testing.utils import assert_frame_equal, assert_series_equal
21+
22+
__all__ = [
23+
"assert_frame_equal",
24+
"assert_series_equal",
25+
]

noxfile.py

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import multiprocessing
2121
import os
2222
import pathlib
23-
import re
2423
import shutil
2524
import time
2625
from typing import Dict, List
@@ -588,99 +587,36 @@ def prerelease(session: nox.sessions.Session, tests_path, extra_pytest_options=(
588587
constraints_path = str(
589588
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
590589
)
591-
592-
# Ignore officially released versions of certain packages specified in
593-
# testing/constraints-*.txt and install a more recent, pre-release versions
594-
# directly
595-
already_installed = set()
590+
session.install(
591+
*set(UNIT_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_STANDARD_DEPENDENCIES),
592+
"-c",
593+
constraints_path,
594+
"-e",
595+
".",
596+
)
596597

597598
# PyArrow prerelease packages are published to an alternative PyPI host.
598599
# https://arrow.apache.org/docs/python/install.html#installing-nightly-packages
599600
session.install(
601+
"--no-deps",
602+
"--upgrade",
600603
"--extra-index-url",
601604
"https://pypi.fury.io/arrow-nightlies/",
602-
"--prefer-binary",
603-
"--pre",
604-
"--upgrade",
605605
"pyarrow",
606-
)
607-
already_installed.add("pyarrow")
608-
609-
session.install(
610-
"--prefer-binary",
611-
"--pre",
612-
"--upgrade",
613606
# We exclude each version individually so that we can continue to test
614607
# some prerelease packages. See:
615608
# https://github.com/googleapis/python-bigquery-dataframes/pull/268#discussion_r1423205172
616609
# "pandas!=2.1.4, !=2.2.0rc0, !=2.2.0, !=2.2.1",
617610
"pandas",
618-
)
619-
already_installed.add("pandas")
620-
621-
# Try to avoid a cap on our SQLGlot so that bigframes
622-
# can be integrated with SQLMesh. See:
623-
# https://github.com/googleapis/python-bigquery-dataframes/issues/942
624-
# If SQLGlot introduces something that breaks us, lets file an issue
625-
# upstream and/or make sure we fix bigframes to work with it.
626-
session.install(
627-
"--upgrade",
628-
"git+https://github.com/tobymao/sqlglot.git#egg=sqlglot",
629-
)
630-
already_installed.add("sqlglot")
631-
632-
# Workaround https://github.com/googleapis/python-db-dtypes-pandas/issues/178
633-
session.install("--no-deps", "db-dtypes")
634-
already_installed.add("db-dtypes")
635-
636-
# Ensure we catch breaking changes in the client libraries early.
637-
session.install(
638-
"--upgrade",
611+
# Workaround https://github.com/googleapis/python-db-dtypes-pandas/issues/178
612+
"db-dtypes",
613+
# Ensure we catch breaking changes in the client libraries early.
639614
"git+https://github.com/googleapis/python-bigquery.git#egg=google-cloud-bigquery",
640-
)
641-
already_installed.add("google-cloud-bigquery")
642-
session.install(
643615
"--upgrade",
644616
"-e",
645617
"git+https://github.com/googleapis/google-cloud-python.git#egg=google-cloud-bigquery-storage&subdirectory=packages/google-cloud-bigquery-storage",
646-
)
647-
already_installed.add("google-cloud-bigquery-storage")
648-
session.install(
649-
"--upgrade",
650618
"git+https://github.com/googleapis/python-bigquery-pandas.git#egg=pandas-gbq",
651619
)
652-
already_installed.add("pandas-gbq")
653-
654-
session.install(
655-
*set(UNIT_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_STANDARD_DEPENDENCIES),
656-
"-c",
657-
constraints_path,
658-
)
659-
660-
# Because we test minimum dependency versions on the minimum Python
661-
# version, the first version we test with in the unit tests sessions has a
662-
# constraints file containing all dependencies and extras.
663-
with open(
664-
CURRENT_DIRECTORY / "testing" / f"constraints-{DEFAULT_PYTHON_VERSION}.txt",
665-
encoding="utf-8",
666-
) as constraints_file:
667-
constraints_text = constraints_file.read()
668-
669-
# Ignore leading whitespace and comment lines.
670-
deps = [
671-
match.group(1)
672-
for match in re.finditer(
673-
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
674-
)
675-
if match.group(1) not in already_installed
676-
]
677-
678-
print(already_installed)
679-
680-
# We use --no-deps to ensure that pre-release versions aren't overwritten
681-
# by the version ranges in setup.py.
682-
session.install(*deps)
683-
session.install("--no-deps", "-e", ".")
684620

685621
# Print out prerelease package versions.
686622
session.run("python", "-m", "pip", "freeze")

tests/system/small/bigquery/test_array.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@
6767
)
6868
def test_array_length(input_data, expected):
6969
series = bpd.Series(input_data)
70-
expected = pd.Series(expected, dtype=bigframes.dtypes.INT_DTYPE)
70+
expected = pd.Series(
71+
expected,
72+
index=pd.Index(range(len(input_data)), dtype="Int64"),
73+
dtype=bigframes.dtypes.INT_DTYPE,
74+
)
7175
pd.testing.assert_series_equal(
7276
bbq.array_length(series).to_pandas(),
7377
expected,

tests/system/small/bigquery/test_sql.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import pandas as pd
1615
import pytest
1716

1817
import bigframes.bigquery as bbq
1918
import bigframes.dtypes as dtypes
2019
import bigframes.pandas as bpd
20+
import bigframes.testing
2121

2222

2323
def test_sql_scalar_for_all_scalar_types(scalars_df_null_index):
@@ -59,8 +59,8 @@ def test_sql_scalar_for_bool_series(scalars_df_index):
5959
series: bpd.Series = scalars_df_index["bool_col"]
6060
result = bbq.sql_scalar("CAST({0} AS INT64)", [series])
6161
expected = series.astype(dtypes.INT_DTYPE)
62-
expected.name = None
63-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
62+
expected.name = result.name
63+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
6464

6565

6666
@pytest.mark.parametrize(
@@ -83,8 +83,8 @@ def test_sql_scalar_outputs_all_scalar_types(scalars_df_index, column_name):
8383
series: bpd.Series = scalars_df_index[column_name]
8484
result = bbq.sql_scalar("{0}", [series])
8585
expected = series
86-
expected.name = None
87-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
86+
expected.name = result.name
87+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
8888

8989

9090
def test_sql_scalar_for_array_series(repeated_df):
@@ -114,14 +114,14 @@ def test_sql_scalar_for_array_series(repeated_df):
114114
+ repeated_df["numeric_list_col"].list.len()
115115
+ repeated_df["string_list_col"].list.len()
116116
)
117-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
117+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
118118

119119

120120
def test_sql_scalar_outputs_array_series(repeated_df):
121121
result = bbq.sql_scalar("{0}", [repeated_df["int_list_col"]])
122122
expected = repeated_df["int_list_col"]
123-
expected.name = None
124-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
123+
expected.name = result.name
124+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
125125

126126

127127
def test_sql_scalar_for_struct_series(nested_structs_df):
@@ -132,14 +132,14 @@ def test_sql_scalar_for_struct_series(nested_structs_df):
132132
expected = nested_structs_df["person"].struct.field(
133133
"name"
134134
).str.len() + nested_structs_df["person"].struct.field("age")
135-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
135+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
136136

137137

138138
def test_sql_scalar_outputs_struct_series(nested_structs_df):
139139
result = bbq.sql_scalar("{0}", [nested_structs_df["person"]])
140140
expected = nested_structs_df["person"]
141-
expected.name = None
142-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
141+
expected.name = result.name
142+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
143143

144144

145145
def test_sql_scalar_for_json_series(json_df):
@@ -150,12 +150,12 @@ def test_sql_scalar_for_json_series(json_df):
150150
],
151151
)
152152
expected = bbq.json_value(json_df["json_col"], "$.int_value")
153-
expected.name = None
154-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
153+
expected.name = result.name
154+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
155155

156156

157157
def test_sql_scalar_outputs_json_series(json_df):
158158
result = bbq.sql_scalar("{0}", [json_df["json_col"]])
159159
expected = json_df["json_col"]
160-
expected.name = None
161-
pd.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())
160+
expected.name = result.name
161+
bigframes.testing.assert_series_equal(result.to_pandas(), expected.to_pandas())

0 commit comments

Comments
 (0)