Skip to content

Commit 4b21ac1

Browse files
committed
[hdf5/Feature] implement dataFrame and dataArray getter
1 parent 549b609 commit 4b21ac1

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

backend/hdf5/FeatureHDF5.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ void FeatureHDF5::data(const std::string &name_or_id) {
167167
}
168168

169169

170-
shared_ptr<IDataArray> FeatureHDF5::data() const {
170+
shared_ptr<IDataArray> FeatureHDF5::dataArray() const {
171+
if (targetType() != TargetType::DataArray) {
172+
throw std::runtime_error("Cannot convert Feature data to DataArray! Feature target is of type DataFrame!");
173+
}
171174
shared_ptr<IDataArray> da;
172-
173175
if (group().hasGroup("data")) {
174176
H5Group other_group = group().openGroup("data", false);
175177
da = make_shared<DataArrayHDF5>(file(), block, other_group);
@@ -181,6 +183,23 @@ shared_ptr<IDataArray> FeatureHDF5::data() const {
181183
}
182184

183185

186+
shared_ptr<IDataFrame> FeatureHDF5::dataFrame() const {
187+
if (targetType() != TargetType::DataFrame) {
188+
throw std::runtime_error("Cannot convert Feature data to DataFrame! Feature target is of type DataArray!");
189+
}
190+
shared_ptr<IDataFrame> df;
191+
if (group().hasGroup("data")) {
192+
H5Group other_group = group().openGroup("data", false);
193+
df = make_shared<DataFrameHDF5>(file(), block, other_group);
194+
195+
if (!block->hasEntity(df)) {
196+
throw std::runtime_error("FeatureHDF5::data: DataFrame not found!");
197+
}
198+
}
199+
return df;
200+
}
201+
202+
184203
LinkType FeatureHDF5::linkType() const {
185204
if (group().hasAttr("link_type")) {
186205
string link_type;
@@ -197,7 +216,7 @@ TargetType FeatureHDF5::targetType() const {
197216
group().getAttr("target_type", target_type);
198217
return targetTypeFromString(target_type);
199218
} else {
200-
return TargetType::DataFrame;
219+
return TargetType::DataArray;
201220
}
202221
}
203222

backend/hdf5/FeatureHDF5.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ class FeatureHDF5 : virtual public base::IFeature, public EntityHDF5 {
116116
void data(const DataFrame &data);
117117

118118

119-
std::shared_ptr<base::IDataArray> data() const;
119+
std::shared_ptr<base::IDataArray> dataArray() const;
120120

121121

122+
std::shared_ptr<base::IDataFrame> dataFrame() const;
123+
122124
virtual ~FeatureHDF5();
123125

124126
};

0 commit comments

Comments
 (0)