diff --git a/datajoint/table.py b/datajoint/table.py index fc919ec12..5aa2e5463 100644 --- a/datajoint/table.py +++ b/datajoint/table.py @@ -22,6 +22,7 @@ UnknownAttributeError, IntegrityError, ) +from typing import Union from .version import __version__ as version logger = logging.getLogger(__name__.split(".")[0]) @@ -459,15 +460,30 @@ def delete_quick(self, get_count=False): self._log(query[:255]) return count - def delete(self, transaction=True, safemode=None, force_parts=False): + def delete( + self, + transaction: bool = True, + safemode: Union[bool, None] = None, + force_parts: bool = False, + ) -> int: """ Deletes the contents of the table and its dependent tables, recursively. - :param transaction: if True, use the entire delete becomes an atomic transaction. This is the default and - recommended behavior. Set to False if this delete is nested within another transaction. - :param safemode: If True, prohibit nested transactions and prompt to confirm. Default is dj.config['safemode']. - :param force_parts: Delete from parts even when not deleting from their masters. - :return: number of deleted rows (excluding those from dependent tables) + Args: + transaction: If `True`, use of the entire delete becomes an atomic transaction. + This is the default and recommended behavior. Set to `False` if this delete is + nested within another transaction. + safemode: If `True`, prohibit nested transactions and prompt to confirm. Default + is `dj.config['safemode']`. + force_parts: Delete from parts even when not deleting from their masters. + + Returns: + Number of deleted rows (excluding those from dependent tables). + + Raises: + DataJointError: Delete exceeds maximum number of delete attempts. + DataJointError: When deleting within an existing transaction. + DataJointError: Deleting a part table before its master. """ deleted = set() diff --git a/docs/mkdocs.yaml b/docs/mkdocs.yaml index be50d7fe9..0c5959802 100644 --- a/docs/mkdocs.yaml +++ b/docs/mkdocs.yaml @@ -4,8 +4,8 @@ site_name: DataJoint Python repo_url: https://github.com/datajoint/datajoint-python repo_name: datajoint/datajoint-python nav: - - DataJoint Python: getting_started.md - - Getting Started: getting_started.md + - DataJoint Python: getting_started/index.md + - Getting Started: getting_started/index.md - Concepts: concepts.md - Tutorials: tutorials.md - About: @@ -17,9 +17,13 @@ nav: edit_uri: ./edit/master/docs/src docs_dir: ./src theme: + font: + text: Roboto Slab + code: Source Code Pro name: material custom_dir: src/.overrides - logo: assets/images/project-logo-black.png + icon: + logo: main/project-logo-black favicon: assets/images/project-logo-color.png features: - toc.integrate @@ -38,9 +42,14 @@ plugins: - search - redirects: redirect_maps: - "index.md": "getting_started.md" + "index.md": "getting_started/index.md" - mkdocstrings: default_handler: python + handlers: + python: + selection: + filters: + - "!^_" - gen-files: scripts: - ./src/api/make_pages.py @@ -54,10 +63,16 @@ markdown_extensions: - toc: permalink: true - pymdownx.emoji: + emoji_index: !!python/name:materialx.emoji.twemoji + emoji_generator: !!python/name:materialx.emoji.to_svg options: custom_icons: - .overrides/.icons - mdx_truly_sane_lists + - pymdownx.tabbed: + alternate_style: true + - admonition + - pymdownx.details - pymdownx.superfences: custom_fences: - name: mermaid @@ -68,8 +83,10 @@ extra: version: provider: mike social: - - icon: datajoint/company-logo + - icon: main/company-logo link: https://www.datajoint.com/ + - icon: fontawesome/solid/ticket + link: https://support.djneuro.io/portal/en/home - icon: fontawesome/brands/slack link: https://datajoint.slack.com - icon: fontawesome/brands/linkedin @@ -78,6 +95,10 @@ extra: link: https://twitter.com/DataJointIO - icon: fontawesome/brands/github link: https://github.com/datajoint + - icon: fontawesome/brands/docker + link: https://hub.docker.com/u/datajoint + - icon: fontawesome/brands/python + link: https://pypi.org/user/datajointbot - icon: fontawesome/brands/stack-overflow link: https://stackoverflow.com/questions/tagged/datajoint - icon: fontawesome/brands/youtube diff --git a/docs/src/.overrides/.icons/datajoint/company-logo.svg b/docs/src/.overrides/.icons/datajoint/company-logo.svg deleted file mode 100644 index b99eecb28..000000000 --- a/docs/src/.overrides/.icons/datajoint/company-logo.svg +++ /dev/null @@ -1,20 +0,0 @@ - - www.datajoint.com - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/src/.overrides/.icons/main/company-logo.svg b/docs/src/.overrides/.icons/main/company-logo.svg new file mode 100644 index 000000000..68c75c762 --- /dev/null +++ b/docs/src/.overrides/.icons/main/company-logo.svg @@ -0,0 +1,21 @@ + + www.datajoint.com + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/src/.overrides/.icons/main/project-logo-black.svg b/docs/src/.overrides/.icons/main/project-logo-black.svg new file mode 100644 index 000000000..76bebb11f --- /dev/null +++ b/docs/src/.overrides/.icons/main/project-logo-black.svg @@ -0,0 +1,22 @@ + + + + Asset 3 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/src/.overrides/assets/images/project-logo-black.png b/docs/src/.overrides/assets/images/project-logo-black.png deleted file mode 100644 index 804d2c393..000000000 Binary files a/docs/src/.overrides/assets/images/project-logo-black.png and /dev/null differ diff --git a/docs/src/.overrides/assets/stylesheets/extra.css b/docs/src/.overrides/assets/stylesheets/extra.css index 7d638c039..87aeeabe4 100644 --- a/docs/src/.overrides/assets/stylesheets/extra.css +++ b/docs/src/.overrides/assets/stylesheets/extra.css @@ -1,36 +1,59 @@ -[data-md-color-scheme="datajoint"] { - - --dj-yellow: #fcb954; - - --md-primary-fg-color: var(--dj-yellow); - --md-primary-bg-color: #000000; - --md-primary-fg-color--dark: var(--dj-yellow); - - --md-accent-fg-color: var(--dj-yellow); - - --md-code-bg-color: #e4f3f6; +:root { + --dj-primary: #00a0df; + --dj-secondary: #ff5113; + --dj-background: #808285; + --dj-black: #000000; + --dj-white: #ffffff; +} - --md-footer-fg-color: var(--dj-yellow); +[data-md-color-scheme="datajoint"] { + /* ribbon */ + /* ribbon + markdown heading expansion */ + --md-primary-fg-color: var(--dj-black); + /* ribbon text */ + --md-primary-bg-color: var(--dj-primary); + + /* navigation */ + /* navigation header + links */ + --md-typeset-a-color: var(--dj-primary); + /* navigation on hover + diagram outline */ + --md-accent-fg-color: var(--dj-secondary); + + /* main */ + /* main header + already viewed*/ + --md-default-fg-color--light: var(--dj-background); + /* primary text */ + --md-typeset-color: var(--dj-black); + /* code comments + diagram text */ + --md-code-fg-color: var(--dj-secondary); + + /* footer */ + /* previous/next text */ + --md-footer-fg-color: var(--dj-primary); } [data-md-color-scheme="slate"] { - - --dj-yellow: #fcb954; - - --md-typeset-color: #e4f3f6; - --md-typeset-a-color: #17b2ff; - - --md-default-fg-color: #e4f3f6; - --md-default-fg-color--light: var(--dj-yellow); - - --md-primary-fg-color: var(--dj-yellow); - --md-primary-bg-color: #000000; - --md-primary-fg-color--dark: var(--dj-yellow); - - --md-accent-fg-color: var(--dj-yellow); - - --md-code-fg-color: #76c9e9; - --md-code-hl-comment-color: #ffd28d; - - --md-footer-fg-color: var(--dj-yellow); + /* ribbon */ + /* ribbon + markdown heading expansion */ + --md-primary-fg-color: var(--dj-primary); + /* ribbon text */ + --md-primary-bg-color: var(--dj-white); + + /* navigation */ + /* navigation header + links */ + --md-typeset-a-color: var(--dj-primary); + /* navigation on hover + diagram outline */ + --md-accent-fg-color: var(--dj-secondary); + + /* main */ + /* main header + already viewed*/ + --md-default-fg-color--light: var(--dj-background); + /* primary text */ + --md-typeset-color: var(--dj-white); + /* code comments + diagram text */ + --md-code-fg-color: var(--dj-secondary); + + /* footer */ + /* previous/next text */ + --md-footer-fg-color: var(--dj-white); } \ No newline at end of file diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md deleted file mode 100644 index f34d65bd7..000000000 --- a/docs/src/getting_started.md +++ /dev/null @@ -1 +0,0 @@ -# Installation \ No newline at end of file diff --git a/docs/src/getting_started/index.md b/docs/src/getting_started/index.md new file mode 100644 index 000000000..f36541042 --- /dev/null +++ b/docs/src/getting_started/index.md @@ -0,0 +1,173 @@ +## Installation + +=== "conda" + + !!! note "Pre-Requisites" + + - Ensure you have [conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html#regular-installation) installed. + + To add the `conda-forge` channel: + + ```bash + conda config --add channels conda-forge + ``` + + To install: + + ```bash + conda install -c conda-forge datajoint + ``` + +=== "pip + :fontawesome-brands-windows:" + + !!! note "Pre-Requisites" + + - Ensure you have [pip](https://pip.pypa.io/en/stable/installation/) installed. + - Install [graphviz](https://graphviz.org/download/#windows) pre-requisite for diagram visualization. + + To install: + + ```bash + pip install datajoint + ``` + +=== "pip + :fontawesome-brands-apple:" + + !!! note "Pre-Requisites" + + - Ensure you have [pip](https://pip.pypa.io/en/stable/installation/) installed. + - Install [graphviz](https://graphviz.org/download/#mac) pre-requisite for diagram visualization. + + To install: + + ```bash + pip install datajoint + ``` + +=== "pip + :fontawesome-brands-linux:" + + !!! note "Pre-Requisites" + + - Ensure you have [pip](https://pip.pypa.io/en/stable/installation/) installed. + - Install [graphviz](https://graphviz.org/download/#linux) pre-requisite for diagram visualization. + + To install: + + ```bash + pip install datajoint + ``` + +## Connection + +!!! note + + Although you may connect to any MySQL server of your choice, the DataJoint company offers an online tutorial environment. Simply sign up for a free [DataJoint account](https://accounts.datajoint.io). You will be granted privileges to create schemas that are prefixed as `{user}_`. + +=== "environment variables" + + Before using `datajoint`, set the following environment variables like so: + + ```bash linenums="1" + DJ_HOST=tutorial-db.datajoint.io + DJ_USER={user} + DJ_PASS={password} + ``` + +=== "memory" + + To set connection settings within Python, perform: + + ```python linenums="1" + import datajoint as dj + + dj.config["database.host"] = "tutorial-db.datajoint.io" + dj.config["database.user"] = "{user}" + dj.config["database.password"] = "{password}" + ``` + +=== "file" + + Before using `datajoint`, create a file named `dj_local_conf.json` in the current directory like so: + + ```json linenums="1" + { + "database.host": "tutorial-db.datajoint.io", + "database.user": "{user}", + "database.password": "{password}" + } + ``` + +## Data Pipeline Definition + +Let's definite a simple data pipeline. + +```python linenums="1" +import datajoint as dj + +schema = dj.Schema(f"{dj.config['database.user']}_shapes") + + +@schema +class Rectangle(dj.Manual): + definition = """ + shape_id: int + --- + shape_height: float + shape_width: float + """ + + +@schema +class Area(dj.Computed): + definition = """ + -> Rectangle + --- + shape_area: float + """ + def make(self, key): + rectangle = (Rectangle & key).fetch1() + Area.insert1( + dict( + shape_id=rectangle["shape_id"], + shape_area=rectangle["shape_height"] * rectangle["shape_width"], + ) + ) +``` + +## Diagram + +The diagram displays the relationship of the data model in the data pipeline. + +```python +dj.Diagram(schema) +``` + +![pipeline](./shapes_pipeline.svg) + +## Add data + +Let's add data for a rectangle: + +```python +Rectangle.insert1(dict(shape_id=1, shape_height=2, shape_width=4)) +``` + +## Run computation + +Let's start the computations on our entity: `Area`. + +```python +Area.populate(display_progress=True) +``` + +## Query + +Let's inspect the results. + +```python +Area & "shape_area >= 8" +``` + +| shaped_id | shape_area | +| --- | --- | +| 1 | 8.0 | \ No newline at end of file diff --git a/docs/src/getting_started/shapes_pipeline.svg b/docs/src/getting_started/shapes_pipeline.svg new file mode 100644 index 000000000..40df7cafc --- /dev/null +++ b/docs/src/getting_started/shapes_pipeline.svg @@ -0,0 +1,29 @@ + + +%3 + + + +Area + + +Area + + + + + +Rectangle + + +Rectangle + + + + + +Rectangle->Area + + + + \ No newline at end of file