Skip to content

Commit 958fb44

Browse files
2 parents 507c8a5 + 7ba4bbc commit 958fb44

31 files changed

+247
-59
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
.. code-block:: python
2-
3-
>>> schema.external_table.delete_garbage()
1+
Use ``dj.config`` for configuration.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
.. code-block:: python
1+
This is done by saving the path in the ``cache`` key of the DataJoint configuration dictionary:
22

3-
>>> schema.external_table.clean_store('external-name')
3+
.. code-block:: python
4+
5+
dj.config['cache'] = '/temp/dj-cache'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. code-block:: python
2+
3+
>>> schema.external_table.delete_garbage()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. code-block:: python
2+
3+
>>> schema.external_table.clean_store('external-name')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The ``populate`` method accepts a number of optional arguments that provide more features and allow greater control over the method's behavior.
2+
3+
- ``restrictions`` - A list of restrictions, restricting as ``(tab.key_source & AndList(restrictions)) - tab.proj()``.
4+
Here ``target`` is the table to be populated, usually ``tab`` itself.
5+
- ``suppress_errors`` - If ``True``, encountering an error will cancel the current ``make`` call, log the error, and continue to the next ``make`` call.
6+
Error messages will be logged in the job reservation table (if ``reserve_jobs`` is ``True``) and returned as a list.
7+
See also ``return_exception_objects`` and ``reserve_jobs``.
8+
Defaults to ``False``.
9+
- ``return_exception_objects`` - If ``True``, error objects are returned instead of error messages.
10+
This applies only when ``suppress_errors`` is ``True``.
11+
Defaults to ``False``.
12+
- ``reserve_jobs`` - If ``True``, reserves job to indicate to other distributed processes.
13+
The job reservation table may be access as ``schema.jobs``.
14+
Errors are logged in the jobs table.
15+
Defaults to ``False``.
16+
- ``order`` - The order of execution, either ``"original"``, ``"reverse"``, or ``"random"``.
17+
Defaults to ``"original"``.
18+
- ``display_progress`` - If ``True``, displays a progress bar.
19+
Defaults to ``False``.
20+
- ``limit`` - If not ``None``, checks at most this number of keys.
21+
Defaults to ``None``.
22+
- ``max_calls`` - If not ``None``, populates at most this many keys.
23+
Defaults to ``None``, which means no limit.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The method ``table.progress`` reports how many ``key_source`` entries have been populated and how many remain.
2+
Two optional parameters allow more advanced use of the method.
3+
A parameter of restriction conditions can be provided, specifying which entities to consider.
4+
A Boolean parameter ``display`` (default is ``True``) allows disabling the output, such that the numbers of remaining and total entities are returned but not printed.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A custom key source can be configured by setting the ``key_source`` property within a table class, after the ``definition`` string.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. code-block:: python
2+
3+
@schema
4+
class EEG(dj.Imported):
5+
definition = """
6+
-> Recording
7+
---
8+
sample_rate : float
9+
eeg_data : longblob
10+
"""
11+
key_source = Recording & 'recording_type = "EEG"'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. code-block:: python
2+
3+
@schema
4+
class Mouse(dj.Manual):
5+
definition = """
6+
mouse_name : varchar(64)
7+
---
8+
mouse_dob : datetime
9+
"""
10+
11+
@schema
12+
class MouseDeath(dj.Manual):
13+
definition = """
14+
-> Mouse
15+
---
16+
death_date : datetime
17+
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. code-block:: python
2+
3+
@schema
4+
class EEGRecording(dj.Manual):
5+
definition = """
6+
-> Session
7+
eeg_recording_id : int
8+
---
9+
eeg_system : varchar(64)
10+
num_channels : int
11+
"""
12+
13+
@schema
14+
class ChannelData(dj.Imported):
15+
definition = """
16+
-> EEGRecording
17+
channel_idx : int
18+
---
19+
channel_data : longblob
20+
"""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. code-block:: python
2+
3+
@schema
4+
class Mouse(dj.Manual):
5+
definition = """
6+
mouse_name : varchar(64)
7+
---
8+
mouse_dob : datetime
9+
"""
10+
11+
@schema
12+
class SubjectGroup(dj.Manual):
13+
definition = """
14+
group_number : int
15+
---
16+
group_name : varchar(64)
17+
"""
18+
19+
class GroupMember(dj.Part):
20+
definition = """
21+
-> master
22+
-> Mouse
23+
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. code-block:: python
2+
3+
@schema
4+
class RecordingModality(dj.Lookup):
5+
definition = """
6+
modality : varchar(64)
7+
"""
8+
9+
@schema
10+
class MultimodalSession(dj.Manual):
11+
definition = """
12+
-> Session
13+
modes : int
14+
"""
15+
16+
class SessionMode(dj.Part):
17+
definition = """
18+
-> master
19+
-> RecordingModality
20+
"""

docs-parts/concepts/empty.txt

Whitespace-only changes.

docs-parts/definition/02-Creating-Tables_lang1.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ For example, the following code defines the table ``Person``:
1717
@schema
1818
class Person(dj.Manual):
1919
definition = '''
20-
# table definition goes here
20+
username : varchar(20) # unique user name
21+
---
22+
first_name : varchar(30)
23+
last_name : varchar(30)
2124
'''
2225
2326
@@ -28,11 +31,11 @@ The decorator attaches the information about the table to the class, and then re
2831
The class will become usable after you define the ``definition`` property as described in :ref:`definitions`.
2932

3033
DataJoint classes in Python
31-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
3235

33-
DataJoint for Python is implemented through the use of classes.
34-
Working with classes usually implies that one might create different class instances with various internal states.
35-
However, DataJoint classes only serve as interfaces to data that actually reside within tables on the database server.
36+
DataJoint for Python is implemented through the use of classes providing access to the actual tables stored on the database.
37+
Since only a single table exists on the database for any class, interactions with all instances of the class are equivalent.
38+
As such, most methods can be called on the classes themselves rather than on an object, for convenience.
3639
Whether calling a DataJoint method on a class or on an instance, the result will only depend on or apply to the corresponding table.
3740
All of the basic functionality of DataJoint is built to operate on the classes themselves, even when called on an instance.
3841
For example, calling ``Person.insert(...)`` (on the class) and ``Person.insert(...)`` (on an instance) both have the identical effect of inserting data into the table on the database server.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

2-
The table is created at the time of the class definition.
3-
In fact, it is one of the jobs performed by the decorator ``@schema`` of the class.
2+
Users do not need to do anything special to have a table created in the database.
3+
Tables are created at the time of class definition.
4+
In fact, table creation on the database is one of the jobs performed by the decorator ``@schema`` of the class.
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
2-
Dropping part tables
3-
--------------------
4-
51
A :ref:`part table <master-part>` is usually removed as a consequence of calling ``drop`` on its master table.
62
To enforce this workflow, calling ``drop`` directly on a part table produces an error.
73
In some cases, it may be necessary to override this behavior.
84
To remove a part table without removing its master, use the argument ``force=True``.
9-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The function ``create_virtual_module`` of the ``dj.schema`` class provides access to virtual modules.
2+
It creates a python module with the given name from the name of a schema on the server, automatically adds classes to it corresponding to the tables in the schema.
3+
4+
The function can take several parameters:
5+
6+
``module_name``: displayed module name.
7+
8+
``schema_name``: name of the database in MySQL.
9+
10+
``create_schema``: if ``True``, create the schema on the database server if it does not already exist; if ``False`` (default), raise an error when the schema is not found.
11+
12+
``create_tables``: if ``True``, ``module.schema`` can be used as the decorator for declaring new classes; if ``False``, such use will raise an error stating that the module is intend only to work with existing tables.
13+
14+
The function returns the Python module containing classes from the schema object with all the table classes already declared inside it.

docs-parts/existing/empty.txt

Whitespace-only changes.

docs-parts/manipulation/1-Insert_lang1.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The entity also may take the form of a sequence of values in the same order as t
1515
1616
lab.Person.insert1(['alice', 'Alice', 'Cooper'])
1717
18-
Additionally, the entity may be inserted as a `numpy.record <https://docs.scipy.org/doc/numpy/reference/generated/numpy.record.html#numpy.record>`_.
18+
Additionally, the entity may be inserted as a `NumPy record array <https://docs.scipy.org/doc/numpy/reference/generated/numpy.record.html#numpy.record>`_ or `Pandas DataFrame <https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html>`_.
1919

2020
The ``insert`` method accepts a sequence or a generator of multiple entities and is used to insert multiple entities at once.
2121

@@ -25,3 +25,18 @@ The ``insert`` method accepts a sequence or a generator of multiple entities and
2525
['alice', 'Alice', 'Cooper'],
2626
['bob', 'Bob', 'Dylan'],
2727
['carol', 'Carol', 'Douglas']])
28+
29+
Several optional parameters can be used with ``insert``:
30+
31+
``replace`` If ``True``, replaces the existing entity.
32+
(Default ``False``.)
33+
34+
``skip_duplicates`` If ``True``, silently skip duplicate inserts.
35+
(Default ``False``.)
36+
37+
``ignore_extra_fields`` If ``False``, fields that are not in the heading raise an error.
38+
(Default ``False``.)
39+
40+
``allow_direct_insert`` If ``True``, allows inserts outside of populate calls.
41+
Applies only in auto-populated tables.
42+
(Default ``None``.)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
.. code-block:: python
3+
4+
# Server-side inserts are faster...
5+
phase_two.Protocol.insert(phase_one.Protocol)
6+
7+
# ...than fetching before inserting
8+
protocols = phase_one.Protocol.fetch()
9+
phase_two.Protocol.insert(protocols)
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
Entities in a :ref:`part table <master-part>` are usually removed as a consequence of calling ``delete`` on the master table.
31
To enforce this workflow, calling ``delete`` directly on a part table produces an error.
42
In some cases, it may be necessary to override this behavior.
53
To remove entities from a part table without calling ``delete`` master, use the argument ``force=True``.

docs-parts/queries/03-Fetch_lang1.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ As separate variables
2222

2323
.. code-block:: python
2424
25-
name, img = query.fetch1('name', 'image') # when tab has exactly one entity
25+
name, img = query.fetch1('name', 'image') # when query has exactly one entity
2626
name, img = query.fetch('name', 'image') # [name, ...] [image, ...]
2727
2828
Primary key values
@@ -33,6 +33,8 @@ Primary key values
3333
keydict = tab.fetch1("KEY") # single key dict when tab has exactly one entity
3434
keylist = tab.fetch("KEY") # list of key dictionaries [{}, ...]
3535
36+
``KEY`` can also used when returning attribute values as separate variables, such that one of the returned variables contains the entire primary keys.
37+
3638
Usage with Pandas
3739
~~~~~~~~~~~~~~~~~
3840

@@ -44,3 +46,11 @@ For example:
4446
4547
import pandas as pd
4648
frame = pd.DataFrame(tab.fetch())
49+
50+
Calling ``fetch()`` with the argument ``format="frame"`` returns results as ``pandas.DataFrame`` objects with no need for conversion.
51+
52+
.. code-block:: python
53+
54+
frame = tab.fetch('format="frame"')
55+
56+
Returning results as a ``DataFrame`` is not possible when fetching a particular subset of attributes or when ``as_dict`` is set to ``True``.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

22
* another table
3-
* a query expression
43
* a mapping, e.g. ``dict``
54
* an expression in a character string
6-
* a collection of conditions as a ``list`` or ``tuple``
5+
* a collection of conditions as a ``list``, ``tuple``, or Pandas ``DataFrame``
76
* a Boolean expression (``True`` or ``False``)
87
* an ``AndList``
98
* a ``Not`` object
10-
9+
* a query expression
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11

2-
A collection can be a list or tuple.
3-
42
.. code-block:: python
53
6-
# a list:
7-
cond_list = ['first_name = "Aaron"', 'last_name = "Aaronson"']
4+
# All the sessions performed by Alice
5+
Session & 'user = "Alice"'
86
9-
# a tuple:
10-
cond_tuple = ('first_name = "Aaron"', 'last_name = "Aaronson"')
7+
# All the experiments at least one minute long
8+
Experiment & 'duration >= 60'
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11

2-
.. code-block:: python
2+
A collection can be a list, a tuple, or a Pandas ``DataFrame``.
33

4-
Student() & ['first_name = "Aaron"', 'last_name = "Aaronson"']
4+
.. code-block:: python
55
6-
.. figure:: ../_static/img/python_collection.png
7-
:align: center
8-
:alt: restriction by collection
6+
# a list:
7+
cond_list = ['first_name = "Aaron"', 'last_name = "Aaronson"']
98
10-
Restriction by a collection, returning any entities matching any condition in the collection.
9+
# a tuple:
10+
cond_tuple = ('first_name = "Aaron"', 'last_name = "Aaronson"')
1111
12+
# a dataframe:
13+
import pandas as pd
14+
cond_frame = pd.DataFrame(
15+
data={'first_name': ['Aaron'], 'last_name': ['Aaronson']})
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2-
``A & True`` and ``A - False`` are equivalent to ``A``.
3-
``A & False`` and ``A - True`` are empty.
2+
.. code-block:: python
3+
4+
Student() & ['first_name = "Aaron"', 'last_name = "Aaronson"']
5+
6+
.. figure:: ../_static/img/python_collection.png
7+
:align: center
8+
:alt: restriction by collection
9+
10+
Restriction by a collection, returning all entities matching any condition in the collection.
411

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11

2-
Restriction by an ``AndList``
3-
-----------------------------
4-
5-
The special function ``dj.AndList`` represents logical conjunction (logical AND).
6-
Restriction of table ``A`` by an ``AndList`` will return all entities in ``A`` that meet *all* of the conditions in the list.
7-
``A & dj.AndList([c1, c2, c3])`` is equivalent to ``A & c1 & c2 & c3``.
8-
Usually, it is more convenient to simply write out all of the conditions, as ``A & c1 & c2 & c3``.
9-
However, when a list of conditions has already been generated, the list can simply be passed as the argument to ``dj.AndList``.
10-
11-
Restriction of table ``A`` by an empty ``AndList``, as in ``A & dj.AndList([])``, will return all of the entities in ``A``.
12-
Exclusion by an empty ``AndList`` will return no entities.
13-
14-
Restriction by a ``Not`` object
15-
-------------------------------
16-
17-
The special function ``dj.Not`` represents logical negation, such that ``A & dj.Not(cond)`` is equivalent to ``A - cond``.
2+
``A & True`` and ``A - False`` are equivalent to ``A``.
183

4+
``A & False`` and ``A - True`` are empty.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
Restriction by an ``AndList``
3+
-----------------------------
4+
5+
The special function ``dj.AndList`` represents logical conjunction (logical AND).
6+
Restriction of table ``A`` by an ``AndList`` will return all entities in ``A`` that meet *all* of the conditions in the list.
7+
``A & dj.AndList([c1, c2, c3])`` is equivalent to ``A & c1 & c2 & c3``.
8+
Usually, it is more convenient to simply write out all of the conditions, as ``A & c1 & c2 & c3``.
9+
However, when a list of conditions has already been generated, the list can simply be passed as the argument to ``dj.AndList``.
10+
11+
Restriction of table ``A`` by an empty ``AndList``, as in ``A & dj.AndList([])``, will return all of the entities in ``A``.
12+
Exclusion by an empty ``AndList`` will return no entities.
13+
14+
Restriction by a ``Not`` object
15+
-------------------------------
16+
17+
The special function ``dj.Not`` represents logical negation, such that ``A & dj.Not(cond)`` is equivalent to ``A - cond``.
18+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. code-block:: python
2+
3+
query = Session & 'user = "Alice"'
4+
Experiment & query

docs-parts/queries/09-Aggr_lang1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# Number of students in each course section
55
Section.aggr(Enroll, n="count(*)")
66
# Average grade in each course
7-
Course.aggr(Grade * LetterGrade, avg_grade: avg(points))
7+
Course.aggr(Grade * LetterGrade, avg_grade="avg(points)")

0 commit comments

Comments
 (0)