@@ -2050,40 +2050,56 @@ class MLMExtensionHooks(ExtensionHooks):
20502050
20512051 @staticmethod
20522052 def _migrate_1_0_to_1_1 (obj : dict [str , Any ]) -> None :
2053- if "mlm:framework" in obj ["properties" ]:
2054- framework = obj ["properties" ]["mlm:framework" ]
2055- # remove invalid characters at beginning and end
2056- forbidden_chars = ["." , "_" , "-" , " " , "\t " , "\n " , "\r " , "\f " , "\v " ]
2057- if framework [0 ] in forbidden_chars or framework [- 1 ] in forbidden_chars :
2058- warnings .warn (
2059- "Value for mlm:framework is invalid in mlm>=1.1, as it must"
2060- "not start or end with one of the following characters: "
2061- "._- and whitespace. These characters are therefore removed while"
2062- "migrating the STAC object to v1.1." ,
2063- SyntaxWarning ,
2064- )
2065- while obj ["properties" ]["mlm:framework" ][0 ] in forbidden_chars :
2066- new_str = obj ["properties" ]["mlm:framework" ][1 :]
2067- obj ["properties" ]["mlm:framework" ] = new_str
2068- while obj ["properties" ]["mlm:framework" ][- 1 ] in forbidden_chars :
2069- new_str = obj ["properties" ]["mlm:framework" ][:- 1 ]
2070- obj ["properties" ]["mlm:framework" ] = new_str
2071-
2072- # rename frameworks
2073- if obj ["properties" ]["mlm:framework" ] == "Scikit-learn" :
2074- obj ["properties" ]["mlm:framework" ] = "scikit-learn"
2075- warnings .warn (
2076- "mlm:framework value Scikit-learn is no longer valid in mlm>=1.1. "
2077- "Renaming it to scikit-learn" ,
2078- SyntaxWarning ,
2079- )
2080- if obj ["properties" ]["mlm:framework" ] == "Huggingface" :
2081- obj ["properties" ]["mlm:framework" ] = "Hugging Face"
2082- warnings .warn (
2083- "mlm:framework value Huggingface is no longer valid in mlm>=1.1. "
2084- "Renaming it to Hugging Face" ,
2085- SyntaxWarning ,
2086- )
2053+ def migrate (props_obj : dict [str , Any ]) -> None :
2054+ if "mlm:framework" in props_obj :
2055+ framework = props_obj ["mlm:framework" ]
2056+ # remove invalid characters at beginning and end
2057+ forbidden_chars = ["." , "_" , "-" , " " , "\t " , "\n " , "\r " , "\f " , "\v " ]
2058+ if framework [0 ] in forbidden_chars or framework [- 1 ] in forbidden_chars :
2059+ warnings .warn (
2060+ "Value for mlm:framework is invalid in mlm>=1.1, as it must"
2061+ "not start or end with one of the following characters: "
2062+ "._- and whitespace. These characters are therefore removed "
2063+ "while migrating the STAC object to v1.1." ,
2064+ SyntaxWarning ,
2065+ )
2066+ while props_obj ["mlm:framework" ][0 ] in forbidden_chars :
2067+ new_str = props_obj ["mlm:framework" ][1 :]
2068+ props_obj ["mlm:framework" ] = new_str
2069+ while props_obj ["mlm:framework" ][- 1 ] in forbidden_chars :
2070+ new_str = props_obj ["mlm:framework" ][:- 1 ]
2071+ props_obj ["mlm:framework" ] = new_str
2072+
2073+ # rename frameworks
2074+ if props_obj ["mlm:framework" ] == "Scikit-learn" :
2075+ props_obj ["mlm:framework" ] = "scikit-learn"
2076+ warnings .warn (
2077+ "mlm:framework value Scikit-learn is no longer valid in "
2078+ "mlm>=1.1. Renaming it to scikit-learn" ,
2079+ SyntaxWarning ,
2080+ )
2081+ if props_obj ["mlm:framework" ] == "Huggingface" :
2082+ props_obj ["mlm:framework" ] = "Hugging Face"
2083+ warnings .warn (
2084+ "mlm:framework value Huggingface is no longer valid in "
2085+ "mlm>=1.1. Renaming it to Hugging Face" ,
2086+ SyntaxWarning ,
2087+ )
2088+
2089+ if obj ["type" ] == "Feature" :
2090+ migrate (obj ["properties" ])
2091+ if obj ["type" ] == "Collection" :
2092+ migrate (obj )
2093+
2094+ if "assets" in obj :
2095+ for asset_name in obj ["assets" ]:
2096+ asset = obj ["assets" ][asset_name ]
2097+ migrate (asset )
2098+
2099+ if obj ["type" ] == "Collection" and "item_assets" in obj :
2100+ for asset_name in obj ["item_assets" ]:
2101+ asset = obj ["item_assets" ][asset_name ]
2102+ migrate (asset )
20872103
20882104 @staticmethod
20892105 def _migrate_1_1_to_1_2 (obj : dict [str , Any ]) -> None :
0 commit comments