Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ repos:
- id: end-of-file-fixer
- id: check-ast
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10
rev: v0.12.0
hooks:
# Run the linter.
- id: ruff
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.6.5
rev: 0.7.14
hooks:
# Run the pip compile
- id: pip-compile
Expand Down
18 changes: 17 additions & 1 deletion documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ upload your datasets to HDX.
- [Tags](#tags)
- [Maintainer](#maintainer)
- [Organization](#organization)
- [Custom Visualization](#customviz)
- [Resource Generation](#resource-generation)
- [QuickCharts Generation](#quickcharts-generation)
- [Resource Specific Operations](#resource-specific-operations)
Expand Down Expand Up @@ -790,7 +791,22 @@ If you want to set the organization, you do it like this:
ORGANIZATION is either a string id, dictionary or an Organization
object.

### Resource generation
### Custom Visualization

If you want to add a custom visualization to a dataset, you can do this:

dataset.set_custom_viz(URL)

URL is a string containing the url of your visualization.

You can get any existing visualization like this:

url = dataset.get_custom_viz()

The return value is a string if a visualization has been set on the dataset,
otherwise it is None.

### Resource Generation

There are a range of helpful functions to generate resources. In the following
examples, RESOURCE DATA takes the form {"name": NAME, "description":
Expand Down
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ run = """

[envs.hatch-static-analysis]
config-path = "none"
dependencies = ["ruff==0.9.10"]
dependencies = ["ruff==0.12.0"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"defopt>=7.0.0",
"email_validator",
"hdx-python-country>=3.9.6",
"hdx-python-utilities>=3.8.8",
"hdx-python-utilities>=3.9.0",
"libhxl>=5.2.2",
"makefun",
"quantulum3",
Expand Down
20 changes: 10 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
annotated-types==0.7.0
# via pydantic
astdoc==1.3.0
astdoc==1.3.1
# via mkapi
attrs==25.3.0
# via
Expand All @@ -16,7 +16,7 @@ backrefs==5.9
# via mkdocs-material
cachetools==5.5.2
# via google-auth
certifi==2025.7.14
certifi==2025.8.3
# via requests
cfgv==3.4.0
# via pre-commit
Expand All @@ -32,7 +32,7 @@ click==8.2.1
# typer
colorama==0.4.6
# via mkdocs-material
coverage==7.9.2
coverage==7.10.2
# via pytest-cov
defopt==7.0.0
# via hdx-python-api (pyproject.toml)
Expand All @@ -44,7 +44,7 @@ docopt==0.6.2
# via
# ckanapi
# num2words
docutils==0.21.2
docutils==0.22
# via defopt
email-validator==2.2.0
# via hdx-python-api (pyproject.toml)
Expand All @@ -66,7 +66,7 @@ gspread==6.2.1
# via hdx-python-api (pyproject.toml)
hdx-python-country==3.9.6
# via hdx-python-api (pyproject.toml)
hdx-python-utilities==3.8.8
hdx-python-utilities==3.9.0
# via
# hdx-python-api (pyproject.toml)
# hdx-python-country
Expand Down Expand Up @@ -129,15 +129,15 @@ mergedeep==1.3.4
# via
# mkdocs
# mkdocs-get-deps
mkapi==4.4.4
mkapi==4.4.5
# via hdx-python-api (pyproject.toml)
mkdocs==1.6.1
# via
# mkapi
# mkdocs-material
mkdocs-get-deps==0.2.0
# via mkdocs
mkdocs-material==9.6.15
mkdocs-material==9.6.16
# via mkapi
mkdocs-material-extensions==1.3.1
# via mkdocs-material
Expand Down Expand Up @@ -192,7 +192,7 @@ pygments==2.19.2
# mkdocs-material
# pytest
# rich
pymdown-extensions==10.16
pymdown-extensions==10.16.1
# via mkdocs-material
pyphonetics==0.5.3
# via hdx-python-utilities
Expand Down Expand Up @@ -251,7 +251,7 @@ requests-oauthlib==2.0.0
# via google-auth-oauthlib
rfc3986==2.0.0
# via frictionless
rich==14.0.0
rich==14.1.0
# via typer
rpds-py==0.26.0
# via
Expand Down Expand Up @@ -313,7 +313,7 @@ urllib3==2.5.0
# requests
validators==0.35.0
# via frictionless
virtualenv==20.32.0
virtualenv==20.33.1
# via pre-commit
watchdog==6.0.0
# via mkdocs
Expand Down
22 changes: 22 additions & 0 deletions src/hdx/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,28 @@ def remove_filetype(self, filetype: str) -> bool:
)
return self._remove_string_from_commastring("file_types", filetype)

def set_custom_viz(self, url: str) -> None:
"""Set custom visualization url for dataset

Args:
url (str): Custom visualization url

Returns:
None
"""
self.data["customviz"] = [{"url": url}]

def get_custom_viz(self) -> Optional[str]:
"""Get custom visualization url for dataset

Returns:
Optional[str]: Custom visualization url or None:
"""
viz = self.data.get("customviz")
if not isinstance(viz, list):
return None
return viz[0].get("url")

def preview_off(self) -> None:
"""Set dataset preview off

Expand Down
7 changes: 7 additions & 0 deletions tests/hdx/data/test_dataset_noncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,10 @@ def test_load_save_to_json(self, vocabulary_read):
save_text("null", path)
dataset = Dataset.load_from_json(path)
assert dataset is None

def test_custom_viz(self):
dataset = Dataset({"name": "lala", "title": "title", "notes": "description"})
url = "http://lala"
dataset.set_custom_viz(url)
assert dataset.get_custom_viz() == url
assert dataset["customviz"] == [{"url": "http://lala"}]
Loading