Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
pymemri
Commits
11cb5a81
Commit
11cb5a81
authored
2 years ago
by
Eelco van der Wel
Browse files
Options
Download
Plain Diff
Merge branch 'eelco/move-item' into 'dev'
Move Item to central schema See merge request
!252
parents
0b776152
10ce61ed
Pipeline
#10744
passed with stages
in 1 minute and 29 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
pymemri/data/schema/__init__.py
+1
-1
pymemri/data/schema/__init__.py
pymemri/data/schema/_central_schema.py
+22
-1
pymemri/data/schema/_central_schema.py
pymemri/data/schema/itembase.py
+3
-21
pymemri/data/schema/itembase.py
pymemri/data/schema/photo.py
+1
-2
pymemri/data/schema/photo.py
pymemri/data/schema/schema.py
+0
-1
pymemri/data/schema/schema.py
pymemri/exporters/exporters.py
+1
-1
pymemri/exporters/exporters.py
tests/data/test_item.py
+2
-4
tests/data/test_item.py
tests/exporters/test_query.py
+1
-2
tests/exporters/test_query.py
with
31 additions
and
33 deletions
+31
-33
pymemri/data/schema/__init__.py
+
1
-
1
View file @
11cb5a81
from
.item
import
Edge
,
Item
,
ItemBase
# noqa: F405, type: ignore
from
.item
base
import
Edge
,
ItemBase
# noqa: F405, type: ignore
from
.schema
import
*
# noqa: F405, type: ignore
This diff is collapsed.
Click to expand it.
pymemri/data/schema/_central_schema.py
+
22
-
1
View file @
11cb5a81
...
...
@@ -5,7 +5,22 @@
from
datetime
import
datetime
from
typing
import
List
,
Optional
,
Union
from
pymemri.data.schema.item
import
Item
from
pymemri.data.schema.itembase
import
ItemBase
class
Item
(
ItemBase
):
# Properties
id
:
Optional
[
str
]
=
None
dateCreated
:
Optional
[
datetime
]
=
None
dateModified
:
Optional
[
datetime
]
=
None
dateServerModified
:
Optional
[
datetime
]
=
None
deleted
:
Optional
[
bool
]
=
None
externalId
:
Optional
[
str
]
=
None
isMock
:
Optional
[
bool
]
=
None
# Edges
language
:
List
[
"Language"
]
=
[]
label
:
List
[
"CategoricalPrediction"
]
=
[]
class
Account
(
Item
):
...
...
@@ -242,6 +257,12 @@ class LabellingTask(Item):
view
:
List
[
"CVUStoredDefinition"
]
=
[]
class
Language
(
Item
):
# Properties
languageCode
:
Optional
[
str
]
=
None
languageName
:
Optional
[
str
]
=
None
class
Location
(
Item
):
# Properties
latitude
:
Optional
[
float
]
=
None
...
...
This diff is collapsed.
Click to expand it.
pymemri/data/schema/item.py
→
pymemri/data/schema/item
base
.py
+
3
-
21
View file @
11cb5a81
...
...
@@ -8,7 +8,6 @@ from typing import (
Dict
,
Generic
,
List
,
Optional
,
Tuple
,
Type
,
TypeVar
,
...
...
@@ -26,7 +25,6 @@ from .utils import get_args, get_origin, type_or_union_to_tuple, type_to_str
if
TYPE_CHECKING
:
from
...pod.client
import
PodClient
from
._central_schema
import
CategoricalPrediction
SOURCE
,
TARGET
,
TYPE
,
EDGE_TYPE
,
LABEL
,
SEQUENCE
,
ALL_EDGES
=
(
"_source"
,
...
...
@@ -117,11 +115,11 @@ class _ItemMeta(ModelMetaclass):
return
cls
TargetType
=
TypeVar
(
"TargetType"
,
bound
=
"Item"
)
TargetType
=
TypeVar
(
"TargetType"
,
bound
=
"Item
Base
"
)
class
Edge
(
GenericModel
,
Generic
[
TargetType
],
smart_union
=
True
,
copy_on_model_validation
=
False
):
source
:
"Item"
source
:
"Item
Base
"
target
:
TargetType
name
:
str
...
...
@@ -142,7 +140,7 @@ class Edge(GenericModel, Generic[TargetType], smart_union=True, copy_on_model_va
def
get_target_types_as_str
(
cls
)
->
Tuple
[
str
]:
return
tuple
(
type_to_str
(
t
)
for
t
in
cls
.
get_target_types
())
@
validator
(
"target"
,
pre
=
True
)
@
validator
(
"target"
,
pre
=
True
,
allow_reuse
=
True
)
def
validate_target
(
cls
,
val
:
Any
)
->
TargetType
:
"""
To allow for overwriting schema classes on a different place, validator
...
...
@@ -437,21 +435,5 @@ class ItemBase(BaseModel, metaclass=_ItemMeta, extra=Extra.forbid):
return
cls
(
**
json
)
class
Item
(
ItemBase
):
id
:
Optional
[
str
]
=
None
dateCreated
:
Optional
[
datetime
]
=
None
dateModified
:
Optional
[
datetime
]
=
None
dateServerModified
:
Optional
[
datetime
]
=
None
deleted
:
bool
=
False
# TODO following edges and properties are not ItemBase properties in central schema/pod,
# Taken from old ItemBase
externalId
:
Optional
[
str
]
=
None
isMock
:
Optional
[
bool
]
=
None
# Edges
label
:
List
[
"CategoricalPrediction"
]
=
[]
Edge
.
update_forward_refs
()
ItemBase
.
update_forward_refs
()
This diff is collapsed.
Click to expand it.
pymemri/data/schema/photo.py
+
1
-
2
View file @
11cb5a81
...
...
@@ -6,8 +6,7 @@ from typing import Any, List, Optional, Tuple
import
numpy
as
np
from
PIL
import
Image
from
._central_schema
import
File
from
.item
import
Item
from
._central_schema
import
File
,
Item
DEFAULT_ENCODING
=
"PNG"
...
...
This diff is collapsed.
Click to expand it.
pymemri/data/schema/schema.py
+
0
-
1
View file @
11cb5a81
...
...
@@ -6,7 +6,6 @@ from pydantic.fields import Field
from
._central_schema
import
*
# noqa
from
.dataset
import
Dataset
# noqa
from
.item
import
Item
from
.photo
import
Photo
# noqa
from
.utils
import
resolve_forward_refs
...
...
This diff is collapsed.
Click to expand it.
pymemri/exporters/exporters.py
+
1
-
1
View file @
11cb5a81
...
...
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Any, List
import
pandas
as
pd
if
TYPE_CHECKING
:
from
..data.schema
.item
import
Item
from
..data.schema
import
Item
from
..pod.client
import
PodClient
...
...
This diff is collapsed.
Click to expand it.
tests/data/test_item.py
+
2
-
4
View file @
11cb5a81
...
...
@@ -4,8 +4,7 @@ from typing import List, Optional, Union
import
pytest
from
pydantic
import
ValidationError
from
pymemri.data.schema
import
Account
,
Item
,
Person
,
get_schema
from
pymemri.data.schema.item
import
Edge
from
pymemri.data.schema
import
Account
,
Edge
,
Item
,
Person
,
get_schema
from
pymemri.pod.client
import
PodClient
...
...
@@ -46,7 +45,7 @@ def test_item_init():
def
test_init_with_edges
():
accounts
=
[
Account
(
handle
=
"1"
),
Account
(
handle
=
"2"
)]
item
=
MyItem
(
str_property
=
"test"
,
account_edge
=
accounts
)
assert
item
.
property_dict
()
==
{
"deleted"
:
False
,
"str_property"
:
"test"
}
assert
item
.
property_dict
()
==
{
"str_property"
:
"test"
}
assert
len
(
item
.
account_edge
)
==
len
(
item
.
__edges__
[
"account_edge"
])
==
2
...
...
@@ -61,7 +60,6 @@ def test_property_dict():
"float_property"
:
3.0
,
"bool_property"
:
False
,
"dt_property"
:
round
(
dt
.
timestamp
()
*
1000
),
"deleted"
:
False
,
}
assert
property_dict
==
correct_properties
...
...
This diff is collapsed.
Click to expand it.
tests/exporters/test_query.py
+
1
-
2
View file @
11cb5a81
...
...
@@ -3,8 +3,7 @@ import random
import
pandas
as
pd
import
pytest
from
pymemri.data.schema
import
Account
,
CategoricalPrediction
,
Message
,
Person
from
pymemri.data.schema.item
import
Edge
from
pymemri.data.schema
import
Account
,
CategoricalPrediction
,
Edge
,
Message
,
Person
from
pymemri.exporters.exporters
import
Query
from
pymemri.pod.client
import
PodClient
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets