Skip to content

Commit de051c8

Browse files
committed
Apply unsafe fixes
fixes were checked and tests passed
1 parent d209174 commit de051c8

File tree

9 files changed

+21
-32
lines changed

9 files changed

+21
-32
lines changed

src/cchdo/hydro/accessors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def to_matdate(dt):
264264
def dt_list_to_str_list(dtl):
265265
return list(map(to_matdate, dtl))
266266

267-
for _, value in mat_dict.items():
267+
for value in mat_dict.values():
268268
if value.get("attrs", {}).get("standard_name") == "time":
269269
# the case of list of lists is bottle closure times, which is a sparse array
270270
if any(isinstance(v, list) for v in value["data"]):
@@ -392,13 +392,13 @@ def sum_lon(deg_float):
392392

393393
sect_id = ""
394394
sect_ids = prof.filter_by_attrs(whp_name="SECT_ID")
395-
for _, ids in sect_ids.items():
395+
for ids in sect_ids.values():
396396
sect_id = str(ids.values)
397397
break
398398

399399
depth = ""
400400
depths = prof.filter_by_attrs(whp_name="DEPTH")
401-
for _, meters in depths.items():
401+
for meters in depths.values():
402402
depth = f"{meters.values:.0f}"
403403
if depth == "nan":
404404
depth = ""

src/cchdo/hydro/dt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _parse_datetime(date_val: str) -> np.datetime64:
4646

4747
if time_pad:
4848
if np.any(np.char.str_len(time_arr[time_arr != ""]) < 4):
49-
warn("Time values are being padded with zeros")
49+
warn("Time values are being padded with zeros", stacklevel=2)
5050
if not np.all(time_arr == ""):
5151
time_arr[time_arr != ""] = np.char.zfill(time_arr[time_arr != ""], 4)
5252

src/cchdo/hydro/exchange/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def __post_init__(self):
323323
self.error_cols.values(),
324324
)
325325
]
326-
if not all([shape == shapes[0] for shape in shapes]):
326+
if not all(shape == shapes[0] for shape in shapes):
327327
# TODO Error handling
328328
raise ValueError("shape error")
329329

@@ -634,7 +634,7 @@ def whp_errors(self):
634634
@property
635635
def _np_data_block(self):
636636
_raw_data = tuple(
637-
tuple((*self.ctd_headers.values(), *line.replace(" ", "").split(",")))
637+
(*self.ctd_headers.values(), *line.replace(" ", "").split(","))
638638
for line in self.data
639639
)
640640
return np.array(_raw_data, dtype="U")
@@ -931,7 +931,7 @@ def read_csv(
931931
0,
932932
0,
933933
)
934-
new_data = tuple((",".join(params_units_list), *splitdata[1:]))
934+
new_data = (",".join(params_units_list), *splitdata[1:])
935935
exchange_data = _ExchangeInfo(
936936
stamp_slice=NONE_SLICE,
937937
comments_slice=NONE_SLICE,

src/cchdo/hydro/exchange/helpers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def gen_template(
5858

5959
ftype = FileType(ftype)
6060

61-
exclude = set(
62-
[
61+
exclude = {
6362
"EXPOCODE",
6463
"STNNBR",
6564
"CASTNO",
@@ -71,8 +70,7 @@ def gen_template(
7170
"CTDPRS",
7271
"BTL_TIME",
7372
"BTL_DATE",
74-
]
75-
)
73+
}
7674

7775
params = [
7876
"EXPOCODE",

src/cchdo/hydro/legacy/coards/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_filename(expocode, station, cast, extension):
162162
station = _pad_station_cast(station)
163163
cast = _pad_station_cast(cast)
164164

165-
stem = "_".join((expocode, station, cast, extension))
165+
stem = f"{expocode}_{station}_{cast}_{extension}"
166166
return f"{stem}.{FILE_EXTENSION}"
167167

168168

src/cchdo/hydro/legacy/woce/__init__.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_filename(expocode, station, cast, file_ext):
126126
station = _pad_station_cast(station)
127127
cast = _pad_station_cast(cast)
128128
return "{}.{}".format(
129-
"_".join((expocode, station, cast)),
129+
f"{expocode}_{station}_{cast}",
130130
file_ext,
131131
)
132132

@@ -281,9 +281,7 @@ def quality_flags_of(column):
281281
flags = []
282282
for column in columns:
283283
format_str = column.attrs.get("cchdo.hydro._format", "%s")
284-
str_column = list(
285-
map(lambda x: format_str % x, column.fillna(FILL_VALUE).to_numpy())
286-
)
284+
str_column = [format_str % x for x in column.fillna(FILL_VALUE).to_numpy()]
287285
for i, d in enumerate(str_column):
288286
if len(d) > COLUMN_WIDTH:
289287
extra = len(d) - COLUMN_WIDTH
@@ -298,12 +296,7 @@ def quality_flags_of(column):
298296

299297
if acc.FLAG_NAME in column.attrs:
300298
flags.append(
301-
list(
302-
map(
303-
lambda x: f"{x:1d}",
304-
column.attrs[acc.FLAG_NAME].fillna(9).to_numpy().astype(int),
305-
)
306-
)
299+
[f"{x:1d}" for x in column.attrs[acc.FLAG_NAME].fillna(9).to_numpy().astype(int)]
307300
)
308301

309302
for row_d, row_f in zip_longest(zip(*data, strict=True), zip(*flags, strict=True), fillvalue=""):
@@ -336,7 +329,7 @@ def write_bottle(ds: xr.Dataset):
336329
record_1 += "\n"
337330

338331
data = write_data(ds, columns, base_format)
339-
return "".join([record_1, data]).encode("ascii", "replace")
332+
return f"{record_1}{data}".encode("ascii", "replace")
340333

341334

342335
def write_ctd(ds: xr.Dataset):
@@ -367,9 +360,9 @@ def write_ctd(ds: xr.Dataset):
367360
f"INSTRUMENT NO. {instrument_no: >5s} SAMPLING RATE {sampling_rate:>6.2f} HZ"
368361
)
369362

370-
headers = "\n".join([record1, record2, record3])
363+
headers = f"{record1}\n{record2}\n{record3}"
371364
data = write_data(ds, columns, base_format)
372-
return "\n".join([headers, data]).encode("ascii", "replace")
365+
return f"{headers}\n{data}".encode("ascii", "replace")
373366

374367

375368
def to_woce(ds: xr.Dataset) -> bytes:

src/cchdo/hydro/tests/test_core_ops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ def test_remove_param(param, flag, error, empty, require_empty):
270270
*filter(lambda x: not x[0], zip(bools, params, units, data, strict=True)), strict=True
271271
)
272272
else:
273-
_params = tuple()
274-
_units = tuple()
275-
_data = tuple()
273+
_params = ()
274+
_units = ()
275+
_data = ()
276276

277277
expected_ds = read_exchange(
278278
io.BytesIO(simple_bottle_exchange(params=_params, units=_units, data=_data)),

src/cchdo/hydro/tests/test_rename.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_rename():
2424
name_dict = {"var1": "new_var1"}
2525
result = rename_with_bookkeeping(example, name_dict, attrs=["ancillary_variables"])
2626
assert "new_var1" in result.data_vars.keys()
27-
for var, da in result.filter_by_attrs(ancillary_variables=is_not_none).items():
27+
for da in result.filter_by_attrs(ancillary_variables=is_not_none).values():
2828
assert "new_var1" in da.attrs["ancillary_variables"]
2929
assert "var2" in da.attrs["ancillary_variables"]
3030

src/cchdo/hydro/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def add_geometry_var(dataset: xr.Dataset) -> xr.Dataset:
6767
def add_cdom_coordinate(dataset: xr.Dataset) -> xr.Dataset:
6868
"""Find all the paraters in the cdom group and add their wavelength in a new coordinate"""
6969

70-
cdom_names = [
71-
name for name in filter(lambda x: x.nc_group == "cdom", WHPNames.values())
72-
]
70+
cdom_names = list(filter(lambda x: x.nc_group == "cdom", WHPNames.values()))
7371

7472
cdom_names = sorted(cdom_names, key=lambda x: x.radiation_wavelength or 0)
7573

0 commit comments

Comments
 (0)