-
Notifications
You must be signed in to change notification settings - Fork 4
Decouple transfer tests from GCS using local CSV fixtures #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,18 +15,13 @@ | |
| # =============================================================================== | ||
| import os | ||
| import re | ||
| import time | ||
| import threading | ||
| import time | ||
| from concurrent.futures import ThreadPoolExecutor, as_completed | ||
| from datetime import datetime, UTC | ||
| from zoneinfo import ZoneInfo | ||
|
|
||
| import pandas as pd | ||
| from pandas import isna, notna | ||
| from pydantic import ValidationError | ||
| from sqlalchemy.exc import DatabaseError | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from core.enums import ( | ||
| WellPurpose as WellPurposeEnum, | ||
| CasingMaterial as WellCasingMaterialEnum, | ||
|
|
@@ -47,20 +42,23 @@ | |
| GeologicFormation, | ||
| ThingAquiferAssociation, | ||
| ) | ||
| from db.engine import session_ctx | ||
| from pandas import isna, notna | ||
| from pydantic import ValidationError | ||
| from schemas.thing import CreateWell, CreateWellScreen | ||
| from services.gcs_helper import get_storage_bucket | ||
| from services.util import ( | ||
| get_state_from_point, | ||
| get_county_from_point, | ||
| get_quad_name_from_point, | ||
| ) | ||
| from db.engine import session_ctx | ||
| from sqlalchemy.exc import DatabaseError | ||
| from sqlalchemy.orm import Session | ||
| from transfers.transferer import ChunkTransferer, Transferer | ||
| from transfers.util import ( | ||
| make_location, | ||
| make_location_data_provenance, | ||
| filter_to_valid_point_ids, | ||
| read_csv, | ||
| logger, | ||
| replace_nans, | ||
| get_transferable_wells, | ||
|
|
@@ -220,14 +218,19 @@ class WellTransferer(Transferer): | |
|
|
||
| def __init__(self, *args, **kw): | ||
| super().__init__(*args, **kw) | ||
| self._cached_elevations = get_cached_elevations() | ||
| if self.flags.get("CSV_PATHS"): | ||
| # Local CSV mode runs in test/dev without GCS; disable the shared cache | ||
| # so elevation lookups don’t reach out to the bucket. | ||
| self._cached_elevations = {} | ||
| else: | ||
|
Comment on lines
219
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With Useful? React with 👍 / 👎. |
||
| self._cached_elevations = get_cached_elevations() | ||
|
Comment on lines
+221
to
+226
|
||
| self._added_locations = {} | ||
| self._aquifers = None | ||
| self._measuring_point_estimator = MeasuringPointEstimator() | ||
|
|
||
| def _get_dfs(self): | ||
| wdf = read_csv("WellData", dtype={"OSEWelltagID": str}) | ||
| ldf = read_csv("Location") | ||
| wdf = self._read_csv("WellData", dtype={"OSEWelltagID": str}) | ||
| ldf = self._read_csv("Location") | ||
| ldf = ldf.drop(["PointID", "SSMA_TimeStamp"], axis=1) | ||
| wdf = wdf.join(ldf.set_index("LocationId"), on="LocationId") | ||
| wdf = wdf[wdf["SiteType"] == "GW"] | ||
|
|
@@ -622,7 +625,10 @@ def _get_or_create_aquifer_system( | |
| return None, False | ||
|
|
||
| def _after_hook(self, session): | ||
| dump_cached_elevations(self._cached_elevations) | ||
| if self.flags.get("CSV_PATHS"): | ||
| logger.info("Skipping cached elevation dump while using CSV_PATHS") | ||
| else: | ||
| dump_cached_elevations(self._cached_elevations) | ||
|
|
||
| self._row_by_pointid = { | ||
| pid: row | ||
|
|
@@ -1592,7 +1598,7 @@ def _get_dfs(self): | |
| if self.source_table is None: | ||
| raise ValueError("source_table must be set") | ||
|
|
||
| input_df = read_csv(self.source_table, self.source_dtypes) | ||
| input_df = self._read_csv(self.source_table, dtype=self.source_dtypes) | ||
| wdf = replace_nans(input_df) | ||
| cleaned_df = filter_to_valid_point_ids(wdf) | ||
| return input_df, cleaned_df | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline type coercion and null check could be simplified by extracting this logic into a helper function, especially since similar patterns appear in
_make_emailand_make_phone. This would improve consistency and reduce duplication across the codebase.