Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Fixed regressions

Bug fixes
~~~~~~~~~
- Bug in :func:`read_spss` where passing a ``pathlib.Path`` as ``path`` would raise a ``TypeError`` (:issue:`33666`)
- Bug in :meth:`Series.str.startswith` and :meth:`Series.str.endswith` with ``category`` dtype not propagating ``na`` parameter (:issue:`36241`)
- Bug in :class:`Series` constructor where integer overflow would occur for sufficiently large scalar inputs when an index was provided (:issue:`36291`)

Expand Down
4 changes: 3 additions & 1 deletion pandas/io/spss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from pandas.core.api import DataFrame

from pandas.io.common import stringify_path


def read_spss(
path: Union[str, Path],
Expand Down Expand Up @@ -40,6 +42,6 @@ def read_spss(
usecols = list(usecols) # pyreadstat requires a list

df, _ = pyreadstat.read_sav(
path, usecols=usecols, apply_value_formats=convert_categoricals
stringify_path(path), usecols=usecols, apply_value_formats=convert_categoricals
)
return df
7 changes: 5 additions & 2 deletions pandas/tests/io/test_spss.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import numpy as np
import pytest

Expand All @@ -7,9 +9,10 @@
pyreadstat = pytest.importorskip("pyreadstat")


def test_spss_labelled_num(datapath):
@pytest.mark.parametrize("path_klass", [lambda p: p, Path])
def test_spss_labelled_num(path_klass, datapath):
# test file from the Haven project (https://haven.tidyverse.org/)
fname = datapath("io", "data", "spss", "labelled-num.sav")
fname = path_klass(datapath("io", "data", "spss", "labelled-num.sav"))

df = pd.read_spss(fname, convert_categoricals=True)
expected = pd.DataFrame({"VAR00002": "This is one"}, index=[0])
Expand Down