Skip to content

Commit

Permalink
PEP-8 compliance
Browse files Browse the repository at this point in the history
Mostly by running:

autopep8 --in-place . --max-line-length 160 -r

This fixes #4, and also fixes #6.
  • Loading branch information
lfasnacht committed Apr 25, 2018
1 parent eb83ff0 commit bffdf91
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 557 deletions.
14 changes: 7 additions & 7 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Quick start
>>> del m['a_sample_key']
>>> print(m.keys())
['other_key']

The contents of the dictionary are stored to disk. For example, in another python interpreter:

::
Expand All @@ -27,7 +27,7 @@ The contents of the dictionary are stored to disk. For example, in another pytho
>>> m = mmapdict('/tmp/test.mmdpickle')
>>> print(m['other_key'])
[1, 2, 3]


It is also possible to open the file in read-only mode, in which case any modification will fail:

Expand All @@ -42,29 +42,29 @@ It is also possible to open the file in read-only mode, in which case any modifi
raise io.UnsupportedOperation('not writable')
io.UnsupportedOperation: not writable


Of course, the main interest is to store numpy arrays:

::

>>> import numpy as np
>>> from mmappickle.dict import mmapdict
>>> m = mmapdict('/tmp/test.mmdpickle')
>>> m['test'] = np.array([1,2,3],dtype=np.uint8)
>>> m['test'] = np.array([1,2,3], dtype=np.uint8)
>>> m['test'][1] = 4
>>> print(m['test'])
[1 4 3]
>>> print(type(m['test']))
<class 'numpy.core.memmap.memmap'>

As you can see, the ``m['test']`` is now memory-mapped. This means that its content is not loaded in memory, but instead accessed directly from the file.

Unfortunately, the array has to exist in order to serialize it to the ``mmapdict``. If the array exceed the available memory, this won't work. Instead one should use stubs:

::

>>> from mmappickle.stubs import EmptyNDArray
>>> m['test_large']=EmptyNDArray((300,300,300))
>>> m['test_large'] = EmptyNDArray((300,300,300))
>>> print(type(m['test_large']))
<class 'numpy.core.memmap.memmap'>

Expand All @@ -78,7 +78,7 @@ Finally, one last useful trick is the :meth:`mmappickle.mmapdict.vacuum` method.
>>> #Here, /tmp/test.mmdpickle still occupies ~216M of hard disk
>>> m.vacuum()
>>> #Now the disk space has been reclaimed.

.. warning ::
When running :meth:`mmappickle.mmapdict.vacuum`, it is crucial that there are no other references to the file content, either in this process or in other.
Expand Down

0 comments on commit bffdf91

Please sign in to comment.