test_flags.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import pytest
  2. import pandas as pd
  3. class TestFlags:
  4. def test_equality(self):
  5. a = pd.DataFrame().set_flags(allows_duplicate_labels=True).flags
  6. b = pd.DataFrame().set_flags(allows_duplicate_labels=False).flags
  7. assert a == a
  8. assert b == b
  9. assert a != b
  10. assert a != 2
  11. def test_set(self):
  12. df = pd.DataFrame().set_flags(allows_duplicate_labels=True)
  13. a = df.flags
  14. a.allows_duplicate_labels = False
  15. assert a.allows_duplicate_labels is False
  16. a["allows_duplicate_labels"] = True
  17. assert a.allows_duplicate_labels is True
  18. def test_repr(self):
  19. a = repr(pd.DataFrame({"A"}).set_flags(allows_duplicate_labels=True).flags)
  20. assert a == "<Flags(allows_duplicate_labels=True)>"
  21. a = repr(pd.DataFrame({"A"}).set_flags(allows_duplicate_labels=False).flags)
  22. assert a == "<Flags(allows_duplicate_labels=False)>"
  23. def test_obj_ref(self):
  24. df = pd.DataFrame()
  25. flags = df.flags
  26. del df
  27. with pytest.raises(ValueError, match="object has been deleted"):
  28. flags.allows_duplicate_labels = True
  29. def test_getitem(self):
  30. df = pd.DataFrame()
  31. flags = df.flags
  32. assert flags["allows_duplicate_labels"] is True
  33. flags["allows_duplicate_labels"] = False
  34. assert flags["allows_duplicate_labels"] is False
  35. with pytest.raises(KeyError, match="a"):
  36. flags["a"]
  37. with pytest.raises(ValueError, match="a"):
  38. flags["a"] = 10