Skip to content

Commit 0ed5afd

Browse files
authored
Fix main for Python > 11 (#1039)
# Description Please include a summary of the changes. Relates to <issue> # Checklist - [ ] My code uses type hinting for function and method arguments and return values. - [ ] I have created tests which cover my code. - [ ] The test code either 1. demonstrates at least one valuable use case (e.g. integration tests) or 2. verifies that outputs are as expected for given inputs (e.g. unit tests). - [ ] New tests pass locally with my changes.
2 parents 7b116df + 33f6917 commit 0ed5afd

File tree

6 files changed

+39
-37
lines changed

6 files changed

+39
-37
lines changed

gempy/API/examples_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _generate_anticline_model(compute_model: bool) -> gp.data.GeoModel:
180180
)
181181
)
182182

183-
# Map geological series to surfaces
183+
# Map geological series to surfaces
184184
gp.map_stack_to_surfaces(
185185
gempy_model=geo_data,
186186
mapping_object={"Strat_Series": ('rock2', 'rock1')}

gempy/core/data/grid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class GridTypes(enum.Flag):
2727

2828
# ? What should we do with the extent?
2929

30-
values: Annotated[np.ndarray, Field(exclude=True)] = np.empty((0, 3))
31-
length: Annotated[np.ndarray, Field(exclude=True)] = np.empty(0)
30+
values: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.empty((0, 3)))
31+
length: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.empty(0))
3232

3333
_octree_grid: Optional[RegularGrid] = None
3434
_dense_grid: Optional[RegularGrid] = None

gempy/core/data/grid_modules/regular_grid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class RegularGrid:
1616
Class with the methods and properties to manage 3D regular grids where the model will be interpolated.
1717
1818
"""
19-
resolution: Annotated[np.ndarray, numpy_array_short_validator] = np.ones((0, 3), dtype='int64')
20-
extent: Annotated[np.ndarray, numpy_array_short_validator] = np.zeros(6, dtype='float64') #: this is the ORTHOGONAL extent. If the grid is rotated, the extent will be different
21-
values: Annotated[np.ndarray, Field(exclude=True)] = np.zeros((0, 3))
22-
mask_topo: Annotated[np.ndarray, Field(exclude=True)] = np.zeros((0, 3), dtype=bool)
19+
resolution: Annotated[np.ndarray, numpy_array_short_validator] = dataclasses.field(default_factory=lambda: np.ones((0, 3), dtype='int64'))
20+
extent: Annotated[np.ndarray, numpy_array_short_validator] = dataclasses.field(default_factory=lambda: np.zeros(6, dtype='float64')) #: this is the ORTHOGONAL extent. If the grid is rotated, the extent will be different
21+
values: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.zeros((0, 3)))
22+
mask_topo: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.zeros((0, 3), dtype=bool))
2323
_transform: Transform | None = None #: If a transform exists, it will be applied to the grid
2424

2525
def __init__(self, extent: np.ndarray, resolution: np.ndarray, transform: Optional[Transform] = None):

gempy/core/data/grid_modules/topography.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Topography:
2727
source: Optional[str] = None
2828

2929
# Fields managed internally
30-
values: short_array_type = field(init=False, default=np.zeros((0, 3)))
30+
values: short_array_type = field(init=False, default_factory=lambda: np.zeros((0, 3)))
3131
resolution: Tuple[int, int] = Field(init=True, default=(0, 0))
32-
raster_shape: Tuple[int, ...] = field(init=False, default=())
32+
raster_shape: Tuple[int, ...] = field(init=False, default_factory=tuple)
3333
_mask_topo: Optional[np.ndarray] = field(init=False, default=None, repr=False)
3434
_x: Optional[np.ndarray] = field(init=False, default=None, repr=False)
3535
_y: Optional[np.ndarray] = field(init=False, default=None, repr=False)

test/test_api/test_initialization_and_compute_api.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
def test_api_create_data():
1111
geo_data = _create_data()
12-
1312
pprint(geo_data)
14-
15-
return geo_data
1613

1714

1815
def _create_data():

test/test_api/test_model_construction_granular.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,51 @@
2323
"""
2424

2525
def test_read_input_points():
26+
_, _ = _read_data()
27+
28+
29+
def _read_data() -> tuple[SurfacePointsTable, OrientationsTable]:
2630
data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
2731
surface_points_file = pooch.retrieve(
2832
url=data_path + "data/input_data/jan_models/model1_surface_points.csv",
2933
known_hash="6f1a39ed77e87a4057f03629c946b1876b87e24409cadfe0e1cf7ab1488f69e4"
3034
)
31-
3235
orientations_file = pooch.retrieve(
3336
url=data_path + "data/input_data/jan_models/model1_orientations.csv",
3437
known_hash="04c307ae23f70252fe54144a2fb95ca7d96584a2d497ea539ed32dfd23e7cd5d"
3538
)
36-
3739
print(pooch.file_hash(surface_points_file))
3840
print(pooch.file_hash(orientations_file))
39-
4041
surface_points: SurfacePointsTable = read_surface_points(
4142
path=surface_points_file,
4243
)
43-
4444
orientations: OrientationsTable = read_orientations(
4545
path=orientations_file
4646
)
47-
4847
return surface_points, orientations
4948

5049

51-
def test_create_grid() -> gp.data.Grid:
50+
def test_create_grid():
51+
_generate_grid()
52+
53+
54+
def _generate_grid():
5255
grid: gp.data.Grid = gp.data.Grid(
5356
extent=[0, 1000, 0, 1000, 0, 500],
5457
resolution=[50, 5, 50]
5558
)
56-
5759
return grid
5860

5961

60-
def test_create_structural_frame() -> StructuralFrame:
62+
def test_create_structural_frame():
6163
# * Structural elements
62-
surface_points, orientations = test_read_input_points()
64+
_create_structural_frame()
65+
66+
67+
def _create_structural_frame():
68+
surface_points, orientations = _read_data()
6369
surface_points_groups = surface_points.get_surface_points_by_id_groups()
6470
orientations_groups = orientations.get_orientations_by_id_groups()
65-
6671
structural_elements = []
6772
color_gen = ColorsGenerator()
6873
for i in range(len(surface_points_groups)):
@@ -75,52 +80,52 @@ def test_create_structural_frame() -> StructuralFrame:
7580
)
7681

7782
structural_elements.append(structural_element)
78-
7983
# * Structural groups definitions
8084
default_formation: Stack = Stack(
8185
name="default_formation",
8286
elements=structural_elements,
8387
structural_relation=gp.data.StackRelationType.ERODE
8488
)
85-
8689
# ? Should I move this to the constructor?
8790
structural_frame: StructuralFrame = StructuralFrame(
8891
structural_groups=[default_formation],
8992
color_gen=color_gen
9093
)
91-
9294
return structural_frame
9395

9496

95-
def test_create_interpolation_options() -> InterpolationOptions:
97+
def test_create_interpolation_options():
98+
interpolation_options = _generate_interpolation_options()
99+
100+
101+
def _generate_interpolation_options():
96102
range_ = 1000.0
97103
interpolation_options: InterpolationOptions = InterpolationOptions.from_args(
98104
range=range_,
99105
c_o=(range_ ** 2) / 14 / 3,
100106
)
101-
102107
return interpolation_options
103108

104109

105-
def test_create_geomodel() -> GeoModel:
110+
def _create_geomodel() -> GeoModel:
106111
geo_model: GeoModel = GeoModel.from_args(
107112
name="horizontal",
108-
structural_frame=test_create_structural_frame(),
109-
grid=test_create_grid(),
110-
interpolation_options=test_create_interpolation_options()
113+
structural_frame=_create_structural_frame(),
114+
grid=_generate_grid(),
115+
interpolation_options=_generate_interpolation_options()
111116
)
112117

113118
return geo_model
114119

115120

116121
def test_structural_frame_surface_points():
117-
structural_frame: StructuralFrame = test_create_structural_frame()
122+
structural_frame: StructuralFrame = _create_structural_frame()
118123
print(structural_frame.surface_points_copy)
119124
pass
120125

121126

122-
def test_interpolate_numpy() -> GeoModel:
123-
geo_model: GeoModel = test_create_geomodel()
127+
def _interpolate_numpy() -> GeoModel:
128+
geo_model: GeoModel = _create_geomodel()
124129

125130
solutions: gempy_engine.core.data.solutions.Solutions = gempy_engine.compute_model(
126131
interpolation_input=geo_model.interpolation_input_copy,
@@ -147,11 +152,11 @@ def test_interpolate_numpy() -> GeoModel:
147152

148153

149154
def test_interpolate_aesara():
150-
geo_model: GeoModel = test_create_geomodel()
155+
geo_model: GeoModel = _create_geomodel()
151156

152157

153158
def test_plot_input():
154-
geo_model: GeoModel = test_create_geomodel()
159+
geo_model: GeoModel = _create_geomodel()
155160
gp_viewer: gempy_viewer = require_gempy_viewer()
156161
# TODO: Add all the plot data in a plot options class
157162

@@ -164,7 +169,7 @@ def test_plot_input():
164169

165170

166171
def test_plot_results():
167-
solved_geo_model: GeoModel = test_interpolate_numpy()
172+
solved_geo_model: GeoModel = _interpolate_numpy()
168173
gp_viewer: gempy_viewer = require_gempy_viewer()
169174

170175
gp_viewer.plot_2d(

0 commit comments

Comments
 (0)