code: def _replace(obj, **kwargs):
      """Copy and replace dataclass instance.
  
      Compared to ``dataclasses.replace`` this first creates a copy where each
      field in the object is copied. Thus, each field of the returned object is
      different from the source object.
      """
  
      clone = object.__new__(obj.__class__)
      clone.__dict__ = valmap(copy.copy, obj.__dict__)
  
      return dataclasses.replace(clone, **kwargs)
  
file_path: gluonts/src/gluonts/zebras/_util.py
imports: import copy
  import dataclasses
  import numpy
  from toolz import valmap
label_desc: Use image node_id 2 for calling a global function with example usage: _replace(obj) and returns: dataclasses