Skip to content

Commit 39f8e68

Browse files
committed
Address cases where cells file is empty
1 parent 4e0c9b3 commit 39f8e68

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

config_files/survey_year_2003_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ survey_year: 2003 # survey year being considered
1111
species:
1212
text_code: pacific_hake # target species for the survey year -- species name
1313
number_code: 22500 # target species for the survey year -- numeric code
14-
CAN_haul_offset: 900 # The value to be added to the Canadian's haul number
14+
CAN_haul_offset: 0 # The value to be added to the Canadian's haul number
1515

1616
##############################################################################
1717
# Report generation

echopop/utils/load_nasc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def read_echoview_export(filename: str, transect_number: int, validator: MetaMod
3838
# ---- Set the column names to lowercase
3939
export_file.columns = export_file.columns.str.lower()
4040

41+
# Replace with empty placeholder
42+
if len(export_file) == 0:
43+
export_file = validator.generate_empty_df()
44+
4145
# Validate
4246
export_valid = validator.validate_df(export_file, filename)
4347

echopop/utils/validate_df.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,13 @@ class EchoviewCells(BaseDataFrame):
920920
921921
"""
922922

923-
interval: Series[int] = Field(ge=1, nullable=False)
924-
layer: Series[int] = Field(ge=1, nullable=False)
923+
interval: Series[int] = Field(ge=0, nullable=False)
924+
layer: Series[int] = Field(ge=0, nullable=False)
925925
prc_nasc: Series[float] = Field(ge=0.0, nullable=False)
926926
process_id: Series[int]
927927
region_class: Series[str]
928928
region_id: Series[int]
929-
region_name: Series[str]
929+
region_name: Series[str] = Field(nullable=True)
930930
standard_deviation: Optional[Series[float]] = Field(ge=0.0, nullable=False)
931931
sv_mean: Series[float] = Field(ge=-999, nullable=True)
932932

@@ -939,6 +939,20 @@ def pre_validate(cls, df: pd.DataFrame) -> pd.DataFrame:
939939

940940
return df
941941

942+
@classmethod
943+
def generate_empty_df(cls) -> pd.DataFrame:
944+
"""Generate an empty DataFrame with the correct columns"""
945+
return pd.DataFrame({
946+
"interval": [0],
947+
"layer": [0],
948+
"prc_nasc": [0.0],
949+
"process_id": [0],
950+
"region_class": ["DEFAULT"],
951+
"region_id": [-99999],
952+
"region_name": ["DEFAULT"],
953+
"standard_deviation": [0.0],
954+
"sv_mean": [0.0],
955+
})
942956

943957
class EchoviewIntervals(BaseDataFrame):
944958
"""

0 commit comments

Comments
 (0)