Skip to content

Commit

Permalink
Merge pull request #6905 from cpcloud/query-doc
Browse files Browse the repository at this point in the history
DOC: note about query strings in HDFStore selection
  • Loading branch information
cpcloud committed Apr 17, 2014
2 parents f30278e + f8becdd commit 39b9f79
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,37 @@ The right-hand side of the sub-expression (after a comparsion operator) can be:
- lists, e.g. ``"['A','B']"``
- variables that are defined in the local names space, e.g. ``date``

.. note::

Passing a string to a query by interpolating it into the query
expression is not recommended. Simply assign the string of interest to a
variable and use that variable in an expression. For example, do this

.. code-block:: python
string = "HolyMoly'"
store.select('df', 'index == string')
instead of this

.. code-block:: python
string = "HolyMoly'"
store.select('df', 'index == %s' % string)
The latter will **not** work and will raise a ``SyntaxError``.Note that
there's a single quote followed by a double quote in the ``string``
variable.
If you *must* interpolate, use the ``'%r'`` format specifier
.. code-block:: python
store.select('df', 'index == %r' % string)
which will quote ``string``.
Here are some examples:

.. ipython:: python
Expand Down

0 comments on commit 39b9f79

Please sign in to comment.