From a19d26f6d0b1fd8d8184b202d1cb6f1a1479c683 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk>
Date: Fri, 13 Jan 2023 20:11:06 +0000
Subject: [PATCH] refactor(aliby): fixes error from !54

---
 src/agora/io/writer.py | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/agora/io/writer.py b/src/agora/io/writer.py
index fecc45da..0ff20f7d 100644
--- a/src/agora/io/writer.py
+++ b/src/agora/io/writer.py
@@ -563,18 +563,22 @@ class Writer(BridgeH5):
                 dset = f[indices_path]
                 dset[()] = df.index.get_level_values(level=name).tolist()
             # create dataset and write columns
-
-           #Always write a timepoint dataset
-            tp_path = path + "/timepoint"
-            f.create_dataset(
-                name=tp_path,
-                shape=(df.shape[1],),
-                maxshape=(max_tps,),
-                dtype="uint16",
-            )
-            tps = list(range(df.shape[1]))
-            f[tp_path][tps] = tps
-
+            if (
+                df.columns.dtype == int
+                or df.columns.dtype == np.dtype("uint")
+                or df.columns.name == "timepoint"
+            ):
+                tp_path = path + "/timepoint"
+                f.create_dataset(
+                    name=tp_path,
+                    shape=(df.shape[1],),
+                    maxshape=(max_tps,),
+                    dtype="uint16",
+                )
+                tps = list(range(df.shape[1]))
+                f[tp_path][tps] = tps
+            else:
+                f[path].attrs["columns"] = df.columns.tolist()
         else:
 
             # path exists
@@ -597,9 +601,7 @@ class Writer(BridgeH5):
                 )
                 # split indices in existing and additional
                 new = df.index.tolist()
-                if (
-                    df.index.nlevels == 1
-                ):
+                if df.index.nlevels == 1:
                     # cover cases with a single index
                     new = [(x,) for x in df.index.tolist()]
                 (
-- 
GitLab