Skip to content

Commit 3b1da1b

Browse files
committed
fixes warning messages from pandas
1 parent 9df9d92 commit 3b1da1b

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/dwcahandler/dwca/core_dwca.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ def _add_new_columns(self, df_content, delta_df_content):
235235
delta_df_columns = delta_df_content.columns.to_list()
236236
new_columns = list(set(delta_df_columns) - set(df_columns))
237237
if len(new_columns) > 0:
238-
df_content[new_columns] = nan
238+
# Set to empty string instead of nan to resolve warning message
239+
# see https://pandas.pydata.org/pdeps/0006-ban-upcasting.html
240+
df_content[new_columns] = ""
239241

240242
return new_columns
241243

tests/test_merge_dwca.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tests import make_dwca
66
from dwcahandler import DwcaHandler
77
from io import BytesIO
8-
8+
from numpy import nan
99

1010
class TestMergeDwcaContent:
1111

@@ -82,13 +82,13 @@ def test_merge_core_and_ext_records(self):
8282

8383
delta_occ_df = pd.DataFrame(data=[["3", "species3", "-40.0000", "144.0000", "Observation"],
8484
["4", "species4", "-10.0000", "144.0000", "Observation"],
85-
["5", "species5", "-20.0000", "145.0000", ""],
86-
["6", "species6", "-30.0000", "146.3048", ""]],
85+
["5", "species5", "-20.0000", "145.0000", nan],
86+
["6", "species6", "-30.0000", "146.3048", nan]],
8787
columns=["occurrenceID", "scientificName", "decimalLatitude", "decimalLongitude",
8888
"basisOfRecord"])
8989

9090
delta_multimedia_df = pd.DataFrame(data=[["3", "https://new-image3.webp", "image/webp", "StillImage", "RightsHolder3"],
91-
["4", "https://image4.webp", "image/webp", "StillImage", None],
91+
["4", "https://image4.webp", "image/webp", "StillImage", nan],
9292
["5", "https://image5.webp", "image/webp", "StillImage", "RightsHolder5"],
9393
["6", "https://image6.webp", "image/webp", "StillImage", "RightsHolder6"]],
9494
columns=["occurrenceID", "identifier", "format", "type", "rightsHolder"])
@@ -105,18 +105,19 @@ def test_merge_core_and_ext_records(self):
105105
output_dwca_path=output_obj,
106106
keys_lookup=keys_lookup)
107107

108-
expected_occ_df = pd.DataFrame(data=[["1", "species1", "-30.0000", "144.0000", None],
109-
["2", "species2", "-28.0000", "115.0000", None],
108+
expected_occ_df = pd.DataFrame(data=[["1", "species1", "-30.0000", "144.0000", nan],
109+
["2", "species2", "-28.0000", "115.0000", nan],
110110
["3", "species3", "-40.0000", "144.0000", "Observation"],
111111
["4", "species4", "-10.0000", "144.0000", "Observation"],
112-
["5", "species5", "-20.0000", "145.0000", None],
113-
["6", "species6", "-30.0000", "146.3048", None]],
114-
columns=['occurrenceID', 'scientificName', 'decimalLatitude', 'decimalLongitude', 'basisOfRecord'])
112+
["5", "species5", "-20.0000", "145.0000", nan],
113+
["6", "species6", "-30.0000", "146.3048", nan]],
114+
columns=['occurrenceID', 'scientificName', 'decimalLatitude', 'decimalLongitude',
115+
'basisOfRecord'])
115116

116-
expected_multimedia_df = pd.DataFrame(data=[["1", "https://image1.jpg", "image/jpeg", "StillImage", None],
117-
["2", "https://image2.jpg", "image/jpeg", "StillImage", None],
117+
expected_multimedia_df = pd.DataFrame(data=[["1", "https://image1.jpg", "image/jpeg", "StillImage", nan],
118+
["2", "https://image2.jpg", "image/jpeg", "StillImage", nan],
118119
["3", "https://new-image3.webp", "image/webp", "StillImage", "RightsHolder3"],
119-
["4", "https://image4.webp", "image/webp", "StillImage", None],
120+
["4", "https://image4.webp", "image/webp", "StillImage", nan],
120121
["5", "https://image5.webp", "image/webp", "StillImage", "RightsHolder5"],
121122
["6", "https://image6.webp", "image/webp", "StillImage", "RightsHolder6"]],
122123
columns=["occurrenceID", "identifier", "format", "type", "rightsHolder"])

0 commit comments

Comments
 (0)