Skip to content

Commit

Permalink
use ordered_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Jul 24, 2024
1 parent 9a3f033 commit 5b25a07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 8 additions & 3 deletions ostap/io/compress_shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
'ENCODING'
)
# =============================================================================
import os, abc, shelve, shutil, glob, datetime, collections
import os, abc, shelve, shutil, glob, datetime
from sys import version_info as python_version
from ostap.io.dbase import dbopen, whichdb, Item
from ostap.core.meta_info import meta_info
from ostap.core.meta_info import meta_info,
from ostap.io.pickling import ( Pickler , Unpickler, BytesIO,
PROTOCOL,
HIGHEST_PROTOCOL, DEFAULT_PROTOCOL )
Expand All @@ -66,6 +66,11 @@
if '__main__' == __name__ : logger = getLogger ( 'ostap.io.compress_shelve' )
else : logger = getLogger ( __name__ )
# =============================================================================
## ordered dict type to be used a
ordered_dict = dict
if python_version < (3.7) :
from collections import OrderedDict as ordered_dict
# =============================================================================
## encoding
ENCODING = 'utf-8'
# =============================================================================
Expand Down Expand Up @@ -269,7 +274,7 @@ def __init__(
elif 'sqlite3' != self.dbtype and self.mode in ( 'c' , 'n' ) : write = True
else : write = False
if write :
dct = collections.OrderedDict()
dct = ordered_dict()
dct [ 'Created by' ] = meta_info.User
dct [ 'Created at' ] = datetime.datetime.now ().strftime( '%Y-%m-%d %H:%M:%S' )
dct [ 'Created with Ostap version' ] = meta_info.Ostap
Expand Down
9 changes: 7 additions & 2 deletions ostap/io/sqliteshelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
import sqlite3
from ostap.io.sqlitedict import SqliteDict
from ostap.io.dbase import Item, TmpDB
from ostap.core.meta_info import meta_info
from ostap.core.meta_info import meta_info, python_info
from ostap.io.pickling import ( Pickler, Unpickler, BytesIO ,
PROTOCOL,
HIGHEST_PROTOCOL, DEFAULT_PROTOCOL )
Expand All @@ -143,6 +143,11 @@
if '__main__' == __name__ : logger = getLogger ( 'ostap.io.sqliteshelve' )
else : logger = getLogger ( __name__ )
# =============================================================================
## ordered dict type to be used
ordered_dict = dict
if python_info < (3.7) :
from collections import OrderedDict as ordered_dict
# =============================================================================
_modes_ = {
# =========================================================================
# 'r' Open existing database for reading only
Expand Down Expand Up @@ -291,7 +296,7 @@ def __init__ ( self ,
self.__sizes = {}

if self.flag in ( 'w' , 'n' ) :
dct = collections.OrderedDict()
dct = ordered_dict()
dct [ 'Created by' ] = meta_info.User
dct [ 'Created at' ] = datetime.datetime.now ().strftime( '%Y-%m-%d %H:%M:%S' )
dct [ 'Created with Ostap version' ] = meta_info.Ostap
Expand Down
7 changes: 2 additions & 5 deletions ostap/plotting/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)
# =============================================================================
from sys import version_info as python_version
from ostap.core.ostap_types import ordered_dict
from ostap.utils.cidict import cidict
from ostap.utils.utils import KeepCanvas, keepCanvas
from ostap.core.core import cidict_fun
Expand Down Expand Up @@ -668,11 +669,7 @@ def _cnv_pads_ ( self ) :
"""`pads' : get (an ordered) dict of pads for the given canvas partition (if prepared)
"""
if not hasattr ( self , '__pads' ) :
if (3,7) <= python_version :
self.__pads = {}
else :
from collections import OrderedDict
self.__pads = OrderedDict ()
self.__pads = ordered_dict ()
return self.__pads
# =============================================================================
def _cnv_del_pads_ ( self ) :
Expand Down

0 comments on commit 5b25a07

Please sign in to comment.