Skip to content

Add test to check numeric precision GH33234 #51753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged
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
27 changes: 27 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,33 @@ def func(ser):
tm.assert_frame_equal(res, expected)


def test_groupby_agg_precision(any_real_numeric_dtype):
if any_real_numeric_dtype in tm.ALL_INT_NUMPY_DTYPES:
max_value = np.iinfo(any_real_numeric_dtype).max
if any_real_numeric_dtype in tm.FLOAT_NUMPY_DTYPES:
max_value = np.finfo(any_real_numeric_dtype).max
if any_real_numeric_dtype in tm.FLOAT_EA_DTYPES:
max_value = np.finfo(any_real_numeric_dtype.lower()).max
if any_real_numeric_dtype in tm.ALL_INT_EA_DTYPES:
max_value = np.iinfo(any_real_numeric_dtype.lower()).max

df = DataFrame(
{
"key1": ["a"],
"key2": ["b"],
"key3": pd.array([max_value], dtype=any_real_numeric_dtype),
}
)
arrays = [["a"], ["b"]]
index = MultiIndex.from_arrays(arrays, names=("key1", "key2"))

expected = DataFrame(
{"key3": pd.array([max_value], dtype=any_real_numeric_dtype)}, index=index
)
result = df.groupby(["key1", "key2"]).agg(lambda x: x)
tm.assert_frame_equal(result, expected)


def test_groupby_aggregate_directory(reduction_func):
# GH#32793
if reduction_func in ["corrwith", "nth"]:
Expand Down