1818)
1919
2020import numpy as np
21- import pandas as pd
2221import polars as pl
2322import scipy as sp
2423from pydantic import BaseModel , ConfigDict , Field , model_serializer
@@ -686,11 +685,7 @@ def from_csv(
686685 f"The CSV file ({ filename } ) does not exist or is not accessible." ,
687686 filename ,
688687 )
689- csv_file = pd .read_csv (
690- filename ,
691- encoding = "utf-8" ,
692- on_bad_lines = "error" ,
693- )
688+ csv_file = pl .read_csv (filename , encoding = "utf-8" )
694689
695690 required_columns = {
696691 "WELL_NAME" ,
@@ -701,7 +696,7 @@ def from_csv(
701696 "EAST" ,
702697 "TVD" ,
703698 }
704- missing_required_columns = required_columns - set (csv_file .keys () )
699+ missing_required_columns = required_columns - set (csv_file .columns )
705700 if missing_required_columns :
706701 raise ObservationConfigError .with_context (
707702 f"The rft observations file { filename } is missing required column(s) "
@@ -711,9 +706,10 @@ def from_csv(
711706
712707 rft_observations = []
713708 invalid_observations = []
714- for row in csv_file .itertuples (index = True ):
715- east_val = validate_float (str (row .EAST ), "EAST" )
716- north_val = validate_float (str (row .NORTH ), "NORTH" )
709+ columns = set (csv_file .columns )
710+ for index , row in enumerate (csv_file .iter_rows (named = True )):
711+ east_val = validate_float (str (row ["EAST" ]), "EAST" )
712+ north_val = validate_float (str (row ["NORTH" ]), "NORTH" )
717713 radius = radius if radius is not None else DEFAULT_LOCALIZATION_RADIUS
718714
719715 shape_id = shape_registry .register (
@@ -725,22 +721,20 @@ def from_csv(
725721 )
726722
727723 rft_observation = cls (
728- name = f"{ observation_dict ['name' ]} [{ row . Index } ]" ,
729- well = str (row . WELL_NAME ),
730- date = str (row . DATE ),
724+ name = f"{ observation_dict ['name' ]} [{ index } ]" ,
725+ well = str (row [ " WELL_NAME" ] ),
726+ date = str (row [ " DATE" ] ),
731727 property = observed_property ,
732- value = validate_float (
733- str (getattr (row , observed_property )), observed_property
734- ),
735- error = validate_float (str (row .ERROR ), "ERROR" ),
728+ value = validate_float (str (row [observed_property ]), observed_property ),
729+ error = validate_float (str (row ["ERROR" ]), "ERROR" ),
736730 east = east_val ,
737731 north = north_val ,
738732 shape_id = shape_id ,
739- tvd = validate_float (str (row . TVD ), "TVD" ),
740- md = validate_float (str (row . MD ), "MD" ) if "MD" in csv_file else None ,
733+ tvd = validate_float (str (row [ " TVD" ] ), "TVD" ),
734+ md = validate_float (str (row [ "MD" ] ), "MD" ) if "MD" in columns else None ,
741735 zone = (
742- str (row . ZONE )
743- if "ZONE" in csv_file and row . ZONE is not None
736+ str (row [ " ZONE" ] )
737+ if "ZONE" in columns and row [ " ZONE" ] is not None
744738 else None
745739 ),
746740 )
@@ -1007,11 +1001,10 @@ class SeismicObservation(BaseObservation):
10071001 TOLERANCE : ClassVar [float ] = 0.1
10081002
10091003 @staticmethod
1010- def _load_observations (filepath : Path ) -> pd .DataFrame :
1011- df = pd .read_csv (
1004+ def _load_observations (filepath : Path ) -> pl .DataFrame :
1005+ df = pl .read_csv (
10121006 filepath ,
10131007 encoding = "utf-8" ,
1014- on_bad_lines = "error" ,
10151008 )
10161009
10171010 required_columns = {
@@ -1020,7 +1013,7 @@ def _load_observations(filepath: Path) -> pd.DataFrame:
10201013 "OBS" ,
10211014 "OBS_ERROR" ,
10221015 }
1023- missing_required_columns = required_columns - set (df .keys () )
1016+ missing_required_columns = required_columns - set (df .columns )
10241017 if missing_required_columns :
10251018 raise ObservationConfigError .with_context (
10261019 f"The seismic observations file { filepath } "
@@ -1119,11 +1112,11 @@ def from_obs_dict(
11191112 boundary_id = shape_registry .register (boundary )
11201113
11211114 seismic_observations = []
1122- for row in df .itertuples ( ):
1123- east = validate_float (str (row . X_UTME ), "X_UTME" )
1124- north = validate_float (str (row . Y_UTMN ), "Y_UTMN" )
1125- value = validate_float (str (row . OBS ), "OBS" )
1126- error = validate_float (str (row . OBS_ERROR ), "OBS_ERROR" )
1115+ for row in df .iter_rows ( named = True ):
1116+ east = validate_float (str (row [ " X_UTME" ] ), "X_UTME" )
1117+ north = validate_float (str (row [ " Y_UTMN" ] ), "Y_UTMN" )
1118+ value = validate_float (str (row [ " OBS" ] ), "OBS" )
1119+ error = validate_float (str (row [ " OBS_ERROR" ] ), "OBS_ERROR" )
11271120
11281121 # Currently supports only default localization radius as behavior of
11291122 # LOCALIZATION keyword is undefined. All shapes are being registered
0 commit comments