AI, ML & Data Engineering
20 lessons from merged PRs in Hugging Face Transformers, DuckDB and pandas, summarized in our own words. Fixes for ML pipelines and analytical SQL.
brain_seed_starter(instance_id="<your-brain-id>", stack="ai-data")20 fixes from merged PRs
Every lesson below is a short summary in our own words and links to its upstream GitHub pull request in a permissive-licensed repository. Seed them into your Brain so your coding agent can find them when a similar problem comes up.
- Symptom
Gemma3ForConditionalGeneration in transformers uses 1-indexed position ids while the reference implementation uses 0-indexed ones.
Cause and fixCause: The modular Gemma3 class inherited from the PaliGemma class, carrying over a position-id adjustment that is specific to PaliGemma input ordering. Fix: The inherited adjustment was removed from the Gemma3 conditional-generation code in modular_gemma3.py and the generated modeling_gemma3.py.
- Symptom
Creating GenerationConfig(cache_implementation="static") in transformers is rejected unless a full cache config is supplied too.
Cause and fixCause: Static cache setup required extra cache parameters up front, although generate() can infer them at inference time. Fix: The validation in generation/configuration_utils.py was changed so a static cache_implementation alone is accepted.
- Symptom
A user-set YaRN factor in a transformers rope config is ignored when original_max_position_embeddings is also present.
Cause and fixCause: The factor derived implicitly from the position-embedding values took priority over the explicit factor. Fix: modeling_rope_utils.py now gives the explicit factor precedence and emits warnings when the YaRN parameters are missing or inconsistent.
- Symptom
The cardinality error logged during training of Deformable DETR, Grounding DINO, RT-DETR and similar models is wrong.
Cause and fixCause: These models use sigmoid or focal loss without a background class, so the argmax-against-last-class check from original DETR has no meaning for them. Fix: Their cardinality calculation now counts a query as an object when the maximum sigmoid score exceeds 0.5; the original DETR loss keeps its softmax logic.
- Symptom
Loading facebook/sam3 with Sam3Model in transformers 5.10.1 leaves the text encoder weights unloaded and randomly initialized, reported as both missing and unexpected.
Cause and fixCause: The key conversion was registered by model type, which other models share, rather than for the specific CLIP text class that Sam3 loads and used to unwrap manually. Fix: The mapping in conversion_mapping.py is now keyed by class name, so the conversion applies only to the model class that needs it.
- Symptom
The error position in the JSON from errors_as_json via json_execute_serialized_sql() always points to the same wrong character instead of the failing spot.
Cause and fixCause: Binding a table macro caught the exception and unconditionally re-attached the macro reference's query location, overwriting a position already stored in the error. Fix: In BoundStatementBinder::Bind for TableFunctionRef, AddQueryLocation is now called only if the error has no position yet.
- Symptom
In DuckDB, casting a float or double to a decimal rounds differently from PostgreSQL and loses precision, e.g. 1.45 to decimal(3,1).
Cause and fixCause: These casts used statistical (round-half-even) rounding. Fix: The cast operators in cast_operators.cpp now use half-up rounding for float and double to decimal conversion.
- Symptom
read_parquet with union_by_name=true fails in DuckDB 1.5.1 when some files store an optional nested column as a plain NULL-like scalar type instead of a STRUCT.
Cause and fixCause: ConstructMapExpression sent non-nested local columns through remap_struct, which accepts only nested sources. Fix: Non-nested local columns are now handled by the ordinary cast path, so NULL-like columns stay readable while real scalar-versus-struct conflicts still give a cast error.
- Symptom
Reading several JSON files whose keys differ only by letter case in DuckDB fails with a duplicate column name error such as Image_1.
Cause and fixCause: The suffix added to make colliding names unique could itself collide with a name that already existed. Fix: read_json.cpp now checks the suffixed name against existing columns when resolving collisions; nested JSON with the same issue is still not covered.
- Symptom
A DuckDB query with ROLLUP or CUBE style grouping sets returns wrong results when the duplicate groups optimizer is on.
Cause and fixCause: Removing unused group-by columns while several grouping sets exist let the duplicate groups optimizer drop groups generated by rollup and cube. Fix: remove_unused_columns.cpp no longer removes unused group columns when there is more than one grouping set.
- Symptom
DuckDB refuses to implicitly or explicitly cast a custom aliased type to a UNION that contains it as a member.
Cause and fixCause: The cast rules rejected any type with a mismatching alias before considering union members. Fix: union_casts.cpp and cast_rules.cpp now try casting the source to a member of the target union when the existing member-to-member route fails, keeping member-to-member casts first.
- Symptom
After CALL truncate_duckdb_logs() on a CSV log file in DuckDB, the file shows a blank line before the header or has no header at all after a restart.
Cause and fixCause: Truncating the on-disk file left the CSV writer state and the header dialect option untouched, so the header was written wrongly or skipped in append mode. Fix: Truncation now resets the CSVWriter state and the CSV header option after cutting the file to zero length, before calling Initialize(true).
- Symptom
A DuckDB select-list expression combining an equality test with an OR over two null checks returns false instead of NULL for rows where only one column is NULL.
Cause and fixCause: The EqualOrNullSimplification optimizer rule rewrites the pattern into IS NOT DISTINCT FROM, which is only valid for predicates; in projections it turns NULL into false. Fix: Limited the rewrite in equal_or_null_simplification.cpp to root filter and join predicates, leaving projection expressions unchanged, and added an optimizer test.
- Symptom
Indexing with a Categorical built from Interval values in pandas is very slow.
Cause and fixCause: Hashing the categories turned the IntervalIndex into an object array, which then fell back to string conversion in hash_object_array. Fix: CategoricalDtype._hash_categories now passes the extension array itself to hash_array, and IntervalArray gains a _hash_pandas_object that hashes left, right and closed directly.
- Symptom
In pandas, assigning with loc to a new key silently changes the dtype of the Series or DataFrame, for example int to float or extension dtype to object.
Cause and fixCause: Expansion paths disagree on dtype handling: some use concat-like casting, so adding a row can change dtype without notice. Fix: The PR adds a deprecation warning, raised from infer_and_maybe_downcast via _post_expansion_casting, saying dtype will be kept in future, while int-to-float promotion for NaN stays allowed.
- Symptom
Creating a pandas Categorical with a huge number of categories is slow because an is_unique check runs repeatedly.
Cause and fixCause: Construction went through CategoricalDtype.update_dtype, which revalidated categories that were already validated. Fix: _simple_new and __init__ now check ordered directly and use _from_fastpath, and update_dtype also uses _from_fastpath to skip repeated uniqueness and NA checks.
- Symptom
pandas CI jobs time out because the micromamba solver spends about 25 minutes resolving environments.
Cause and fixCause: boto3 publishes nearly daily, and the huge number of candidate versions slows the solver. Fix: The CI dependency files got a lower version bound of 1.27 on boto3, limiting how many versions the solver must consider.
- Symptom
DataFrame.describe(include=['datetime']) on a frame without datetime columns raises the unhelpful error 'No objects to concatenate'.
Cause and fixCause: The per-dtype describe results were concatenated even when the requested dtype matched no columns, leaving nothing to join. Fix: describe.py now raises a ValueError stating that no columns match the given include or exclude dtypes.
- Symptom
Reading compressed CSV through fsspec fails with 'ValueError: seek of closed file' on a Tar filesystem after upgrading to fsspec 2026.4.
Cause and fixCause: pandas.io.common._get_filepath_or_buffer called fsspec.open(...).open() and discarded the OpenFile object, which fsspec requires to stay alive while the handle is used. Fix: The function now keeps the OpenFile alive for as long as the returned file handle is in use, so the temporary fsspec upper pin can be removed.
- Symptom
pandas bar plots with stacked=True and subplots=True stack values differently than expected.
Cause and fixCause: Combining stacked with subplots computed offsets incorrectly, especially when columns did not all have values at the same positions. Fix: The plotting code now checks for stacked plus subplots in bar plots and computes offsets per subplot.