ptr-editor 0.2.0__tar.gz → 0.4.0__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.
Files changed (155) hide show
  1. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/PKG-INFO +1 -2
  2. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/pyproject.toml +12 -5
  3. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/__init__.py +3 -0
  4. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/fields.py +7 -0
  5. ptr_editor-0.4.0/src/attrs_xml/pandas.py +295 -0
  6. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/xml/converter.py +192 -1
  7. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/xml/custom_disambiguator.py +25 -0
  8. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/xml/io.py +101 -102
  9. ptr_editor-0.4.0/src/attrs_xml/xml/lxml_adapter.py +204 -0
  10. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/xml/utils.py +1 -1
  11. ptr_editor-0.4.0/src/juice_jsoc/__init__.py +19 -0
  12. ptr_editor-0.4.0/src/juice_jsoc/apl/__init__.py +42 -0
  13. ptr_editor-0.4.0/src/juice_jsoc/apl/elements.py +730 -0
  14. ptr_editor-0.4.0/src/juice_jsoc/apl/jsoc-apl-schema.json +195 -0
  15. ptr_editor-0.4.0/src/juice_jsoc/base.py +27 -0
  16. ptr_editor-0.4.0/src/juice_jsoc/diffing.py +171 -0
  17. ptr_editor-0.4.0/src/juice_jsoc/itl/__init__.py +46 -0
  18. ptr_editor-0.4.0/src/juice_jsoc/itl/elements.py +1096 -0
  19. ptr_editor-0.4.0/src/juice_jsoc/itl/jsoc-itl-schema.json +424 -0
  20. ptr_editor-0.4.0/src/juice_jsoc/opl/__init__.py +46 -0
  21. ptr_editor-0.4.0/src/juice_jsoc/opl/csv.py +202 -0
  22. ptr_editor-0.4.0/src/juice_jsoc/opl/elements.py +1148 -0
  23. ptr_editor-0.4.0/src/juice_jsoc/opl/jsoc-opl-schema.json +380 -0
  24. ptr_editor-0.4.0/src/juice_jsoc/schema.py +160 -0
  25. ptr_editor-0.4.0/src/juice_jsoc/utils.py +51 -0
  26. ptr_editor-0.4.0/src/juice_opl/__init__.py +39 -0
  27. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/agm_config/agm_config.py +13 -0
  28. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/core/ptr_element.py +1 -1
  29. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/metadata.py +32 -13
  30. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/io/simplified_converter2.py +5 -10
  31. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/segment_mixin.py +57 -0
  32. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/segments_collection_mixin.py +114 -23
  33. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/.gitignore +0 -0
  34. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/LICENSE +0 -0
  35. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/README.md +0 -0
  36. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/README.md +0 -0
  37. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/__init__.py +0 -0
  38. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/base_element.py +0 -0
  39. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/converter_factory.py +0 -0
  40. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/decorators.py +0 -0
  41. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/decorators_utils.py +0 -0
  42. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/field_transformer.py +0 -0
  43. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/inspect.py +0 -0
  44. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/protocols.py +0 -0
  45. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/sentinels.py +0 -0
  46. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/type_utils.py +0 -0
  47. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/core/validator_factory.py +0 -0
  48. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/elements_registry.py +0 -0
  49. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/formatting.py +0 -0
  50. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/globals.py +0 -0
  51. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/resolution/__init__.py +0 -0
  52. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/resolution/registry.py +0 -0
  53. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/resolution/strategies.py +0 -0
  54. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/xml/__init__.py +0 -0
  55. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/attrs_xml/xml/converters.py +0 -0
  56. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_cli/README.md +0 -0
  57. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_cli/__init__.py +0 -0
  58. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_cli/commands/__init__.py +0 -0
  59. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_cli/commands/validate.py +0 -0
  60. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_cli/commands/version.py +0 -0
  61. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_cli/main.py +0 -0
  62. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_compare/__init__.py +0 -0
  63. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/__init__.py +0 -0
  64. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/accessors/__init__.py +0 -0
  65. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/accessors/accessor.py +0 -0
  66. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/accessors/attrs_dict_accessor.py +0 -0
  67. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/agm_config/__init__.py +0 -0
  68. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/agm_config/agm_utils.py +0 -0
  69. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/agm_config/html.py +0 -0
  70. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/agm_validator/__init__.py +0 -0
  71. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/agm_validator/agm_config_validator.py +0 -0
  72. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/context/README.md +0 -0
  73. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/context/__init__.py +0 -0
  74. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/context/defaults.py +0 -0
  75. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/context/presets.py +0 -0
  76. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/context/service_config.py +0 -0
  77. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/context/services.py +0 -0
  78. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/core/__init__.py +0 -0
  79. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/core/codenames_gen.py +0 -0
  80. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/core/logging.py +0 -0
  81. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/core/tree_utils.py +0 -0
  82. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/data/__init__.py +0 -0
  83. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/data/snippets.txt +0 -0
  84. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/diffing/__init__.py +0 -0
  85. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/diffing/diff_report.py +0 -0
  86. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/diffing/matcher.py +0 -0
  87. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/diffing/text_diff_result.py +0 -0
  88. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/diffing/timeline_differ_simple.py +0 -0
  89. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/diffing/visualize.py +0 -0
  90. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/__init__.py +0 -0
  91. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/additional_elements.py +0 -0
  92. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/agm_config.py +0 -0
  93. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/array.py +0 -0
  94. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/attitude.py +0 -0
  95. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/blocks.py +0 -0
  96. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/directions.py +0 -0
  97. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/doc.py +0 -0
  98. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/offset.py +0 -0
  99. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/phase_angle.py +0 -0
  100. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/ref_typed_mixin.py +0 -0
  101. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/surface.py +0 -0
  102. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/timeline.py +0 -0
  103. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/units.py +0 -0
  104. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements/values.py +0 -0
  105. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/elements_extractor/__init__.py +0 -0
  106. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/extra/__init__.py +0 -0
  107. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/extra/add_block_comments.py +0 -0
  108. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/factory/__init__.py +0 -0
  109. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/factory/attitudes.py +0 -0
  110. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/factory/blocks.py +0 -0
  111. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/generators/__init__.py +0 -0
  112. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/generators/base.py +0 -0
  113. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/generators/generators.py +0 -0
  114. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/generators/processor.py +0 -0
  115. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/html.py +0 -0
  116. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/io/__init__.py +0 -0
  117. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/io/ptr_converter_setup.py +0 -0
  118. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/io/simplified_converter.py +0 -0
  119. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/io/xml_formatting.py +0 -0
  120. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/py.typed +0 -0
  121. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/services/__init__.py +0 -0
  122. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/services/quick_access.py +0 -0
  123. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/services/resolution_strategies.py +0 -0
  124. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/spice_accessors/__init__.py +0 -0
  125. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/spice_accessors/directions.py +0 -0
  126. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/spice_accessors/eval_directions.py +0 -0
  127. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/templates/__init__.py +0 -0
  128. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/templates/html.py +0 -0
  129. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/templates/register.py +0 -0
  130. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/templates/template.py +0 -0
  131. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/README.md +0 -0
  132. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/__init__.py +0 -0
  133. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/combinators.py +0 -0
  134. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/html.py +0 -0
  135. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/ptr_validators.py +0 -0
  136. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/result.py +0 -0
  137. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/ruleset_registry.py +0 -0
  138. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/runner.py +0 -0
  139. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/validation/validator.py +0 -0
  140. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/versioned_file_manager/__init__.py +0 -0
  141. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/versioned_file_manager/file_info.py +0 -0
  142. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/versioned_file_manager/html.py +0 -0
  143. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_editor/versioned_file_manager/manager.py +0 -0
  144. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_solver/__init__.py +0 -0
  145. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_solver/cached_solver.py +0 -0
  146. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_solver/ptr_solver.py +0 -0
  147. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/ptr_solver/solvable_mixin.py +0 -0
  148. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/__init__.py +0 -0
  149. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/config.py +0 -0
  150. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/interface.py +0 -0
  151. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/merging.py +0 -0
  152. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/opl.py +0 -0
  153. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/ops.py +0 -0
  154. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/plot.py +0 -0
  155. {ptr_editor-0.2.0 → ptr_editor-0.4.0}/src/time_segments/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ptr-editor
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Utilities to edit PTR files.
5
5
  Project-URL: documentation, https://luca-penasa.github.io/ptr-editor
6
6
  Project-URL: homepage, https://luca-penasa.github.io/ptr-editor
@@ -38,7 +38,6 @@ Requires-Dist: quick-spice-manager>=0.0.3
38
38
  Requires-Dist: requests-cache>=1.2.1
39
39
  Requires-Dist: requests>=2.31.0
40
40
  Requires-Dist: xmldiff>=2.7.0
41
- Requires-Dist: xmltodict>=0.14.2
42
41
  Description-Content-Type: text/markdown
43
42
 
44
43
  # Ptr Editor
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ptr-editor"
3
- version = "0.2.0"
3
+ version = "0.4.0"
4
4
  description = "Utilities to edit PTR files."
5
5
  authors = [
6
6
  { name = "Luca Penasa", email = "luca.penasa@inaf.it" },
@@ -27,7 +27,6 @@ dependencies = [
27
27
  "importlib-metadata>=8.5.0,<9",
28
28
  "loguru>=0.7.2,<0.8",
29
29
  "pandas>=2.2.3,<3",
30
- "xmltodict>=0.14.2", # main xml to dict conveter and vice-versa
31
30
  "cattrs>=24",
32
31
  "ptwrapper>=2.7.0",
33
32
  "planetary-coverage>=1.2.0",
@@ -83,7 +82,6 @@ dev = [
83
82
  "bump-my-version>=0.27.0,<0.28",
84
83
  "rust-just>=1.36.0,<2",
85
84
  "xmldiff>=2.7.0,<3",
86
- "xmltodict>=0.14.2,<0.15",
87
85
  "xmlformatter>=0.2.8,<0.3",
88
86
  "pandas-stubs>=2.2.3.241126,<3",
89
87
  "pylint>=3.3.7",
@@ -117,7 +115,10 @@ include = [
117
115
  "src/ptr_compare",
118
116
  "src/ptr_solver",
119
117
  "src/time_segments",
120
- "src/ptr_cli"
118
+ "src/ptr_cli",
119
+ "src/juice_jsoc",
120
+ "src/juice_opl",
121
+
121
122
 
122
123
  ]
123
124
 
@@ -128,7 +129,10 @@ include = [
128
129
  "src/ptr_compare",
129
130
  "src/ptr_solver",
130
131
  "src/time_segments",
131
- "src/ptr_cli"
132
+ "src/ptr_cli",
133
+ "src/juice_jsoc",
134
+ "src/juice_opl",
135
+
132
136
  ]
133
137
 
134
138
  [tool.hatch.build.targets.wheel.sources]
@@ -138,6 +142,9 @@ include = [
138
142
  "src/ptr_solver" = "ptr_solver"
139
143
  "src/time_segments" = "time_segments"
140
144
  "src/ptr_cli" = "ptr_cli"
145
+ "src/juice_jsoc" = "juice_jsoc"
146
+ "src/juice_opl" = "juice_opl"
147
+
141
148
 
142
149
  [build-system]
143
150
  requires = ["hatchling"]
@@ -52,6 +52,7 @@ from attrs_xml.core import (
52
52
  )
53
53
  from attrs_xml.elements_registry import ElementsRegistry
54
54
  from attrs_xml.globals import are_defaults_disabled, disable_defaults
55
+ from attrs_xml.pandas import attrs_flatten, attrs_to_dataframe
55
56
 
56
57
  __all__ = [
57
58
  "UNSET",
@@ -63,6 +64,8 @@ __all__ = [
63
64
  "__version__",
64
65
  "are_defaults_disabled",
65
66
  "attr",
67
+ "attrs_flatten",
68
+ "attrs_to_dataframe",
66
69
  "disable_defaults",
67
70
  "element",
68
71
  "element_define",
@@ -34,6 +34,7 @@ def _custom_field(
34
34
  tag_aliases: str | list[str] | None = None,
35
35
  xml_type=None,
36
36
  cattrs_omit: bool = False,
37
+ mixed: bool = False,
37
38
  post_converter=None, # function that process the value after the automated one
38
39
  **kwargs,
39
40
  ) -> Any:
@@ -45,6 +46,10 @@ def _custom_field(
45
46
  Can be a single string or a list of strings.
46
47
  xml_type: Type of XML element ("text", "attr", or None for element)
47
48
  cattrs_omit: Whether to omit this field during cattrs structuring
49
+ mixed: When True, the field is serialised as a mixed-type element list:
50
+ each item uses its own ``default_name`` as its XML tag rather than a
51
+ shared tag derived from the field name. Only applies to fields
52
+ typed as ``list[A | B | ...]``.
48
53
  post_converter: Function to process the value after automated conversion
49
54
  **kwargs: Additional arguments passed to attrs.field()
50
55
  """
@@ -52,6 +57,8 @@ def _custom_field(
52
57
  mdata["xml_tag"] = tag
53
58
  mdata["xml_type"] = xml_type
54
59
  mdata["cattrs_omit"] = cattrs_omit
60
+ if mixed:
61
+ mdata["xml_mixed"] = True
55
62
 
56
63
  # Normalize tag_aliases to a list
57
64
  if tag_aliases is not None:
@@ -0,0 +1,295 @@
1
+ """Utilities for converting attrs objects to pandas DataFrames.
2
+
3
+ The main entry points are:
4
+
5
+ - :func:`attrs_flatten` – flatten a single attrs object (or dict/list/scalar)
6
+ into a flat ``{column: value}`` dict.
7
+ - :func:`attrs_to_dataframe` – convert a sequence of attrs objects into a
8
+ ``pd.DataFrame`` with automatic column detection and optional filtering.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from typing import TYPE_CHECKING, Any
14
+
15
+ if TYPE_CHECKING:
16
+ import pandas as pd
17
+
18
+
19
+ def _resolve_dotpath(obj: Any, path: str) -> Any:
20
+ """Resolve a dot-notation attribute path on *obj*.
21
+
22
+ Each segment is resolved with ``getattr``; if a segment is missing,
23
+ ``None`` is returned. If the resolved value is callable it is called
24
+ with no arguments before being returned.
25
+
26
+ Examples::
27
+
28
+ _resolve_dotpath(seg, "attitude.mode") # → seg.attitude.mode
29
+ _resolve_dotpath(seg, "status") # → seg.status (or seg.status())
30
+ """
31
+ value: Any = obj
32
+ for part in path.split("."):
33
+ value = getattr(value, part, None)
34
+ if value is None:
35
+ return None
36
+ return value() if callable(value) else value
37
+
38
+
39
+ def _get_class_properties(cls: type) -> list[str]:
40
+ """Return the names of all public ``@property`` members defined on *cls*.
41
+
42
+ Private names (leading ``_``) are excluded.
43
+ """
44
+ import inspect
45
+ return [
46
+ name
47
+ for name, _ in inspect.getmembers(cls, predicate=lambda v: isinstance(v, property))
48
+ if not name.startswith("_")
49
+ ]
50
+
51
+
52
+ def attrs_flatten(
53
+ obj: Any,
54
+ *,
55
+ prefix: str = "",
56
+ sep: str = ".",
57
+ max_depth: int = 3,
58
+ include_properties: bool = False,
59
+ extra_fields: dict[str, Any] | None = None,
60
+ extra_attrs: list[str] | None = None,
61
+ _depth: int = 0,
62
+ ) -> dict[str, Any]:
63
+ """Flatten an attrs object (or dict / list / scalar) into a flat dict.
64
+
65
+ Rules:
66
+
67
+ - **attrs object**: each public field (no leading ``_``) is recursed into,
68
+ with ``sep`` inserted between the parent key and the field name, e.g.
69
+ field ``inner`` with sub-field ``x`` → key ``inner<sep>x``.
70
+ - **dict**: each key is recursed into using the same naming convention,
71
+ supporting arbitrary nesting, e.g. ``{"a": {"b": 1}}`` →
72
+ ``{"params<sep>a<sep>b": 1}``.
73
+ - **list**: stored as a single cell value. Fan-out by index is not
74
+ performed because different rows may have different list lengths,
75
+ producing ragged columns that cause confusion in DataFrames.
76
+ - **scalar**: stored as-is.
77
+
78
+ Args:
79
+ obj: The object to flatten. Can be an attrs instance, dict, list,
80
+ or any scalar.
81
+ prefix: Column name prefix accumulated during recursion. Leave as
82
+ ``""`` for the root call.
83
+ sep: Separator inserted between key segments. Default is ``"."``.
84
+ max_depth: Maximum recursion depth. Objects deeper than this are
85
+ stored as-is. Default is ``3``.
86
+ extra_fields: Optional dict mapping column names to pre-computed values
87
+ (typically properties or computed fields). These are
88
+ added directly to the result at the top level.
89
+ include_properties: If ``True``, all public ``@property`` members of
90
+ the root object's class are automatically extracted
91
+ and added as columns. Properties already covered
92
+ by attrs fields, ``extra_fields``, or ``extra_attrs``
93
+ are skipped. Default is ``False``.
94
+ extra_attrs: Optional list of attribute paths (dot notation supported)
95
+ to extract from the root object. Each path is resolved
96
+ via successive ``getattr`` calls; if the final value is
97
+ callable it is called with no arguments. The column name
98
+ used is the path as given (e.g. ``"attitude.mode"`` →
99
+ column ``"attitude.mode"``). Paths that are already
100
+ present as flattened attrs fields are skipped.
101
+ _depth: Internal recursion counter – do not set manually.
102
+
103
+ Returns:
104
+ A flat ``{str: Any}`` dict ready to become a DataFrame row.
105
+
106
+ Examples:
107
+ >>> import attrs
108
+ >>> @attrs.define
109
+ ... class Inner:
110
+ ... x: float = 1.0
111
+ ... y: float = 2.0
112
+ ...
113
+ >>> @attrs.define
114
+ ... class Outer:
115
+ ... name: str = "a"
116
+ ... inner: Inner = attrs.Factory(Inner)
117
+ ... tags: list = attrs.Factory(list)
118
+ ... meta: dict = attrs.Factory(dict)
119
+ ...
120
+ >>> attrs_flatten(Outer(name="a", inner=Inner(x=3, y=4),
121
+ ... tags=["x"], meta={"k": 1}))
122
+ {'name': 'a', 'inner.x': 3.0, 'inner.y': 4.0, 'tags': ['x'], 'meta.k': 1}
123
+ """
124
+ import attrs as _attrs
125
+
126
+ result: dict[str, Any] = {}
127
+
128
+ if _depth > max_depth:
129
+ result[prefix] = obj
130
+ return result
131
+
132
+ if _attrs.has(type(obj)):
133
+ for f in _attrs.fields(type(obj)):
134
+ if f.name.startswith("_"):
135
+ continue
136
+ key = f"{prefix}{sep}{f.name}" if prefix else f.name
137
+ val = getattr(obj, f.name)
138
+ result.update(
139
+ attrs_flatten(val, prefix=key, sep=sep, max_depth=max_depth, _depth=_depth + 1)
140
+ )
141
+ elif isinstance(obj, dict):
142
+ if not obj:
143
+ # Empty dict: contribute no columns for this row; pandas will NaN-fill
144
+ # any nested keys that other rows produced from this same field.
145
+ pass
146
+ else:
147
+ for k, v in obj.items():
148
+ key = f"{prefix}{sep}{k}" if prefix else str(k)
149
+ result.update(
150
+ attrs_flatten(v, prefix=key, sep=sep, max_depth=max_depth, _depth=_depth + 1)
151
+ )
152
+
153
+ elif isinstance(obj, list):
154
+ result[prefix] = obj
155
+
156
+ else:
157
+ result[prefix] = obj
158
+
159
+ # Add extra fields at the top level only (when prefix is empty)
160
+ if _depth == 0:
161
+ import attrs as _attrs
162
+
163
+ # Build set of existing field names to avoid duplicates
164
+ existing_fields = set(result.keys())
165
+
166
+ # Also check for attrs fields if object is an attrs class
167
+ if _attrs.has(type(obj)):
168
+ existing_fields.update(f.name for f in _attrs.fields(type(obj)))
169
+
170
+ # Automatically add public @property members
171
+ if include_properties:
172
+ for prop_name in _get_class_properties(type(obj)):
173
+ if prop_name not in existing_fields:
174
+ try:
175
+ result[prop_name] = getattr(obj, prop_name)
176
+ except Exception:
177
+ result[prop_name] = None
178
+ existing_fields.add(prop_name)
179
+
180
+ # Add extra_fields, checking for duplicates
181
+ if extra_fields:
182
+ for field_name, value in extra_fields.items():
183
+ if field_name not in existing_fields:
184
+ result[field_name] = value
185
+
186
+ # Add extra_attrs (dot-notation supported), checking for duplicates
187
+ if extra_attrs:
188
+ for attr_path in extra_attrs:
189
+ if attr_path not in existing_fields:
190
+ result[attr_path] = _resolve_dotpath(obj, attr_path)
191
+
192
+ return result
193
+
194
+
195
+ def attrs_to_dataframe(
196
+ objects: list[Any],
197
+ *,
198
+ sep: str = ".",
199
+ max_depth: int = 3,
200
+ include: list[str] | None = None,
201
+ exclude: list[str] | None = None,
202
+ include_properties: bool = True,
203
+ extra_fields: dict[str, Any] | None = None,
204
+ extra_attrs: list[str] | None = None,
205
+ ) -> "pd.DataFrame":
206
+ """Convert a sequence of attrs objects into a pandas DataFrame.
207
+
208
+ Each object is flattened with :func:`attrs_flatten` and becomes one row.
209
+ Column names are derived automatically: nested attrs objects and dicts
210
+ produce ``parent<sep>child`` column names (default separator is ``"."``).
211
+
212
+ Args:
213
+ objects: Sequence of attrs instances (or dicts/scalars) to convert.
214
+ sep: Separator inserted between key segments when building column names
215
+ from nested structures. Default is ``"."``.
216
+ max_depth: Maximum recursion depth for nested attrs objects / dicts.
217
+ Default is ``3``.
218
+ include: If given, only columns whose name is in this list are kept.
219
+ Use the full flattened name for nested columns
220
+ (e.g. ``"inner.x"`` with the default separator).
221
+ exclude: Field names (or flattened column names) to drop from every row.
222
+ include_properties: If ``True``, all public ``@property`` members of
223
+ each object's class are automatically extracted and
224
+ added as columns. Properties already covered by
225
+ attrs fields, ``extra_fields``, or ``extra_attrs``
226
+ are skipped. Default is ``False``.
227
+ extra_fields: Optional dict mapping column names to callables that
228
+ extract values from each object. The callables receive
229
+ the object and return the column value. Useful for
230
+ arbitrary computed fields. Names already present as
231
+ flattened attrs fields are skipped.
232
+ extra_attrs: Optional list of attribute paths (dot notation supported)
233
+ to extract from each object. Each path is resolved via
234
+ successive ``getattr`` calls
235
+ (e.g. ``"attitude.mode"`` → ``obj.attitude.mode``); if
236
+ the resolved value is callable it is called with no
237
+ arguments. The column is named after the path as given.
238
+ Paths already covered by attrs fields or ``extra_fields``
239
+ are skipped.
240
+
241
+ Returns:
242
+ ``pd.DataFrame`` with one row per object.
243
+
244
+ Examples:
245
+ >>> df = attrs_to_dataframe(plan.activities)
246
+ >>> df = attrs_to_dataframe(plan.activities, include=["id", "unit", "start"])
247
+ >>> df = attrs_to_dataframe(plan.activities, exclude=["instrument_area"])
248
+ >>> df = attrs_to_dataframe(plan.activities, sep="__", max_depth=2)
249
+ >>> df = attrs_to_dataframe(
250
+ ... plan.activities,
251
+ ... extra_fields={
252
+ ... "duration": lambda x: x.end_time - x.start_time,
253
+ ... "category": lambda x: getattr(x, "category", "default")
254
+ ... }
255
+ ... )
256
+ >>> df = attrs_to_dataframe(
257
+ ... plan.activities,
258
+ ... extra_attrs=["status", "attitude.mode", "computed_priority"]
259
+ ... )
260
+ >>> df = attrs_to_dataframe(
261
+ ... plan.activities,
262
+ ... include_properties=True,
263
+ ... )
264
+ """
265
+ import pandas as pd
266
+
267
+ exclude_set: set[str] = set(exclude or [])
268
+
269
+ # Filter extra_attrs: exclude those that are already in extra_fields
270
+ extra_fields_set = set(extra_fields.keys()) if extra_fields else set()
271
+ filtered_extra_attrs = None
272
+ if extra_attrs:
273
+ filtered_extra_attrs = [
274
+ attr for attr in extra_attrs
275
+ if attr not in extra_fields_set
276
+ ]
277
+
278
+ rows = []
279
+ for obj in objects:
280
+ # Compute extra field values for this object
281
+ computed_extra = {}
282
+ if extra_fields:
283
+ for field_name, extractor in extra_fields.items():
284
+ computed_extra[field_name] = extractor(obj)
285
+
286
+ row = attrs_flatten(obj, sep=sep, max_depth=max_depth, include_properties=include_properties, extra_fields=computed_extra, extra_attrs=filtered_extra_attrs)
287
+
288
+ if include is not None:
289
+ row = {k: v for k, v in row.items() if k in include}
290
+ if exclude_set:
291
+ row = {k: v for k, v in row.items() if k not in exclude_set}
292
+
293
+ rows.append(row)
294
+
295
+ return pd.DataFrame(rows)
@@ -20,7 +20,7 @@ from attrs_xml.formatting import (
20
20
  )
21
21
  from attrs_xml.globals import global_config
22
22
  from attrs_xml.xml.converters import format_timestamp
23
- from attrs_xml.xml.custom_disambiguator import custom_create_default_dis_func
23
+ from attrs_xml.xml.custom_disambiguator import XML_TAG_MARKER, custom_create_default_dis_func
24
24
 
25
25
 
26
26
  class CustomConverter(cattrs.Converter):
@@ -177,6 +177,189 @@ def _expects_list_type(field_type: Any) -> bool:
177
177
  # Cache for field mappings per class to avoid rebuilding on every call
178
178
  _FIELD_MAPPING_CACHE: dict[type, dict] = {}
179
179
 
180
+ # ---------------------------------------------------------------------------
181
+ # Mixed-type element list support
182
+ # ---------------------------------------------------------------------------
183
+
184
+ #: Marker key injected into dicts to carry the originating XML tag name so
185
+ #: that ambiguous union members (sharing the same dict structure) can be
186
+ #: correctly disambiguated during structuring. See ``_collect_mixed_list_fields``
187
+ #: and ``custom_disambiguator.py``.
188
+ XML_TAG_MARKER = "__xml_tag__"
189
+
190
+ #: Cache: cls → {field_name: tuple[union_member_types]}
191
+ _MIXED_LIST_FIELD_CACHE: dict[type, dict[str, tuple[type, ...]]] = {}
192
+
193
+
194
+ def _get_mixed_element_list_types(field_type: Any) -> tuple[type, ...] | None:
195
+ """Return the union member types when *field_type* is ``list[A | B | …]``
196
+ with ≥ 2 distinct ``BaseElement`` subclasses; otherwise return *None*.
197
+
198
+ This is used both in the serialisation path (to decide whether to use each
199
+ item's ``default_name`` as the XML tag) and in the structuring
200
+ (parsing) path (to locate mixed children in the parsed dict).
201
+ """
202
+ from types import UnionType
203
+
204
+ from typing import Union # noqa: F811 (shadowed by top-level import is fine here)
205
+
206
+ from attrs_xml.core.base_element import BaseElement
207
+
208
+ origin = get_origin(field_type)
209
+ if origin not in (list, tuple, set):
210
+ return None
211
+
212
+ args = get_args(field_type)
213
+ if not args:
214
+ return None
215
+
216
+ inner_type = args[0]
217
+ inner_origin = get_origin(inner_type)
218
+
219
+ # Accept both ``typing.Union[A, B]`` and the Python 3.10+ ``A | B`` syntax.
220
+ if inner_origin is not Union and not isinstance(inner_type, UnionType):
221
+ return None
222
+
223
+ element_types = tuple(
224
+ arg
225
+ for arg in get_args(inner_type)
226
+ if arg is not type(None)
227
+ and isinstance(arg, type)
228
+ and issubclass(arg, BaseElement)
229
+ )
230
+
231
+ return element_types if len(element_types) >= 2 else None
232
+
233
+
234
+ def _get_class_mixed_list_fields(cls: type) -> dict[str, tuple[type, ...]]:
235
+ """Return a cached mapping of *field_name* → *union_types* for every field
236
+ on *cls* that has been explicitly opted in to mixed-type element list
237
+ serialisation via ``element(mixed=True)``.
238
+ """
239
+ if cls not in _MIXED_LIST_FIELD_CACHE:
240
+ result: dict[str, tuple[type, ...]] = {}
241
+ for f in fields(cls):
242
+ if not f.metadata.get("xml_mixed"):
243
+ continue
244
+ union_types = _get_mixed_element_list_types(f.type)
245
+ if union_types:
246
+ result[f.name] = union_types
247
+ _MIXED_LIST_FIELD_CACHE[cls] = result
248
+ return _MIXED_LIST_FIELD_CACHE[cls]
249
+
250
+
251
+ def _collect_mixed_list_fields(val: dict, cls: type) -> dict:
252
+ """Pre-process *val* to collect mixed-type list fields from separate tag keys.
253
+
254
+ When XML has mixed children such as::
255
+
256
+ <root>
257
+ <sequence name="Seq1"/>
258
+ <command name="Cmd1"/>
259
+ <sequence name="Seq2"/>
260
+ </root>
261
+
262
+ The lxml parser preserves document order via a ``__xml_children__`` key
263
+ (a flat list of all interleaved children tagged with ``XML_TAG_MARKER``).
264
+ When that key is present this function uses it directly, giving exact
265
+ document order.
266
+
267
+ When ``__xml_children__`` is absent (non-interleaved or pre-existing dict),
268
+ it falls back to collecting per-tag keys in dict-insertion order.
269
+
270
+ In both cases, consumed per-tag keys are removed and the result is stored
271
+ under the field's expected dict key. ``__xml_children__`` is always
272
+ removed after processing to prevent it leaking into the structure hook.
273
+ """
274
+ if not isinstance(val, dict) or not has(cls):
275
+ return val
276
+
277
+ mixed_fields = _get_class_mixed_list_fields(cls)
278
+
279
+ # Always strip __xml_children__ to prevent ForbiddenExtraKeysError when
280
+ # the element has no mixed fields, or after it has been consumed.
281
+ if not mixed_fields:
282
+ if "__xml_children__" in val:
283
+ val = {k: v for k, v in val.items() if k != "__xml_children__"}
284
+ return val
285
+
286
+ overrides = generate_converter_overrides(cls)
287
+ modified_val: dict | None = None
288
+
289
+ for field_name, union_types in mixed_fields.items():
290
+ # Determine the expected dict key for this field after renaming.
291
+ primary_key = field_name
292
+ if field_name in overrides:
293
+ override_obj = overrides[field_name]
294
+ renamed_to = (
295
+ override_obj.rename if hasattr(override_obj, "rename") else None
296
+ )
297
+ if renamed_to:
298
+ primary_key = renamed_to
299
+
300
+ # If the primary key is already present, nothing to do for this field.
301
+ if primary_key in (modified_val or val):
302
+ continue
303
+
304
+ # Build tag → set mapping from each union member's default_name.
305
+ tag_to_type = {
306
+ t.default_name: t
307
+ for t in union_types
308
+ if getattr(t, "default_name", None)
309
+ }
310
+
311
+ src = modified_val if modified_val is not None else val
312
+
313
+ # ── Fast path: use document-order children list if the lxml parser
314
+ # detected interleaved tags for this element. ────────────────────
315
+ if "__xml_children__" in src:
316
+ relevant = [
317
+ c
318
+ for c in src["__xml_children__"]
319
+ if c.get(XML_TAG_MARKER) in tag_to_type
320
+ ]
321
+ if relevant:
322
+ if modified_val is None:
323
+ modified_val = dict(val)
324
+ # Remove the per-tag keys consumed by this field.
325
+ for t in tag_to_type:
326
+ modified_val.pop(t, None)
327
+ modified_val.pop("__xml_children__", None)
328
+ modified_val[primary_key] = relevant
329
+ continue
330
+
331
+ # ── Fallback: collect per-tag keys in dict-insertion order ──────────
332
+ member_tags_in_val = [k for k in src if k in tag_to_type]
333
+ if not member_tags_in_val:
334
+ continue
335
+
336
+ if modified_val is None:
337
+ modified_val = dict(val)
338
+
339
+ collected: list = []
340
+ for key in list(modified_val.keys()):
341
+ if key not in tag_to_type:
342
+ continue
343
+ items = modified_val.pop(key)
344
+ if not isinstance(items, list):
345
+ items = [items]
346
+ for item in items:
347
+ if isinstance(item, dict):
348
+ collected.append({XML_TAG_MARKER: key, **item})
349
+ else:
350
+ collected.append(item)
351
+
352
+ if collected:
353
+ modified_val[primary_key] = collected
354
+
355
+ # Ensure __xml_children__ is stripped even if no field consumed it.
356
+ if modified_val is not None:
357
+ modified_val.pop("__xml_children__", None)
358
+ elif "__xml_children__" in val:
359
+ modified_val = {k: v for k, v in val.items() if k != "__xml_children__"}
360
+
361
+ return modified_val if modified_val is not None else val
362
+
180
363
 
181
364
  def _resolve_tag_aliases(val: dict, cls: type) -> dict:
182
365
  """Resolve tag aliases by renaming aliased keys to their primary tag names.
@@ -345,6 +528,14 @@ def make_structure_hook_factory(converter: Converter):
345
528
  # Pre-process: resolve tag aliases first
346
529
  val = _resolve_tag_aliases(val, cls)
347
530
 
531
+ # Pre-process: collect mixed-type list fields from per-tag keys.
532
+ # For fields typed as list[A | B | C] without an explicit xml_tag,
533
+ # the parsed dict has separate keys "a_tag", "b_tag", … rather than
534
+ # one "fieldName" key. This step merges them into the expected key
535
+ # and attaches XML_TAG_MARKER so the disambiguator can determine
536
+ # the concrete type of each item.
537
+ val = _collect_mixed_list_fields(val, cls)
538
+
348
539
  # Pre-process: fix list values before attempting to structure
349
540
  val = _fix_list_fields_in_dict(val, cls)
350
541
 
@@ -32,6 +32,11 @@ from cattrs._compat import (
32
32
  Mapping,
33
33
  )
34
34
 
35
+ #: Marker key used by ``_collect_mixed_list_fields`` (converter.py) to embed
36
+ #: the originating XML tag inside a dict item so that the disambiguator can
37
+ #: reliably select the correct union member even when the dict structures of
38
+ #: the union members are otherwise identical.
39
+ XML_TAG_MARKER = "__xml_tag__"
35
40
 
36
41
  def custom_create_default_dis_func(
37
42
  converter: BaseConverter,
@@ -228,6 +233,13 @@ def custom_create_default_dis_func(
228
233
  msg = "Could not create a disambiguation function for the given classes"
229
234
  raise ValueError(msg)
230
235
 
236
+ # Build a default_name → type lookup for the XML_TAG_MARKER fast-path.
237
+ _tag_to_cls: dict[str | None, type[AttrsInstance]] = {
238
+ getattr(cls, "default_name", None): cls
239
+ for cls in classes
240
+ if getattr(cls, "default_name", None) is not None
241
+ }
242
+
231
243
  if fallback is None:
232
244
 
233
245
  def dis_func(data: Mapping[Any, Any]) -> type[AttrsInstance] | None:
@@ -235,6 +247,13 @@ def custom_create_default_dis_func(
235
247
  msg = "Only input mappings are supported"
236
248
  raise TypeError(msg)
237
249
 
250
+ # Fast-path: honour the XML tag marker injected by
251
+ # _collect_mixed_list_fields during mixed-type list parsing.
252
+ if XML_TAG_MARKER in data:
253
+ result = _tag_to_cls.get(data[XML_TAG_MARKER])
254
+ if result is not None:
255
+ return result
256
+
238
257
  # First try literal discriminators
239
258
  for discriminator_name, value_map in literal_discriminators.items():
240
259
  if discriminator_name in data:
@@ -257,6 +276,12 @@ def custom_create_default_dis_func(
257
276
  msg = "Only input mappings are supported"
258
277
  raise TypeError(msg)
259
278
 
279
+ # Fast-path: honour the XML tag marker.
280
+ if XML_TAG_MARKER in data:
281
+ result = _tag_to_cls.get(data[XML_TAG_MARKER])
282
+ if result is not None:
283
+ return result
284
+
260
285
  # First try literal discriminators
261
286
  for discriminator_name, value_map in literal_discriminators.items():
262
287
  if discriminator_name in data: