@@ -990,44 +990,42 @@ def read_catalog_line(line):
990
990
prev_id = 0
991
991
# if the first catalog doesn't start at zero
992
992
if catalog_id != prev_id :
993
- prev_id = catalog_id
994
993
if not empty :
995
- events . append ( temp_event )
994
+ events = [ temp_event ]
996
995
else :
997
996
events = []
998
997
for id in range (catalog_id ):
999
998
yield cls (data = [], catalog_id = id , ** kwargs )
999
+ prev_id = catalog_id
1000
+ continue
1000
1001
# accumulate event if catalog_id is the same as previous event
1001
1002
if catalog_id == prev_id :
1002
- prev_id = catalog_id
1003
1003
if not all ([val in (None , '' ) for val in temp_event ]):
1004
1004
events .append (temp_event )
1005
+ prev_id = catalog_id
1005
1006
# create and yield class if the events are from different catalogs
1006
1007
elif catalog_id == prev_id + 1 :
1007
- catalog = cls (data = events , catalog_id = prev_id , ** kwargs )
1008
- prev_id = catalog_id
1008
+ yield cls (data = events , catalog_id = prev_id , ** kwargs )
1009
1009
# add event to new event list
1010
1010
if not empty :
1011
1011
events = [temp_event ]
1012
1012
else :
1013
1013
events = []
1014
- yield catalog
1014
+ prev_id = catalog_id
1015
1015
# this implies there are empty catalogs, because they are not listed in the ascii file
1016
1016
elif catalog_id > prev_id + 1 :
1017
- catalog = cls (data = events , catalog_id = prev_id , ** kwargs )
1018
- yield catalog
1019
- # add event to new event list
1020
- if not empty :
1021
- events = [temp_event ]
1022
- else :
1023
- events = []
1017
+ yield cls (data = events , catalog_id = prev_id , ** kwargs )
1024
1018
# if prev_id = 0 and catalog_id = 2, then we skipped one catalog. thus, we skip catalog_id - prev_id - 1 catalogs
1025
1019
num_empty_catalogs = catalog_id - prev_id - 1
1026
- # create empty catalog classes
1020
+ # first yield empty catalog classes
1027
1021
for id in range (num_empty_catalogs ):
1028
1022
yield cls (data = [], catalog_id = catalog_id - num_empty_catalogs + id , ** kwargs )
1029
- # finally we want to yield the buffered catalog to preserve order
1030
1023
prev_id = catalog_id
1024
+ # add event to new event list
1025
+ if not empty :
1026
+ events = [temp_event ]
1027
+ else :
1028
+ events = []
1031
1029
else :
1032
1030
raise ValueError (
1033
1031
"catalog_id should be monotonically increasing and events should be ordered by catalog_id" )
0 commit comments