Skip to content

refactor: Refactor arrayHelpers functions#223

Open
RomainBaville wants to merge 12 commits intomainfrom
RomainBaville/refactor/RefactorArrayHelperFunction
Open

refactor: Refactor arrayHelpers functions#223
RomainBaville wants to merge 12 commits intomainfrom
RomainBaville/refactor/RefactorArrayHelperFunction

Conversation

@RomainBaville
Copy link
Contributor

@RomainBaville RomainBaville commented Feb 9, 2026

This pr aims to refactor arrayHelpers functions to have just one function dealing with dataset or multiblock dataset instead of multiple functions.
During the factorisation of the arrayHelpers functions, a small clean is made in the tests to.

@RomainBaville RomainBaville added type: feature type: cleanup test-geos-integration Triggers the testing of geosPythonPackages import and integration in GEOS CI labels Feb 9, 2026
@RomainBaville RomainBaville self-assigned this Feb 10, 2026
- get the attribute and they number of component on one piece of a mesh (one for dataset, one for multiblockDataset and one for the both)
- get all the cells dimension of a mesh (for any meshes)
- get the GlobalIds array on one piece of a mesh (for any meshes)
- get the vtk or array data of an attribute (dataset and vtkFieldData only)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- get the vtk or array data of an attribute (dataset and vtkFieldData only)
- get the vtk or data array of an attribute (dataset and vtkFieldData only)

piece: Piece,
) -> tuple[ list[ Any ], list[ Any ] ]:
"""Check if each value is valid , ie if that value is a data of the attribute in at least one dataset of the multiblock.
"""Check if each value is valid, ie if that value is a data of the mesh's attribute.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Check if each value is valid, ie if that value is a data of the mesh's attribute.
"""Check if each value is valid, ie if that value is a data of the mesh attribute.

dict[str, int]: Dictionary of the names of the attributes as keys, and number of components as values.
Raises:
ValueError: The piece must be cells or points only
AttributeError: One attribute one the mesh is null.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
AttributeError: One attribute one the mesh is null.
AttributeError: One attribute of the mesh is null.

Comment on lines 142 to 156
def test_getAttributesWithNumberOfComponentsRaises() -> None:
"""Test the fails of the function getAttributesWithNumberOfComponents."""
# ValueError
with pytest.raises( ValueError ):
arrayHelpers.getAttributesWithNumberOfComponents( vtkPolyData(), Piece.BOTH )

# AttributeError
mesh: vtkPolyData = vtkPolyData()
mesh.GetCellData().AddArray( vtkDoubleArray() )
with pytest.raises( AttributeError ):
arrayHelpers.getAttributesWithNumberOfComponents( mesh, Piece.CELLS )

# TypeError
with pytest.raises( TypeError ):
arrayHelpers.getAttributesWithNumberOfComponents( vtkCellData(), Piece.CELLS )
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to improve maintainability and clarity, I would avoid testing several test case in the same function as you're doing here.

Comment on lines 276 to 285
def test_checkValidValuesInObjectRaises( dataSetTest: Any ) -> None:
"""Test the fails of checkValidValuesInObject."""
# AttributeError
mesh: vtkMultiBlockDataSet = dataSetTest( "multiblock" )
with pytest.raises( AttributeError ):
arrayHelpers.checkValidValuesInObject( mesh, "PORO", [], Piece.CELLS )

@pytest.mark.parametrize( "piece, expected", [ ( Piece.POINTS, {
'GLOBAL_IDS_POINTS': 1,
'PointAttribute': 3,
} ), ( Piece.CELLS, {
'CELL_MARKERS': 1,
'PERM': 3,
'PORO': 1,
'FAULT': 1,
'GLOBAL_IDS_CELLS': 1,
'CellAttribute': 3,
} ) ] )
def test_getAttributesFromDataSet( dataSetTest: vtkDataSet, piece: Piece, expected: dict[ str, int ] ) -> None:
"""Test getting attribute list as dict from dataset."""
vtkDataSetTest: vtkDataSet = dataSetTest( "dataset" )
attributes: dict[ str, int ] = arrayHelpers.getAttributesFromDataSet( vtkDataSetTest, piece )
assert attributes == expected
# TypeError
with pytest.raises( TypeError ):
arrayHelpers.checkValidValuesInObject( vtkCellData(), "AttributeName", [], Piece.CELLS )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same remark, please split the test cases.

Comment on lines 368 to 377
def test_getVtkArrayTypeInObjectRaises( dataSetTest: Any ) -> None:
"""Test the fails of the function getVtkArrayTypeInObject."""
# AttributeError
mesh: vtkDataSet = dataSetTest( "dataset" )
with pytest.raises( AttributeError ):
arrayHelpers.getVtkArrayTypeInObject( mesh, "attributeName", Piece.CELLS )

assert ( obtained == expected )
# TypeError
with pytest.raises( TypeError ):
arrayHelpers.getVtkArrayTypeInObject( vtkCellData(), "PORO", Piece.CELLS )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same remark

Comment on lines 418 to 432
def test_getNumberOfComponentsRaises( dataSetTest: Any, ) -> None:
"""Test getNumberOfComponents fails."""
# TypeError
meshWrongType: vtkCellData = vtkCellData()
with pytest.raises( TypeError ):
arrayHelpers.getNumberOfComponents( mesh, "attribute", Piece.CELLS )
arrayHelpers.getNumberOfComponents( meshWrongType, "PORO", Piece.CELLS )

# AttributeError
mesh: vtkDataSet = dataSetTest( "multiblockGeosOutput" )
with pytest.raises( AttributeError ):
arrayHelpers.getNumberOfComponents( mesh, "attributeName", Piece.POINTS )

@pytest.mark.parametrize( "attributeName, piece, expected", [
( "PERM", Piece.CELLS, ( "AX1", "AX2", "AX3" ) ),
( "PORO", Piece.CELLS, () ),
] )
def test_getComponentNamesDataSet( dataSetTest: vtkDataSet, attributeName: str, piece: Piece,
expected: tuple[ str, ...] ) -> None:
"""Test getting the component names of an attribute from a dataset."""
vtkDataSetTest: vtkDataSet = dataSetTest( "dataset" )
obtained: tuple[ str, ...] = arrayHelpers.getComponentNamesDataSet( vtkDataSetTest, attributeName, piece )
assert obtained == expected
# ValueError
with pytest.raises( ValueError ):
arrayHelpers.getNumberOfComponents( mesh, "ghostRank", Piece.BOTH )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Comment on lines 449 to 465
def test_getComponentNamesRaises( dataSetTest: Any, ) -> None:
"""Test getting the component names fails."""
# TypeError
meshWrongType: vtkFieldData = vtkFieldData()
with pytest.raises( TypeError ):
arrayHelpers.getComponentNames( meshWrongType, "PORO", Piece.CELLS )

# AttributeError
mesh: vtkDataSet = dataSetTest( "multiblockGeosOutput" )
with pytest.raises( AttributeError ):
arrayHelpers.getComponentNames( mesh, "attributeName", Piece.POINTS )

# ValueError
with pytest.raises( ValueError ):
arrayHelpers.getComponentNames( mesh, "ghostRank", Piece.BOTH )


Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flag: ready for review test-geos-integration Triggers the testing of geosPythonPackages import and integration in GEOS CI type: cleanup type: feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants