Skip to content

Commit a6f01de

Browse files
committed
bugfix: cells with the new line character treated as empty
1 parent 27fbe85 commit a6f01de

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pandas as pd # type: ignore[reportMissingImports]
2+
3+
def has_meaningful_value(row, column_name: str) -> bool:
4+
"""
5+
Treat pandas NaN / None / '' / whitespace-only (e.g. '\\n\\n') as empty.
6+
"""
7+
value = row[column_name]
8+
9+
if pd.isna(value):
10+
return False
11+
12+
return str(value).strip() != ""

server/workers/common/common/aquanavi/mapping.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import re
22
import sys
33
import hashlib
4-
import pandas as pd
4+
import logging
5+
import pandas as pd # type: ignore[reportMissingImports]
56

67
from pathlib import Path
78
from .helpers.coordinates import get_row_coordinates_with_collision_offset
9+
from .helpers.text_content_validation import has_meaningful_value
810
from .constants.constants import COLUMNS
911

12+
logger = logging.getLogger(__name__)
13+
1014
PATH_TO_FOLDER_IN_CONTAINER = "common/common/aquanavi/"
1115
CSV_PATH_WITH_REAL_DATA = f"{PATH_TO_FOLDER_IN_CONTAINER}mesocosm_data_cleaned.csv"
1216
CSV_PATH_WITH_TEST_DATA = f"{PATH_TO_FOLDER_IN_CONTAINER}mesocosm_test_data.csv"
@@ -182,28 +186,28 @@ def get_not_available_message_and_increase_counter(name):
182186
count_of_not_available_parts += 1
183187
return f"{name}: description not available"
184188

185-
if (row[COLUMNS['description']]):
189+
if has_meaningful_value(row, COLUMNS['description']):
186190
abstract_parts.append(f"Facility description: {get_and_process_value(row, COLUMNS['description'], True, JOIN_PARTS_WITH['description'])}")
187191
else:
188192
abstract_parts.append(get_not_available_message_and_increase_counter("Facility description"))
189193

190-
if (row[COLUMNS['equipment']]):
194+
if has_meaningful_value(row, COLUMNS['equipment']):
191195
abstract_parts.append(f"Equipment: {get_and_process_value(row, COLUMNS['equipment'], True, JOIN_PARTS_WITH['equipment'])}")
192196
else:
193197
abstract_parts.append(get_not_available_message_and_increase_counter('Equipment'))
194198

195-
if (row[COLUMNS['controlled_parameters']]):
199+
if has_meaningful_value(row, COLUMNS['controlled_parameters']):
196200
abstract_parts.append(f"Controlled parameters: {get_and_process_value(row, COLUMNS['controlled_parameters'], True, JOIN_PARTS_WITH['controlled_parameters'])}")
197201
else:
198202
abstract_parts.append(get_not_available_message_and_increase_counter('Controlled Parameters'))
199203

200-
if (row[COLUMNS['grand_challenges']]):
201-
abstract_parts.append(f"Grand challenges: {get_and_process_value(row, COLUMNS['grand_challenges'], True, JOIN_PARTS_WITH['grand_challenges'])}")
204+
if has_meaningful_value(row, COLUMNS['grand_challenges']):
205+
abstract_parts.append(f"Grand challenges: {get_and_process_value(row, COLUMNS['grand_challenges'], True, JOIN_PARTS_WITH['grand_challenges'])}")
202206
else:
203207
abstract_parts.append(get_not_available_message_and_increase_counter('Grand challenges'))
204208

205-
if (row[COLUMNS['research_topics']]):
206-
abstract_parts.append(f"Research topics: {get_and_process_value(row, COLUMNS['research_topics'], True, JOIN_PARTS_WITH['research_topics'])}")
209+
if has_meaningful_value(row, COLUMNS['research_topics']):
210+
abstract_parts.append(f"Research topics: {get_and_process_value(row, COLUMNS['research_topics'], True, JOIN_PARTS_WITH['research_topics'])}")
207211
else:
208212
abstract_parts.append(get_not_available_message_and_increase_counter('Research topics'))
209213

0 commit comments

Comments
 (0)