test_indexing.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import numpy as np
  2. import pytest
  3. from pandas import DataFrame, SparseDataFrame
  4. from pandas.util import testing as tm
  5. pytestmark = pytest.mark.skip("Wrong SparseBlock initialization (GH 17386)")
  6. @pytest.mark.parametrize('data', [
  7. [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
  8. [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [np.nan, np.nan]],
  9. [
  10. [1.0, 1.0 + 1.0j],
  11. [2.0 + 2.0j, 2.0],
  12. [3.0, 3.0 + 3.0j],
  13. [4.0 + 4.0j, 4.0],
  14. [np.nan, np.nan]
  15. ]
  16. ])
  17. @pytest.mark.xfail(reason='Wrong SparseBlock initialization (GH#17386)')
  18. def test_where_with_numeric_data(data):
  19. # GH 17386
  20. lower_bound = 1.5
  21. sparse = SparseDataFrame(data)
  22. result = sparse.where(sparse > lower_bound)
  23. dense = DataFrame(data)
  24. dense_expected = dense.where(dense > lower_bound)
  25. sparse_expected = SparseDataFrame(dense_expected)
  26. tm.assert_frame_equal(result, dense_expected)
  27. tm.assert_sp_frame_equal(result, sparse_expected)
  28. @pytest.mark.parametrize('data', [
  29. [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
  30. [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [np.nan, np.nan]],
  31. [
  32. [1.0, 1.0 + 1.0j],
  33. [2.0 + 2.0j, 2.0],
  34. [3.0, 3.0 + 3.0j],
  35. [4.0 + 4.0j, 4.0],
  36. [np.nan, np.nan]
  37. ]
  38. ])
  39. @pytest.mark.parametrize('other', [
  40. True,
  41. -100,
  42. 0.1,
  43. 100.0 + 100.0j
  44. ])
  45. @pytest.mark.xfail(reason='Wrong SparseBlock initialization (GH#17386)')
  46. def test_where_with_numeric_data_and_other(data, other):
  47. # GH 17386
  48. lower_bound = 1.5
  49. sparse = SparseDataFrame(data)
  50. result = sparse.where(sparse > lower_bound, other)
  51. dense = DataFrame(data)
  52. dense_expected = dense.where(dense > lower_bound, other)
  53. sparse_expected = SparseDataFrame(dense_expected,
  54. default_fill_value=other)
  55. tm.assert_frame_equal(result, dense_expected)
  56. tm.assert_sp_frame_equal(result, sparse_expected)
  57. @pytest.mark.xfail(reason='Wrong SparseBlock initialization (GH#17386)')
  58. def test_where_with_bool_data():
  59. # GH 17386
  60. data = [[False, False], [True, True], [False, False]]
  61. cond = True
  62. sparse = SparseDataFrame(data)
  63. result = sparse.where(sparse == cond)
  64. dense = DataFrame(data)
  65. dense_expected = dense.where(dense == cond)
  66. sparse_expected = SparseDataFrame(dense_expected)
  67. tm.assert_frame_equal(result, dense_expected)
  68. tm.assert_sp_frame_equal(result, sparse_expected)
  69. @pytest.mark.parametrize('other', [
  70. True,
  71. 0,
  72. 0.1,
  73. 100.0 + 100.0j
  74. ])
  75. @pytest.mark.xfail(reason='Wrong SparseBlock initialization (GH#17386)')
  76. def test_where_with_bool_data_and_other(other):
  77. # GH 17386
  78. data = [[False, False], [True, True], [False, False]]
  79. cond = True
  80. sparse = SparseDataFrame(data)
  81. result = sparse.where(sparse == cond, other)
  82. dense = DataFrame(data)
  83. dense_expected = dense.where(dense == cond, other)
  84. sparse_expected = SparseDataFrame(dense_expected,
  85. default_fill_value=other)
  86. tm.assert_frame_equal(result, dense_expected)
  87. tm.assert_sp_frame_equal(result, sparse_expected)