sqlutilpy 0.25.0__tar.gz → 0.26.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlutilpy
3
- Version: 0.25.0
3
+ Version: 0.26.0
4
4
  Summary: Database query code returning numpy arrays
5
5
  Author-email: "Sergey E. Koposov" <skoposov@ed.ac.uk>
6
6
  License: BSD
@@ -44,11 +44,11 @@ pip install sqlutilpy
44
44
  Throughout this readme, I will assume that if you are using PostgreSQL, then
45
45
  the .pgpass file ( https://www.postgresql.org/docs/11/libpq-pgpass.html )
46
46
  has been created with your login/password details for Postgresql. If that is not the case, many of the
47
- commands given below will also need user='....' and password='...' options
47
+ commands given below will also need user='....' and password='...' options.
48
48
 
49
49
  ## Connection information
50
50
 
51
- Most of the sqlutilpy commands require hostname, database name, user etc.
51
+ Most of the `sqlutilpy` commands require hostname, database name.
52
52
  If you don't want to always type it, you can use standard PostgreSQL environment variables
53
53
  like PGPORT, PGDATABASE, PGUSER, PGHOST for the port, database name, user name and hostname
54
54
  of the connection.
@@ -56,7 +56,8 @@ of the connection.
56
56
 
57
57
  ## Querying the database and retrieving the results
58
58
 
59
- This command will run the query and put the columns into variables ra,dec
59
+ This command will run the query and put the columns into variables ra,dec:
60
+
60
61
  ```python
61
62
  import sqlutilpy
62
63
  ra,dec = squtilpy.get('select ra,dec from mytable',
@@ -64,23 +65,28 @@ ra,dec = squtilpy.get('select ra,dec from mytable',
64
65
  db='THE_NAME_OF_MY_DB')
65
66
  ```
66
67
 
67
- By default sqlutilpy.get executes the query and returns the tuple with
68
- results. You can return the results as dictionary using asDict option.
68
+ By default `sqlutilpy.get` executes the query and returns the tuple with
69
+ arrays. One array for each column in the query result.
70
+ You can return the results as dictionary using `asDict` option.
69
71
 
70
72
  ## Uploading your arrays as column in a table
71
73
 
74
+ You can use `sqlutilpy.upload` to upload your arrays as columns in a table.
75
+
72
76
  ```python
73
77
  x = np.arange(10)
74
78
  y = x**.5
75
79
  sqlutilpy.upload('mytable',(x,y),('xcol','ycol'))
76
80
  ```
77
- This will create a table called mytable with columns xcol and ycol
81
+ This will create a table called `mytable` with columns `xcol` and `ycol`
78
82
 
79
83
  ## Join query involving your local data and the database table
80
84
 
81
- Imagine you have arrays myid and y and you want to to extract all the
82
- information from somebigtable for objects with id=myid. In principle
83
- you could upload the arrays in the DB and run a query, but local_join function does that for you.
85
+ Sometimes it is beneficial to run a join query involving your local data and the data in the database.
86
+
87
+ Imagine you have arrays `myid` and `y` and you want to extract all the
88
+ information from `somebigtable` for objects with `id=myid`. In principle,
89
+ you could upload the arrays in the DB and run a query, but `local_join` function does that for you.
84
90
 
85
91
  ```python
86
92
  myid = np.arange(10)
@@ -91,15 +97,14 @@ R=sqlutilpy.local_join('''select * from mytmptable as m,
91
97
  'mytmptable',(myid, y),('myid','ycol'))
92
98
  ```
93
99
 
94
- It executes a query as if you arrays were in mytmptable. (behind the scenes
95
- it uploads the data to the db and runs a query)
100
+ It executes a query as if your arrays were in `mytmptable`. What happens behind the scenes
101
+ is that it uploads the data to the database and runs a query against it.
96
102
 
97
103
  ## Keeping the connection open.
98
104
 
99
105
  Often it is beneficial to preserve an open connection to the database. You can do that if you first
100
- obtain the connection using sqlutilpy.getConnection() and then provide it directly
101
- to sqlutil.get() and friends using conn=conn argument
102
- ```python
106
+ obtain the connection using `sqlutilpy.getConnection()` and then provide it directly
107
+ to `sqlutil.get()` and similar commands using `conn=` keyword:
103
108
  conn = sqlutilpy.getConnection(db='mydb', user='meuser', password='something', host='hostname')
104
109
  R= sqlutilpy.get('select 1', conn=conn)
105
110
  R1= sqlutilpy.get('select 1', conn=conn)
@@ -107,5 +112,5 @@ R1= sqlutilpy.get('select 1', conn=conn)
107
112
 
108
113
  # How to cite the software
109
114
 
110
- If you use this package, please cite it through zenodo https://doi.org/10.5281/zenodo.6867957
115
+ If you use this package, please cite it through Zenodo https://doi.org/10.5281/zenodo.5160118
111
116
 
@@ -24,11 +24,11 @@ pip install sqlutilpy
24
24
  Throughout this readme, I will assume that if you are using PostgreSQL, then
25
25
  the .pgpass file ( https://www.postgresql.org/docs/11/libpq-pgpass.html )
26
26
  has been created with your login/password details for Postgresql. If that is not the case, many of the
27
- commands given below will also need user='....' and password='...' options
27
+ commands given below will also need user='....' and password='...' options.
28
28
 
29
29
  ## Connection information
30
30
 
31
- Most of the sqlutilpy commands require hostname, database name, user etc.
31
+ Most of the `sqlutilpy` commands require hostname, database name.
32
32
  If you don't want to always type it, you can use standard PostgreSQL environment variables
33
33
  like PGPORT, PGDATABASE, PGUSER, PGHOST for the port, database name, user name and hostname
34
34
  of the connection.
@@ -36,7 +36,8 @@ of the connection.
36
36
 
37
37
  ## Querying the database and retrieving the results
38
38
 
39
- This command will run the query and put the columns into variables ra,dec
39
+ This command will run the query and put the columns into variables ra,dec:
40
+
40
41
  ```python
41
42
  import sqlutilpy
42
43
  ra,dec = squtilpy.get('select ra,dec from mytable',
@@ -44,23 +45,28 @@ ra,dec = squtilpy.get('select ra,dec from mytable',
44
45
  db='THE_NAME_OF_MY_DB')
45
46
  ```
46
47
 
47
- By default sqlutilpy.get executes the query and returns the tuple with
48
- results. You can return the results as dictionary using asDict option.
48
+ By default `sqlutilpy.get` executes the query and returns the tuple with
49
+ arrays. One array for each column in the query result.
50
+ You can return the results as dictionary using `asDict` option.
49
51
 
50
52
  ## Uploading your arrays as column in a table
51
53
 
54
+ You can use `sqlutilpy.upload` to upload your arrays as columns in a table.
55
+
52
56
  ```python
53
57
  x = np.arange(10)
54
58
  y = x**.5
55
59
  sqlutilpy.upload('mytable',(x,y),('xcol','ycol'))
56
60
  ```
57
- This will create a table called mytable with columns xcol and ycol
61
+ This will create a table called `mytable` with columns `xcol` and `ycol`
58
62
 
59
63
  ## Join query involving your local data and the database table
60
64
 
61
- Imagine you have arrays myid and y and you want to to extract all the
62
- information from somebigtable for objects with id=myid. In principle
63
- you could upload the arrays in the DB and run a query, but local_join function does that for you.
65
+ Sometimes it is beneficial to run a join query involving your local data and the data in the database.
66
+
67
+ Imagine you have arrays `myid` and `y` and you want to extract all the
68
+ information from `somebigtable` for objects with `id=myid`. In principle,
69
+ you could upload the arrays in the DB and run a query, but `local_join` function does that for you.
64
70
 
65
71
  ```python
66
72
  myid = np.arange(10)
@@ -71,15 +77,14 @@ R=sqlutilpy.local_join('''select * from mytmptable as m,
71
77
  'mytmptable',(myid, y),('myid','ycol'))
72
78
  ```
73
79
 
74
- It executes a query as if you arrays were in mytmptable. (behind the scenes
75
- it uploads the data to the db and runs a query)
80
+ It executes a query as if your arrays were in `mytmptable`. What happens behind the scenes
81
+ is that it uploads the data to the database and runs a query against it.
76
82
 
77
83
  ## Keeping the connection open.
78
84
 
79
85
  Often it is beneficial to preserve an open connection to the database. You can do that if you first
80
- obtain the connection using sqlutilpy.getConnection() and then provide it directly
81
- to sqlutil.get() and friends using conn=conn argument
82
- ```python
86
+ obtain the connection using `sqlutilpy.getConnection()` and then provide it directly
87
+ to `sqlutil.get()` and similar commands using `conn=` keyword:
83
88
  conn = sqlutilpy.getConnection(db='mydb', user='meuser', password='something', host='hostname')
84
89
  R= sqlutilpy.get('select 1', conn=conn)
85
90
  R1= sqlutilpy.get('select 1', conn=conn)
@@ -87,5 +92,5 @@ R1= sqlutilpy.get('select 1', conn=conn)
87
92
 
88
93
  # How to cite the software
89
94
 
90
- If you use this package, please cite it through zenodo https://doi.org/10.5281/zenodo.6867957
95
+ If you use this package, please cite it through Zenodo https://doi.org/10.5281/zenodo.5160118
91
96
 
@@ -7,7 +7,6 @@ import psycopg
7
7
  import threading
8
8
  import collections
9
9
  import warnings
10
- from numpy.core import numeric as sb
11
10
 
12
11
  try:
13
12
  import astropy.table as atpy
@@ -140,9 +139,9 @@ def __fromrecords(recList, dtype=None, intNullVal=None):
140
139
  """
141
140
 
142
141
  shape = None
143
- descr = sb.dtype((np.record, dtype))
142
+ descr = np.dtype((np.record, dtype))
144
143
  try:
145
- retval = sb.array(recList, dtype=descr)
144
+ retval = np.array(recList, dtype=descr)
146
145
  except TypeError: # list of lists instead of list of tuples
147
146
  shape = (len(recList), )
148
147
  _array = np.recarray(shape, descr)
@@ -411,7 +410,8 @@ def get(query,
411
410
  proc.join(0.2)
412
411
  # in the converter process
413
412
  if proc.is_alive():
414
- proc.terminate()
413
+ # could not kill
414
+ pass
415
415
  raise
416
416
  if proc is not None:
417
417
  proc.join()
@@ -739,7 +739,7 @@ table/pandas/dictionary or provide a separate list of arrays and their names')
739
739
  cur.execute(query1)
740
740
  nsplit = 100000
741
741
  N = len(arrays[0])
742
- names = ','.join(names)
742
+ names = ','.join(['"%s"' % _ for _ in names])
743
743
  for i in range(0, N, nsplit):
744
744
  try:
745
745
  with cur.copy(f'''copy {tableName}({names}) from stdin
@@ -0,0 +1 @@
1
+ __version__ = '0.26.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlutilpy
3
- Version: 0.25.0
3
+ Version: 0.26.0
4
4
  Summary: Database query code returning numpy arrays
5
5
  Author-email: "Sergey E. Koposov" <skoposov@ed.ac.uk>
6
6
  License: BSD
@@ -44,11 +44,11 @@ pip install sqlutilpy
44
44
  Throughout this readme, I will assume that if you are using PostgreSQL, then
45
45
  the .pgpass file ( https://www.postgresql.org/docs/11/libpq-pgpass.html )
46
46
  has been created with your login/password details for Postgresql. If that is not the case, many of the
47
- commands given below will also need user='....' and password='...' options
47
+ commands given below will also need user='....' and password='...' options.
48
48
 
49
49
  ## Connection information
50
50
 
51
- Most of the sqlutilpy commands require hostname, database name, user etc.
51
+ Most of the `sqlutilpy` commands require hostname, database name.
52
52
  If you don't want to always type it, you can use standard PostgreSQL environment variables
53
53
  like PGPORT, PGDATABASE, PGUSER, PGHOST for the port, database name, user name and hostname
54
54
  of the connection.
@@ -56,7 +56,8 @@ of the connection.
56
56
 
57
57
  ## Querying the database and retrieving the results
58
58
 
59
- This command will run the query and put the columns into variables ra,dec
59
+ This command will run the query and put the columns into variables ra,dec:
60
+
60
61
  ```python
61
62
  import sqlutilpy
62
63
  ra,dec = squtilpy.get('select ra,dec from mytable',
@@ -64,23 +65,28 @@ ra,dec = squtilpy.get('select ra,dec from mytable',
64
65
  db='THE_NAME_OF_MY_DB')
65
66
  ```
66
67
 
67
- By default sqlutilpy.get executes the query and returns the tuple with
68
- results. You can return the results as dictionary using asDict option.
68
+ By default `sqlutilpy.get` executes the query and returns the tuple with
69
+ arrays. One array for each column in the query result.
70
+ You can return the results as dictionary using `asDict` option.
69
71
 
70
72
  ## Uploading your arrays as column in a table
71
73
 
74
+ You can use `sqlutilpy.upload` to upload your arrays as columns in a table.
75
+
72
76
  ```python
73
77
  x = np.arange(10)
74
78
  y = x**.5
75
79
  sqlutilpy.upload('mytable',(x,y),('xcol','ycol'))
76
80
  ```
77
- This will create a table called mytable with columns xcol and ycol
81
+ This will create a table called `mytable` with columns `xcol` and `ycol`
78
82
 
79
83
  ## Join query involving your local data and the database table
80
84
 
81
- Imagine you have arrays myid and y and you want to to extract all the
82
- information from somebigtable for objects with id=myid. In principle
83
- you could upload the arrays in the DB and run a query, but local_join function does that for you.
85
+ Sometimes it is beneficial to run a join query involving your local data and the data in the database.
86
+
87
+ Imagine you have arrays `myid` and `y` and you want to extract all the
88
+ information from `somebigtable` for objects with `id=myid`. In principle,
89
+ you could upload the arrays in the DB and run a query, but `local_join` function does that for you.
84
90
 
85
91
  ```python
86
92
  myid = np.arange(10)
@@ -91,15 +97,14 @@ R=sqlutilpy.local_join('''select * from mytmptable as m,
91
97
  'mytmptable',(myid, y),('myid','ycol'))
92
98
  ```
93
99
 
94
- It executes a query as if you arrays were in mytmptable. (behind the scenes
95
- it uploads the data to the db and runs a query)
100
+ It executes a query as if your arrays were in `mytmptable`. What happens behind the scenes
101
+ is that it uploads the data to the database and runs a query against it.
96
102
 
97
103
  ## Keeping the connection open.
98
104
 
99
105
  Often it is beneficial to preserve an open connection to the database. You can do that if you first
100
- obtain the connection using sqlutilpy.getConnection() and then provide it directly
101
- to sqlutil.get() and friends using conn=conn argument
102
- ```python
106
+ obtain the connection using `sqlutilpy.getConnection()` and then provide it directly
107
+ to `sqlutil.get()` and similar commands using `conn=` keyword:
103
108
  conn = sqlutilpy.getConnection(db='mydb', user='meuser', password='something', host='hostname')
104
109
  R= sqlutilpy.get('select 1', conn=conn)
105
110
  R1= sqlutilpy.get('select 1', conn=conn)
@@ -107,5 +112,5 @@ R1= sqlutilpy.get('select 1', conn=conn)
107
112
 
108
113
  # How to cite the software
109
114
 
110
- If you use this package, please cite it through zenodo https://doi.org/10.5281/zenodo.6867957
115
+ If you use this package, please cite it through Zenodo https://doi.org/10.5281/zenodo.5160118
111
116
 
@@ -340,12 +340,12 @@ def test_upload(setup):
340
340
  'xi32': xi32,
341
341
  'xi64': xi64,
342
342
  'xf32': xf32,
343
- 'xf64': xf64,
343
+ 'XF64': xf64, # one uppercase
344
344
  'xbool': xbool
345
345
  })
346
346
  sqlutil.upload(mytab, astroTab, **kw)
347
347
  yi16, yi32, yi64, yf32, yf64, ybool = sqlutil.get(
348
- '''select xi16,xi32,xi64,xf32,xf64,xbool from %s''' % (mytab), **kw)
348
+ '''select xi16,xi32,xi64,xf32,"XF64",xbool from %s''' % (mytab), **kw)
349
349
  try:
350
350
  assert ((xi16 == yi16).all())
351
351
  assert ((xi32 == yi32).all())
@@ -357,7 +357,7 @@ def test_upload(setup):
357
357
  sqlutil.execute('drop table %s' % mytab, **kw)
358
358
  sqlutil.upload(mytab, astroTab.to_pandas(), **kw)
359
359
  yi16, yi32, yi64, yf32, yf64, ybool = sqlutil.get(
360
- '''select xi16,xi32,xi64,xf32,xf64,xbool from %s''' % (mytab), **kw)
360
+ '''select xi16,xi32,xi64,xf32,"XF64",xbool from %s''' % (mytab), **kw)
361
361
  try:
362
362
  assert ((xi16 == yi16).all())
363
363
  assert ((xi32 == yi32).all())
@@ -1 +0,0 @@
1
- __version__ = '0.25.0'
File without changes
File without changes
File without changes
File without changes
File without changes