Skip to content

Commit

Permalink
address with_target_names review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
oojo12 committed Nov 1, 2022
1 parent b4ed2a3 commit 39d29c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/dataset/impl_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,8 @@ impl<L, R: Records, T: AsTargets<Elem = L>> DatasetBase<R, T> {
/// Returns target names
///
/// A target name gives a human-readable string describing the purpose of a single target.
pub fn target_names(&self) -> Vec<String> {
if !self.target_names.is_empty() {
self.target_names.clone()
} else {
(0..self.ntargets())
.map(|idx| format!("class-{}", idx))
.collect()
}
pub fn target_names(&self) -> &[String] {
&self.target_names
}

/// Return the number of targets in the dataset
Expand Down
6 changes: 6 additions & 0 deletions src/dataset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ mod tests {
assert_eq!(dataset.target_names, vec!["test"]);
}

#[test]
fn empty_target_name() {
let dataset = Dataset::new(array![[1., 2.], [1., 2.]], array![[0., 1.], [2., 3.]]);
assert_eq!(dataset.target_names, Vec::<String>::new());
}

#[test]
fn dataset_implements_required_methods() {
let mut rng = SmallRng::seed_from_u64(42);
Expand Down

0 comments on commit 39d29c5

Please sign in to comment.