forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccumulate.py
43 lines (31 loc) · 1.45 KB
/
accumulate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest
import pandas as pd
from pandas.tests.extension.base.base import BaseExtensionTests
class BaseAccumulateTests(BaseExtensionTests):
"""
Accumulation specific tests. Generally these only
make sense for numeric/boolean operations.
"""
def check_accumulate(self, s, op_name, skipna):
result = getattr(s, op_name)(skipna=skipna)
if result.dtype == pd.Float32Dtype() and op_name == "cumprod" and skipna:
pytest.skip(
f"Float32 precision lead to large differences with op {op_name} "
f"and skipna={skipna}"
)
expected = getattr(s.astype("float64"), op_name)(skipna=skipna)
self.assert_series_equal(result, expected, check_dtype=False)
class BaseNoAccumulateTests(BaseAccumulateTests):
"""we don't define any accumulations"""
@pytest.mark.parametrize("skipna", [True, False])
def test_accumulate_series_numeric(self, data, all_numeric_accumulations, skipna):
op_name = all_numeric_accumulations
ser = pd.Series(data)
with pytest.raises(NotImplementedError):
getattr(ser, op_name)(skipna=skipna)
class BaseNumericAccumulateTests(BaseAccumulateTests):
@pytest.mark.parametrize("skipna", [True, False])
def test_accumulate_series(self, data, all_numeric_accumulations, skipna):
op_name = all_numeric_accumulations
ser = pd.Series(data)
self.check_accumulate(ser, op_name, skipna)