Skip to content
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

cleanup: get rid of unit test warnings caused by our code #973

Merged
merged 2 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,10 @@ def to_geodataframe(
"""
if geopandas is None:
raise ValueError(_NO_GEOPANDAS_ERROR)
return geopandas.GeoDataFrame(crs=_COORDINATE_REFERENCE_SYSTEM)

# Since an empty GeoDataFrame has no geometry column, we do not CRS on it,
# because that's deprecated.
return geopandas.GeoDataFrame()

def to_dataframe_iterable(
self,
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ def disable_add_server_timeout_header(request):
noop_add_server_timeout_header,
):
yield


def pytest_configure(config):
# Explicitly register custom test markers to avoid warnings.
config.addinivalue_line("markers", "enable_add_server_timeout_header")
43 changes: 32 additions & 11 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,8 +1866,7 @@ def test_to_geodataframe(self):
df = row_iterator.to_geodataframe(create_bqstorage_client=False)
self.assertIsInstance(df, geopandas.GeoDataFrame)
self.assertEqual(len(df), 0) # verify the number of rows
self.assertEqual(df.crs.srs, "EPSG:4326")
self.assertEqual(df.crs.name, "WGS 84")
self.assertIsNone(df.crs)


class TestRowIterator(unittest.TestCase):
Expand Down Expand Up @@ -4027,8 +4026,14 @@ def test_to_geodataframe(self):
self.assertEqual(df.name.dtype.name, "object")
self.assertEqual(df.geog.dtype.name, "geometry")
self.assertIsInstance(df.geog, geopandas.GeoSeries)
self.assertEqual(list(map(str, df.area)), ["0.0", "nan", "0.5"])
self.assertEqual(list(map(str, df.geog.area)), ["0.0", "nan", "0.5"])

with warnings.catch_warnings():
# Computing the area on a GeoDataFrame that uses a geographic Coordinate
# Reference System (CRS) produces a warning that we are not interested in.
warnings.filterwarnings("ignore", category=UserWarning)
self.assertEqual(list(map(str, df.area)), ["0.0", "nan", "0.5"])
self.assertEqual(list(map(str, df.geog.area)), ["0.0", "nan", "0.5"])
plamut marked this conversation as resolved.
Show resolved Hide resolved

self.assertEqual(df.crs.srs, "EPSG:4326")
self.assertEqual(df.crs.name, "WGS 84")
self.assertEqual(df.geog.crs.srs, "EPSG:4326")
Expand Down Expand Up @@ -4099,8 +4104,14 @@ def test_to_geodataframe_w_geography_column(self):
self.assertEqual(df.geog.dtype.name, "geometry")
self.assertEqual(df.geog2.dtype.name, "object")
self.assertIsInstance(df.geog, geopandas.GeoSeries)
self.assertEqual(list(map(str, df.area)), ["0.0", "nan", "0.5"])
self.assertEqual(list(map(str, df.geog.area)), ["0.0", "nan", "0.5"])

with warnings.catch_warnings():
# Computing the area on a GeoDataFrame that uses a geographic Coordinate
# Reference System (CRS) produces a warning that we are not interested in.
warnings.filterwarnings("ignore", category=UserWarning)
self.assertEqual(list(map(str, df.area)), ["0.0", "nan", "0.5"])
self.assertEqual(list(map(str, df.geog.area)), ["0.0", "nan", "0.5"])

self.assertEqual(
[v.__class__.__name__ for v in df.geog], ["Point", "NoneType", "Polygon"]
)
Expand All @@ -4110,10 +4121,14 @@ def test_to_geodataframe_w_geography_column(self):
self.assertEqual(
[v.__class__.__name__ for v in df.geog2], ["Point", "Point", "Point"]
)

# and can easily be converted to a GeoSeries
self.assertEqual(
list(map(str, geopandas.GeoSeries(df.geog2).area)), ["0.0", "0.0", "0.0"]
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
self.assertEqual(
list(map(str, geopandas.GeoSeries(df.geog2).area)),
["0.0", "0.0", "0.0"],
)

@unittest.skipIf(geopandas is None, "Requires `geopandas`")
@mock.patch("google.cloud.bigquery.table.RowIterator.to_dataframe")
Expand Down Expand Up @@ -4165,8 +4180,14 @@ def test_rowiterator_to_geodataframe_delegation(self, to_dataframe):
self.assertEqual(df.name.dtype.name, "object")
self.assertEqual(df.g.dtype.name, "geometry")
self.assertIsInstance(df.g, geopandas.GeoSeries)
self.assertEqual(list(map(str, df.area)), ["0.0"])
self.assertEqual(list(map(str, df.g.area)), ["0.0"])

with warnings.catch_warnings():
# Computing the area on a GeoDataFrame that uses a geographic Coordinate
# Reference System (CRS) produces a warning that we are not interested in.
warnings.filterwarnings("ignore", category=UserWarning)
self.assertEqual(list(map(str, df.area)), ["0.0"])
self.assertEqual(list(map(str, df.g.area)), ["0.0"])

self.assertEqual([v.__class__.__name__ for v in df.g], ["Point"])


Expand Down