@@ -1645,11 +1645,14 @@ def simplify(feature: dict) -> dict:
1645
1645
#
1646
1646
# class_label: -> class_label:
1647
1647
# names: -> names:
1648
- # - negative -> 0 : negative
1649
- # - positive -> 1 : positive
1648
+ # - negative -> '0' : negative
1649
+ # - positive -> '1' : positive
1650
1650
#
1651
1651
if isinstance (feature .get ("class_label" ), dict ) and isinstance (feature ["class_label" ].get ("names" ), list ):
1652
- feature ["class_label" ]["names" ] = dict (enumerate (feature ["class_label" ]["names" ]))
1652
+ # server-side requirement: keys must be strings
1653
+ feature ["class_label" ]["names" ] = {
1654
+ str (label_id ): label_name for label_id , label_name in enumerate (feature ["class_label" ]["names" ])
1655
+ }
1653
1656
return feature
1654
1657
1655
1658
def to_yaml_inner (obj : Union [dict , list ]) -> dict :
@@ -1698,14 +1701,14 @@ def unsimplify(feature: dict) -> dict:
1698
1701
#
1699
1702
# class_label: -> class_label:
1700
1703
# names: -> names:
1701
- # 0 : negative -> - negative
1702
- # 1 : positive -> - positive
1704
+ # '0' : negative -> - negative
1705
+ # '1' : positive -> - positive
1703
1706
#
1704
1707
if isinstance (feature .get ("class_label" ), dict ) and isinstance (feature ["class_label" ].get ("names" ), dict ):
1705
- label_ids = sorted (feature ["class_label" ]["names" ])
1706
- if label_ids and label_ids != list (range (label_ids [- 1 ] + 1 )):
1708
+ label_ids = sorted (feature ["class_label" ]["names" ], key = int )
1709
+ if label_ids and [ int ( label_id ) for label_id in label_ids ] != list (range (int ( label_ids [- 1 ]) + 1 )):
1707
1710
raise ValueError (
1708
- f"ClassLabel expected a value for all label ids [0:{ label_ids [- 1 ] + 1 } ] but some ids are missing."
1711
+ f"ClassLabel expected a value for all label ids [0:{ int ( label_ids [- 1 ]) + 1 } ] but some ids are missing."
1709
1712
)
1710
1713
feature ["class_label" ]["names" ] = [feature ["class_label" ]["names" ][label_id ] for label_id in label_ids ]
1711
1714
return feature
0 commit comments