Skip to content

Commit bc083e6

Browse files
committed
Correctly handle null column descriptions
1 parent 0051368 commit bc083e6

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/opencosmo/dataset/dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ def with_new_columns(
737737
"""
738738
if isinstance(descriptions, str):
739739
descriptions = {key: descriptions for key in new_columns.keys()}
740+
print(descriptions)
740741
new_state = self.__state.with_new_columns(descriptions, **new_columns)
741742
return Dataset(self.__handler, self.__header, new_state, self.__tree)
742743

src/opencosmo/dataset/state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def with_new_columns(
197197
new_im_handler = self.__im_handler
198198
derived_update = {}
199199
new_unit_handler = self.__unit_handler
200+
print(new_columns)
200201
for name, new_col in new_columns.items():
201202
if name in column_names:
202203
raise ValueError(f"Dataset already has column named {name}")
@@ -216,7 +217,7 @@ def with_new_columns(
216217
new_unit_handler = new_unit_handler.with_new_columns(**{name: None})
217218

218219
new_im_handler = new_im_handler.with_new_column(
219-
name, new_col, descriptions.get(name)
220+
name, new_col, descriptions.get(name, "None")
220221
)
221222

222223
elif not new_col.check_parent_existance(column_names):
@@ -226,7 +227,7 @@ def with_new_columns(
226227
)
227228
else:
228229
unit = new_col.get_units(self.__unit_handler.base_units)
229-
new_col.description = descriptions.get(name)
230+
new_col.description = descriptions.get(name, "None")
230231
new_unit_handler = new_unit_handler.with_new_columns(**{name: unit})
231232
derived_update[name] = new_col
232233
column_names.add(name)

test/test_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ def test_descriptions_after_insert(input_path, tmp_path):
6060
p = tmp_path / "test.hdf5"
6161
random_data = np.random.randint(0, 100, len(ds))
6262
ds = ds.with_new_columns(random_data=random_data)
63-
assert ds.descriptions["random_data"] is None
63+
assert ds.descriptions["random_data"] == "None"
6464
oc.write(p, ds)
6565
ds = oc.open(p)
6666
descriptions = ds.descriptions
67-
assert descriptions["random_data"] is None
67+
assert descriptions["random_data"] == "None"
6868

6969

7070
def test_description_with_insert(input_path, tmp_path):
7171
ds = oc.open(input_path)
7272
p = tmp_path / "test.hdf5"
7373
random_data = np.random.randint(0, 100, len(ds))
7474
ds = ds.with_new_columns(
75-
random_data=random_data, description="random data for a test"
75+
random_data=random_data, descriptions="random data for a test"
7676
)
7777
assert ds.descriptions["random_data"] == "random data for a test"
7878
oc.write(p, ds)
@@ -89,7 +89,7 @@ def test_description_with_insert_multiple(input_path, tmp_path):
8989
ds = ds.with_new_columns(
9090
random_data=random_data,
9191
halo_px=fof_halo_px,
92-
description={
92+
descriptions={
9393
"random_data": "random data for a test",
9494
"halo_px": "halo x momentum",
9595
},

0 commit comments

Comments
 (0)