Skip to content

Commit b06da98

Browse files
committed
Fixed regex for projection.
1 parent f39d655 commit b06da98

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

datajoint/expression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ def proj(self, *attributes, **named_attributes):
313313
Each attribute name can only be used once.
314314
"""
315315
# new attributes in parentheses are included again with the new name without removing original
316-
duplication_pattern = re.compile(r'\s*\(\s*(?P<name>[a-z][a-z_0-9]*)\s*\)\s*$')
316+
duplication_pattern = re.compile(r'\s*\(\s*(?P<name>\w*[a-z]+\w*)\s*$\)\s*$')
317317
# attributes without parentheses renamed
318-
rename_pattern = re.compile(r'\s*(?P<name>[a-z][a-z_0-9]*)\s*$')
318+
rename_pattern = re.compile(r'\s*(?P<name>\w*[a-z]+\w*)\s*$')
319319
replicate_map = {k: m.group('name')
320320
for k, m in ((k, duplication_pattern.match(v)) for k, v in named_attributes.items()) if m}
321321
rename_map = {k: m.group('name')

tests/test_relational_operand.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
from .schema import (Experiment, TTest3, Trial, Ephys, Child, Parent, SubjectA, SessionA,
1414
SessionStatusA, SessionDateA)
1515

16+
from . import PREFIX, CONN_INFO
17+
18+
from time import sleep
19+
1620

1721
def setup():
1822
"""
@@ -177,6 +181,15 @@ def test_project():
177181
assert_equal(len((D() & cond).proj()), len((D() & cond)),
178182
'projection failed: altered its argument''s cardinality')
179183

184+
@staticmethod
185+
def test_rename_non_dj_attribute():
186+
schema = PREFIX + '_test1'
187+
connection = dj.conn(**CONN_INFO)
188+
connection.query(f'CREATE TABLE {schema}.test_table (oldID int PRIMARY KEY)').fetchall()
189+
mySchema = dj.VirtualModule(schema, schema)
190+
assert 'oldID' not in mySchema.TestTable.proj(new_name='oldID').heading.attributes.keys(), 'Failed to rename attribute correctly'
191+
connection.query(f'DROP TABLE {schema}.test_table')
192+
180193
@staticmethod
181194
def test_union():
182195
x = set(zip(*IJ.fetch('i', 'j')))

0 commit comments

Comments
 (0)