Skip to content

to_geotiff(compression=None) leaks a raw AttributeError instead of a clear error #2978

@brendancol

Description

@brendancol

Describe the bug

to_geotiff(arr, path, compression=None) raises a raw AttributeError: 'NoneType' object has no attribute 'lower' from _compression_tag (xrspatial/geotiff/_encode.py).

The compression parameter is typed and documented as str (default 'zstd'), so None was never a supported value. PR #2977 added a type guard at the public boundary that rejects non-string compression, but it exempts None to keep the same guard shape as the low-level writer, so None still falls through to the downstream .lower() call.

Reproduction

import numpy as np
from xrspatial.geotiff import to_geotiff
to_geotiff(np.ones((4, 4), dtype="float32"), "out.tif", compression=None)
# AttributeError: 'NoneType' object has no attribute 'lower'

Decision needed

This needs a small design call before fixing:

  • Treat None as an alias for the 'none' codec (no compression), or
  • Reject None at the public boundary with the same TypeError as other invalid types.

Either one is a few lines, but the choice affects the documented contract, which is why I'm splitting it out from the type-guard fix in #2977.

Context

Surfaced during review of #2977 (issue #2975).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggeotiffGeoTIFF moduleinput-validationInput validation and error messages

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions