namanpenguin commited on
Commit
28cd8d3
·
verified ·
1 Parent(s): 39918b3

Update dataset_utils.py

Browse files
Files changed (1) hide show
  1. dataset_utils.py +11 -4
dataset_utils.py CHANGED
@@ -142,14 +142,21 @@ def save_label_encoders(label_encoders):
142
  def load_label_encoders():
143
  """
144
  Loads a dictionary of label encoders from a pickle file.
 
145
 
146
  Returns:
147
  dict: Loaded dictionary of LabelEncoder objects.
148
  """
149
- with open(LABEL_ENCODERS_PATH, "rb") as f:
150
- return pickle.load(f)
151
- print(f"Label encoders loaded from {LABEL_ENCODERS_PATH}")
152
-
 
 
 
 
 
 
153
 
154
  def get_num_labels(label_encoders):
155
  """
 
142
  def load_label_encoders():
143
  """
144
  Loads a dictionary of label encoders from a pickle file.
145
+ Handles scikit-learn version mismatches gracefully.
146
 
147
  Returns:
148
  dict: Loaded dictionary of LabelEncoder objects.
149
  """
150
+ try:
151
+ with open(LABEL_ENCODERS_PATH, "rb") as f:
152
+ label_encoders = pickle.load(f)
153
+ print(f"Label encoders loaded from {LABEL_ENCODERS_PATH}")
154
+ return label_encoders
155
+ except Exception as e:
156
+ print(f"Warning: Could not load label encoders from {LABEL_ENCODERS_PATH}: {str(e)}")
157
+ print("Creating new label encoders...")
158
+ # Create empty label encoders as fallback
159
+ return {col: LabelEncoder() for col in LABEL_COLUMNS}
160
 
161
  def get_num_labels(label_encoders):
162
  """