MCPcopy
hub / github.com/pydata/xarray / _replace

Method _replace

xarray/core/dataset.py:877–925  ·  view source on GitHub ↗

Fastpath constructor for internal use. Returns an object with optionally with replaced attributes. Explicitly passed arguments are *not* copied when placed on the new dataset. It is up to the caller to ensure that they have the right type and are not used elsewhere.

(
        self,
        variables: dict[Hashable, Variable] | None = None,
        coord_names: set[Hashable] | None = None,
        dims: dict[Any, int] | None = None,
        attrs: dict[Hashable, Any] | Default | None = _default,
        indexes: dict[Hashable, Index] | None = None,
        encoding: dict | Default | None = _default,
        inplace: bool = False,
    )

Source from the content-addressed store, hash-verified

875 return obj
876
877 def _replace(
878 self,
879 variables: dict[Hashable, Variable] | None = None,
880 coord_names: set[Hashable] | None = None,
881 dims: dict[Any, int] | None = None,
882 attrs: dict[Hashable, Any] | Default | None = _default,
883 indexes: dict[Hashable, Index] | None = None,
884 encoding: dict | Default | None = _default,
885 inplace: bool = False,
886 ) -> Self:
887 """Fastpath constructor for internal use.
888
889 Returns an object with optionally with replaced attributes.
890
891 Explicitly passed arguments are *not* copied when placed on the new
892 dataset. It is up to the caller to ensure that they have the right type
893 and are not used elsewhere.
894 """
895 if inplace:
896 if variables is not None:
897 self._variables = variables
898 if coord_names is not None:
899 self._coord_names = coord_names
900 if dims is not None:
901 self._dims = dims
902 if attrs is not _default:
903 self._attrs = attrs
904 if indexes is not None:
905 self._indexes = indexes
906 if encoding is not _default:
907 self._encoding = encoding
908 obj = self
909 else:
910 if variables is None:
911 variables = self._variables.copy()
912 if coord_names is None:
913 coord_names = self._coord_names.copy()
914 if dims is None:
915 dims = self._dims.copy()
916 if attrs is _default:
917 attrs = copy.copy(self._attrs)
918 if indexes is None:
919 indexes = self._indexes.copy()
920 if encoding is _default:
921 encoding = copy.copy(self._encoding)
922 obj = self._construct_direct(
923 variables, coord_names, dims, attrs, indexes, encoding
924 )
925 return obj
926
927 def _replace_with_new_dims(
928 self,

Callers 15

drop_encodingMethod · 0.95
_overwrite_indexesMethod · 0.95
_copyMethod · 0.95
as_numpyMethod · 0.95
_copy_listedMethod · 0.95
chunkMethod · 0.95
_renameMethod · 0.95
rename_dimsMethod · 0.95
rename_varsMethod · 0.95
set_xindexMethod · 0.95

Calls 2

_construct_directMethod · 0.95
copyMethod · 0.45

Tested by 1

test_replaceMethod · 0.36