Skip to content

Commit

Permalink
Fix the legacy woce writer not writing the data block if no quality f…
Browse files Browse the repository at this point in the history
…lags are in the file
  • Loading branch information
DocOtak committed Aug 30, 2024
1 parent edfc563 commit a9139e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
v1.0.2.10 (2024-09-??)
=====================
* (Major Bug) Fix not calculating the correct string length for string fields that have an inconsistent length (e.g. station)
* (Bug) Fix the legacy woce writer not writing the data block if no quality flags are in the file

v1.0.2.9 (2024-08-08)
=====================
Expand Down
4 changes: 3 additions & 1 deletion cchdo/hydro/legacy/woce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 2023-04-16
from importlib.resources import open_text
from io import BytesIO
from itertools import zip_longest
from zipfile import ZIP_DEFLATED, ZipFile

import numpy as np
Expand Down Expand Up @@ -347,7 +348,8 @@ def quality_flags_of(column):
)
)

for row_d, row_f in zip(zip(*data), zip(*flags)):
for row_d, row_f in zip_longest(zip(*data), zip(*flags), fillvalue=""):
print(row_d, row_f)
data_lines.append(base_format.format(*row_d, "".join(row_f)))

return "".join([record2, record3, record4, *data_lines])
Expand Down
19 changes: 18 additions & 1 deletion cchdo/hydro/tests/test_accessors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
from importlib.resources import read_text
from io import BytesIO
from zipfile import ZipFile

import pytest
import xarray as xr
from xarray.testing import assert_identical

from cchdo.hydro.accessors import CCHDOAccessor
from cchdo.hydro.exchange import FileType, read_exchange
from cchdo.hydro.exchange import FileType, read_csv, read_exchange

exp_stn_cast = json.loads(read_text("cchdo.hydro.tests.data", "stns_test_data.json"))

Expand Down Expand Up @@ -161,3 +163,18 @@ def test_nc_serialize_all_ctdetime(tmp_path):
ds.cchdo.to_coards()
ds.cchdo.to_woce()
ds.cchdo.to_sum()


def test_woce_ctd_no_flags(tmp_path):
"""make sure data is written to the woce files when there are no qc flags"""
test_data = b"""EXPOCODE,SECT_ID,STNNBR,CASTNO,DATE,TIME,LATITUDE,LONGITUDE,CTDPRS [DBAR],CTDTMP [DEG C],CTDSAL [PSS-78],CTDOXY [UMOL/KG],CTDFLUOR [MG/M^3],CTDBEAMCP [/METER]
64PE20110724,AR07E,9,1,20110729,1919,59.57017,-38.77183,3006.0,1.2096,34.8913,304.0,0.0,0.161
"""
ds = read_csv(test_data, ftype="C")
zip_data = BytesIO(ds.cchdo.to_woce())
with ZipFile(zip_data) as zf:
fname = zf.namelist()[0]
with zf.open(fname) as ctd:
# this asserts that the above data block exists somewhere in the resulting file
# the previous bug would just have a blank data block section
assert b"3006.0 1.2096 34.8913 304.0" in ctd.read()

0 comments on commit a9139e7

Please sign in to comment.