11from __future__ import annotations
22
3- import inspect
43import logging
54import re
65from collections .abc import Mapping , Sequence
76from datetime import datetime
87from enum import StrEnum
98from pathlib import Path
10- from typing import Annotated , Any , Literal , Self , assert_never , get_args , get_type_hints
9+ from typing import Annotated , Any , Literal , Self , assert_never , get_type_hints
1110
1211import numpy as np
1312import pandas as pd
@@ -94,6 +93,33 @@ def strip_dataframe_whitespaces(df: pl.DataFrame) -> pl.DataFrame:
9493 )
9594
9695
96+ def _make_summary_key (
97+ keyword : str ,
98+ number : str | None = None ,
99+ well : str | None = None ,
100+ nx : str | None = None ,
101+ ny : str | None = None ,
102+ lgr_name : str | None = None ,
103+ i : str | None = None ,
104+ j : str | None = None ,
105+ k : str | None = None ,
106+ ) -> str :
107+ def _int_or_none (s : str | None ) -> int | None :
108+ return int (s ) if s is not None else None
109+
110+ return make_summary_key (
111+ keyword = keyword ,
112+ number = _int_or_none (number ),
113+ name = well ,
114+ nx = _int_or_none (nx ),
115+ ny = _int_or_none (ny ),
116+ lgr_name = lgr_name ,
117+ li = _int_or_none (i ),
118+ lj = _int_or_none (j ),
119+ lk = _int_or_none (k ),
120+ )
121+
122+
97123class SummaryObservation (_SummaryValues ):
98124 error_mode : ErrorModes | None = Field (default = None , exclude = True )
99125 error_min : float | None = Field (default = None , exclude = True )
@@ -219,12 +245,6 @@ def from_bulk_config_dict(
219245
220246 required_csv_columns = ["keyword" , "value" , "error" , "date" ]
221247
222- make_summary_key_optional_args = [
223- name
224- for name , param in inspect .signature (make_summary_key ).parameters .items ()
225- if param .default is not inspect .Parameter .empty
226- ]
227-
228248 csv_file = observation_dict .get ("VALUES" )
229249 if csv_file is None :
230250 raise _missing_value_error (context , "VALUES" )
@@ -241,9 +261,10 @@ def from_bulk_config_dict(
241261 ) from err
242262 csv_df = strip_dataframe_whitespaces (csv_df )
243263
244- # Rename 'well' column to 'name' to match make_summary_key parameter names
245- if "well" in csv_df .columns :
246- csv_df = csv_df .rename ({"well" : "name" })
264+ make_summary_key_optional_args = set (get_type_hints (_make_summary_key )) - {
265+ "keyword" , # keyword is not optional
266+ "return" , # return is not a parameter
267+ }
247268
248269 for col in csv_df .columns :
249270 if col not in {
@@ -319,18 +340,13 @@ def from_bulk_config_dict(
319340 for i , row in enumerate (csv_df .iter_rows (named = True )):
320341 kw = validate_nonempty_string (row ["keyword" ], "keyword" , context )
321342
322- arg_type_hints = get_type_hints (make_summary_key )
323343 optional_kw_args = {
324- kw_arg : validate_int (val , kw )
325- if (val := row .get (kw_arg )) is not None
326- and int in get_args (arg_type_hints .get (kw_arg ))
327- else val
328- for kw_arg in make_summary_key_optional_args
344+ kw_arg : row .get (kw_arg ) for kw_arg in make_summary_key_optional_args
329345 }
330346 try :
331- summary_key = make_summary_key (
347+ summary_key = _make_summary_key (
332348 keyword = kw ,
333- ** optional_kw_args , # type: ignore[arg-type]
349+ ** optional_kw_args ,
334350 )
335351 except InvalidSummaryKeyError as e :
336352 raise _ill_configured_summary_key (kw , csv_file , i + 1 , e ) from e
@@ -342,7 +358,7 @@ def from_bulk_config_dict(
342358 date = row ["date" ]
343359 standardized_date = _parse_date (date ).isoformat ()
344360
345- loc_values = well_localization .get (row .get ("name " ), {})
361+ loc_values = well_localization .get (row .get ("well " ), {})
346362 shape_id = cls .get_shape_id (
347363 loc_values .get ("east" ),
348364 loc_values .get ("north" ),
0 commit comments