diff --git a/deepchem/data/datasets.py b/deepchem/data/datasets.py
index f80a399ca..dd5ba637f 100644
--- a/deepchem/data/datasets.py
+++ b/deepchem/data/datasets.py
@@ -2286,6 +2286,7 @@ class DiskDataset(Dataset):
     basename = "shard-%d" % shard_num
     DiskDataset.write_data_to_disk(self.data_dir, basename, X, y, w, ids)
     self._cached_shards = None
+    self.legacy_metadata = True
 
   def select(self,
              indices: Sequence[int],

diff --git a/deepchem/data/tests/test_setshard.py b/deepchem/data/tests/test_setshard.py
new file mode 100644
index 000000000..0fcf4b03e
--- /dev/null
+++ b/deepchem/data/tests/test_setshard.py
@@ -0,0 +1,21 @@
+import deepchem as dc
+import numpy as np
+
+
+def test_setshard_with_X_y():
+  """Test setsharding on a simple example"""
+  X = np.random.rand(10, 3)
+  y = np.random.rand(10,)
+  dataset = dc.data.DiskDataset.from_numpy(X, y)
+  X_shape, y_shape, _, _ = dataset.get_shape()
+  assert X_shape[0] == 10
+  assert y_shape[0] == 10
+  for i, (X, y, w, ids) in enumerate(dataset.itershards()):
+    X = X[1:]
+    y = y[1:]
+    w = w[1:]
+    ids = ids[1:]
+    dataset.set_shard(i, X, y, w, ids)
+  X_shape, y_shape, _, _ = dataset.get_shape()
+  assert X_shape[0] == 9
+  assert y_shape[0] == 9

Bug in dataset.get_shape() when used after dataset.set_shard()
## 🐛 Bug

## To Reproduce

<!-- If you have a code sample, error messages, stack traces, please provide it here as well. -->

## Expected behavior

```
import deepchem as dc
import numpy as np
X = np.random.randn(10, 3)
y = np.random.randn(10)

dataset = dc.data.DiskDataset.from_numpy(X, y)
dataset.get_shape()  # Output: ((10, 3), (10,), (10,), (10,))

for i, (X, y, w, ids) in enumerate(dataset.itershards()):
    X = X[1:]
    y = y[1:]
    w = w[1:]
    ids = ids[1:]
    dataset.set_shard(i, X, y, w, ids)

dataset.get_shape()  
# Output: ((10, 3), (10,), (10,), (10,))
# Expected output: ((9, 3), (9, ), (9, ), (9,))
```

Edit 1:

This prints correctly:
```
for i, (X, y, w, ids) in enumerate(dataset.itershards()):
    print (X.shape)  # Output: (9, 3)
```
## Environment
* DeepChem version: 2.6.0.dev

## Additional context
The fix is probably a simple one.

deepchem/data/tests/test_setshard.py::test_setshard_with_X_y