Skip to content

FiboaBaseConverter: bounded drops, and schemas up front - #264

Closed
ivorbosloper wants to merge 2 commits into
mainfrom
split/base-drops
Closed

ivorbosloper wants to merge 2 commits into
mainfrom
split/base-drops

Conversation

@ivorbosloper

@ivorbosloper ivorbosloper commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

First of the structural PRs (datasets: #231-#263). Two rules every converter needs and none had.

Rows that cannot validate are dropped, up to 1% of the file. A row with no id or crop:code, or an empty geometry, fails at the very end of a conversion — hours of work discarded for a handful of rows. Dropping silently would hide a broken mapping, so above 1% the conversion fails and names the source column and the count. This is how si 2019 was caught publishing 820,151 fields with no id (#231).

What "required" means comes from the schemas, not from a list here. The core schema requires id and geometry, the crop extension crop:code and crop:code_list, and a converter that declares an extension takes on its rules with it — so there is nothing for a converter to repeat. (Thanks @m-mohr; the first version hardcoded ("id", "crop:code").)

Schemas are fetched before any source data is read, so a converter knows what every row must carry before it downloads anything — and a schema host that is down says so immediately rather than after a wait. One retry for a dropped connection, then out: the long backoff made sense when the fetch happened at the write step, with hours of work behind it.

One converter comes along: Europe-LAND's LT 2024 ships an empty crop_code beside a populated crop_name, so every row would be dropped; the name is the best code there is.

max_dropped_share stays a class attribute, so a converter whose source really is that patchy can raise it, and the error says how many rows it would have dropped.

#265 builds on this — same file.

@ivorbosloper
ivorbosloper force-pushed the split/base-drops branch 2 times, most recently from 8da77df to 5270f8a Compare September 12, 2026 15:10
@ivorbosloper ivorbosloper changed the title FiboaBaseConverter: drop what cannot validate, bounded, and fetch schemas first FiboaBaseConverter: bounded drops, and schemas up front Sep 12, 2026
Comment thread fiboa_cli/conversion/fiboa_converter.py Outdated
AREA_KEY = "metrics:area"
# Properties that a schema requires to be non-null; rows lacking them cannot
# validate, so they are dropped (with a warning) rather than failing the run.
REQUIRED_NON_NULL = ("id", "crop:code")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be clear from the schemas and seems unnecessary to list in converters.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!

area_calculate_missing = False
use_variant_as_determination = False
# rows lacking a REQUIRED_NON_NULL value are dropped up to this share, else it's an error
max_dropped_share = 0.01

@m-mohr m-mohr Sep 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty arbitrary number. I feel like we should decide for a consistent behavior (all or none). Maybe leave choice to users. Depending on the usecase you may want different behavior.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some check that increases quality. Don't raise problems if the error margin is low, but set some default threshold.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like from a scientific perspective just ignoring errors when the error number is low is the wrong approach and doesn't necessarily increases quality. It depends on the usecase. We should probably discuss this further how we want to go ahead with such cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_file(uri)
break
except Exception as e:
if attempt == attempts - 1:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a conversion retries make sense to me, but with prewarm I'd rather want the process to fail immediately instead of waiting 4mins, I think?

ivorbosloper and others added 2 commits September 13, 2026 20:04
…emas first

Two rules that every converter needs and none had.

**Rows that cannot validate are dropped, up to 1% of the file.** A row with no
`id` or no `crop:code` fails validation at the very end of a conversion, after
everything has been read and written; the same goes for a row with an empty or
missing geometry, which geopandas also refuses to Hilbert-sort. Dropping them
silently would hide a broken mapping, so the share is bounded: above 1% the
conversion fails and says which column and how many rows, because that is a
converter bug rather than a few bad rows in the source.

The lookup happens before columns are renamed, so the message names the source
column a reader will find in the data.

**Schemas are fetched before any real work.** The schema hosts (vecorel.org,
fiboa.org) fail intermittently, and a blip after a long download used to kill
the conversion at the write step, discarding hours of work. Eight attempts with
exponential backoff, before the first byte of source data is read; `load_file`
caches per process, so a successful pre-warm makes the write network-free.

The Europe-LAND base converter comes along because the new rule exposes it:
LT 2024 ships an entirely empty `crop_code` column beside a populated
`crop_name`, so every row would be dropped. The name is the best available code
there, and is used as one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DVx9uQV2QPM8ecPAY3ZjXG
A converter should not have to repeat what its schemas already say: the core
schema requires id and geometry, the crop extension crop:code and
crop:code_list, and a converter that declares an extension takes on its rules
with it. The hardcoded pair is gone; the merged schema of the collection says
what every row must carry, out of the copy _prewarm_schemas has already
fetched.

And the pre-warm itself fails fast now. It runs before anything is downloaded
or converted, so waiting four minutes on a schema host buys nothing — one
retry for a dropped connection, then out. The retries were written when the
fetch happened at the write step, with hours of work behind it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DVx9uQV2QPM8ecPAY3ZjXG
@ivorbosloper

Copy link
Copy Markdown
Collaborator Author

vecorel-cli 0.2.18 carries this upstream. Its BaseConverter now drops rows that cannot validate under max_dropped_share, reads the required properties from the declared schemas (which is what @m-mohr asked for on #264 — no list in a converter), checks id uniqueness, refuses a converter that declares both sources and variants, and fetches the schemas before any source data.

#280 bumps the pin and brings along the two converter fixes the checks fire on (hr's rolling sources, Europe-LAND's empty crop_code). What is left of this PR that is not upstream is the sweep tests over every converter in this repository; I will carry those into #280 rather than keep this branch alive. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants