framework icon indicating copy to clipboard operation
framework copied to clipboard

SpssParser ignores timezones

Open roll opened this issue 3 years ago • 0 comments

Overview

See this failing test:

def test_spss_parser_write_timezone(tmpdir):
    source = Resource("data/timezone.csv")
    target = source.write(str(tmpdir.join("table.sav")))
    with target:

        # Assert schema
        assert target.schema.to_descriptor() == {
            "fields": [
                {"name": "datetime", "type": "datetime"},
                {"name": "time", "type": "time"},
            ],
        }

        # Assert rows
        assert target.read_rows() == [
            {
                "datetime": datetime(2020, 1, 1, 15),
                "time": time(15),
            },
            {
                "datetime": datetime(2020, 1, 1, 15, 0, tzinfo=tzutc()),
                "time": time(15, 0, tzinfo=tzutc()),
            },
            {
                "datetime": datetime(2020, 1, 1, 15, 0, tzinfo=tzoffset(None, 10800)),
                "time": time(15, 0, tzinfo=tzoffset(None, 10800)),
            },
            {
                "datetime": datetime(2020, 1, 1, 15, 0, tzinfo=tzoffset(None, -10800)),
                "time": time(15, 0, tzinfo=tzoffset(None, -10800)),
            },
        ]

There are 2 strategies to fix it:

  • as in pandas -- full TZ support
  • as in SQL -- convert to UTC

roll avatar Jul 30 '22 06:07 roll