Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test de la correction du problème de parsing | |
| """ | |
| import pandas as pd | |
| def test_direct_csv_loading(): | |
| """Test du chargement direct des CSV depuis HuggingFace""" | |
| dataset_id = "HackathonCRA/2024" | |
| csv_files = [ | |
| "Interventions-(sortie-excel)-Station_Expérimentale_de_Kerguéhennec-2020.csv", | |
| "Interventions-(sortie-excel)-Station_Expérimentale_de_Kerguéhennec-2021.csv", | |
| "Interventions-(sortie-excel)-Station_Expérimentale_de_Kerguéhennec-2022.csv", | |
| "Interventions-(sortie-excel)-Station_Expérimentale_de_Kerguéhennec-2023.csv", | |
| "Interventions-(sortie-excel)-Station_Expérimentale_de_Kerguéhennec-2024.csv", | |
| "Interventions-(sortie-excel)-Station_Expérimentale_de_Kerguéhennec-2025.csv" | |
| ] | |
| print("🧪 Test du chargement CSV direct depuis HuggingFace") | |
| print("=" * 60) | |
| all_dataframes = [] | |
| for csv_file in csv_files: | |
| try: | |
| # URL directe vers le fichier | |
| file_url = f"https://huggingface.co/datasets/{dataset_id}/resolve/main/{csv_file}" | |
| print(f"📥 Test: {csv_file}") | |
| # Charger avec pandas en forçant tout en string | |
| df_temp = pd.read_csv(file_url, dtype=str, na_filter=False, nrows=5) # Juste 5 lignes pour test | |
| print(f" ✅ Succès: {df_temp.shape[0]} lignes, {df_temp.shape[1]} colonnes") | |
| print(f" 📊 Colonnes: {list(df_temp.columns)[:5]}...") | |
| df_temp['source_file'] = csv_file | |
| all_dataframes.append(df_temp) | |
| except Exception as e: | |
| print(f" ❌ Erreur: {str(e)[:100]}...") | |
| continue | |
| if all_dataframes: | |
| # Concaténer | |
| df_combined = pd.concat(all_dataframes, ignore_index=True) | |
| print(f"\n🎯 RÉSULTAT:") | |
| print(f" ✅ {len(csv_files)} fichiers testés") | |
| print(f" ✅ {len(all_dataframes)} fichiers chargés avec succès") | |
| print(f" ✅ {df_combined.shape[0]} lignes totales") | |
| print(f" ✅ {df_combined.shape[1]} colonnes") | |
| # Vérifier millesime | |
| if 'millesime' in df_combined.columns: | |
| print(f" 📅 Années détectées: {sorted(df_combined['millesime'].unique())}") | |
| print(f"\n💡 La solution de chargement direct fonctionne !") | |
| return True | |
| else: | |
| print(f"\n❌ Aucun fichier n'a pu être chargé") | |
| return False | |
| if __name__ == "__main__": | |
| test_direct_csv_loading() | |