Skip to content

Commit f3bb641

Browse files
committed
Added feature types for Rover data frames
1 parent 19b8035 commit f3bb641

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/xgboost/dmatrix.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ def initialize(data, label: nil, weight: nil, missing: Float::NAN)
3434
elsif rover?(data)
3535
nrow, ncol = data.shape
3636
feature_names = data.keys
37+
feature_types =
38+
data.types.map do |_, v|
39+
v = v.to_s
40+
if v.start_with?("int") || v.start_with?("uint")
41+
"int"
42+
elsif v.start_with?("float")
43+
"float"
44+
else
45+
raise Error, "Unknown feature type: #{v}"
46+
end
47+
end
3748
data = data.to_numo
3849
else
3950
nrow = data.count

test/dmatrix_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ def test_rover
8484
dataset = XGBoost::DMatrix.new(data, label: label)
8585
names = ["x0", "x1", "x2", "x3"]
8686
assert_equal names, dataset.feature_names
87-
# TODO add types
88-
# types = ["float", "float", "float", "int"]
89-
# assert_equal types, dataset.feature_types
87+
types = ["float", "float", "float", "int"]
88+
assert_equal types, dataset.feature_types
9089
end
9190

9291
def test_invalid

0 commit comments

Comments
 (0)