A calibration report may display two valid offset values while assigning each to the wrong station. One way this happens is when a table is sorted for display, then its values are copied into an export that uses a different station order. The values and row counts can be correct while their association changes. This matters for offline review because a plausible offset from another station can be harder to spot than a missing reading.

A pandas Series has both values and an index. When it is assigned to a DataFrame column using a label-based loc selection, pandas aligns the Series to the destination's index. Converting the Series to a NumPy array gives the values without the Series index. At that point, an assignment to a column uses array order. The conversion is appropriate when producing an array, but the order must match the receiving format first.

Use an example in reverse order

Suppose an export expects S07 followed by S12. The offsets arrive in a Series ordered S12 then S07. In this synthetic fixture, the S12 offset is negative 0.25 millimeter and the S07 offset is positive 0.10 millimeter. The station identifiers and values are invented. No offset is written to equipment.

import pandas as pd

export_order = pd.Index(["S07", "S12"], name="station")

offsets = pd.Series([-0.25, 0.10],

index=pd.Index(["S12", "S07"], name="station"),

name="offset_mm")

report = pd.DataFrame(index=export_order)

report["aligned_mm"] = 0.0

report["positional_mm"] = 0.0

report.loc[:, "aligned_mm"] = offsets

report.loc[:, "positional_mm"] = offsets.to_numpy()

assert report["aligned_mm"].tolist() == [0.10, -0.25]

assert report["positional_mm"].tolist() == [-0.25, 0.10]

if not offsets.index.is_unique or not export_order.is_unique:

raise ValueError("Station identifiers must be unique")

if len(export_order.difference(offsets.index)):

raise ValueError("A requested station is missing an offset")

ordered = offsets.reindex(export_order)

if ordered.isna().any():

raise ValueError("A requested offset has no value")

values = ordered.to_numpy()

assert values.tolist() == [0.10, -0.25]

Both intermediate columns contain the same two numbers. Only the first column assigns positive 0.10 to S07 and negative 0.25 to S12 as the source specifies. The final steps make the destination order explicit before removing the labels. They also catch a missing station or missing value while the code can still report which requested identity is affected.

Make the index meaningful

An index is useful for alignment only if its labels represent the identity used by both objects. If each table replaced its original index with a fresh sequence of row numbers after sorting, labels zero and one on both sides say nothing about whether the station identities agree. Retain the station field and make it an index for alignment, or perform a validated join using that field and inspect the join result. Avoid aligning on sequential row numbers unless order itself is the defined contract and was checked at the boundary.

Sometimes a station has more than one offset because several tools or revisions share that station. Decide which revision applies before exporting, or include tool and revision in a compound identity. A duplicate check on the assembled key makes the intended relationship testable. Also decide what to do with extra incoming stations. This fixture ignores them because the recipient specifies a subset. A full-set export may need to reject both missing and unexpected keys.

Verify what the recipient receives

Document the destination order along with the units, offset convention, and calibration revision. If the format accepts an accompanying manifest, include the station list or define it by a versioned template that the recipient can verify. A correct array with the wrong template attached creates the same ambiguity as an unsorted assignment.

Check the serialized result by reading it as the recipient would. Compare the values against the source by station identity, in addition to checking shape and data type. Use a small test where source order differs from destination order and each station has a distinct offset. Add a test with a missing station and a duplicate identifier. This catches ordering errors that an all-zero calibration table or an already sorted fixture would conceal.

Sources

pandas API reference, DataFrame.loc and assignment with a Series

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html

pandas API reference, Series.reindex

https://pandas.pydata.org/docs/reference/api/pandas.Series.reindex.html

pandas API reference, Series.to_numpy

https://pandas.pydata.org/docs/reference/api/pandas.Series.to_numpy.html