| 271 | |
| 272 | @pytest.mark.parametrize("op", ["mean"]) |
| 273 | def test_reduce_to_float(op, using_python_scalars): |
| 274 | # some reduce ops always return float, even if the result |
| 275 | # is a rounded number |
| 276 | df = pd.DataFrame( |
| 277 | { |
| 278 | "A": ["a", "b", "b"], |
| 279 | "B": [1, None, 3], |
| 280 | "C": pd.array([1, None, 3], dtype="Int64"), |
| 281 | } |
| 282 | ) |
| 283 | |
| 284 | # op |
| 285 | result = getattr(df.C, op)() |
| 286 | if using_python_scalars: |
| 287 | assert type(result) == float |
| 288 | else: |
| 289 | assert isinstance(result, np.float64) |
| 290 | |
| 291 | # groupby |
| 292 | result = getattr(df.groupby("A"), op)() |
| 293 | |
| 294 | expected = pd.DataFrame( |
| 295 | {"B": np.array([1.0, 3.0]), "C": pd.array([1, 3], dtype="Float64")}, |
| 296 | index=pd.Index(["a", "b"], name="A"), |
| 297 | ) |
| 298 | tm.assert_frame_equal(result, expected) |
| 299 | |
| 300 | |
| 301 | @pytest.mark.parametrize( |