Skip to content

Commit 105ebc9

Browse files
committed
Use OrderedDict for DataFrame in system tests.
1 parent a580425 commit 105ebc9

File tree

1 file changed

+67
-52
lines changed

1 file changed

+67
-52
lines changed

bigquery/tests/system.py

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -743,21 +743,22 @@ def test_load_table_from_dataframe_w_nulls(self):
743743
)
744744
num_rows = 100
745745
nulls = [None] * num_rows
746-
dataframe = pandas.DataFrame(
747-
{
748-
"bool_col": nulls,
749-
"bytes_col": nulls,
750-
"date_col": nulls,
751-
"dt_col": nulls,
752-
"float_col": nulls,
753-
"geo_col": nulls,
754-
"int_col": nulls,
755-
"num_col": nulls,
756-
"str_col": nulls,
757-
"time_col": nulls,
758-
"ts_col": nulls,
759-
}
746+
df_data = collections.OrderedDict(
747+
[
748+
("bool_col", nulls),
749+
("bytes_col", nulls),
750+
("date_col", nulls),
751+
("dt_col", nulls),
752+
("float_col", nulls),
753+
("geo_col", nulls),
754+
("int_col", nulls),
755+
("num_col", nulls),
756+
("str_col", nulls),
757+
("time_col", nulls),
758+
("ts_col", nulls),
759+
]
760760
)
761+
dataframe = pandas.DataFrame(df_data, columns=df_data.keys())
761762

762763
dataset_id = _make_dataset_id("bq_load_test")
763764
self.temp_dataset(dataset_id)
@@ -796,7 +797,7 @@ def test_load_table_from_dataframe_w_required(self):
796797
)
797798

798799
records = [{"name": "Chip", "age": 2}, {"name": "Dale", "age": 3}]
799-
dataframe = pandas.DataFrame(records)
800+
dataframe = pandas.DataFrame(records, columns=["name", "age"])
800801
job_config = bigquery.LoadJobConfig(schema=table_schema)
801802
dataset_id = _make_dataset_id("bq_load_test")
802803
self.temp_dataset(dataset_id)
@@ -847,44 +848,58 @@ def test_load_table_from_dataframe_w_explicit_schema(self):
847848
# https://jira.apache.org/jira/browse/ARROW-2587
848849
# bigquery.SchemaField("struct_col", "RECORD", fields=scalars_schema),
849850
)
850-
dataframe = pandas.DataFrame(
851-
{
852-
"bool_col": [True, None, False],
853-
"bytes_col": [b"abc", None, b"def"],
854-
"date_col": [datetime.date(1, 1, 1), None, datetime.date(9999, 12, 31)],
855-
"dt_col": [
856-
datetime.datetime(1, 1, 1, 0, 0, 0),
857-
None,
858-
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999),
859-
],
860-
"float_col": [float("-inf"), float("nan"), float("inf")],
861-
"geo_col": [
862-
"POINT(30 10)",
863-
None,
864-
"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))",
865-
],
866-
"int_col": [-9223372036854775808, None, 9223372036854775807],
867-
"num_col": [
868-
decimal.Decimal("-99999999999999999999999999999.999999999"),
869-
None,
870-
decimal.Decimal("99999999999999999999999999999.999999999"),
871-
],
872-
"str_col": ["abc", None, "def"],
873-
"time_col": [
874-
datetime.time(0, 0, 0),
875-
None,
876-
datetime.time(23, 59, 59, 999999),
877-
],
878-
"ts_col": [
879-
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
880-
None,
881-
datetime.datetime(
882-
9999, 12, 31, 23, 59, 59, 999999, tzinfo=pytz.utc
883-
),
884-
],
885-
},
886-
dtype="object",
851+
df_data = collections.OrderedDict(
852+
[
853+
("bool_col", [True, None, False]),
854+
("bytes_col", [b"abc", None, b"def"]),
855+
(
856+
"date_col",
857+
[datetime.date(1, 1, 1), None, datetime.date(9999, 12, 31)],
858+
),
859+
(
860+
"dt_col",
861+
[
862+
datetime.datetime(1, 1, 1, 0, 0, 0),
863+
None,
864+
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999),
865+
],
866+
),
867+
("float_col", [float("-inf"), float("nan"), float("inf")]),
868+
(
869+
"geo_col",
870+
[
871+
"POINT(30 10)",
872+
None,
873+
"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))",
874+
],
875+
),
876+
("int_col", [-9223372036854775808, None, 9223372036854775807]),
877+
(
878+
"num_col",
879+
[
880+
decimal.Decimal("-99999999999999999999999999999.999999999"),
881+
None,
882+
decimal.Decimal("99999999999999999999999999999.999999999"),
883+
],
884+
),
885+
("str_col", ["abc", None, "def"]),
886+
(
887+
"time_col",
888+
[datetime.time(0, 0, 0), None, datetime.time(23, 59, 59, 999999)],
889+
),
890+
(
891+
"ts_col",
892+
[
893+
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
894+
None,
895+
datetime.datetime(
896+
9999, 12, 31, 23, 59, 59, 999999, tzinfo=pytz.utc
897+
),
898+
],
899+
),
900+
]
887901
)
902+
dataframe = pandas.DataFrame(df_data, dtype="object", columns=df_data.keys())
888903

889904
dataset_id = _make_dataset_id("bq_load_test")
890905
self.temp_dataset(dataset_id)

0 commit comments

Comments
 (0)