Skip to content

Commit

Permalink
Fixes #25
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
  • Loading branch information
jeandet committed Dec 3, 2023
1 parent ec5237c commit 14ae6f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pycdfpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def _add_variable_wrapper(self, name: str, values: np.ndarray or None = None, da
v, t = _values_view_and_type(values, data_type)
var = self._add_variable(
name=name, values=v, data_type=t, is_nrv=is_nrv, compression=compression)
elif data_type is not None:
v,t = _values_view_and_type([], data_type)
var = self._add_variable(
name=name, values=v, data_type=t, is_nrv=is_nrv, compression=compression)
else:
var = self._add_variable(
name=name, is_nrv=is_nrv, compression=compression)
Expand Down
8 changes: 8 additions & 0 deletions tests/python_saving/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,13 @@ def test_can_save_a_GZ_compressed_CDF(self):
cdf.compression = pycdfpp.CompressionType.gzip_compression
self.assertTrue(pycdfpp.save(cdf,f.name))


def test_can_save_a_cdf_with_an_empty_var(self):
#https://github.com/SciQLop/CDFpp/issues/25
with NamedTemporaryFile() as f:
cdf = pycdfpp.CDF()
cdf.add_variable("test", data_type=pycdfpp.DataType.CDF_TIME_TT2000)
self.assertTrue(pycdfpp.save(cdf,f.name))

if __name__ == '__main__':
unittest.main()

0 comments on commit 14ae6f2

Please sign in to comment.