Skip to content

Retain cached data array values when changing dtype #358

Closed

Description

@davidhassell

Currently (cfdm v1.12.3.0), when you change the data type, any cached values are removed:

>>> import cfdm
>>> d = cfdm.example_field(0).data
>>> d
<Data(5, 8): [[0.007, ..., 0.013]] 1>
>>> d._get_cached_elements()
{0: array(0.007), -1: array(0.013)}
>>> d.dtype = 'float32'
>>> d._get_cached_elements()
{}

This is always safe, but there's no reason not to keep and cached elements, after having cast them to the new data type.

What we'd like to see is:

>>> d.dtype = 'float32'
>>> d._get_cached_elements()
{0: array(0.007, dtype=float32), -1: array(0.013, dtype=float32)}

PR to follow.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions