예제 #1
0
 def test_append_slice_with_coordinates_attribute(self):
     dst_path = "my.zarr"
     self.add_path(dst_path)
     ds1, ds2 = new_append_test_datasets(["2001-01-01"],
                                         ["2001-01-02", "2001-01-03"])
     ds1.attrs["coordinates"] = "test value 1"
     ds2.attrs["coordinates"] = "test value 2"
     ds1.to_zarr(dst_path)
     append_slice(dst_path, ds2, dimension="t")
     ds3 = xr.open_zarr(dst_path, decode_coords=False)
     self.assertNotIn("coordinates", ds3.attrs)
예제 #2
0
 def test_append_to_non_increasing_append_mode_all(self):
     dst_path = "my.zarr"
     self.add_path(dst_path)
     ds1, ds2 = new_append_test_datasets(
         ["2001-01-01", "2001-01-03", "2001-01-02"],
         ["2001-01-04", "2001-01-05", "2001-01-06"]
     )
     ds1.to_zarr(dst_path)
     w = DatasetWriter(dst_path, output_append=True, output_append_dim="t",
                       output_append_mode=AppendMode.all)
     w.write_dataset(ds2)
예제 #3
0
 def test_append_non_increasing_append_newer(self):
     dst_path = "my.zarr"
     self.add_path(dst_path)
     ds1, ds2 = new_append_test_datasets(
         ["2001-01-01", "2001-01-02", "2001-01-03"],
         ["2001-01-05", "2001-01-04", "2001-01-03", "2001-02-02"]
     )
     ds1.to_zarr(dst_path)
     w = DatasetWriter(dst_path, output_append=True,
                       output_append_dim="t",
                       output_append_mode=AppendMode.newer)
     with pytest.raises(ValueError,
                        match="must be increasing"):
         w.write_dataset(ds2)
예제 #4
0
 def test_append_overlapping_forbid_overlap(self):
     dst_path = "my.zarr"
     self.add_path(dst_path)
     ds1, ds2 = new_append_test_datasets(
         ["2001-01-01", "2001-01-02", "2001-01-03"],
         ["2001-01-02", "2001-01-03", "2001-01-04"]
     )
     ds1.to_zarr(dst_path)
     with pytest.raises(ValueError,
                        match="may not overlap"):
         w = DatasetWriter(dst_path, output_append=True,
                           output_append_dim="t",
                           output_append_mode=AppendMode.no_overlap)
         w.write_dataset(ds2)
예제 #5
0
 def test_append_overlapping_append_newer(self):
     for consolidated in False, True:
         with self.subTest(consolidated=consolidated):
             dst_path = "my.zarr"
             self.add_path(dst_path)
             ds1, ds2 = new_append_test_datasets(
                 ["2001-01-01", "2001-01-02", "2001-01-03"],
                 ["2001-01-02", "2001-01-03", "2001-01-04", "2001-02-05"]
             )
             ds1.to_zarr(dst_path, consolidated=consolidated)
             w = DatasetWriter(dst_path, output_append=True,
                               output_append_dim="t",
                               output_append_mode=AppendMode.newer,
                               output_consolidated=consolidated)
             w.write_dataset(ds2)
             ds3 = xr.open_zarr(dst_path, consolidated=consolidated)
             expected = np.array(["2001-01-01", "2001-01-02", "2001-01-03",
                                  "2001-01-04", "2001-02-05"],
                                 dtype="datetime64[ns]")
             np.testing.assert_equal(expected, ds3.t.data)
예제 #6
0
 def test_append_overlapping_replace(self):
     dst_path = "my.zarr"
     self.add_path(dst_path)
     ds1, ds2 = new_append_test_datasets(
         ["2001-01-01", "2001-01-02", "2001-01-03", "2001-01-05"],
         ["2001-01-02", "2001-01-03", "2001-01-04", "2001-01-06"]
     )
     ds1.to_zarr(dst_path)
     w = DatasetWriter(dst_path, output_append=True,
                       output_append_dim="t",
                       output_append_mode=AppendMode.replace,
                       output_consolidated=False)
     w.write_dataset(ds2)
     ds3 = xr.open_zarr(dst_path, consolidated=False)
     np.testing.assert_equal(
         np.array(["2001-01-01", "2001-01-02", "2001-01-03",
                   "2001-01-04", "2001-01-05", "2001-01-06"],
                  dtype="datetime64[ns]"), ds3.t.data)
     np.testing.assert_equal(
         np.array([0, 1, 1, 1, 0, 1]),
         ds3.v.isel(x=0, y=0)
     )