Skip to content

Commit 4243118

Browse files
Merge pull request #12 from insightindustry/develop
PR for v.0.2.0
2 parents 6b6e776 + 0204776 commit 4243118

File tree

10 files changed

+210
-65
lines changed

10 files changed

+210
-65
lines changed

CHANGES.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
------------------
22

3+
Release 0.2.0
4+
=========================================
5+
6+
.. image:: https://travis-ci.com/insightindustry/spss-converter.svg?branch=v.0.2.0
7+
:target: https://travis-ci.com/insightindustry/spss-converter
8+
:alt: Build Status (Travis CI)
9+
10+
.. image:: https://codecov.io/gh/insightindustry/spss-converter/branch/v.0.2.0/graph/badge.svg
11+
:target: https://codecov.io/gh/insightindustry/spss-converter
12+
:alt: Code Coverage Status (Codecov)
13+
14+
.. image:: https://readthedocs.org/projects/spss-converter/badge/?version=v.0.2.0
15+
:target: http://spss-converter.readthedocs.io/en/latest/?badge=v.0.2.0
16+
:alt: Documentation Status (ReadTheDocs)
17+
18+
* Added explicit support for the ``layout`` keyword argument in
19+
``write.from_json()`` and ``write.from_yaml()`` (#11).
20+
* Loosened version requirements for Pandas and Pyreadstat.
21+
22+
------------------
23+
324
Release 0.1.2
425
=========================================
526

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ SPSS Converter
2424
:target: http://spss-converter.readthedocs.io/en/latest/?badge=latest
2525
:alt: Documentation Status (ReadTheDocs)
2626

27+
* - `v.0.2 <https://github.com/insightindustry/spss-converter/tree/v.0.2.0>`_
28+
-
29+
.. image:: https://travis-ci.com/insightindustry/spss-converter.svg?branch=v.0.2.0
30+
:target: https://travis-ci.com/insightindustry/spss-converter
31+
:alt: Build Status (Travis CI)
32+
33+
.. image:: https://codecov.io/gh/insightindustry/spss-converter/branch/v.0.2.0/graph/badge.svg
34+
:target: https://codecov.io/gh/insightindustry/spss-converter
35+
:alt: Code Coverage Status (Codecov)
36+
37+
.. image:: https://readthedocs.org/projects/spss-converter/badge/?version=v.0.2.0
38+
:target: http://spss-converter.readthedocs.io/en/latest/?badge=v.0.2.0
39+
:alt: Documentation Status (ReadTheDocs)
40+
2741
* - `v.0.1 <https://github.com/insightindustry/spss-converter/tree/v.0.1.0>`_
2842
-
2943
.. image:: https://travis-ci.com/insightindustry/spss-converter.svg?branch=v.0.1.0

docs/_dependencies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:header-rows: 1
33

44
* - Python 3.x
5-
* - | * `Pandas v0.24 <https://pandas.pydata.org/docs/>`_ or higher
5+
* - | * `Pandas v1.2 <https://pandas.pydata.org/docs/>`_ or higher
66
| * `Pyreadstat v1.0 <https://github.com/Roche/pyreadstat>`_ or higher
77
| * `OpenPyXL v.3.0.7 <https://openpyxl.readthedocs.io/en/stable/>`_ or higher
88
| * `PyYAML v3.10 <https://github.com/yaml/pyyaml>`_ or higher

docs/_unit_tests_code_coverage.rst

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,30 @@
1818
:target: http://spss-converter.readthedocs.io/en/latest/?badge=latest
1919
:alt: Documentation Status (ReadTheDocs)
2020

21-
* - `v.0.1 <https://github.com/insightindustry/spss-converter/tree/v.0.1.2>`_
22-
-
23-
.. image:: https://travis-ci.com/insightindustry/spss-converter.svg?branch=v.0.1.2
24-
:target: https://travis-ci.com/insightindustry/spss-converter
25-
:alt: Build Status (Travis CI)
26-
27-
.. image:: https://codecov.io/gh/insightindustry/spss-converter/branch/v.0.1.2/graph/badge.svg
28-
:target: https://codecov.io/gh/insightindustry/spss-converter
29-
:alt: Code Coverage Status (Codecov)
30-
31-
.. image:: https://readthedocs.org/projects/spss-converter/badge/?version=v.0.1.2
32-
:target: http://spss-converter.readthedocs.io/en/latest/?badge=v.0.1.2
33-
:alt: Documentation Status (ReadTheDocs)
21+
* - `v.0.2 <https://github.com/insightindustry/spss-converter/tree/v.0.2.0>`_
22+
-
23+
.. image:: https://travis-ci.com/insightindustry/spss-converter.svg?branch=v.0.2.0
24+
:target: https://travis-ci.com/insightindustry/spss-converter
25+
:alt: Build Status (Travis CI)
26+
27+
.. image:: https://codecov.io/gh/insightindustry/spss-converter/branch/v.0.2.0/graph/badge.svg
28+
:target: https://codecov.io/gh/insightindustry/spss-converter
29+
:alt: Code Coverage Status (Codecov)
30+
31+
.. image:: https://readthedocs.org/projects/spss-converter/badge/?version=v.0.2.0
32+
:target: http://spss-converter.readthedocs.io/en/latest/?badge=v.0.2.0
33+
:alt: Documentation Status (ReadTheDocs)
34+
35+
* - `v.0.1 <https://github.com/insightindustry/spss-converter/tree/v.0.1.2>`_
36+
-
37+
.. image:: https://travis-ci.com/insightindustry/spss-converter.svg?branch=v.0.1.2
38+
:target: https://travis-ci.com/insightindustry/spss-converter
39+
:alt: Build Status (Travis CI)
40+
41+
.. image:: https://codecov.io/gh/insightindustry/spss-converter/branch/v.0.1.2/graph/badge.svg
42+
:target: https://codecov.io/gh/insightindustry/spss-converter
43+
:alt: Code Coverage Status (Codecov)
44+
45+
.. image:: https://readthedocs.org/projects/spss-converter/badge/?version=v.0.1.2
46+
:target: http://spss-converter.readthedocs.io/en/latest/?badge=v.0.1.2
47+
:alt: Documentation Status (ReadTheDocs)

requirements.dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pandas==1.2.0
2-
pyreadstat==1.0.6
1+
pandas>=1.2.0
2+
pyreadstat>=1.0.6
33
PyYAML==5.3.1
44
simplejson==3.17.2
55
validator-collection>=1.5.0

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pandas==1.2.0
2-
pyreadstat==1.0.6
1+
pandas>=1.2.0
2+
pyreadstat>=1.0.6
33
PyYAML==5.3.1
44
simplejson==3.17.2
55
validator-collection>=1.5.0

spss_converter/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '0.1.2'
2+
__version__ = '0.2.0'

spss_converter/write.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def from_dict(as_dict: dict,
221221

222222
def from_json(as_json: Union[str, 'PathLike[Any]', BytesIO],
223223
target: Optional[Union['PathLike[Any]', BytesIO]] = None,
224+
layout: str = 'records',
224225
compress: bool = False,
225226
**kwargs):
226227
"""Convert JSON data into an SPSS dataset.
@@ -242,12 +243,33 @@ def from_json(as_json: Union[str, 'PathLike[Any]', BytesIO],
242243
:type target: Path-like / :class:`BytesIO <python:io.BytesIO>` /
243244
:obj:`None <python:None>`
244245
246+
:param layout: Indicates the layout schema to use for the JSON representation of the
247+
data. Accepts:
248+
249+
* ``records``, where the resulting JSON object represents an array of objects
250+
where each object corresponds to a single record, with key/value pairs for each
251+
column and that record's corresponding value
252+
* ``table``, where the resulting JSON object contains a metadata (data map)
253+
describing the data schema along with the resulting collection of record objects
254+
255+
Defaults to ``records``.
256+
257+
:type layout: :class:`str <python:str>`
258+
245259
:param compress: If ``True``, will return data in the compressed ZSAV format. If
246260
``False``, will return data in the standards SAV format. Defaults to ``False``.
247261
:type compress: :class:`bool <python:bool>`
248262
249263
:param kwargs: Additional keyword arguments which will be passed onto the
250264
:func:`pandas.read_json() <pandas:pandas.read_json>` function.
265+
266+
.. warning::
267+
268+
If you supply an ``orient`` keyword argument (which is supported by
269+
:func:`pandas.read_json() <pandas:pandas.read_json>`), the ``orient``
270+
value will *override* the value supplied for ``layout``. This is an
271+
advanced use case, so use with caution.
272+
251273
:type kwargs: :class:`dict <python:dict>`
252274
253275
:returns: A :class:`BytesIO <python:io.BytesIO>` object containing the SPSS data if
@@ -256,7 +278,16 @@ def from_json(as_json: Union[str, 'PathLike[Any]', BytesIO],
256278
:rtype: :class:`BytesIO <python:io.BytesIO>` or :obj:`None <python:None>`
257279
258280
"""
259-
df = pandas.read_json(as_json, **kwargs)
281+
if layout not in ['records', 'table']:
282+
raise errors.InvalidLayoutError('layout must be either "records" or "table". '
283+
f'Was: "{layout}"')
284+
285+
orient = kwargs.pop('orient', layout)
286+
287+
df = pandas.read_json(as_json,
288+
orient = orient,
289+
**kwargs)
290+
260291
result = from_dataframe(df,
261292
target = target,
262293
compress = compress)
@@ -266,6 +297,7 @@ def from_json(as_json: Union[str, 'PathLike[Any]', BytesIO],
266297

267298
def from_yaml(as_yaml: Union[str, 'PathLike[Any]', BytesIO],
268299
target: Optional[Union['PathLike[Any]', BytesIO]] = None,
300+
layout: str = 'records',
269301
compress: bool = False,
270302
**kwargs):
271303
"""Convert YAML data into an SPSS dataset.
@@ -287,12 +319,35 @@ def from_yaml(as_yaml: Union[str, 'PathLike[Any]', BytesIO],
287319
:type target: Path-like / :class:`BytesIO <python:io.BytesIO>` /
288320
:obj:`None <python:None>`
289321
322+
:param layout: Indicates the layout schema to expect for the YAML representation of the
323+
data. Accepts:
324+
325+
* ``records``, where the resulting JSON object represents an array of objects
326+
where each object corresponds to a single record, with key/value pairs for each
327+
column and that record's corresponding value
328+
* ``table``, where the resulting JSON object contains a metadata (data map)
329+
describing the data schema along with the resulting collection of record objects
330+
331+
Defaults to ``records``.
332+
:type layout: :class:`str <python:str>`
333+
290334
:param compress: If ``True``, will return data in the compressed ZSAV format. If
291335
``False``, will return data in the standards SAV format. Defaults to ``False``.
292336
:type compress: :class:`bool <python:bool>`
293337
294338
:param kwargs: Additional keyword arguments which will be passed onto the
295-
:meth:`DataFrame.from_dict() <pandas:pandas.DataFrame.from_dict>` method.
339+
:meth:`pandas.from_json() <pandas:pandas.from_json>` function.
340+
341+
:param kwargs: Additional keyword arguments which will be passed onto the
342+
:func:`pandas.read_json() <pandas:pandas.read_json>` function.
343+
344+
.. warning::
345+
346+
If you supply an ``orient`` keyword argument (which is supported by
347+
:func:`pandas.read_json() <pandas:pandas.read_json>`), the ``orient``
348+
value will *override* the value supplied for ``layout``. This is an
349+
advanced use case, so use with caution.
350+
296351
:type kwargs: :class:`dict <python:dict>`
297352
298353
:returns: A :class:`BytesIO <python:io.BytesIO>` object containing the SPSS data if
@@ -312,6 +367,7 @@ def from_yaml(as_yaml: Union[str, 'PathLike[Any]', BytesIO],
312367

313368
return from_json(as_json,
314369
target = target,
370+
layout = layout,
315371
compress = compress,
316372
**kwargs)
317373

0 commit comments

Comments
 (0)