Skip to content

Commit 0f28a1a

Browse files
authored
Merge pull request #402 from aperture-data/release-0.4.22
Release 0.4.22
2 parents 5006eee + 73bd8d3 commit 0f28a1a

24 files changed

+223
-160
lines changed

aperturedb/BBoxDataCSV.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from aperturedb import ParallelLoader
33
from aperturedb import CSVParser
44

5-
HEADER_X_POS = "x_pos"
6-
HEADER_Y_POS = "y_pos"
7-
HEADER_WIDTH = "width"
5+
HEADER_X_POS = "x_pos"
6+
HEADER_Y_POS = "y_pos"
7+
HEADER_WIDTH = "width"
88
HEADER_HEIGHT = "height"
9-
IMG_KEY_PROP = "img_key_prop"
10-
IMG_KEY_VAL = "img_key_value"
9+
IMG_KEY_PROP = "img_key_prop"
10+
IMG_KEY_VAL = "img_key_value"
1111

1212

1313
class BBoxDataCSV(CSVParser.CSVParser):
@@ -57,7 +57,7 @@ class BBoxDataCSV(CSVParser.CSVParser):
5757
5858
"""
5959

60-
def __init__(self, filename, **kwargs):
60+
def __init__(self, filename: str, **kwargs):
6161

6262
super().__init__(filename, **kwargs)
6363

@@ -117,7 +117,7 @@ def getitem(self, idx):
117117

118118
return q, []
119119

120-
def validate(self):
120+
def validate(self) -> None:
121121

122122
self.header = list(self.df.columns.values)
123123

aperturedb/BlobDataCSV.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import os
33
from aperturedb import CSVParser
44

5-
PROPERTIES = "properties"
5+
PROPERTIES = "properties"
66
CONSTRAINTS = "constraints"
7-
BLOB_PATH = "filename"
7+
BLOB_PATH = "filename"
88

99
logger = logging.getLogger(__name__)
1010

@@ -48,7 +48,7 @@ class BlobDataCSV(CSVParser.CSVParser):
4848
:::
4949
"""
5050

51-
def __init__(self, filename, **kwargs):
51+
def __init__(self, filename: str, **kwargs):
5252

5353
super().__init__(filename, **kwargs)
5454

aperturedb/BlobNewestDataCSV.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class BlobNewestDataCSV(CSVParser.CSVParser):
9292
UPDATE_CONSTRAINT_PREFIX = "updateif_"
9393
GENERATE_PROP_PREFIX = "gen_"
9494

95-
def __init__(self, entity_class, filename, **kwargs):
95+
def __init__(self, entity_class: str, filename: str, **kwargs):
9696
self.known_generators = ["blobsize", "blobsha1", "insertdate"]
9797
self.entity = entity_class
9898
self.keys_set = False
@@ -112,16 +112,16 @@ def __init__(self, entity_class, filename, **kwargs):
112112
def _setupkeys(self):
113113
if not self.keys_set:
114114
self.keys_set = True
115-
self.props_keys = [x for x in self.header[1:]
116-
if not (x.startswith(CSVParser.CONSTRAINTS_PREFIX)
117-
or x.startswith(BlobNewestDataCSV.UPDATE_CONSTRAINT_PREFIX)
118-
or x.startswith(BlobNewestDataCSV.GENERATE_PROP_PREFIX))]
115+
self.props_keys = [x for x in self.header[1:]
116+
if not (x.startswith(CSVParser.CONSTRAINTS_PREFIX)
117+
or x.startswith(BlobNewestDataCSV.UPDATE_CONSTRAINT_PREFIX)
118+
or x.startswith(BlobNewestDataCSV.GENERATE_PROP_PREFIX))]
119119
self.generated_keys = [x for x in self.header[1:]
120120
if x.startswith(BlobNewestDataCSV.GENERATE_PROP_PREFIX)]
121-
self.constraints_keys = [x for x in self.header[1:]
122-
if x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
123-
self.search_keys = [x for x in self.header[1:]
124-
if x.startswith(BlobNewestDataCSV.UPDATE_CONSTRAINT_PREFIX)]
121+
self.constraints_keys = [x for x in self.header[1:]
122+
if x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
123+
self.search_keys = [x for x in self.header[1:]
124+
if x.startswith(BlobNewestDataCSV.UPDATE_CONSTRAINT_PREFIX)]
125125

126126
# derived class interface for retrieving blob
127127
def read_blob(self, idx):
@@ -248,7 +248,7 @@ def getitem(self, idx):
248248
self.filter_generated_constraints(), idx)
249249
# we test generated constraints here as they will stop an update from happening.
250250
generated_positive_constraints = self.create_generated_constraints(
251-
idx, match = True)
251+
idx, match=True)
252252
update_constraints.update(search_constraints)
253253
update_constraints.update(generated_positive_constraints)
254254
properties = self.parse_properties(idx)

aperturedb/CSVParser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Set
12
import pandas as pd
23
import logging
34
from aperturedb.Subscriptable import Subscriptable
@@ -9,10 +10,10 @@
910

1011
logger = logging.getLogger(__name__)
1112

12-
ENTITY_CLASS = "EntityClass"
13+
ENTITY_CLASS = "EntityClass"
1314
CONSTRAINTS_PREFIX = "constraint_"
1415
DATE_PREFIX = "date:"
15-
PROPERTIES = "properties"
16+
PROPERTIES = "properties"
1617
CONSTRAINTS = "constraints"
1718

1819
# This number is based on the partitions one wants to use per core.
@@ -73,7 +74,7 @@ def __init__(self,
7374
f"CSV file too small to be read in parallel. Use normal mode. cpus: {cpus}")
7475
self.df = dataframe.read_csv(
7576
self.filename,
76-
blocksize = blocksize)
77+
blocksize=blocksize)
7778

7879
# len for dask dataframe needs a client.
7980
if not self.use_dask and len(self.df) == 0:
@@ -86,7 +87,7 @@ def __init__(self,
8687
def __len__(self):
8788
return len(self.df.index)
8889

89-
def get_indexed_properties(self):
90+
def get_indexed_properties(self) -> Set[str]:
9091
if self.constraints_keys:
9192
return {self._parse_prop(k)[0] for k in self.constraints_keys}
9293
return set()

aperturedb/ConnectionDataCSV.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
logger = logging.getLogger(__name__)
66

77
CONNECTION_CLASS = "ConnectionClass"
8-
PROPERTIES = "properties"
8+
PROPERTIES = "properties"
99
CONSTRAINTS = "constraints"
1010

1111

@@ -53,21 +53,21 @@ class ConnectionDataCSV(CSVParser):
5353
:::
5454
"""
5555

56-
def __init__(self, filename, **kwargs):
56+
def __init__(self, filename: str, **kwargs):
5757
super().__init__(filename, **kwargs)
5858

59-
self.props_keys = [x for x in self.header[3:]
60-
if not x.startswith(CONSTRAINTS_PREFIX)]
59+
self.props_keys = [x for x in self.header[3:]
60+
if not x.startswith(CONSTRAINTS_PREFIX)]
6161

6262
self.constraints_keys = [x for x in self.header[3:]
6363
if x.startswith(CONSTRAINTS_PREFIX)]
6464

65-
self.src_class = self.header[1].split("@")[0]
66-
self.src_key = self.header[1].split("@")[1]
67-
self.dst_class = self.header[2].split("@")[0]
65+
self.src_class = self.header[1].split("@")[0]
66+
self.src_key = self.header[1].split("@")[1]
67+
self.dst_class = self.header[2].split("@")[0]
6868
# Pandas appends a .n to the column name if there is a duplicate
69-
self.dst_key = self.header[2].split("@")[1].split(".")[0]
70-
self.command = "AddConnection"
69+
self.dst_key = self.header[2].split("@")[1].split(".")[0]
70+
self.command = "AddConnection"
7171

7272
def get_indices(self):
7373
return {

aperturedb/DescriptorDataCSV.py

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

66
logger = logging.getLogger(__name__)
77

8-
HEADER_PATH = "filename"
8+
HEADER_PATH = "filename"
99
HEADER_INDEX = "index"
10-
HEADER_SET = "set"
10+
HEADER_SET = "set"
1111
HEADER_LABEL = "label"
12-
PROPERTIES = "properties"
13-
CONSTRAINTS = "constraints"
12+
PROPERTIES = "properties"
13+
CONSTRAINTS = "constraints"
1414

1515

1616
class DescriptorDataCSV(CSVParser.CSVParser):
@@ -68,14 +68,14 @@ class DescriptorDataCSV(CSVParser.CSVParser):
6868
6969
"""
7070

71-
def __init__(self, filename, **kwargs):
71+
def __init__(self, filename: str, **kwargs):
7272

7373
super().__init__(filename, **kwargs)
7474
self.npy_arrays = {}
7575
self.has_label = False
7676

77-
self.props_keys = [x for x in self.header[3:]
78-
if not x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
77+
self.props_keys = [x for x in self.header[3:]
78+
if not x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
7979
self.constraints_keys = [x for x in self.header[3:]
8080
if x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
8181
self.command = "AddDescriptor"
@@ -91,7 +91,7 @@ def getitem(self, idx):
9191
idx = self.df.index.start + idx
9292
filename = os.path.join(self.relative_path_prefix,
9393
self.df.loc[idx, HEADER_PATH])
94-
index = self.df.loc[idx, HEADER_INDEX]
94+
index = self.df.loc[idx, HEADER_INDEX]
9595
desc_set = self.df.loc[idx, HEADER_SET]
9696

9797
descriptor, desc_ok = self.load_descriptor(filename, index)

aperturedb/DescriptorSetDataCSV.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from aperturedb import ParallelLoader
33
from aperturedb import CSVParser
44

5-
HEADER_NAME = "name"
6-
HEADER_DIM = "dimensions"
5+
HEADER_NAME = "name"
6+
HEADER_DIM = "dimensions"
77
HEADER_ENGINE = "engine"
88
HEADER_METRIC = "metric"
9-
PROPERTIES = "properties"
10-
CONSTRAINTS = "constraints"
9+
PROPERTIES = "properties"
10+
CONSTRAINTS = "constraints"
1111

1212

1313
class DescriptorSetDataCSV(CSVParser.CSVParser):
@@ -46,7 +46,7 @@ class DescriptorSetDataCSV(CSVParser.CSVParser):
4646
:::
4747
"""
4848

49-
def __init__(self, filename, **kwargs):
49+
def __init__(self, filename: str, **kwargs):
5050

5151
super().__init__(filename, **kwargs)
5252

aperturedb/EntityDataCSV.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
logger = logging.getLogger(__name__)
66
ENTITY_CLASS = "EntityClass"
7-
PROPERTIES = "properties"
8-
CONSTRAINTS = "constraints"
7+
PROPERTIES = "properties"
8+
CONSTRAINTS = "constraints"
99

1010

1111
class EntityDataCSV(CSVParser.CSVParser):
@@ -42,7 +42,7 @@ class EntityDataCSV(CSVParser.CSVParser):
4242
4343
"""
4444

45-
def __init__(self, filename, **kwargs):
45+
def __init__(self, filename: str, **kwargs):
4646
super().__init__(filename, **kwargs)
4747

4848
self.props_keys = [x for x in self.header[1:]
@@ -63,7 +63,7 @@ def getitem(self, idx):
6363
eclass = self.df.loc[idx, ENTITY_CLASS]
6464
q = []
6565
ae = self._basic_command(idx,
66-
custom_fields = {
66+
custom_fields={
6767
"class": eclass
6868
})
6969

@@ -122,7 +122,7 @@ def __init__(self, entity_class, filename, df=None, use_dask=False):
122122
self.command = "Delete" + entity_class
123123
self.constraint_keyword = "constraints"
124124
if not use_dask:
125-
self.constraint_keys = [x for x in self.header[0:]]
125+
self.constraint_keys = [x for x in self.header[0:]]
126126

127127
def getitem(self, idx):
128128
idx = self.df.index.start + idx

aperturedb/EntityUpdateDataCSV.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SingleEntityUpdateDataCSV(CSVParser.CSVParser):
7171
"""
7272
UPDATE_CONSTRAINT_PREFIX = "updateif_"
7373

74-
def __init__(self, entity_class, filename, **kwargs):
74+
def __init__(self, entity_class: str, filename: str, **kwargs):
7575

7676
if entity_class in ("Image", "Video", "Blob", "BoundingBox", "Connection", "Polygon", "Descriptor", "DescriptorSet", "Frame"):
7777
self.entity = entity_class
@@ -89,13 +89,13 @@ def __init__(self, entity_class, filename, **kwargs):
8989
def _setupkeys(self):
9090
if not self.keys_set:
9191
self.keys_set = True
92-
self.props_keys = [x for x in self.header[1:]
93-
if not (x.startswith(CSVParser.CONSTRAINTS_PREFIX)
94-
or x.startswith(SingleEntityUpdateDataCSV.UPDATE_CONSTRAINT_PREFIX))]
95-
self.constraints_keys = [x for x in self.header[1:]
96-
if x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
97-
self.search_keys = [x for x in self.header[1:]
98-
if x.startswith(SingleEntityUpdateDataCSV.UPDATE_CONSTRAINT_PREFIX)]
92+
self.props_keys = [x for x in self.header[1:]
93+
if not (x.startswith(CSVParser.CONSTRAINTS_PREFIX)
94+
or x.startswith(SingleEntityUpdateDataCSV.UPDATE_CONSTRAINT_PREFIX))]
95+
self.constraints_keys = [x for x in self.header[1:]
96+
if x.startswith(CSVParser.CONSTRAINTS_PREFIX)]
97+
self.search_keys = [x for x in self.header[1:]
98+
if x.startswith(SingleEntityUpdateDataCSV.UPDATE_CONSTRAINT_PREFIX)]
9999

100100
def getitem(self, idx):
101101
idx = self.df.index.start + idx
@@ -105,7 +105,7 @@ def getitem(self, idx):
105105
self.command = "Add" + self.entity
106106
selector = {} if self.entity_selection is None else {
107107
"class": self.entity_selection}
108-
entity_add = self._basic_command(idx, custom_fields = selector)
108+
entity_add = self._basic_command(idx, custom_fields=selector)
109109
condition_add_failed = {"results": {0: {"status": ["==", 2]}}}
110110
self.command = "Update" + self.entity
111111
update_constraints = self.parse_constraints(idx)

0 commit comments

Comments
 (0)