power-grid-model-io 1.2.88__tar.gz → 1.2.90__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of power-grid-model-io might be problematic. Click here for more details.

Files changed (136) hide show
  1. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/PKG-INFO +1 -1
  2. power_grid_model_io-1.2.90/PYPI_VERSION +1 -0
  3. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/converters/vision_excel_converter.py +2 -1
  4. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_stores/excel_file_store.py +8 -6
  5. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/functions/filters.py +1 -1
  6. power_grid_model_io-1.2.90/src/power_grid_model_io/utils/excel_ambiguity_checker.py +165 -0
  7. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io.egg-info/PKG-INFO +1 -1
  8. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io.egg-info/SOURCES.txt +5 -2
  9. power_grid_model_io-1.2.90/tests/data/vision/excel_ambiguity_check_data.xlsx +0 -0
  10. power_grid_model_io-1.2.90/tests/data/zip/foo.zip.license +3 -0
  11. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/test_vision_excel_converter.py +8 -0
  12. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_stores/test_excel_file_store.py +8 -7
  13. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_uuid_excel_cvtr.py +7 -9
  14. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/converters/test_vision_excel_converter.py +3 -4
  15. power_grid_model_io-1.2.88/PYPI_VERSION +0 -1
  16. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/LICENSE +0 -0
  17. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/MANIFEST.in +0 -0
  18. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/README.md +0 -0
  19. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/VERSION +0 -0
  20. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/pyproject.toml +0 -0
  21. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/setup.cfg +0 -0
  22. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/setup.py +0 -0
  23. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/__init__.py +0 -0
  24. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/__init__.py +0 -0
  25. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/examples/__init__.py +0 -0
  26. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/examples/multipliers.yaml +0 -0
  27. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/excel/__init__.py +0 -0
  28. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/excel/vision_en.yaml +0 -0
  29. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/excel/vision_en_9_7.yaml +0 -0
  30. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/config/excel/vision_nl.yaml +0 -0
  31. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/converters/__init__.py +0 -0
  32. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/converters/base_converter.py +0 -0
  33. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/converters/pandapower_converter.py +0 -0
  34. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/converters/pgm_json_converter.py +0 -0
  35. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/converters/tabular_converter.py +0 -0
  36. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_stores/__init__.py +0 -0
  37. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_stores/base_data_store.py +0 -0
  38. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_stores/csv_dir_store.py +0 -0
  39. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_stores/json_file_store.py +0 -0
  40. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_stores/vision_excel_file_store.py +0 -0
  41. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_types/__init__.py +0 -0
  42. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_types/_data_types.py +0 -0
  43. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/data_types/tabular_data.py +0 -0
  44. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/functions/__init__.py +0 -0
  45. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/functions/_functions.py +0 -0
  46. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/functions/phase_to_phase.py +0 -0
  47. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/mappings/__init__.py +0 -0
  48. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/mappings/field_mapping.py +0 -0
  49. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/mappings/multiplier_mapping.py +0 -0
  50. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/mappings/tabular_mapping.py +0 -0
  51. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/mappings/unit_mapping.py +0 -0
  52. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/mappings/value_mapping.py +0 -0
  53. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/__init__.py +0 -0
  54. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/auto_id.py +0 -0
  55. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/dict.py +0 -0
  56. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/download.py +0 -0
  57. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/json.py +0 -0
  58. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/modules.py +0 -0
  59. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/parsing.py +0 -0
  60. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/uuid_excel_cvtr.py +0 -0
  61. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io/utils/zip.py +0 -0
  62. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io.egg-info/dependency_links.txt +0 -0
  63. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io.egg-info/requires.txt +0 -0
  64. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/src/power_grid_model_io.egg-info/top_level.txt +0 -0
  65. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/__init__.py +0 -0
  66. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/conftest.py +0 -0
  67. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/config/dummy_mapping.yaml +0 -0
  68. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/config/mapping.yaml +0 -0
  69. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pgm_asym_output_data.json +0 -0
  70. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pgm_asym_output_data.json.license +0 -0
  71. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pgm_input_data.json +0 -0
  72. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pgm_input_data.json.license +0 -0
  73. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pgm_output_data.json +0 -0
  74. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pgm_output_data.json.license +0 -0
  75. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/pandapower/pp_validation.py +0 -0
  76. /power_grid_model_io-1.2.88/tests/data/vision/pgm_input_data_en.json.license → /power_grid_model_io-1.2.90/tests/data/vision/excel_ambiguity_check_data.xlsx.license +0 -0
  77. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/pgm_input_data_en.json +0 -0
  78. /power_grid_model_io-1.2.88/tests/data/vision/pgm_input_data_nl.json.license → /power_grid_model_io-1.2.90/tests/data/vision/pgm_input_data_en.json.license +0 -0
  79. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/pgm_input_data_nl.json +0 -0
  80. /power_grid_model_io-1.2.88/tests/data/vision/vision_97_en.xlsx.license → /power_grid_model_io-1.2.90/tests/data/vision/pgm_input_data_nl.json.license +0 -0
  81. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/vision_9_5_en.yaml +0 -0
  82. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/vision_9_5_nl.yaml +0 -0
  83. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/vision_en.xlsx +0 -0
  84. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/vision_en.xlsx.license +0 -0
  85. /power_grid_model_io-1.2.88/tests/data/vision/vision_97_en.xlsx → /power_grid_model_io-1.2.90/tests/data/vision/vision_en_9_7.xlsx +0 -0
  86. /power_grid_model_io-1.2.88/tests/data/vision/vision_nl.xlsx.license → /power_grid_model_io-1.2.90/tests/data/vision/vision_en_9_7.xlsx.license +0 -0
  87. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/vision_nl.xlsx +0 -0
  88. /power_grid_model_io-1.2.88/tests/data/vision/vision_validation.vnf.license → /power_grid_model_io-1.2.90/tests/data/vision/vision_nl.xlsx.license +0 -0
  89. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/vision/vision_validation.vnf +0 -0
  90. /power_grid_model_io-1.2.88/tests/data/zip/foo-bar.zip.license → /power_grid_model_io-1.2.90/tests/data/vision/vision_validation.vnf.license +0 -0
  91. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/zip/foo-bar.zip +0 -0
  92. /power_grid_model_io-1.2.88/tests/data/zip/foo.zip.license → /power_grid_model_io-1.2.90/tests/data/zip/foo-bar.zip.license +0 -0
  93. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/data/zip/foo.zip +0 -0
  94. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/test_utils.py +0 -0
  95. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/__init__.py +0 -0
  96. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/conftest.py +0 -0
  97. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/__init__.py +0 -0
  98. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/test_base_converter.py +0 -0
  99. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/test_pandapower_converter_input.py +0 -0
  100. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/test_pandapower_converter_output.py +0 -0
  101. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/test_pgm_json_converter.py +0 -0
  102. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/converters/test_tabular_converter.py +0 -0
  103. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_stores/__init__.py +0 -0
  104. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_stores/test_base_data_store.py +0 -0
  105. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_stores/test_csv_dir_store.py +0 -0
  106. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_stores/test_json_file_store.py +0 -0
  107. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_stores/test_vision_excel_file_store.py +0 -0
  108. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_types/__init__.py +0 -0
  109. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_types/test_data_types.py +0 -0
  110. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/data_types/test_tabular_data.py +0 -0
  111. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/functions/__init__.py +0 -0
  112. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/functions/test_filters.py +0 -0
  113. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/functions/test_functions.py +0 -0
  114. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/functions/test_phase_to_phase.py +0 -0
  115. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/mappings/__init__.py +0 -0
  116. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/mappings/test_field_mapping.py +0 -0
  117. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/mappings/test_multiplier_mapping.py +0 -0
  118. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/mappings/test_tabular_mapping.py +0 -0
  119. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/mappings/test_unit_mapping.py +0 -0
  120. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/mappings/test_value_mapping.py +0 -0
  121. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/__init__.py +0 -0
  122. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_auto_id.py +0 -0
  123. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_dict.py +0 -0
  124. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_download.py +0 -0
  125. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_json.py +0 -0
  126. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_modules.py +0 -0
  127. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_parsing.py +0 -0
  128. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/unit/utils/test_zip.py +0 -0
  129. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/utils.py +0 -0
  130. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/__init__.py +0 -0
  131. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/conftest.py +0 -0
  132. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/converters/__init__.py +0 -0
  133. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/converters/test_pandapower_converter_input.py +0 -0
  134. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/converters/test_pandapower_converter_output.py +0 -0
  135. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/test_test_utils.py +0 -0
  136. {power_grid_model_io-1.2.88 → power_grid_model_io-1.2.90}/tests/validation/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: power-grid-model-io
3
- Version: 1.2.88
3
+ Version: 1.2.90
4
4
  Summary: Power Grid Model Input/Output
5
5
  Author-email: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
6
6
  License: MPL-2.0
@@ -0,0 +1 @@
1
+ 1.2.90
@@ -14,7 +14,8 @@ from power_grid_model_io.converters.tabular_converter import TabularConverter
14
14
  from power_grid_model_io.data_stores.base_data_store import LANGUAGE_EN
15
15
  from power_grid_model_io.data_stores.vision_excel_file_store import VisionExcelFileStore
16
16
 
17
- DEFAULT_MAPPING_FILE = Path(__file__).parent.parent / "config" / "excel" / "vision_{language:s}.yaml"
17
+ CONFIG_PATH = Path(__file__).parent.parent / "config" / "excel"
18
+ DEFAULT_MAPPING_FILE = CONFIG_PATH / "vision_{language:s}.yaml"
18
19
 
19
20
 
20
21
  @dataclass
@@ -167,14 +167,16 @@ class ExcelFileStore(BaseDataStore[TabularData]):
167
167
  if to_rename:
168
168
  columns = data.columns.values.copy()
169
169
  for col_idx, new_name in to_rename.items():
170
+ new_name = new_name[0] if isinstance(new_name, tuple) else new_name
171
+ full_new_name = (new_name, columns[col_idx][1])
170
172
  self._log.warning(
171
173
  "Column is renamed",
172
174
  sheet_name=sheet_name,
173
175
  col_name=columns[col_idx],
174
- new_name=new_name,
176
+ new_name=full_new_name,
175
177
  col_idx=col_idx,
176
178
  )
177
- columns[col_idx] = new_name
179
+ columns[col_idx] = full_new_name
178
180
 
179
181
  if data.columns.nlevels == 1:
180
182
  data.columns = pd.Index(columns)
@@ -218,7 +220,7 @@ class ExcelFileStore(BaseDataStore[TabularData]):
218
220
  if isinstance(col_name, tuple):
219
221
  to_rename[dup_idx] = (f"{col_name[0]}_{counter}",) + col_name[1:]
220
222
  else:
221
- to_rename[dup_idx] = f"{col_name[0]}_{counter}"
223
+ to_rename[dup_idx] = f"{col_name}_{counter}"
222
224
 
223
225
  return to_rename
224
226
 
@@ -253,7 +255,7 @@ class ExcelFileStore(BaseDataStore[TabularData]):
253
255
  grouped: Dict[Union[str, Tuple[str, ...]], Set[int]] = {}
254
256
  columns = data.columns.values
255
257
  for col_idx, col_name in enumerate(columns):
256
- if col_name not in grouped:
257
- grouped[col_name] = set()
258
- grouped[col_name].add(col_idx)
258
+ if col_name[0] not in grouped:
259
+ grouped[col_name[0]] = set()
260
+ grouped[col_name[0]].add(col_idx)
259
261
  return grouped
@@ -16,7 +16,7 @@ def exclude_empty(row: pd.Series, col: str) -> bool:
16
16
  """
17
17
  filter out empty
18
18
  """
19
- if col not in row:
19
+ if col not in row:
20
20
  raise ValueError(f"The column: '{col}' cannot be found for the filter")
21
21
  result = has_value(row[col])
22
22
  if isinstance(result, pd.Series):
@@ -0,0 +1,165 @@
1
+ # SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2
+ #
3
+ # SPDX-License-Identifier: MPL-2.0
4
+ """
5
+ This module provides the ExcelAmbiguityChecker class, which is designed to identify and report ambiguous column names
6
+ within the sheets of an Excel (.xlsx) file. It parses the Excel file, extracts the names of columns from a specified
7
+ row across all sheets, and checks for any duplicates within those names to flag them as ambiguous.
8
+
9
+ Usage:
10
+ checker = ExcelAmbiguityChecker(file_path='path/to/excel/file.xlsx', column_name_in_row=0)
11
+ has_ambiguity, ambiguous_columns = checker.check_ambiguity()
12
+ if has_ambiguity:
13
+ print("Ambiguous column names found:", ambiguous_columns)
14
+ else:
15
+ print("No ambiguous column names found.")
16
+
17
+ Requirements:
18
+ - Python 3.9 or higher (PGM library dependencies)
19
+ - xml.etree.ElementTree for parsing XML structures within the Excel file.
20
+ - zipfile to handle the Excel file as a ZIP archive for parsing.
21
+ """
22
+ import os
23
+ import xml.etree.ElementTree as ET
24
+ import zipfile
25
+ from collections import Counter
26
+ from typing import Dict, List, Optional, Tuple
27
+
28
+ XML_NAME_SPACE = {"": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"} # NOSONAR
29
+ WORK_BOOK = "xl/workbook.xml"
30
+ SHARED_STR_PATH = "xl/sharedStrings.xml"
31
+ FIND_T = ".//t"
32
+ FIND_C = ".//c"
33
+ FIND_V = ".//v"
34
+ NAME = "name"
35
+ FIND_ROW = ".//row"
36
+ FIND_SHEET = ".//sheet"
37
+ FIND_TYPE = "t"
38
+ TYPE_STR = "s"
39
+
40
+
41
+ class ExcelAmbiguityChecker:
42
+ """
43
+ A class to check for ambiguous column names within the sheets of an Excel (.xlsx) file.
44
+
45
+ Attributes:
46
+ _file_path (str): The path to the Excel file to be checked.
47
+ _col_name_in_row (int): The row index (0-based) where column names are expected. Default is 0.
48
+ sheets (dict): A dictionary storing sheet names as keys and lists of column names as values.
49
+
50
+ Methods:
51
+ __init__(self, file_path, column_name_in_row=0): Initializes the ExcelAmbiguityChecker instance.
52
+ _parse_zip(self, zip_file): Parses the shared strings XML file within the Excel ZIP archive.
53
+ _get_column_names_from_row(self, row, shared_strings): Extracts column names from a specified row.
54
+ _parse_excel_file(self): Parses the Excel file to extract sheet names and their corresponding column names.
55
+ """
56
+
57
+ def __init__(self, file_path, column_name_in_row=0) -> None:
58
+ """
59
+ Initializes the ExcelAmbiguityChecker with the path to an Excel file and the row index for column names.
60
+
61
+ Parameters:
62
+ file_path (str): The path to the Excel file.
63
+ column_name_in_row (int): The row index (0-based) where column names are expected. Default is 0.
64
+ """
65
+ self._valid_file = file_path.endswith(".xlsx") and os.path.exists(file_path)
66
+ if self._valid_file:
67
+ self._file_path = file_path
68
+ self._col_name_in_row = column_name_in_row
69
+ self.sheets: Dict[str, List[str]] = {}
70
+ self._parse_excel_file()
71
+
72
+ def _parse_zip(self, zip_file) -> List[Optional[str]]:
73
+ """
74
+ Parses the shared strings XML file within the Excel ZIP archive to extract all shared strings.
75
+
76
+ Parameters:
77
+ zip_file (zipfile.ZipFile): The opened Excel ZIP file.
78
+
79
+ Returns:
80
+ list: A list of shared strings used in the Excel file.
81
+ """
82
+ shared_strings_path = SHARED_STR_PATH
83
+ shared_strings = []
84
+ with zip_file.open(shared_strings_path) as f:
85
+ tree = ET.parse(f)
86
+ for si in tree.findall(FIND_T, namespaces=XML_NAME_SPACE):
87
+ shared_strings.append(si.text)
88
+ return shared_strings
89
+
90
+ def _get_column_names_from_row(self, row, shared_strings) -> List[Optional[str]]:
91
+ """
92
+ Extracts column names from a specified row using shared strings for strings stored in the shared string table.
93
+
94
+ Parameters:
95
+ row (xml.etree.ElementTree.Element): The XML element representing the row.
96
+ shared_strings (list): A list of shared strings extracted from the Excel file.
97
+
98
+ Returns:
99
+ list: A list of column names found in the row.
100
+ """
101
+ column_names = []
102
+ for c in row.findall(FIND_C, namespaces=XML_NAME_SPACE):
103
+ cell_type = c.get(FIND_TYPE)
104
+ value = c.find(FIND_V, namespaces=XML_NAME_SPACE)
105
+ if cell_type == TYPE_STR and value is not None:
106
+ column_names.append(shared_strings[int(value.text)])
107
+ elif value is not None:
108
+ column_names.append(value.text)
109
+ else:
110
+ column_names.append(None)
111
+ return column_names
112
+
113
+ def _parse_excel_file(self) -> None:
114
+ """
115
+ Parses the Excel file to extract sheet names and their corresponding column names.
116
+ """
117
+ with zipfile.ZipFile(self._file_path) as z:
118
+ shared_strings = self._parse_zip(z)
119
+ workbook_xml = z.read(WORK_BOOK)
120
+ xml_tree = ET.fromstring(workbook_xml)
121
+ sheets = xml_tree.findall(FIND_SHEET, namespaces=XML_NAME_SPACE)
122
+
123
+ for index, sheet in enumerate(sheets, start=1):
124
+ sheet_name = str(sheet.get(NAME))
125
+ sheet_file_path = f"xl/worksheets/sheet{index}.xml"
126
+
127
+ with z.open(sheet_file_path) as f:
128
+ sheet_tree = ET.parse(f)
129
+ rows = sheet_tree.findall(FIND_ROW, namespaces=XML_NAME_SPACE)
130
+ if rows:
131
+ column_names = self._get_column_names_from_row(rows[self._col_name_in_row], shared_strings)
132
+ self.sheets[sheet_name] = [name for name in column_names if name is not None]
133
+
134
+ def list_sheets(self) -> List[str]:
135
+ """
136
+ Get the list of all sheet names in the Excel file.
137
+
138
+ Returns:
139
+ List[str]: list of all sheet names
140
+ """
141
+ return list(self.sheets.keys())
142
+
143
+ def check_ambiguity(self) -> Tuple[bool, Dict[str, List[str]]]:
144
+ """
145
+ Check if there is ambiguity in column names across sheets.
146
+
147
+ Returns:
148
+ Tuple[bool, Dict[str, List[str]]]: A tuple containing a boolean indicating if any ambiguity was found,
149
+ and a dictionary with sheet names as keys and lists of ambiguous column names as values.
150
+ """
151
+ res: Dict[str, List[str]] = {}
152
+ if not self._valid_file:
153
+ return False, res
154
+ for sheet_name, column_names in self.sheets.items():
155
+ column_name_counts = Counter(column_names)
156
+ duplicates = [name for name, count in column_name_counts.items() if count > 1]
157
+ if duplicates:
158
+ res[sheet_name] = duplicates
159
+ return bool(res), res
160
+
161
+
162
+ # Example usage
163
+ if __name__ == "__main__":
164
+ excel_file_checker = ExcelAmbiguityChecker("excel_ambiguity_check_data.xlsx")
165
+ excel_file_checker.check_ambiguity()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: power-grid-model-io
3
- Version: 1.2.88
3
+ Version: 1.2.90
4
4
  Summary: Power Grid Model Input/Output
5
5
  Author-email: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
6
6
  License: MPL-2.0
@@ -47,6 +47,7 @@ src/power_grid_model_io/utils/__init__.py
47
47
  src/power_grid_model_io/utils/auto_id.py
48
48
  src/power_grid_model_io/utils/dict.py
49
49
  src/power_grid_model_io/utils/download.py
50
+ src/power_grid_model_io/utils/excel_ambiguity_checker.py
50
51
  src/power_grid_model_io/utils/json.py
51
52
  src/power_grid_model_io/utils/modules.py
52
53
  src/power_grid_model_io/utils/parsing.py
@@ -65,16 +66,18 @@ tests/data/pandapower/pgm_input_data.json.license
65
66
  tests/data/pandapower/pgm_output_data.json
66
67
  tests/data/pandapower/pgm_output_data.json.license
67
68
  tests/data/pandapower/pp_validation.py
69
+ tests/data/vision/excel_ambiguity_check_data.xlsx
70
+ tests/data/vision/excel_ambiguity_check_data.xlsx.license
68
71
  tests/data/vision/pgm_input_data_en.json
69
72
  tests/data/vision/pgm_input_data_en.json.license
70
73
  tests/data/vision/pgm_input_data_nl.json
71
74
  tests/data/vision/pgm_input_data_nl.json.license
72
- tests/data/vision/vision_97_en.xlsx
73
- tests/data/vision/vision_97_en.xlsx.license
74
75
  tests/data/vision/vision_9_5_en.yaml
75
76
  tests/data/vision/vision_9_5_nl.yaml
76
77
  tests/data/vision/vision_en.xlsx
77
78
  tests/data/vision/vision_en.xlsx.license
79
+ tests/data/vision/vision_en_9_7.xlsx
80
+ tests/data/vision/vision_en_9_7.xlsx.license
78
81
  tests/data/vision/vision_nl.xlsx
79
82
  tests/data/vision/vision_nl.xlsx.license
80
83
  tests/data/vision/vision_validation.vnf
@@ -0,0 +1,3 @@
1
+ SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2
+
3
+ SPDX-License-Identifier: MPL-2.0
@@ -7,6 +7,7 @@ from unittest.mock import patch
7
7
  import pytest
8
8
 
9
9
  from power_grid_model_io.converters.vision_excel_converter import DEFAULT_MAPPING_FILE, VisionExcelConverter
10
+ from power_grid_model_io.utils.excel_ambiguity_checker import ExcelAmbiguityChecker
10
11
 
11
12
 
12
13
  @pytest.fixture
@@ -139,3 +140,10 @@ def test_get_appliance_id(converter: VisionExcelConverter):
139
140
 
140
141
  with pytest.raises(KeyError):
141
142
  converter.get_appliance_id(table="Sources", node_number=1, sub_number=3)
143
+
144
+
145
+ def test_ambiguity_in_vision_excel():
146
+ ambiguious_test_file = Path(__file__).parents[2] / "data" / "vision" / "excel_ambiguity_check_data.xlsx"
147
+ excel_file_checker = ExcelAmbiguityChecker(file_path=ambiguious_test_file.as_posix())
148
+ res, _ = excel_file_checker.check_ambiguity()
149
+ assert res == True
@@ -308,7 +308,7 @@ def test_handle_duplicate_columns(mock_check_duplicate_values: MagicMock):
308
308
  [102, 202, 302, 111, 202, 102],
309
309
  [103, 203, 303, 103, 203, 103],
310
310
  ],
311
- columns=["A", "B", "C", "A", "B", "A"],
311
+ columns=[("A", ""), ("B", ""), ("C", ""), ("A", ""), ("B", ""), ("A", "KW")],
312
312
  )
313
313
  store = ExcelFileStore()
314
314
  mock_check_duplicate_values.return_value = {3: "A_2", 4: "B_2", 5: "A_3"}
@@ -319,17 +319,18 @@ def test_handle_duplicate_columns(mock_check_duplicate_values: MagicMock):
319
319
 
320
320
  # Assert
321
321
  assert len(cap_log) == 3
322
- assert_log_exists(cap_log, "warning", "Column is renamed", col_name="A", new_name="A_2", col_idx=3)
323
- assert_log_exists(cap_log, "warning", "Column is renamed", col_name="B", new_name="B_2", col_idx=4)
324
- assert_log_exists(cap_log, "warning", "Column is renamed", col_name="A", new_name="A_3", col_idx=5)
322
+ assert_log_exists(cap_log, "warning", "Column is renamed", col_name=("A", ""), new_name=("A_2", ""), col_idx=3)
323
+ assert_log_exists(cap_log, "warning", "Column is renamed", col_name=("B", ""), new_name=("B_2", ""), col_idx=4)
324
+ assert_log_exists(cap_log, "warning", "Column is renamed", col_name=("A", "KW"), new_name=("A_3", "KW"), col_idx=5)
325
325
 
326
326
  expected = pd.DataFrame(
327
327
  [ # A B C A_2 B_2 A_3
328
+ # KW
328
329
  [101, 201, 301, 101, 201, 101],
329
330
  [102, 202, 302, 111, 202, 102],
330
331
  [103, 203, 303, 103, 203, 103],
331
332
  ],
332
- columns=["A", "B", "C", "A_2", "B_2", "A_3"],
333
+ columns=[("A", ""), ("B", ""), ("C", ""), ("A_2", ""), ("B_2", ""), ("A_3", "KW")],
333
334
  )
334
335
  pd.testing.assert_frame_equal(actual, expected)
335
336
 
@@ -455,10 +456,10 @@ def test_group_columns_by_index():
455
456
 
456
457
  def test_group_columns_by_index__multi():
457
458
  # Arrange
458
- data = pd.DataFrame(columns=pd.MultiIndex.from_tuples([("A", 1), ("B", 2), ("C", 3), ("A", 1), ("B", 2), ("A", 1)]))
459
+ data = pd.DataFrame(columns=pd.MultiIndex.from_tuples([("A", 1), ("B", 2), ("C", 3), ("A", 4), ("B", 5), ("A", 6)]))
459
460
 
460
461
  # Act
461
462
  grouped = ExcelFileStore._group_columns_by_index(data=data)
462
463
 
463
464
  # Assert
464
- assert grouped == {("A", 1): {0, 3, 5}, ("B", 2): {1, 4}, ("C", 3): {2}}
465
+ assert grouped == {"A": {0, 3, 5}, "B": {1, 4}, "C": {2}}
@@ -5,26 +5,24 @@
5
5
  from pathlib import Path
6
6
 
7
7
  from power_grid_model_io.converters import VisionExcelConverter
8
+ from power_grid_model_io.converters.vision_excel_converter import CONFIG_PATH
8
9
  from power_grid_model_io.data_stores.base_data_store import DICT_KEY_NUMBER, LANGUAGE_EN, VISION_EXCEL_LAN_DICT
9
10
  from power_grid_model_io.utils.uuid_excel_cvtr import convert_guid_vision_excel
10
11
 
11
- terms_chaged = {"Grounding1": "N1", "Grounding2": "N2", "Grounding3": "N3", "Load.Behaviour": "Behaviour"}
12
+ terms_changed = {"Grounding1": "N1", "Grounding2": "N2", "Grounding3": "N3", "Load.Behaviour": "Behaviour"}
12
13
 
13
14
  DATA_DIR = Path(__file__).parents[2] / "data" / "vision"
14
- SOURCE_FILE = DATA_DIR / "vision_97_en.xlsx"
15
+ SOURCE_FILE = DATA_DIR / "vision_en_9_7.xlsx"
15
16
  REFERENCE_FILE = DATA_DIR / "vision_en.xlsx"
16
- SRC_CONFIG_DIR = Path("src") / "power_grid_model_io" / "config" / "excel"
17
- MAPPING_FILE_DIR = Path(__file__).parents[3] / SRC_CONFIG_DIR
18
- VISION_95_MAPPING_FILE = MAPPING_FILE_DIR / "vision_en.yaml"
19
- VISION_97_MAPPING_FILE = MAPPING_FILE_DIR / "vision_en_9_7.yaml"
17
+ MAPPING_FILE_EN_9_7 = CONFIG_PATH / "vision_en_9_7.yaml"
20
18
 
21
19
 
22
20
  def test_convert_guid_vision_excel():
23
21
  new_file = convert_guid_vision_excel(
24
- SOURCE_FILE, number=VISION_EXCEL_LAN_DICT[LANGUAGE_EN][DICT_KEY_NUMBER], terms_changed=terms_chaged
22
+ SOURCE_FILE, number=VISION_EXCEL_LAN_DICT[LANGUAGE_EN][DICT_KEY_NUMBER], terms_changed=terms_changed
25
23
  )
26
- vision_cvtr_new = VisionExcelConverter(source_file=new_file, mapping_file=VISION_97_MAPPING_FILE)
27
- vision_cvtr_ref = VisionExcelConverter(source_file=REFERENCE_FILE, mapping_file=VISION_95_MAPPING_FILE)
24
+ vision_cvtr_new = VisionExcelConverter(source_file=new_file, mapping_file=MAPPING_FILE_EN_9_7)
25
+ vision_cvtr_ref = VisionExcelConverter(source_file=REFERENCE_FILE)
28
26
 
29
27
  data_new = vision_cvtr_new.load_input_data()
30
28
  data_ref = vision_cvtr_ref.load_input_data()
@@ -14,6 +14,7 @@ import pytest
14
14
  from power_grid_model.data_types import SingleDataset
15
15
 
16
16
  from power_grid_model_io.converters import VisionExcelConverter
17
+ from power_grid_model_io.converters.vision_excel_converter import CONFIG_PATH
17
18
  from power_grid_model_io.data_stores.base_data_store import DICT_KEY_NUMBER, LANGUAGE_EN, VISION_EXCEL_LAN_DICT
18
19
  from power_grid_model_io.data_types import ExtraInfo
19
20
  from power_grid_model_io.utils.json import JsonEncoder
@@ -23,15 +24,13 @@ from ..utils import compare_extra_info, component_attributes, component_objects,
23
24
 
24
25
  DATA_PATH = Path(__file__).parents[2] / "data" / "vision"
25
26
  SOURCE_FILE = DATA_PATH / "vision_{language:s}.xlsx"
26
- SOURCE_FILE_97 = DATA_PATH / "vision_97_{language:s}.xlsx"
27
+ SOURCE_FILE_97 = DATA_PATH / "vision_{language:s}_9_7.xlsx"
27
28
  VALIDATION_FILE = DATA_PATH / "pgm_input_data_{language:s}.json"
28
29
  LANGUAGES = ["en", "nl"]
29
30
  LANGUAGES_97 = ["en"]
30
31
  VALIDATION_EN = Path(str(VALIDATION_FILE).format(language="en"))
31
32
  CUSTOM_MAPPING_FILE = DATA_PATH / "vision_9_5_{language:s}.yaml"
32
- VISION_97_MAPPING_FILE = (
33
- Path(__file__).parent.parent.parent.parent / "src/power_grid_model_io/config/excel" / "vision_en_9_7.yaml"
34
- )
33
+ VISION_97_MAPPING_FILE = CONFIG_PATH / "vision_en_9_7.yaml"
35
34
  terms_changed = {"Grounding1": "N1", "Grounding2": "N2", "Grounding3": "N3", "Load.Behaviour": "Behaviour"}
36
35
 
37
36
 
@@ -1 +0,0 @@
1
- 1.2.88