Starlark: Move between fields and tags

I have a simple Starlark script which checks if field values are not numeric and moves them to tags if so.
My problem is that whenever I copy an entry to tags and delete it in field it also disappears in tags even though I only pop in the field dict.

def apply(metric):
  
  new_tags = {}
  for k, v in metric.fields.items():
    if type(v) != "float" and type(v) != "int":

        new_tags.update({k:v})
        metric.fields.pop(k)
        
  metric.tags.update(new_tags.items())

  return metric

Deleting the field entries at the end results in the same behaviour.

If I wanted to switch string fields to tags I would use something similar to this:

def apply(metric):
  new_tags = {}
  for k, v in metric.fields.items():
    if type(v) == "string":
      metric.fields.pop(k)
      metric.tags[k] = v

  return metric
- metric value=42,foo="bar"
+ metric,foo=bar value=42

edit: you can of course switch the logic back to checking explicitly for int/floats to avoid booleans as well.

Did you replicate it? I tried it but still no tags. Your example is just removing the entry from fields but does not move it to tags.