Skip to content

Commit 916d13b

Browse files
committed
Refactoring: formatting, print statements
1 parent 6e8b524 commit 916d13b

File tree

15 files changed

+203
-203
lines changed

15 files changed

+203
-203
lines changed

qpython/_pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _write_pandas_data_frame(self, data, qtype = None):
183183
self._buffer.write(struct.pack('=bxi', QGENERAL_LIST, len(index_columns)))
184184
for column in index_columns:
185185
self._write_pandas_series(data[column], qtype = data.meta[column] if hasattr(data, 'meta') else None)
186-
186+
187187
data.set_index(index_columns, inplace = True)
188188

189189
self._buffer.write(struct.pack('=bxb', QTABLE, QDICTIONARY))
@@ -198,4 +198,4 @@ def _write_generic_list(self, data):
198198
self._buffer.write(struct.pack('=bxi', QGENERAL_LIST, len(data)))
199199
for element in data:
200200
# assume nan represents a string null
201-
self._write(' ' if type(element) in [float, numpy.float32, numpy.float64] and numpy.isnan(element) else element)
201+
self._write(' ' if type(element) in [float, numpy.float32, numpy.float64] and numpy.isnan(element) else element)

qpython/qcollection.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def raw(self, idx):
5454
index.
5555
5656
>>> t = qlist(numpy.array([366, 121, qnull(QDATE)]), qtype=QDATE_LIST)
57-
>>> print t[0]
57+
>>> print(t[0])
5858
2001-01-01 [metadata(qtype=-14)]
59-
>>> print t.raw(0)
59+
>>> print(t.raw(0))
6060
366
6161
6262
:Parameters:
@@ -121,31 +121,31 @@ def qlist(array, adjust_dtype = True, **meta):
121121
- `byte numpy.array`:
122122
123123
>>> v = qlist(numpy.array([0x01, 0x02, 0xff], dtype=numpy.byte))
124-
>>> print '%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v)
124+
>>> print('%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v))
125125
<class 'qpython.qcollection.QList'> dtype: int8 qtype: -4: [ 1 2 -1]
126126
127127
- `int32 numpy.array` with explicit conversion to `QBYTE_LIST`:
128128
129129
>>> v = qlist(numpy.array([1, 2, -1]), qtype = QBYTE_LIST)
130-
>>> print '%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v)
130+
>>> print('%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v))
131131
<class 'qpython.qcollection.QList'> dtype: int8 qtype: -4: [ 1 2 -1]
132132
133133
- plain Python `integer` list with explicit conversion to `QBYTE_LIST`:
134134
135135
>>> v = qlist([1, 2, -1], qtype = QBYTE_LIST)
136-
>>> print '%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v)
136+
>>> print('%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v))
137137
<class 'qpython.qcollection.QList'> dtype: int8 qtype: -4: [ 1 2 -1]
138138
139139
- numpy datetime64 array with implicit conversion to `QDATE_LIST`:
140140
141141
>>> v = qlist(numpy.array([numpy.datetime64('2001-01-01'), numpy.datetime64('2000-05-01'), numpy.datetime64('NaT')], dtype='datetime64[D]'))
142-
>>> print '%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v)
142+
>>> print('%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v))
143143
<class 'qpython.qcollection.QList'> dtype: datetime64[D] qtype: -14: ['2001-01-01' '2000-05-01' 'NaT']
144144
145145
- numpy datetime64 array with explicit conversion to `QDATE_LIST`:
146146
147147
>>> v = qlist(numpy.array([numpy.datetime64('2001-01-01'), numpy.datetime64('2000-05-01'), numpy.datetime64('NaT')], dtype='datetime64[D]'), qtype = QDATE_LIST)
148-
>>> print '%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v)
148+
>>> print('%s dtype: %s qtype: %d: %s' % (type(v), v.dtype, v.meta.qtype, v))
149149
<class 'qpython.qcollection.QList'> dtype: datetime64[D] qtype: -14: ['2001-01-01' '2000-05-01' 'NaT']
150150
151151
@@ -171,7 +171,7 @@ def qlist(array, adjust_dtype = True, **meta):
171171
for i in xrange(len(array)):
172172
tarray[i] = array[i]
173173
array = tarray
174-
else:
174+
else:
175175
array = numpy.array(array)
176176

177177
if not isinstance(array, numpy.ndarray):
@@ -203,13 +203,13 @@ class QDictionary(object):
203203
Dictionary examples:
204204
205205
>>> # q: 1 2!`abc`cdefgh
206-
>>> print QDictionary(qlist(numpy.array([1, 2], dtype=numpy.int64), qtype=QLONG_LIST),
207-
... qlist(numpy.array(['abc', 'cdefgh']), qtype = QSYMBOL_LIST))
206+
>>> print(QDictionary(qlist(numpy.array([1, 2], dtype=numpy.int64), qtype=QLONG_LIST),
207+
... qlist(numpy.array(['abc', 'cdefgh']), qtype = QSYMBOL_LIST)))
208208
[1 2]!['abc' 'cdefgh']
209209
210210
>>> # q: (1;2h;3.234;"4")!(`one;2 3;"456";(7;8 9))
211-
>>> print QDictionary([numpy.int64(1), numpy.int16(2), numpy.float64(3.234), '4'],
212-
... [numpy.string_('one'), qlist(numpy.array([2, 3]), qtype=QLONG_LIST), '456', [numpy.int64(7), qlist(numpy.array([8, 9]), qtype=QLONG_LIST)]])
211+
>>> print(QDictionary([numpy.int64(1), numpy.int16(2), numpy.float64(3.234), '4'],
212+
... [numpy.string_('one'), qlist(numpy.array([2, 3]), qtype=QLONG_LIST), '456', [numpy.int64(7), qlist(numpy.array([8, 9]), qtype=QLONG_LIST)]]))
213213
[1, 2, 3.234, '4']!['one', QList([2, 3], dtype=int64), '456', [7, QList([8, 9], dtype=int64)]]
214214
215215
:Parameters:
@@ -320,22 +320,22 @@ def qtable(columns, data, **meta):
320320
>>> t = qtable(qlist(numpy.array(['name', 'iq']), qtype = QSYMBOL_LIST),
321321
... [qlist(numpy.array(['Dent', 'Beeblebrox', 'Prefect'])),
322322
... qlist(numpy.array([98, 42, 126], dtype=numpy.int64))])
323-
>>> print '%s dtype: %s meta: %s: %s' % (type(t), t.dtype, t.meta, t)
323+
>>> print('%s dtype: %s meta: %s: %s' % (type(t), t.dtype, t.meta, t))
324324
<class 'qpython.qcollection.QTable'> dtype: [('name', 'S10'), ('iq', '<i8')] meta: metadata(iq=-7, qtype=98, name=-11): [('Dent', 98L) ('Beeblebrox', 42L) ('Prefect', 126L)]
325325
326326
>>> # q: flip `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)
327327
>>> t = qtable(qlist(numpy.array(['name', 'iq']), qtype = QSYMBOL_LIST),
328328
... [qlist(['Dent', 'Beeblebrox', 'Prefect'], qtype = QSYMBOL_LIST),
329329
... qlist([98, 42, 126], qtype = QLONG_LIST)])
330-
>>> print '%s dtype: %s meta: %s: %s' % (type(t), t.dtype, t.meta, t)
330+
>>> print('%s dtype: %s meta: %s: %s' % (type(t), t.dtype, t.meta, t))
331331
<class 'qpython.qcollection.QTable'> dtype: [('name', 'S10'), ('iq', '<i8')] meta: metadata(iq=-7, qtype=98, name=-11): [('Dent', 98L) ('Beeblebrox', 42L) ('Prefect', 126L)]
332332
333333
>>> # q: flip `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)
334334
>>> t = qtable(['name', 'iq'],
335335
... [['Dent', 'Beeblebrox', 'Prefect'],
336336
... [98, 42, 126]],
337337
... name = QSYMBOL, iq = QLONG)
338-
>>> print '%s dtype: %s meta: %s: %s' % (type(t), t.dtype, t.meta, t)
338+
>>> print('%s dtype: %s meta: %s: %s' % (type(t), t.dtype, t.meta, t))
339339
<class 'qpython.qcollection.QTable'> dtype: [('name', 'S10'), ('iq', '<i8')] meta: metadata(iq=-7, qtype=98, name=-11): [('Dent', 98L) ('Beeblebrox', 42L) ('Prefect', 126L)]
340340
341341
>>> # q: flip `name`iq`fullname!(`Dent`Beeblebrox`Prefect;98 42 126;("Arthur Dent"; "Zaphod Beeblebrox"; "Ford Prefect"))
@@ -377,7 +377,7 @@ def qtable(columns, data, **meta):
377377
data[i] = qlist(data[i], qtype = QGENERAL_LIST)
378378
else:
379379
data[i] = qlist(data[i])
380-
380+
381381
meta[columns[i]] = data[i].meta.qtype
382382
dtypes.append((columns[i], data[i].dtype))
383383

@@ -403,9 +403,9 @@ class QKeyedTable(object):
403403
... qtable(['pos', 'dates'],
404404
... [qlist(numpy.array(['d1', 'd2', 'd3']), qtype = QSYMBOL_LIST),
405405
... qlist(numpy.array([366, 121, qnull(QDATE)]), qtype = QDATE_LIST)]))
406-
>>> print '%s: %s' % (type(t), t)
407-
>>> print '%s dtype: %s meta: %s' % (type(t.keys), t.keys.dtype, t.keys.meta)
408-
>>> print '%s dtype: %s meta: %s' % (type(t.values), t.values.dtype, t.values.meta)
406+
>>> print('%s: %s' % (type(t), t))
407+
>>> print('%s dtype: %s meta: %s' % (type(t.keys), t.keys.dtype, t.keys.meta))
408+
>>> print('%s dtype: %s meta: %s' % (type(t.values), t.values.dtype, t.values.meta))
409409
<class 'qpython.qcollection.QKeyedTable'>: [(1001L,) (1002L,) (1003L,)]![('d1', 366) ('d2', 121) ('d3', -2147483648)]
410410
<class 'qpython.qcollection.QTable'> dtype: [('eid', '<i8')] meta: metadata(qtype=98, eid=-7)
411411
<class 'qpython.qcollection.QTable'> dtype: [('pos', 'S2'), ('dates', '<i4')] meta: metadata(dates=-14, qtype=98, pos=-11)

qpython/qconnection.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class QConnection(object):
5252
used with a ``with`` statement::
5353
5454
with qconnection.QConnection(host = 'localhost', port = 5000) as q:
55-
print q
56-
print q('{`int$ til x}', 10)
55+
print(q)
56+
print(q('{`int$ til x}', 10))
5757
5858
:Parameters:
5959
- `host` (`string`) - q service hostname
@@ -222,27 +222,27 @@ def sync(self, query, *parameters, **options):
222222
223223
Executes a q expression:
224224
225-
>>> print q.sync('til 10')
225+
>>> print(q.sync('til 10'))
226226
[0 1 2 3 4 5 6 7 8 9]
227227
228228
Executes an anonymous q function with a single parameter:
229229
230-
>>> print q.sync('{til x}', 10)
230+
>>> print(q.sync('{til x}', 10))
231231
[0 1 2 3 4 5 6 7 8 9]
232232
233233
Executes an anonymous q function with two parameters:
234234
235-
>>> print q.sync('{y + til x}', 10, 1)
235+
>>> print(q.sync('{y + til x}', 10, 1))
236236
[ 1 2 3 4 5 6 7 8 9 10]
237237
238-
>>> print q.sync('{y + til x}', *[10, 1])
238+
>>> print(q.sync('{y + til x}', *[10, 1]))
239239
[ 1 2 3 4 5 6 7 8 9 10]
240240
241241
The :func:`.sync` is called from the overloaded :func:`.__call__`
242242
function. This allows :class:`.QConnection` instance to be called as
243243
a function:
244244
245-
>>> print q('{y + til x}', 10, 1)
245+
>>> print(q('{y + til x}', 10, 1))
246246
[ 1 2 3 4 5 6 7 8 9 10]
247247
248248
@@ -304,20 +304,20 @@ def receive(self, data_only = True, **options):
304304
Retrieves query result along with meta-information:
305305
306306
>>> q.query(qconnection.MessageType.SYNC,'{x}', 10)
307-
>>> print q.receive(data_only = False, raw = False)
307+
>>> print(q.receive(data_only = False, raw = False))
308308
QMessage: message type: 2, data size: 13, is_compressed: False, data: 10
309309
310310
Retrieves parsed query result:
311311
312312
>>> q.query(qconnection.MessageType.SYNC,'{x}', 10)
313-
>>> print q.receive(data_only = True, raw = False)
313+
>>> print(q.receive(data_only = True, raw = False))
314314
10
315315
316316
Retrieves not-parsed (raw) query result:
317317
318318
>>> from binascii import hexlify
319319
>>> q.query(qconnection.MessageType.SYNC,'{x}', 10)
320-
>>> print hexlify(q.receive(data_only = True, raw = True))
320+
>>> print(hexlify(q.receive(data_only = True, raw = True)))
321321
fa0a000000
322322
323323
:Parameters:

qpython/qtemporal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def array_from_raw_qtemporal(raw, qtype):
148148
Examples:
149149
150150
>>> raw = numpy.array([366, 121, qnull(QDATE)])
151-
>>> print array_from_raw_qtemporal(raw, qtype = QDATE)
151+
>>> print(array_from_raw_qtemporal(raw, qtype = QDATE))
152152
['2001-01-01' '2000-05-01' 'NaT']
153153
154154
:Parameters:
@@ -185,7 +185,7 @@ def array_to_raw_qtemporal(array, qtype):
185185
Examples:
186186
187187
>>> na_dt = numpy.arange('1999-01-01', '2005-12-31', dtype='datetime64[D]')
188-
>>> print array_to_raw_qtemporal(na_dt, qtype = QDATE_LIST)
188+
>>> print(array_to_raw_qtemporal(na_dt, qtype = QDATE_LIST))
189189
[-365 -364 -363 ..., 2188 2189 2190]
190190
>>> array_to_raw_qtemporal(numpy.arange(-20, 30, dtype='int32'), qtype = QDATE_LIST)
191191
Traceback (most recent call last):

qpython/qtype.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
#
1+
#
22
# Copyright (c) 2011-2014 Exxeleron GmbH
3-
#
3+
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
66
# You may obtain a copy of the License at
7-
#
7+
#
88
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
9+
#
1010
# Unless required by applicable law or agreed to in writing, software
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#
15+
#
1616

1717
'''
1818
The `qpython.qtype` module defines number of utility function which help to work
@@ -152,15 +152,15 @@
152152

153153

154154

155-
ATOM_SIZE = ( 0, 1, 16, 0, 1, 2, 4, 8, 4, 8, 1, 0, 8, 4, 4, 8, 8, 4, 4, 4 )
155+
ATOM_SIZE = (0, 1, 16, 0, 1, 2, 4, 8, 4, 8, 1, 0, 8, 4, 4, 8, 8, 4, 4, 4)
156156

157157

158158

159-
# mapping of q atoms to corresponding Python types
159+
# mapping of q atoms to corresponding Python types
160160
PY_TYPE = {
161161
QBOOL: numpy.bool_,
162162
QBYTE: numpy.byte,
163-
QGUID: numpy.object_,
163+
QGUID: numpy.object_,
164164
QSHORT: numpy.int16,
165165
QINT: numpy.int32,
166166
QLONG: numpy.int64,
@@ -181,7 +181,7 @@
181181
}
182182

183183

184-
# mapping of Python types to corresponding q atoms
184+
# mapping of Python types to corresponding q atoms
185185
Q_TYPE = {
186186
bool : QBOOL,
187187
numpy.bool : QBOOL,
@@ -233,12 +233,12 @@
233233
QSHORT: 'h',
234234
QINT: 'i',
235235
QLONG: 'q',
236-
QFLOAT: 'f',
237-
QDOUBLE: 'd',
236+
QFLOAT: 'f',
237+
QDOUBLE: 'd',
238238
QSTRING: 's',
239239
QSYMBOL: 'S',
240240
QCHAR: 'b',
241-
241+
242242
QMONTH: 'i',
243243
QDATE: 'i',
244244
QDATETIME: 'd',
@@ -251,12 +251,12 @@
251251

252252

253253
# null definitions
254-
_QNULL1 = numpy.int8(-2**7)
255-
_QNULL2 = numpy.int16(-2**15)
256-
_QNULL4 = numpy.int32(-2**31)
257-
_QNULL8 = numpy.int64(-2**63)
258-
_QNAN32 = numpy.fromstring('\x00\x00\xc0\x7f', dtype=numpy.float32)[0]
259-
_QNAN64 = numpy.fromstring('\x00\x00\x00\x00\x00\x00\xf8\x7f', dtype=numpy.float64)[0]
254+
_QNULL1 = numpy.int8(-2 ** 7)
255+
_QNULL2 = numpy.int16(-2 ** 15)
256+
_QNULL4 = numpy.int32(-2 ** 31)
257+
_QNULL8 = numpy.int64(-2 ** 63)
258+
_QNAN32 = numpy.fromstring('\x00\x00\xc0\x7f', dtype = numpy.float32)[0]
259+
_QNAN64 = numpy.fromstring('\x00\x00\x00\x00\x00\x00\xf8\x7f', dtype = numpy.float64)[0]
260260
_QNULL_BOOL = numpy.bool_(False)
261261
_QNULL_SYM = numpy.string_('')
262262
_QNULL_GUID = uuid.UUID('00000000-0000-0000-0000-000000000000')
@@ -318,7 +318,7 @@ class QException(Exception):
318318

319319
class QFunction(object):
320320
'''Represents a q function.'''
321-
321+
322322
def __init__(self, qtype):
323323
self.qtype = qtype
324324

@@ -329,7 +329,7 @@ def __str__(self):
329329

330330

331331
class QLambda(QFunction):
332-
332+
333333
'''Represents a q lambda expression.
334334
335335
.. note:: `expression` is trimmed and required to be valid q function
@@ -342,15 +342,15 @@ class QLambda(QFunction):
342342
'''
343343
def __init__(self, expression):
344344
QFunction.__init__(self, QLAMBDA)
345-
345+
346346
if not expression:
347347
raise ValueError('Lambda expression cannot be None or empty')
348-
348+
349349
expression = expression.strip()
350-
350+
351351
if not QLambda._EXPRESSION_REGEX.match(expression):
352352
raise ValueError('Invalid lambda expression: %s' % expression)
353-
353+
354354
self.expression = expression
355355

356356

@@ -367,31 +367,31 @@ def __eq__(self, other):
367367

368368

369369
class QProjection(QFunction):
370-
370+
371371
'''Represents a q projection.
372372
373373
:Parameters:
374374
- `parameters` (`list`) - list of parameters for lambda expression
375375
'''
376376
def __init__(self, parameters):
377377
QFunction.__init__(self, QPROJECTION)
378-
378+
379379
self.parameters = parameters
380380

381-
381+
382382
def __str__(self):
383383
parameters_str = []
384384
for arg in self.parameters:
385385
parameters_str.append('%s' % arg)
386-
386+
387387
return '%s(%s)' % (self.__class__.__name__, ', '.join(parameters_str))
388388

389389

390390
def __eq__(self, other):
391391
return (not self.parameters and not other.parameters) or \
392-
reduce(lambda v1,v2: v1 or v2, map(lambda v: v in self.parameters, other.parameters))
392+
reduce(lambda v1, v2: v1 or v2, map(lambda v: v in self.parameters, other.parameters))
393+
393394

394-
395395
def __ne__(self, other):
396396
return not self.__eq__(other)
397397

0 commit comments

Comments
 (0)