A luminaire schedule exported from a spreadsheet looks tidy until it reaches the quoting system. A beam angle may read '24°', a quantity may be '3.0', and a fixture ID may appear twice because a row was copied. Validate the CSV at the import boundary and return row numbers so the person maintaining the schedule can fix the source.
For a small import, require fixture_id, quantity and beam_angle_deg. Keep IDs as strings so leading zeros survive. Require positive integer quantities and beam angles between 0 and 180 degrees. In this example, fixture_id identifies a schedule line, so a duplicate is an error. If the file uses a product SKU instead, add a separate line identifier because the same product can appear in multiple zones.
import csv
from decimal import Decimal, InvalidOperation
def validate_schedule(path):
required = {"fixture_id", "quantity", "beam_angle_deg"}
issues = []
first_seen = {}
with open(path, encoding="utf-8-sig", newline="") as source:
rows = csv.DictReader(source)
missing = required - set(rows.fieldnames or [])
if missing:
return [f"Missing columns: {', '.join(sorted(missing))}"]
for row in rows:
line = rows.line_num
fixture_id = (row["fixture_id"] or "").strip()
if not fixture_id:
issues.append(f"Line {line}: missing fixture ID")
elif fixture_id in first_seen:
issues.append(
f"Line {line}: duplicate fixture ID {fixture_id!r} "
f"(first seen on line {first_seen[fixture_id]})"
)
else:
first_seen[fixture_id] = line
try:
if int(row["quantity"] or "") < 1:
raise ValueError
except ValueError:
issues.append(f"Line {line}: quantity must be a positive integer")
try:
angle = Decimal(row["beam_angle_deg"] or "")
if not angle.is_finite() or not 0 < angle <= 180:
raise InvalidOperation
except InvalidOperation:
issues.append(f"Line {line}: beam angle must be in (0, 180]")
return issues
fixture_id,quantity,beam_angle_deg
001,4,24
001,3.0,NaN
002,2,36
The second data row produces three errors: a duplicate ID, a non-integer quantity and an invalid beam angle. Report all three together so the spreadsheet owner can fix the file in one pass. Only hand the data to the importer after validation succeeds. These checks validate the file format and ranges. Confirm model-specific angles and availability against the supplier data before issuing a purchase order.
Disclosure: This article is from BOYIN Lighting, a supplier of commercial luminaires. Its product pages show examples of the fixture specifications used when building a schedule.