|
19 | 19 | import operator
|
20 | 20 | import queue
|
21 | 21 | import warnings
|
22 |
| - |
23 |
| -try: |
24 |
| - import importlib.metadata as metadata |
25 |
| -except ImportError: |
26 |
| - import importlib_metadata as metadata |
| 22 | +import pkg_resources |
27 | 23 |
|
28 | 24 | import mock
|
29 | 25 |
|
|
61 | 57 |
|
62 | 58 | bigquery_storage = _versions_helpers.BQ_STORAGE_VERSIONS.try_import()
|
63 | 59 |
|
| 60 | +PANDAS_MINIUM_VERSION = pkg_resources.parse_version("1.0.0") |
| 61 | + |
64 | 62 | if pandas is not None:
|
65 |
| - PANDAS_INSTALLED_VERSION = metadata.version("pandas") |
| 63 | + PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version |
66 | 64 | else:
|
67 |
| - PANDAS_INSTALLED_VERSION = "0.0.0" |
| 65 | + # Set to less than MIN version. |
| 66 | + PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0") |
68 | 67 |
|
69 | 68 |
|
70 | 69 | skip_if_no_bignumeric = pytest.mark.skipif(
|
@@ -543,7 +542,9 @@ def test_bq_to_arrow_array_w_nullable_scalars(module_under_test, bq_type, rows):
|
543 | 542 | ],
|
544 | 543 | )
|
545 | 544 | @pytest.mark.skipif(pandas is None, reason="Requires `pandas`")
|
546 |
| -@pytest.mark.skipif(PANDAS_INSTALLED_VERSION[0:2] not in ["0.", "1."], reason="") |
| 545 | +@pytest.mark.skipif( |
| 546 | + PANDAS_INSTALLED_VERSION >= pkg_resources.parse_version("2.0.0"), reason="" |
| 547 | +) |
547 | 548 | @pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`")
|
548 | 549 | def test_bq_to_arrow_array_w_pandas_timestamp(module_under_test, bq_type, rows):
|
549 | 550 | rows = [pandas.Timestamp(row) for row in rows]
|
@@ -805,7 +806,10 @@ def test_list_columns_and_indexes_with_named_index_same_as_column_name(
|
805 | 806 | assert columns_and_indexes == expected
|
806 | 807 |
|
807 | 808 |
|
808 |
| -@pytest.mark.skipif(pandas is None, reason="Requires `pandas`") |
| 809 | +@pytest.mark.skipif( |
| 810 | + pandas is None or PANDAS_INSTALLED_VERSION < PANDAS_MINIUM_VERSION, |
| 811 | + reason="Requires `pandas version >= 1.0.0` which introduces pandas.NA", |
| 812 | +) |
809 | 813 | def test_dataframe_to_json_generator(module_under_test):
|
810 | 814 | utcnow = datetime.datetime.utcnow()
|
811 | 815 | df_data = collections.OrderedDict(
|
@@ -833,8 +837,16 @@ def test_dataframe_to_json_generator(module_under_test):
|
833 | 837 | assert list(rows) == expected
|
834 | 838 |
|
835 | 839 |
|
836 |
| -@pytest.mark.skipif(pandas is None, reason="Requires `pandas`") |
837 | 840 | def test_dataframe_to_json_generator_repeated_field(module_under_test):
|
| 841 | + pytest.importorskip( |
| 842 | + "pandas", |
| 843 | + minversion=str(PANDAS_MINIUM_VERSION), |
| 844 | + reason=( |
| 845 | + f"Requires `pandas version >= {PANDAS_MINIUM_VERSION}` " |
| 846 | + "which introduces pandas.NA" |
| 847 | + ), |
| 848 | + ) |
| 849 | + |
838 | 850 | df_data = [
|
839 | 851 | collections.OrderedDict(
|
840 | 852 | [("repeated_col", [pandas.NA, 2, None, 4]), ("not_repeated_col", "first")]
|
|
0 commit comments