Skip to content

Impossible to set a dimension with size=0 #1480

Open

Description

@davide-f

To report a non-security related issue, please provide:

  • the version of the software with which you are encountering an issue
  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.)
  • a description of the issue with the steps needed to reproduce it

The python interface does not allow to create dimensions with value=0, as they will be interpreted as unlimited.
It would be nice to enable the possibility to set a dimension with size 0; with C/C++ interface this is possible

Activity

  1. jswhit commented on Apr 25, 2026

    @jswhit
    Collaborator

    I don't think we can change this now without potentially breaking a lot of code. Curious what the use case is? Note that you can create scalar variables by using an empty tuple for the dimension argument in createVariable.

  2. davide-f commented on Apr 27, 2026

    @davide-f
    Author

    In smspp-project, a tool for optimization, we have indices that may be empty and as such indexed over a 0-valued index.

    What about adding an optional argumwnt such as enable_unlimited

    X.createDimension(name, value=None, enable_unlimited=True)

    Such that when enable_unlimited is false, 0 is treated as number?

    This is back compatible. I understand the behavior must not change given usage

  3. jswhit commented on Apr 27, 2026

    @jswhit
    Collaborator

    I think a dimension with size 0 is technically not allowed in netcdf unless the dimension is unlimited (the NC_UNLIMITED size argument is set to 0 in netcdf.h).

  4. Dave-Allured commented on Jul 31, 2026

    @Dave-Allured

    ... It would be nice to enable the possibility to set a dimension with size 0; with C/C++ interface this is possible

    @davide-f I do not think this is possible, even with the C/C++ interface. My understanding is that this would contradict the netCDF data model, which requires all dimensions be non-zero for fixed-size variables. My understanding is that the netcdf-C library enforces this. Size zero is supported only for unlimited dimensions, as you noted.

    If you do not agree, would you please show a minimal example in C?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions