Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ int main(int argc, char** argv)
```

## caveats
- NRZ variables shape, in order to expose a consistent shape, PyCDFpp exposes the reccord count as first dimension and thus its value will be either 0 or 1 (0 mean empty variable).
- NRV variables shape, in order to expose a consistent shape, PyCDFpp exposes the reccord count as first dimension and thus its value will be either 0 or 1 (0 mean empty variable).
15 changes: 9 additions & 6 deletions include/cdfpp/cdf-io/saving/create_records.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ namespace saving
return cpr;
}

int32_t attribute_entry_num_elements(const data_t& entry)
{
return visit(
entry, [](const cdf_none&) -> int32_t { return 0; },
[](const auto& v) -> int32_t { return std::size(v); });
}

inline void create_file_attributes_records(const CDF& cdf, saving_context& svg_ctx)
{
for (const auto& [name, attribute] : cdf.attributes)
Expand Down Expand Up @@ -96,9 +103,7 @@ namespace saving
},
[](const auto&) -> uint32_t { return 0; });
}
aedr.record.NumElements = visit(
data, [](const cdf_none&) -> uint32_t { return 0; },
[](const auto& v) -> uint32_t { return std::size(v); });
aedr.record.NumElements = attribute_entry_num_elements(data);
value_index += 1;
update_size(aedr, aedr.record.NumElements * cdf_type_size(aedr.record.DataType));
}
Expand Down Expand Up @@ -143,9 +148,7 @@ namespace saving
},
[](const auto&) -> int32_t { return 0; });
}
aedr.record.NumElements = visit(
data, [](const cdf_none&) -> int32_t { return 0; },
[](const auto& v) -> int32_t { return std::size(v); });
aedr.record.NumElements = attribute_entry_num_elements(data);
update_size(aedr, aedr.record.NumElements * cdf_type_size(aedr.record.DataType));
vac.adr.record.MAXzEntries = std::max(vac.adr.record.MAXzEntries, aedr.record.Num);
vac.adr.record.NzEntries = std::size(vac.aedrs);
Expand Down
4 changes: 2 additions & 2 deletions include/cdfpp/variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct Variable
stream_collection(os, shape(), ", ");
os << "\n"
<< indent + 2 << "type: " << cdf_type_str(type()) << "\n"
<< indent + 2 << "record varry: " << (is_nrv() ? "Flase" : "True") << "\n"
<< indent + 2 << "record vary: " << (is_nrv() ? "False" : "True") << "\n"
<< indent + 2 << compression_type() << "\n\n";
os << indent + 2 << "Attributes:\n";
std::for_each(std::cbegin(attributes), std::cend(attributes),
Expand All @@ -230,7 +230,7 @@ struct Variable
os << indent << name() << ": ";
stream_collection(os, shape(), ", ");
os << ", [" << cdf_type_str(type())
<< "], record varry:" << (is_nrv() ? "Flase" : "True")
<< "], record vary:" << (is_nrv() ? "False" : "True")
<< ", compression: " << cdf_compression_type_str(compression_type()) << std::endl;
}
return os;
Expand Down
11 changes: 9 additions & 2 deletions pycdfpp/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ data_t to_attr_data_entry(const std::string& values, CDF_Types data_type)
{
if (data_type == CDF_Types::CDF_CHAR or data_type == CDF_Types::CDF_UCHAR)
{
return { no_init_vector<char>(std::cbegin(values), std::cend(values)), data_type };
if (std::size(values) != 0)
{
return { no_init_vector<char>(std::cbegin(values), std::cend(values)), data_type };
}
else
{
return { no_init_vector<char> { { 0 } }, data_type };
}
}
else
{
Expand Down Expand Up @@ -229,7 +236,7 @@ data_t _time_to_data_t(const py::buffer& buffer)
template <typename T>
data_t time_to_data_t(const std::vector<T>& values)
{
return data_t {no_init_vector<T>(std::cbegin(values), std::cend(values))};
return data_t { no_init_vector<T>(std::cbegin(values), std::cend(values)) };
}

template <CDF_Types data_type>
Expand Down
2 changes: 1 addition & 1 deletion tests/full_corpus/test_full_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def tearDown(self):
)
@ddt.unpack
def test_opens_in_memory_remote_files(self, fname, variables, attrs):
cdf = pycdfpp.load(requests.get(f"https://hephaistos.lpp.polytechnique.fr/data/mirrors/CDF/test_files/{fname}").content)
cdf = pycdfpp.load(requests.get(f"https://129.104.27.7/data/mirrors/CDF/test_files/{fname}", verify=False).content)
self.assertIsNotNone(cdf)
self.assertEqual(len(cdf), variables)
self.assertEqual(len(cdf.attributes), attrs)
Expand Down