@@ -104,8 +104,8 @@ def make_new_dset(
104104 else :
105105 shape = (shape ,) if isinstance (shape , int ) else tuple (shape )
106106 if data is not None and (
107- numpy .product (shape , dtype = numpy .ulonglong )
108- != numpy .product (data .shape , dtype = numpy .ulonglong )
107+ numpy .prod (shape , dtype = numpy .ulonglong )
108+ != numpy .prod (data .shape , dtype = numpy .ulonglong )
109109 ):
110110 raise ValueError ("Shape tuple is incompatible with data" )
111111
@@ -399,7 +399,6 @@ def __init__(self, dset, source_sel=None):
399399
400400 if not dset .chunks :
401401 # can only use with chunked datasets
402- # (currently all datasets are chunked, but check for future compat)
403402 raise TypeError ("Chunked dataset required" )
404403
405404 if isinstance (dset .chunks , dict ):
@@ -426,22 +425,15 @@ def __init__(self, dset, source_sel=None):
426425 for dim in range (rank ):
427426 s = self ._sel [dim ]
428427 if s .start < 0 or s .stop > self ._shape [dim ] or s .stop <= s .start :
429- raise ValueError (
430- "Invalid selection - selection region must be within dataset space"
431- )
428+ msg = "Invalid selection - selection region must be within dataset space"
429+ raise ValueError (msg )
432430 index = s .start // self ._layout [dim ]
433431 self ._chunk_index .append (index )
434432
435433 def __iter__ (self ):
436434 return self
437435
438436 def __next__ (self ):
439- def get_ret (item ):
440- if len (item ) == 1 :
441- return item [0 ]
442- else :
443- return tuple (item )
444-
445437 rank = len (self ._shape )
446438 slices = []
447439 if rank == 0 or self ._chunk_index [0 ] * self ._layout [0 ] >= self ._sel [0 ].stop :
@@ -475,7 +467,7 @@ def get_ret(item):
475467 # reset to the start and continue iterating with higher dimension
476468 self ._chunk_index [dim ] = 0
477469 dim -= 1
478- return get_ret (slices )
470+ return tuple (slices )
479471
480472
481473class Dataset (HLObject ):
@@ -910,7 +902,7 @@ def _getQueryParam(self, start, stop, step=None):
910902 step = (1 ,) * rank
911903 param += "["
912904 for i in range (rank ):
913- field = "{}:{}:{}" . format ( start [i ], stop [i ], step [i ])
905+ field = f" { start [i ]} : { stop [i ]} : { step [i ]} "
914906 param += field
915907 if i != (rank - 1 ):
916908 param += ","
@@ -973,7 +965,7 @@ def __getitem__(self, args, new_dtype=None):
973965 mshape = sel.guess_shape(sid)
974966 if mshape is None:
975967 return numpy.array((0,), dtype=new_dtype)
976- if numpy.product (mshape) == 0:
968+ if numpy.prod (mshape) == 0:
977969 return numpy.array(mshape, dtype=new_dtype)
978970 out = numpy.empty(mshape, dtype=new_dtype)
979971 sid_out = h5s.create_simple(mshape)
@@ -993,7 +985,7 @@ def __getitem__(self, args, new_dtype=None):
993985
994986 if self ._shape == ():
995987 selection = sel .select (self , args )
996- self .log .info ("selection.mshape: {}" . format ( selection .mshape ) )
988+ self .log .info (f "selection.mshape: { selection .mshape } " )
997989
998990 # TBD - refactor the following with the code for the non-scalar case
999991 req = "/datasets/" + self .id .uuid + "/value"
@@ -1006,7 +998,7 @@ def __getitem__(self, args, new_dtype=None):
1006998 arr = bytesToArray (rsp , new_dtype , self ._shape )
1007999
10081000 if not self .dtype .shape :
1009- self .log .debug ("reshape arr to: {}" . format ( self ._shape ) )
1001+ self .log .debug (f "reshape arr to: { self ._shape } " )
10101002 arr = numpy .reshape (arr , self ._shape )
10111003 else :
10121004 # got JSON response
@@ -1024,11 +1016,8 @@ def __getitem__(self, args, new_dtype=None):
10241016 arr = numpy .empty ((), dtype = new_dtype )
10251017 arr [()] = data
10261018 if selection .mshape is None :
1027- self .log .info (
1028- "return scalar selection of: {}, dtype: {}, shape: {}" .format (
1029- arr , arr .dtype , arr .shape
1030- )
1031- )
1019+ msg = f"return scalar selection of: { arr } , dtype: { arr .dtype } , shape: { arr .shape } "
1020+ self .log .info (msg )
10321021 val = arr [()]
10331022 if isinstance (val , str ):
10341023 # h5py always returns bytes, so encode the str
@@ -1308,9 +1297,7 @@ def __getitem__(self, args, new_dtype=None):
13081297 points , dtype = "u8"
13091298 ) # must use unsigned 64-bit int
13101299 body = arr_points .tobytes ()
1311- self .log .info (
1312- "point select binary request, num bytes: {}" .format (len (body ))
1313- )
1300+ self .log .info (f"point select binary request, num bytes: { len (body )} " )
13141301 else :
13151302 if delistify :
13161303 self .log .info ("delistifying point selection" )
@@ -1324,7 +1311,7 @@ def __getitem__(self, args, new_dtype=None):
13241311 else :
13251312 # can just assign
13261313 body ["points" ] = points
1327- self .log .info ("sending point selection request: {}" . format ( body ) )
1314+ self .log .info (f "sending point selection request: { body } " )
13281315 rsp = self .POST (req , format = format , body = body )
13291316 if type (rsp ) in (bytes , bytearray ):
13301317 if len (rsp ) // mtype .itemsize != selection .mshape [0 ]:
@@ -1337,18 +1324,14 @@ def __getitem__(self, args, new_dtype=None):
13371324 else :
13381325 data = rsp ["value" ]
13391326 if len (data ) != selection .mshape [0 ]:
1340- raise IOError (
1341- "Expected {} elements, but got {}" .format (
1342- selection .mshape [0 ], len (data )
1343- )
1344- )
1345-
1327+ msg = f"Expected { selection .mshape [0 ]} elements, but got { len (data )} "
1328+ raise IOError (msg )
13461329 arr = numpy .asarray (data , dtype = mtype , order = "C" )
13471330
13481331 else :
13491332 raise ValueError ("selection type not supported" )
13501333
1351- self .log .info ("got arr: {}, cleaning up shape!" . format ( arr . shape ) )
1334+ self .log .info (f "got arr: { arr . shape } , cleaning up shape!" )
13521335 # Patch up the output for NumPy
13531336 if len (names ) == 1 :
13541337 arr = arr [names [0 ]] # Single-field recarray convention
@@ -1368,7 +1351,7 @@ def __setitem__(self, args, val):
13681351 (slices and integers). For advanced indexing, the shapes must
13691352 match.
13701353 """
1371- self .log .info ("Dataset __setitem__, args: {}" . format ( args ) )
1354+ self .log .info (f "Dataset __setitem__, args: { args } " )
13721355 use_base64 = True # may need to set this to false below for some types
13731356
13741357 args = args if isinstance (args , tuple ) else (args ,)
@@ -1378,7 +1361,7 @@ def __setitem__(self, args, val):
13781361 self .log .debug (
13791362 f"val dtype: { val .dtype } , shape: { val .shape } metadata: { val .dtype .metadata } "
13801363 )
1381- if numpy .product (val .shape ) == 0 :
1364+ if numpy .prod (val .shape ) == 0 :
13821365 self .log .info ("no elements in numpy array, skipping write" )
13831366 except AttributeError :
13841367 self .log .debug ("val not ndarray" )
@@ -1428,7 +1411,7 @@ def __setitem__(self, args, val):
14281411 i
14291412 for i in val .reshape (
14301413 (
1431- numpy .product (val .shape [:- 1 ], dtype = numpy .ulonglong ),
1414+ numpy .prod (val .shape [:- 1 ], dtype = numpy .ulonglong ),
14321415 val .shape [- 1 ],
14331416 )
14341417 )
@@ -1480,7 +1463,7 @@ def __setitem__(self, args, val):
14801463 # TBD - need to handle cases where the type shape is different
14811464 self .log .debug ("got numpy array" )
14821465 if val .dtype != self .dtype and val .dtype .shape == self .dtype .shape :
1483- self .log .info ("converting {} to {}" . format ( val . dtype , self .dtype ) )
1466+ self .log .info (f "converting { val . dtype } to { self .dtype } " )
14841467 # convert array
14851468 tmp = numpy .empty (val .shape , dtype = self .dtype )
14861469 tmp [...] = val [...]
@@ -1584,15 +1567,13 @@ def __setitem__(self, args, val):
15841567 data = val .tobytes ()
15851568 data = base64 .b64encode (data )
15861569 data = data .decode ("ascii" )
1587- self .log .debug ("data: {}" .format (data ))
15881570 body ["value_base64" ] = data
1589- self .log .debug ("writing base64 data, {} bytes" . format ( len (data )) )
1571+ self .log .debug (f "writing base64 data, { len (data )} bytes" )
15901572 else :
15911573 if type (val ) is not list :
15921574 val = val .tolist ()
15931575 val = _decode (val )
1594- self .log .debug ("writing json data, {} elements" .format (len (val )))
1595- self .log .debug ("data: {}" .format (val ))
1576+ self .log .debug (f"writing json data, { len (val )} elements" )
15961577 body ["value" ] = val
15971578
15981579 if selection .select_type != sel .H5S_SELECT_ALL :
@@ -1702,7 +1683,7 @@ def __array__(self, dtype=None):
17021683 arr = numpy .empty (self ._shape , dtype = self .dtype if dtype is None else dtype )
17031684
17041685 # Special case for (0,)*-shape datasets
1705- if self ._shape is None or numpy .product (self ._shape ) == 0 :
1686+ if self ._shape is None or numpy .prod (self ._shape ) == 0 :
17061687 return arr
17071688
17081689 self .read_direct (arr )
0 commit comments