test_sas.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. from io import StringIO
  2. import pytest
  3. from pandas import read_sas
  4. import pandas._testing as tm
  5. class TestSas:
  6. def test_sas_buffer_format(self):
  7. # see gh-14947
  8. b = StringIO("")
  9. msg = (
  10. "If this is a buffer object rather than a string "
  11. "name, you must specify a format string"
  12. )
  13. with pytest.raises(ValueError, match=msg):
  14. read_sas(b)
  15. def test_sas_read_no_format_or_extension(self):
  16. # see gh-24548
  17. msg = "unable to infer format of SAS file.+"
  18. with tm.ensure_clean("test_file_no_extension") as path:
  19. with pytest.raises(ValueError, match=msg):
  20. read_sas(path)
  21. def test_sas_archive(datapath):
  22. fname_uncompressed = datapath("io", "sas", "data", "airline.sas7bdat")
  23. df_uncompressed = read_sas(fname_uncompressed)
  24. fname_compressed = datapath("io", "sas", "data", "airline.sas7bdat.gz")
  25. df_compressed = read_sas(fname_compressed, format="sas7bdat")
  26. tm.assert_frame_equal(df_uncompressed, df_compressed)