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
4 changes: 0 additions & 4 deletions src/datajoint/declare.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
"float32": (r"float32$", "float"),
"float64": (r"float64$", "double"),
"int64": (r"int64$", "bigint"),
"uint64": (r"uint64$", "bigint unsigned"),
"int32": (r"int32$", "int"),
"uint32": (r"uint32$", "int unsigned"),
"int16": (r"int16$", "smallint"),
"uint16": (r"uint16$", "smallint unsigned"),
"int8": (r"int8$", "tinyint"),
"uint8": (r"uint8$", "tinyint unsigned"),
"bool": (r"bool$", "tinyint"),
# UUID (stored as binary)
"uuid": (r"uuid$", "binary(16)"),
Expand Down
6 changes: 3 additions & 3 deletions src/datajoint/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _generate_definition(self) -> str:
{pk_lines}
---
status : enum('pending', 'reserved', 'success', 'error', 'ignore')
priority : uint8
priority : int8
created_time=CURRENT_TIMESTAMP(3) : datetime(3)
scheduled_time=CURRENT_TIMESTAMP(3) : datetime(3)
reserved_time=null : datetime(3)
Expand All @@ -165,8 +165,8 @@ def _generate_definition(self) -> str:
error_stack=null : <blob>
user="" : varchar(255)
host="" : varchar(255)
pid=0 : uint32
connection_id=0 : uint64
pid=0 : int32
connection_id=0 : int64
version="" : varchar(64)
"""

Expand Down
2 changes: 1 addition & 1 deletion src/datajoint/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# version bump auto managed by Github Actions:
# label_prs.yaml(prep), release.yaml(bump), post_release.yaml(edit)
# manually set this version will be eventually overwritten by the above actions
__version__ = "2.0.0a21"
__version__ = "2.0.0a22"
8 changes: 4 additions & 4 deletions tests/integration/test_hidden_job_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def schema_job_metadata(connection_test, prefix):

class Source(dj.Lookup):
definition = """
source_id : uint8
source_id : int16
---
value : float32
"""
Expand Down Expand Up @@ -49,7 +49,7 @@ def make(self, key):

class ManualTable(dj.Manual):
definition = """
manual_id : uint8
manual_id : int16
---
data : float32
"""
Expand All @@ -64,7 +64,7 @@ class ComputedWithPart(dj.Computed):
class Detail(dj.Part):
definition = """
-> master
detail_idx : uint8
detail_idx : int16
---
detail_value : float32
"""
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_no_metadata_when_disabled(self, connection_test, prefix):

class Source(dj.Lookup):
definition = """
source_id : uint8
source_id : int16
"""
contents = [(1,), (2,)]

Expand Down
46 changes: 23 additions & 23 deletions tests/integration/test_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ class TestTypeAliasPatterns:
("float32", "FLOAT32"),
("float64", "FLOAT64"),
("int64", "INT64"),
("uint64", "UINT64"),
("int32", "INT32"),
("uint32", "UINT32"),
("int16", "INT16"),
("uint16", "UINT16"),
("int8", "INT8"),
("uint8", "UINT8"),
("bool", "BOOL"),
],
)
Expand All @@ -41,13 +37,9 @@ def test_type_alias_pattern_matching(self, alias, expected_category):
("float32", "float"),
("float64", "double"),
("int64", "bigint"),
("uint64", "bigint unsigned"),
("int32", "int"),
("uint32", "int unsigned"),
("int16", "smallint"),
("uint16", "smallint unsigned"),
("int8", "tinyint"),
("uint8", "tinyint unsigned"),
("bool", "tinyint"),
],
)
Expand All @@ -73,6 +65,26 @@ def test_native_types_still_work(self, native_type, expected_category):
category = match_type(native_type)
assert category == expected_category

@pytest.mark.parametrize(
"native_type,expected_category",
[
("int unsigned", "INTEGER"),
("bigint unsigned", "INTEGER"),
("smallint unsigned", "INTEGER"),
("tinyint unsigned", "INTEGER"),
],
)
def test_native_unsigned_types_pass_through(self, native_type, expected_category):
"""
Test that native MySQL unsigned types are allowed as pass-through.

Note: These are MySQL-specific and not portable to PostgreSQL.
Users should prefer signed core types (int8, int16, int32, int64)
for cross-database compatibility.
"""
category = match_type(native_type)
assert category == expected_category


class TestTypeAliasTableCreation:
"""Test table creation with type aliases."""
Expand Down Expand Up @@ -102,13 +114,9 @@ def test_heading_preserves_type_aliases(self, schema_type_aliases):
assert "float32" in heading_str
assert "float64" in heading_str
assert "int64" in heading_str
assert "uint64" in heading_str
assert "int32" in heading_str
assert "uint32" in heading_str
assert "int16" in heading_str
assert "uint16" in heading_str
assert "int8" in heading_str
assert "uint8" in heading_str
assert "bool" in heading_str


Expand All @@ -125,13 +133,9 @@ def test_insert_and_fetch(self, schema_type_aliases):
val_float32=3.14,
val_float64=2.718281828,
val_int64=9223372036854775807, # max int64
val_uint64=18446744073709551615, # max uint64
val_int32=2147483647, # max int32
val_uint32=4294967295, # max uint32
val_int16=32767, # max int16
val_uint16=65535, # max uint16
val_int8=127, # max int8
val_uint8=255, # max uint8
val_bool=1, # boolean true
)

Expand All @@ -142,25 +146,21 @@ def test_insert_and_fetch(self, schema_type_aliases):
assert abs(fetched["val_float32"] - test_data["val_float32"]) < 0.001
assert abs(fetched["val_float64"] - test_data["val_float64"]) < 1e-9
assert fetched["val_int64"] == test_data["val_int64"]
assert fetched["val_uint64"] == test_data["val_uint64"]
assert fetched["val_int32"] == test_data["val_int32"]
assert fetched["val_uint32"] == test_data["val_uint32"]
assert fetched["val_int16"] == test_data["val_int16"]
assert fetched["val_uint16"] == test_data["val_uint16"]
assert fetched["val_int8"] == test_data["val_int8"]
assert fetched["val_uint8"] == test_data["val_uint8"]
assert fetched["val_bool"] == test_data["val_bool"]

def test_insert_primary_key_with_aliases(self, schema_type_aliases):
"""Test using type aliases in primary key."""
table = TypeAliasPrimaryKey()
table.delete()

table.insert1(dict(pk_int32=100, pk_uint16=200, value="test"))
fetched = (table & dict(pk_int32=100, pk_uint16=200)).fetch1()
table.insert1(dict(pk_int32=100, pk_int16=200, value="test"))
fetched = (table & dict(pk_int32=100, pk_int16=200)).fetch1()

assert fetched["pk_int32"] == 100
assert fetched["pk_uint16"] == 200
assert fetched["pk_int16"] == 200
assert fetched["value"] == "test"

def test_nullable_type_aliases(self, schema_type_aliases):
Expand Down
4 changes: 2 additions & 2 deletions tests/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TTestNoExtra(dj.Manual):

class Auto(dj.Lookup):
definition = """
id : uint8
id : int16
---
name :varchar(12)
"""
Expand Down Expand Up @@ -195,7 +195,7 @@ class Ephys(dj.Imported):
class Channel(dj.Part):
definition = """ # subtable containing individual channels
-> master
channel :uint8 # channel number within Ephys
channel :int16 # channel number within Ephys
----
voltage : <blob>
current = null : <blob> # optional current to test null handling
Expand Down
2 changes: 1 addition & 1 deletion tests/schema_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class H(dj.Part):
class M(dj.Part):
definition = """ # test part_integrity cascade
-> E
id_m : uint16
id_m : int32
---
-> E.H
"""
Expand Down
6 changes: 1 addition & 5 deletions tests/schema_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ class TypeAliasTable(dj.Manual):
val_float32 : float32 # 32-bit float
val_float64 : float64 # 64-bit float
val_int64 : int64 # 64-bit signed integer
val_uint64 : uint64 # 64-bit unsigned integer
val_int32 : int32 # 32-bit signed integer
val_uint32 : uint32 # 32-bit unsigned integer
val_int16 : int16 # 16-bit signed integer
val_uint16 : uint16 # 16-bit unsigned integer
val_int8 : int8 # 8-bit signed integer
val_uint8 : uint8 # 8-bit unsigned integer
val_bool : bool # boolean value
"""

Expand All @@ -30,7 +26,7 @@ class TypeAliasPrimaryKey(dj.Manual):
definition = """
# Table with type alias in primary key
pk_int32 : int32
pk_uint16 : uint16
pk_int16 : int16
---
value : varchar(100)
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/schema_university.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Student(dj.Manual):
definition = """
student_id : int unsigned # university-wide ID number
student_id : int64 # university-wide ID number
---
first_name : varchar(40)
last_name : varchar(40)
Expand Down Expand Up @@ -41,7 +41,7 @@ class StudentMajor(dj.Manual):
class Course(dj.Manual):
definition = """
-> Department
course : int unsigned # course number, e.g. 1010
course : int64 # course number, e.g. 1010
---
course_name : varchar(200) # e.g. "Neurobiology of Sensation and Movement."
credits : decimal(3,1) # number of credits earned by completing the course
Expand Down
Loading