-
Notifications
You must be signed in to change notification settings - Fork 4
NO TICKET: Handle NaN MP height and NULL history entries in legacy data transfers and property reads #542
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
NO TICKET: Handle NaN MP height and NULL history entries in legacy data transfers and property reads #542
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -569,16 +569,9 @@ def _build_well_payload(self, row) -> CreateWell | None: | |
|
|
||
| mpheight = row.MPHeight | ||
| mpheight_description = row.MeasuringPoint | ||
| if mpheight is None: | ||
| mphs = self._measuring_point_estimator.estimate_measuring_point_height( | ||
| row | ||
| ) | ||
| if mphs: | ||
| try: | ||
| mpheight = mphs[0][0] | ||
| mpheight_description = mphs[1][0] | ||
| except IndexError: | ||
| pass | ||
| if mpheight is None or isna(mpheight): | ||
| # Treat missing/NaN MPHeight as unknown during migration. | ||
| mpheight = None | ||
|
|
||
| completion_date, completion_date_parse_failed = _normalize_completion_date( | ||
| row.CompletionDate | ||
|
|
@@ -736,22 +729,9 @@ def _add_notes_and_provenance( | |
| ) | ||
|
|
||
| def _add_histories(self, session: Session, row, well: Thing) -> None: | ||
| mphs = self._measuring_point_estimator.estimate_measuring_point_height(row) | ||
| added_measuring_point = False | ||
| for mph, mph_desc, start_date, end_date in zip(*mphs): | ||
| session.add( | ||
| MeasuringPointHistory( | ||
| thing_id=well.id, | ||
| measuring_point_height=mph, | ||
| measuring_point_description=mph_desc, | ||
| start_date=start_date, | ||
| end_date=end_date, | ||
| ) | ||
| ) | ||
| added_measuring_point = True | ||
|
|
||
| # Preserve transfer intent even when no MP height can be measured/estimated. | ||
| if not added_measuring_point: | ||
| raw_mpheight = getattr(row, "MPHeight", None) | ||
| if raw_mpheight is None or isna(raw_mpheight): | ||
| # No estimator for NaN/missing MPHeight; persist NULL history row. | ||
| raw_desc = getattr(row, "MeasuringPoint", None) | ||
| mp_desc = None if isna(raw_desc) else raw_desc | ||
| session.add( | ||
|
|
@@ -763,6 +743,34 @@ def _add_histories(self, session: Session, row, well: Thing) -> None: | |
| end_date=None, | ||
| ) | ||
| ) | ||
| else: | ||
| mphs = self._measuring_point_estimator.estimate_measuring_point_height(row) | ||
| added_measuring_point = False | ||
| for mph, mph_desc, start_date, end_date in zip(*mphs): | ||
| session.add( | ||
| MeasuringPointHistory( | ||
| thing_id=well.id, | ||
| measuring_point_height=mph, | ||
| measuring_point_description=mph_desc, | ||
| start_date=start_date, | ||
| end_date=end_date, | ||
| ) | ||
| ) | ||
| added_measuring_point = True | ||
|
|
||
| # Preserve transfer intent even when no MP height can be measured/estimated. | ||
| if not added_measuring_point: | ||
| raw_desc = getattr(row, "MeasuringPoint", None) | ||
| mp_desc = None if isna(raw_desc) else raw_desc | ||
| session.add( | ||
| MeasuringPointHistory( | ||
| thing_id=well.id, | ||
| measuring_point_height=None, | ||
| measuring_point_description=mp_desc, | ||
| start_date=datetime.now(tz=UTC).date(), | ||
| end_date=None, | ||
| ) | ||
| ) | ||
|
Comment on lines
+762
to
+773
|
||
|
|
||
| target_id = well.id | ||
| target_table = "thing" | ||
|
|
||
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.
When MPHeight is None or NaN, the measuring point description should also be checked for NaN and converted to None before passing to CreateWell. If
row.MeasuringPointcontains a pandas NaN value (float), it could fail Pydantic validation sincemeasuring_point_descriptionexpectsstr | None, not a float. Consider adding:mpheight_description = None if isna(row.MeasuringPoint) else row.MeasuringPointinside the if block for consistency with the handling in_add_histories(lines 735-736).