Skip to content

Commit 471888e

Browse files
Calculate pandas categorical hash once. (#12)
1 parent 089a748 commit 471888e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/lightgbm/booster.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ def load_pandas_categorical(file_name: nil, model_str: nil)
269269
last_line = model_str[idx..].strip
270270
end
271271
if last_line.start_with?(pandas_key)
272-
JSON.parse(last_line[pandas_key.length..])
272+
pandas_categorical = JSON.parse(last_line[pandas_key.length..])
273+
pandas_categorical.map { |cats| cats.each_with_index.to_h }
273274
end
274275
end
275276

lib/lightgbm/inner_predictor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def cached_feature_name
140140

141141
def apply_pandas_categorical(data, categorical_feature, pandas_categorical)
142142
(categorical_feature || []).each_with_index do |cf, i|
143-
cat_codes = pandas_categorical[i].map.with_index.to_h
143+
cat_codes = pandas_categorical[i]
144144
data.each do |r|
145145
cat = r[cf]
146146
unless cat.nil?

0 commit comments

Comments
 (0)