From 740b59702b3c4e0c6f77ddf8c714df56f7b48a46 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 22 May 2026 10:05:42 +0200 Subject: [PATCH] #14001 Python: Wrap property_data_type to return PropertyDataType enum The auto-generated stub returns a DataContainerString, forcing call sites to use .values[0]. Add a hand-written wrapper on Reservoir (which both EclipseCase and the other reservoir types inherit from) that unwraps the single-value container and returns the typed PropertyDataType so a caller can simply write case.property_data_type(...) == rips.PropertyDataType.INTEGER Update the round-trip tests to use the cleaner form. --- GrpcInterface/Python/rips/case.py | 31 +++++++++++++++++++ .../Python/rips/tests/test_properties.py | 31 +++++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/GrpcInterface/Python/rips/case.py b/GrpcInterface/Python/rips/case.py index d87f76b368..29c7129232 100644 --- a/GrpcInterface/Python/rips/case.py +++ b/GrpcInterface/Python/rips/case.py @@ -51,6 +51,7 @@ import NNCProperties_pb2 import NNCProperties_pb2_grpc from .resinsight_classes import ( Case as Case, + DataContainerString as DataContainerString, EclipseCase as EclipseCase, GeoMechCase as GeoMechCase, PorosityModelType as PorosityModelType, @@ -673,6 +674,36 @@ def available_properties( return self.__properties_stub.GetAvailableProperties(request).property_names +@add_method(Reservoir) +def property_data_type( + self, + property_type: PropertyType, + property_name: str, + porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL, +) -> PropertyDataType: + """Get the data type (FLOAT or INTEGER) of a grid property. + + Inverse of the data_type argument to set_active_cell_property and + set_grid_property. + + Arguments: + property_type (str): string corresponding to property_type enum. + property_name (str): name of an Eclipse property. + porosity_model (str): 'MATRIX_MODEL' or 'FRACTURE_MODEL'. + + Returns: + PropertyDataType.FLOAT or PropertyDataType.INTEGER. + """ + result = self._call_pdm_method_return_value( + "property_data_type", + DataContainerString, + property_type=property_type, + property_name=property_name, + porosity_model=porosity_model, + ) + return PropertyDataType(result.values[0]) + + @add_method(Case) def active_cell_property_async( self, diff --git a/GrpcInterface/Python/rips/tests/test_properties.py b/GrpcInterface/Python/rips/tests/test_properties.py index 16e7220c97..6a8864c6db 100644 --- a/GrpcInterface/Python/rips/tests/test_properties.py +++ b/GrpcInterface/Python/rips/tests/test_properties.py @@ -135,17 +135,20 @@ def test_10k_set_integer_active_cell_property(rips_instance, initialize_test): for expected, actual in zip(integer_values, round_trip): assert expected == int(actual) - data_type = case.property_data_type( - property_type=rips.PropertyType.GENERATED, - property_name="MY_DISCRETE_ACTIVE", + assert ( + case.property_data_type( + property_type=rips.PropertyType.GENERATED, + property_name="MY_DISCRETE_ACTIVE", + ) + == rips.PropertyDataType.INTEGER ) - assert data_type.values[0] == rips.PropertyDataType.INTEGER - - poro_data_type = case.property_data_type( - property_type=rips.PropertyType.STATIC_NATIVE, - property_name="PORO", + assert ( + case.property_data_type( + property_type=rips.PropertyType.STATIC_NATIVE, + property_name="PORO", + ) + == rips.PropertyDataType.FLOAT ) - assert poro_data_type.values[0] == rips.PropertyDataType.FLOAT def test_10k_set_integer_grid_property(rips_instance, initialize_test): @@ -169,11 +172,13 @@ def test_10k_set_integer_grid_property(rips_instance, initialize_test): for expected, actual in zip(integer_values, round_trip): assert expected == int(actual) - data_type = case.property_data_type( - property_type=rips.PropertyType.GENERATED, - property_name="MY_DISCRETE_GRID", + assert ( + case.property_data_type( + property_type=rips.PropertyType.GENERATED, + property_name="MY_DISCRETE_GRID", + ) + == rips.PropertyDataType.INTEGER ) - assert data_type.values[0] == rips.PropertyDataType.INTEGER def test_10k_property_strings(rips_instance, initialize_test):