Skip to content

Commit ac98154

Browse files
Merge pull request #1335 from datajoint/feature/remove-unsigned-core-types
Remove unsigned integer types from core types
2 parents 984a9be + 7688fdd commit ac98154

File tree

8 files changed

+36
-44
lines changed

8 files changed

+36
-44
lines changed

src/datajoint/declare.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@
2525
"float32": (r"float32$", "float"),
2626
"float64": (r"float64$", "double"),
2727
"int64": (r"int64$", "bigint"),
28-
"uint64": (r"uint64$", "bigint unsigned"),
2928
"int32": (r"int32$", "int"),
30-
"uint32": (r"uint32$", "int unsigned"),
3129
"int16": (r"int16$", "smallint"),
32-
"uint16": (r"uint16$", "smallint unsigned"),
3330
"int8": (r"int8$", "tinyint"),
34-
"uint8": (r"uint8$", "tinyint unsigned"),
3531
"bool": (r"bool$", "tinyint"),
3632
# UUID (stored as binary)
3733
"uuid": (r"uuid$", "binary(16)"),

src/datajoint/jobs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _generate_definition(self) -> str:
155155
{pk_lines}
156156
---
157157
status : enum('pending', 'reserved', 'success', 'error', 'ignore')
158-
priority : uint8
158+
priority : int8
159159
created_time=CURRENT_TIMESTAMP(3) : datetime(3)
160160
scheduled_time=CURRENT_TIMESTAMP(3) : datetime(3)
161161
reserved_time=null : datetime(3)
@@ -165,8 +165,8 @@ def _generate_definition(self) -> str:
165165
error_stack=null : <blob>
166166
user="" : varchar(255)
167167
host="" : varchar(255)
168-
pid=0 : uint32
169-
connection_id=0 : uint64
168+
pid=0 : int32
169+
connection_id=0 : int64
170170
version="" : varchar(64)
171171
"""
172172

tests/integration/test_hidden_job_metadata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def schema_job_metadata(connection_test, prefix):
1818

1919
class Source(dj.Lookup):
2020
definition = """
21-
source_id : uint8
21+
source_id : int16
2222
---
2323
value : float32
2424
"""
@@ -49,7 +49,7 @@ def make(self, key):
4949

5050
class ManualTable(dj.Manual):
5151
definition = """
52-
manual_id : uint8
52+
manual_id : int16
5353
---
5454
data : float32
5555
"""
@@ -64,7 +64,7 @@ class ComputedWithPart(dj.Computed):
6464
class Detail(dj.Part):
6565
definition = """
6666
-> master
67-
detail_idx : uint8
67+
detail_idx : int16
6868
---
6969
detail_value : float32
7070
"""
@@ -237,7 +237,7 @@ def test_no_metadata_when_disabled(self, connection_test, prefix):
237237

238238
class Source(dj.Lookup):
239239
definition = """
240-
source_id : uint8
240+
source_id : int16
241241
"""
242242
contents = [(1,), (2,)]
243243

tests/integration/test_type_aliases.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ class TestTypeAliasPatterns:
1818
("float32", "FLOAT32"),
1919
("float64", "FLOAT64"),
2020
("int64", "INT64"),
21-
("uint64", "UINT64"),
2221
("int32", "INT32"),
23-
("uint32", "UINT32"),
2422
("int16", "INT16"),
25-
("uint16", "UINT16"),
2623
("int8", "INT8"),
27-
("uint8", "UINT8"),
2824
("bool", "BOOL"),
2925
],
3026
)
@@ -41,13 +37,9 @@ def test_type_alias_pattern_matching(self, alias, expected_category):
4137
("float32", "float"),
4238
("float64", "double"),
4339
("int64", "bigint"),
44-
("uint64", "bigint unsigned"),
4540
("int32", "int"),
46-
("uint32", "int unsigned"),
4741
("int16", "smallint"),
48-
("uint16", "smallint unsigned"),
4942
("int8", "tinyint"),
50-
("uint8", "tinyint unsigned"),
5143
("bool", "tinyint"),
5244
],
5345
)
@@ -73,6 +65,26 @@ def test_native_types_still_work(self, native_type, expected_category):
7365
category = match_type(native_type)
7466
assert category == expected_category
7567

68+
@pytest.mark.parametrize(
69+
"native_type,expected_category",
70+
[
71+
("int unsigned", "INTEGER"),
72+
("bigint unsigned", "INTEGER"),
73+
("smallint unsigned", "INTEGER"),
74+
("tinyint unsigned", "INTEGER"),
75+
],
76+
)
77+
def test_native_unsigned_types_pass_through(self, native_type, expected_category):
78+
"""
79+
Test that native MySQL unsigned types are allowed as pass-through.
80+
81+
Note: These are MySQL-specific and not portable to PostgreSQL.
82+
Users should prefer signed core types (int8, int16, int32, int64)
83+
for cross-database compatibility.
84+
"""
85+
category = match_type(native_type)
86+
assert category == expected_category
87+
7688

7789
class TestTypeAliasTableCreation:
7890
"""Test table creation with type aliases."""
@@ -102,13 +114,9 @@ def test_heading_preserves_type_aliases(self, schema_type_aliases):
102114
assert "float32" in heading_str
103115
assert "float64" in heading_str
104116
assert "int64" in heading_str
105-
assert "uint64" in heading_str
106117
assert "int32" in heading_str
107-
assert "uint32" in heading_str
108118
assert "int16" in heading_str
109-
assert "uint16" in heading_str
110119
assert "int8" in heading_str
111-
assert "uint8" in heading_str
112120
assert "bool" in heading_str
113121

114122

@@ -125,13 +133,9 @@ def test_insert_and_fetch(self, schema_type_aliases):
125133
val_float32=3.14,
126134
val_float64=2.718281828,
127135
val_int64=9223372036854775807, # max int64
128-
val_uint64=18446744073709551615, # max uint64
129136
val_int32=2147483647, # max int32
130-
val_uint32=4294967295, # max uint32
131137
val_int16=32767, # max int16
132-
val_uint16=65535, # max uint16
133138
val_int8=127, # max int8
134-
val_uint8=255, # max uint8
135139
val_bool=1, # boolean true
136140
)
137141

@@ -142,25 +146,21 @@ def test_insert_and_fetch(self, schema_type_aliases):
142146
assert abs(fetched["val_float32"] - test_data["val_float32"]) < 0.001
143147
assert abs(fetched["val_float64"] - test_data["val_float64"]) < 1e-9
144148
assert fetched["val_int64"] == test_data["val_int64"]
145-
assert fetched["val_uint64"] == test_data["val_uint64"]
146149
assert fetched["val_int32"] == test_data["val_int32"]
147-
assert fetched["val_uint32"] == test_data["val_uint32"]
148150
assert fetched["val_int16"] == test_data["val_int16"]
149-
assert fetched["val_uint16"] == test_data["val_uint16"]
150151
assert fetched["val_int8"] == test_data["val_int8"]
151-
assert fetched["val_uint8"] == test_data["val_uint8"]
152152
assert fetched["val_bool"] == test_data["val_bool"]
153153

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

159-
table.insert1(dict(pk_int32=100, pk_uint16=200, value="test"))
160-
fetched = (table & dict(pk_int32=100, pk_uint16=200)).fetch1()
159+
table.insert1(dict(pk_int32=100, pk_int16=200, value="test"))
160+
fetched = (table & dict(pk_int32=100, pk_int16=200)).fetch1()
161161

162162
assert fetched["pk_int32"] == 100
163-
assert fetched["pk_uint16"] == 200
163+
assert fetched["pk_int16"] == 200
164164
assert fetched["value"] == "test"
165165

166166
def test_nullable_type_aliases(self, schema_type_aliases):

tests/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TTestNoExtra(dj.Manual):
6767

6868
class Auto(dj.Lookup):
6969
definition = """
70-
id : uint8
70+
id : int16
7171
---
7272
name :varchar(12)
7373
"""
@@ -195,7 +195,7 @@ class Ephys(dj.Imported):
195195
class Channel(dj.Part):
196196
definition = """ # subtable containing individual channels
197197
-> master
198-
channel :uint8 # channel number within Ephys
198+
channel :int16 # channel number within Ephys
199199
----
200200
voltage : <blob>
201201
current = null : <blob> # optional current to test null handling

tests/schema_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class H(dj.Part):
143143
class M(dj.Part):
144144
definition = """ # test part_integrity cascade
145145
-> E
146-
id_m : uint16
146+
id_m : int32
147147
---
148148
-> E.H
149149
"""

tests/schema_type_aliases.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ class TypeAliasTable(dj.Manual):
1515
val_float32 : float32 # 32-bit float
1616
val_float64 : float64 # 64-bit float
1717
val_int64 : int64 # 64-bit signed integer
18-
val_uint64 : uint64 # 64-bit unsigned integer
1918
val_int32 : int32 # 32-bit signed integer
20-
val_uint32 : uint32 # 32-bit unsigned integer
2119
val_int16 : int16 # 16-bit signed integer
22-
val_uint16 : uint16 # 16-bit unsigned integer
2320
val_int8 : int8 # 8-bit signed integer
24-
val_uint8 : uint8 # 8-bit unsigned integer
2521
val_bool : bool # boolean value
2622
"""
2723

@@ -30,7 +26,7 @@ class TypeAliasPrimaryKey(dj.Manual):
3026
definition = """
3127
# Table with type alias in primary key
3228
pk_int32 : int32
33-
pk_uint16 : uint16
29+
pk_int16 : int16
3430
---
3531
value : varchar(100)
3632
"""

tests/schema_university.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Student(dj.Manual):
77
definition = """
8-
student_id : int unsigned # university-wide ID number
8+
student_id : int64 # university-wide ID number
99
---
1010
first_name : varchar(40)
1111
last_name : varchar(40)
@@ -41,7 +41,7 @@ class StudentMajor(dj.Manual):
4141
class Course(dj.Manual):
4242
definition = """
4343
-> Department
44-
course : int unsigned # course number, e.g. 1010
44+
course : int64 # course number, e.g. 1010
4545
---
4646
course_name : varchar(200) # e.g. "Neurobiology of Sensation and Movement."
4747
credits : decimal(3,1) # number of credits earned by completing the course

0 commit comments

Comments
 (0)