Skip to content

Commit

Permalink
feat: add simple CSV/TSV widget using panel Tabulator
Browse files Browse the repository at this point in the history
  • Loading branch information
a.pirogov committed Aug 9, 2023
1 parent f38ff20 commit 39925f0
Show file tree
Hide file tree
Showing 11 changed files with 972 additions and 237 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Here we provide notes that summarize the most important changes in each released

Please consult the changelog to inform yourself about breaking changes and security issues.

## [v0.1.1](https://github.com/Materials-Data-Science-and-Informatics/metador-core/tree/v0.1.1) <small>(2023-??-??)</small> { id="0.1.1" }

* added CSV/TSV widget

## [v0.1.0](https://github.com/Materials-Data-Science-and-Informatics/metador-core/tree/v0.1.0) <small>(2023-08-08)</small> { id="0.1.0" }

* updated dependencies to unpin versions
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: software
message: If you use this software, please cite it using these metadata.

title: metador-core
version: 0.1.0
version: 0.1.1
abstract: Core of Metador, the metadata-first research data management framework.
repository-code: "https://github.com/Materials-Data-Science-and-Informatics/metador-core"
license: MIT
Expand Down
8 changes: 4 additions & 4 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"audience": [
{
"@type": "Audience",
"audienceType": "Developers"
"audienceType": "Science/Research"
},
{
"@type": "Audience",
"audienceType": "Science/Research"
"audienceType": "Developers"
}
],
"author": [
Expand Down Expand Up @@ -99,7 +99,7 @@
"identifier": "pandas",
"name": "pandas",
"runtimePlatform": "Python 3",
"version": "^1.4.1"
"version": "^2.0.3"
},
{
"@type": "SoftwareApplication",
Expand Down Expand Up @@ -180,5 +180,5 @@
}
],
"url": "https://github.com/Materials-Data-Science-and-Informatics/metador-core",
"version": "0.1.0"
"version": "0.1.1"
}
178 changes: 139 additions & 39 deletions docs/notebooks/05_Widgets.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/notebooks/files/table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Event,Date,Participants,Duration
Some event,2023-08-08,3,2.43
Another event,2023-08-07,5,1.32
3 changes: 3 additions & 0 deletions docs/notebooks/files/table.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Event Date Participants Duration
Some event 2023-08-08 3 2.43
Another event 2023-08-07 5 1.32
969 changes: 780 additions & 189 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
# ---- DO NOT EDIT, managed by somesy ----
name = "metador-core"
version = "0.1.0"
version = "0.1.1"
description = "Core of Metador, the metadata-first research data management framework."
authors = ["Anton Pirogov <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -50,7 +50,7 @@ isodate = "^0.6.1"
Pint = "^0.21"
Pillow = "^9.1.1"
python-magic = "^0.4.25"
pandas = "^1.4.1"
pandas = "^2.0.3"
overrides = "^7.0.0"
simple-parsing = "^0.0.20"
phantom-types = "^2.1.0"
Expand All @@ -65,6 +65,7 @@ pytest-cov = "^4.1.0"
hypothesis = "^6.58.0"
frozendict = "^2.3.4"
# somesy = {path = "../somesy", develop = true}
notebook = "^7.0.2"

[tool.poetry.group.docs.dependencies]
mkdocs = "^1.4.2"
Expand Down Expand Up @@ -115,6 +116,7 @@ mkdocs-jupyter = "^0.24.2"
'core.file.text.code__0.1.0' = "metador_core.widget.common:CodeWidget"
'core.file.text__0.1.0' = "metador_core.widget.common:TextWidget"
'core.file.json__0.1.0' = "metador_core.widget.common:JSONWidget"
'core.file.csv__0.1.0' = "metador_core.widget.common:CSVWidget"
'core.file.pdf__0.1.0' = "metador_core.widget.common:PDFWidget"
'core.file.image__0.1.0' = "metador_core.widget.common:ImageWidget"
'core.file.audio__0.1.0' = "metador_core.widget.common:AudioWidget"
Expand Down
2 changes: 1 addition & 1 deletion somesy.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "metador-core"
version = "0.1.0"
version = "0.1.1"
description = "Core of Metador, the metadata-first research data management framework."
license = "MIT"
repository = "https://github.com/Materials-Data-Science-and-Informatics/metador-core"
Expand Down
32 changes: 32 additions & 0 deletions src/metador_core/widget/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"""

import json
from io import StringIO
from typing import List, Set, Type

import pandas as pd
import panel as pn
from overrides import overrides
from panel.viewable import Viewable
Expand Down Expand Up @@ -57,6 +59,36 @@ def supports_meta(cls, obj: MetadataSchema) -> bool:
# pass content:


class CSVWidget(FileWidget):
class Plugin(FileWidget.Plugin):
name = "core.file.csv"
version = (0, 1, 0)

MIME_TYPES = {"text/csv", "text/tab-separated-values"}
FILE_EXTS = {".csv", ".tsv"}

@overrides
def show(self) -> Viewable:
df = pd.read_csv(
StringIO(self.file_data().decode("utf-8")),
sep=None, # auto-infer csv/tsv
engine="python", # mute warning
# smart date processing
parse_dates=True,
dayfirst=True,
cache_dates=True,
)
return pn.widgets.Tabulator(
df,
disabled=True,
layout="fit_data_table",
# NOTE: pagination looks buggy, table sometimes won't show up
# need to investigate that further, maybe it's a bug
# pagination="remote",
# page_size=10,
)


class MarkdownWidget(FileWidget):
class Plugin(FileWidget.Plugin):
name = "core.file.text.md"
Expand Down
2 changes: 1 addition & 1 deletion src/metador_core/widget/jupyter/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def silence_flask():
# As this is only used ad-hoc e.g. by a researcher playing in a notebook,
# this should be not a problem ("serious" servers are implemented elsewhere!).

DEFAULT_PANEL_EXTS = ["ace"]
DEFAULT_PANEL_EXTS = ["ace", "tabulator"]

host: str = "127.0.0.1"
port: int = -1
Expand Down

0 comments on commit 39925f0

Please sign in to comment.