Skip to content

Add .nrefs method to accessor that returns number of virtual chunk references #573

@TomNicholas

Description

@TomNicholas

It would be neat to add a method vds.nrefs() to the accessor, which returns the total number of virtual references in the dataset. It's useful to know how many millions of references you're about to try and write to icechunk (or kerchunk json...)

class VirtualDatasetAccessor
    def nrefs(self: xr.Dataset) -> int:
        """Count the number of virtual references in the dataset"""
        from virtualizarr.manifests import ManifestArray
    
        # this just ignores non-virtual variables
        return sum(
            len(var.data.manifest) for var in vds.variables.values() if isinstance(var.data, ManifestArray)
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions