Skip to content

Commit

Permalink
Merge pull request #183 from Renumics/fix/145-get-cell-data-of-intern…
Browse files Browse the repository at this point in the history
…al-columns

Fix/145 get cell data of internal columns
  • Loading branch information
druzsan authored Aug 2, 2023
2 parents 4ec8fde + c0bfc34 commit 0c129ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions renumics/spotlight/backend/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def idx_column(row_count: int) -> Column:
)


def last_edited_at_column(row_count: int, value: datetime) -> Column:
def last_edited_at_column(row_count: int, value: Optional[datetime]) -> Column:
"""create a column containing a constant datetime"""
return Column(
type=datetime,
Expand All @@ -293,7 +293,7 @@ def last_edited_at_column(row_count: int, value: datetime) -> Column:
hidden=True,
editable=False,
optional=False,
values=np.array(row_count * [value]),
values=np.array([value] * row_count, dtype=object),
)


Expand Down
28 changes: 26 additions & 2 deletions renumics/spotlight_plugins/core/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
Video,
)

from renumics.spotlight.dataset.exceptions import ColumnNotExistsError

# for now specify all lazy dtypes right here
# we should probably move closer to the actual dtype definition for easier extensibility
LAZY_DTYPES = [Embedding, Mesh, Image, Video, Sequence1D, np.ndarray, Audio, str]
Expand Down Expand Up @@ -128,7 +130,7 @@ def get_table(request: Request) -> ORJSONResponse:
row_count = len(table)
columns.append(idx_column(row_count))
if not any(column.name == "__last_edited_at__" for column in columns):
columns.append(last_edited_at_column(row_count, datetime.now()))
columns.append(last_edited_at_column(row_count, None))
if not any(column.name == "__last_edited_by__" for column in columns):
columns.append(last_edited_by_column(row_count, app.username))

Expand Down Expand Up @@ -159,7 +161,29 @@ async def get_table_cell(
return None
table.check_generation_id(generation_id)

cell_data = table.get_cell_data(column, row, app.dtypes[column])
try:
dtype = app.dtypes[column]
except KeyError as e:
if column == "__last_edited_by__":
dtype = str
elif column == "__last_edited_at__":
dtype = datetime
elif column == "__idx__":
dtype = int
else:
raise e

try:
cell_data = table.get_cell_data(column, row, dtype)
except ColumnNotExistsError as e:
if column == "__last_edited_by__":
cell_data = ""
elif column == "__last_edited_at__":
cell_data = None
elif column == "__idx__":
cell_data = row
else:
raise e
value = sanitize_values(cell_data)

if isinstance(value, (bytes, str)):
Expand Down
7 changes: 2 additions & 5 deletions src/stores/dataset/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ export interface Dataset {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function convertValue(value: any, type: DataType) {
if (type.kind === 'datetime') {
if (value?.length === 0) {
return null;
} else {
return new Date(Date.parse(value));
}
if (value === null) return null;
return new Date(Date.parse(value));
}

if (type.kind === 'float' && value === null) {
Expand Down

0 comments on commit 0c129ce

Please sign in to comment.