Skip to content

Conversation

@esoteric-ephemera
Copy link
Collaborator

Related to #991, the type hinting and docstr for rotation_axis in GrainBoundaryRester were misleading

gb_energy: tuple[float, float] | None = None,
pretty_formula: str | None = None,
rotation_axis: list[str] | None = None,
rotation_axis: tuple[str | float, str | float, str | float] | None = None,
Copy link
Collaborator

@tsmathis tsmathis Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really work as a union?

and also why is the union str | float? The data types in the db are all int:

db.grain_boundaries.aggregate([
  {
    $project: {
      _id: 0,
      init_axis: "$initial_structure.rotation_axis",
      final_axis: "$final_structure.rotation_axis",
    },
  },
  {
    $facet: {
      init_axis: [
        { $unwind: "$init_axis" },
        { $group: { _id: { $type: "$init_axis" }, count: { $sum: 1 } } },
      ],
      final_axis: [
        { $unwind: "$final_axis" },
        { $group: { _id: { $type: "$final_axis" }, count: { $sum: 1 } } },
      ],
    },
  },
]);

-----
[
  {
    init_axis: [ { _id: 'int', count: 1008 } ],
    final_axis: [ { _id: 'int', count: 1009 } ]
  }
]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously if this all "just works" since later on everything is cast to str and joined as a comma separated string then it's fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The str is a holdover from before, the float is wrong, I'll change that to int. To make the API request, it just needs to format into a str like you said, so it's OK

)

if rotation_axis:
if len(rotation_axis) != 3:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are also instances of rotation_axis = [ 0, 0, 0, 1 ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - changed this overall just to use tuple[ int * 3] or tuple[int * 4] as the type hint and for the value check

@tschaume
Copy link
Member

@esoteric-ephemera Is this ok to merge or does it need additional changes?

@esoteric-ephemera
Copy link
Collaborator Author

@tschaume ready to merge!

@tschaume tschaume merged commit 6d6e970 into materialsproject:main Jul 30, 2025
2 of 4 checks passed
@esoteric-ephemera esoteric-ephemera deleted the gbd branch August 14, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants