Skip to content

Commit

Permalink
Merge pull request #972 from dimitri-yatsenko/master
Browse files Browse the repository at this point in the history
Fix Python 3.10 and allow renaming attributes in proj even if they do not follow datajoint naming conventions.
  • Loading branch information
guzman-raphael authored Jan 19, 2022
2 parents 7b4c1c9 + 240a0c9 commit bf74266
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Release notes

### 0.13.3 -- TBD
* Bugfix - Fix Python 3.10 compatibility (#983) PR #972
* Bugfix - Allow renaming non-conforming attributes in proj (#982) PR #972
* Add - Expose proxy feature for S3 external stores (#961) PR #962
* Bugfix - Dependencies not properly loaded on populate. (#902) PR #919
* Bugfix - Replace use of numpy aliases of built-in types with built-in type. (#938) PR #939
Expand Down
2 changes: 1 addition & 1 deletion LNX-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
interval: 1s
fakeservices.datajoint.io:
<<: *net
image: datajoint/nginx:v0.0.18
image: datajoint/nginx:v0.0.19
environment:
- ADD_db_TYPE=DATABASE
- ADD_db_ENDPOINT=db:3306
Expand Down
2 changes: 1 addition & 1 deletion datajoint/declare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

UUID_DATA_TYPE = 'binary(16)'
MAX_TABLE_NAME_LENGTH = 64
CONSTANT_LITERALS = {'CURRENT_TIMESTAMP'} # SQL literals to be used without quotes (case insensitive)
CONSTANT_LITERALS = {'CURRENT_TIMESTAMP', 'NULL'} # SQL literals to be used without quotes (case insensitive)
EXTERNAL_TABLE_ROOT = '~external'

TYPE_PATTERN = {k: re.compile(v, re.I) for k, v in dict(
Expand Down
5 changes: 3 additions & 2 deletions datajoint/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .preview import preview, repr_html
from .condition import AndList, Not, \
make_condition, assert_join_compatibility, extract_column_names, PromiscuousOperand
from .declare import CONSTANT_LITERALS

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -313,9 +314,9 @@ def proj(self, *attributes, **named_attributes):
Each attribute name can only be used once.
"""
# new attributes in parentheses are included again with the new name without removing original
duplication_pattern = re.compile(r'\s*\(\s*(?P<name>[a-z][a-z_0-9]*)\s*\)\s*$')
duplication_pattern = re.compile(fr'^\s*\(\s*(?!{"|".join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]\w*)\s*\)\s*$')
# attributes without parentheses renamed
rename_pattern = re.compile(r'\s*(?P<name>[a-z][a-z_0-9]*)\s*$')
rename_pattern = re.compile(fr'^\s*(?!{"|".join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]\w*)\s*$')
replicate_map = {k: m.group('name')
for k, m in ((k, duplication_pattern.match(v)) for k, v in named_attributes.items()) if m}
rename_map = {k: m.group('name')
Expand Down
2 changes: 1 addition & 1 deletion datajoint/external.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path, PurePosixPath, PureWindowsPath
from collections import Mapping
from collections.abc import Mapping
from tqdm import tqdm
from .settings import config
from .errors import DataJointError, MissingExternalFile
Expand Down
2 changes: 1 addition & 1 deletion datajoint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}


class Config(collections.MutableMapping):
class Config(collections.abc.MutableMapping):

instance = None

Expand Down
2 changes: 2 additions & 0 deletions docs-parts/intro/Releases_lang1.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
0.13.3 -- TBD
----------------------
* Bugfix - Fix Python 3.10 compatibility (#983) PR #972
* Bugfix - Allow renaming non-conforming attributes in proj (#982) PR #972
* Add - Expose proxy feature for S3 external stores (#961) PR #962
* Bugfix - Dependencies not properly loaded on populate. (#902) PR #919
* Bugfix - Replace use of numpy aliases of built-in types with built-in type. (#938) PR #939
Expand Down
2 changes: 1 addition & 1 deletion local-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
interval: 1s
fakeservices.datajoint.io:
<<: *net
image: datajoint/nginx:v0.0.18
image: datajoint/nginx:v0.0.19
environment:
- ADD_db_TYPE=DATABASE
- ADD_db_ENDPOINT=db:3306
Expand Down
11 changes: 11 additions & 0 deletions tests/test_relational_operand.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from .schema import (Experiment, TTest3, Trial, Ephys, Child, Parent, SubjectA, SessionA,
SessionStatusA, SessionDateA)

from . import PREFIX, CONN_INFO


def setup():
"""
Expand Down Expand Up @@ -177,6 +179,15 @@ def test_project():
assert_equal(len((D() & cond).proj()), len((D() & cond)),
'projection failed: altered its argument''s cardinality')

@staticmethod
def test_rename_non_dj_attribute():
schema = PREFIX + '_test1'
connection = dj.conn(**CONN_INFO)
connection.query(f'CREATE TABLE {schema}.test_table (oldID int PRIMARY KEY)').fetchall()
mySchema = dj.VirtualModule(schema, schema)
assert 'oldID' not in mySchema.TestTable.proj(new_name='oldID').heading.attributes.keys(), 'Failed to rename attribute correctly'
connection.query(f'DROP TABLE {schema}.test_table')

@staticmethod
def test_union():
x = set(zip(*IJ.fetch('i', 'j')))
Expand Down

0 comments on commit bf74266

Please sign in to comment.