Skip to content

Numeric variables files generated from CSV input always have decimals #281

Description

@eirki

I am trying to generate SPSS and Stata files using CSV files + JSON metadata as input as described here. However, in the generated files, every numeric variable has decimals, so 1, 2, 3 become 1.0, 2.0, 3.0.

Steps to reproduce:

inputdata.csv:

"var_a","var_b"
1,1.1
2,2.2
3,3.3

meta.json:

{
    "type": "SPSS",
    "variables": [
        {
            "type": "NUMERIC",
            "name": "var_a",
            "decimals": 0
        },
        {
            "type": "NUMERIC",
            "name": "var_b",
            "decimals": 2
        }
    ]
}

cmd:
readstat inputdata.csv meta.json outputdata.sav

To test, check in SPSS or with pyreadstat:
python -c "import pyreadstat; print(pyreadstat.read_sav('outputdata.sav')[1].original_variable_types)"

My output:
{'var_a': 'F8.2', 'var_b': 'F8.2'}

var_a should be F8.0.

I've poked around with git bisect, and it seems this is a regression introduced in 93036b0. When I checked out the repo from one commit earlier (1b64538) and reran with the same input I got

{'var_a': 'F8.0', 'var_b': 'F8.2'}

Very grateful for any assistance with generating files without all those .0 decimals.

Activity

  1. evanmiller commented on Jan 16, 2023

    @evanmiller
    Contributor

    Duplicate of #177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions