BUG/TST: added TypeError if object dtypes are detected in dataframe
State: open

- [ ] closes #55114 
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [x] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

This PR addresses concern 1 of  #55114 - Having consistent behavior with `Series.round` & `DataFrame.round`. 

My solution was to raise a `TypeError ` in a way similar way to #61206.

I changed the following existing tests, but a little worried that might break some things, so any feedback is appreciated.
1. I deleted `tests/frrame/methods/test_round.py`'s `test_round_mixed_type` as I felt that test conflicted with the current intended behavior of `DataFrame.round`
2. I edited  `tests/copy_view/test_methods.py`'s `test_round` as it was using a dataframe with strings and ints in its test

Labels:
name: Bug
name: DataFrame
description: DataFrame data structure
name: Stale

Comments:
The second concern of the issue #55114 was `round()` did not work for `Series` or `Dataframe` when using `decimal.Decimal` from python's default decimal module. It seems like this is because both NumPy and pandas give array-like structures of `decimal.Decimal` objects a `dtype` of  `object`. When I tested `np.array([decimal.Decimal("1.2234242333")]).round()`, it raised an error.

If `Series.round()` and `DataFrame.round()` not raising an error on `decimal.Decimal` objects is still wanted, I thought a clean solution would be to make a new custom dtype for `decimal.Decimal`. However, that seemed like a pretty big change so wanted to check if there was another way I should be thinking about this bugfix.
i would expect this to attempt to operate pointwise (which would still raise on e.g. strings)
> i would expect this to attempt to operate pointwise (which would still raise on e.g. strings)

Do you mean I should rewrite the code so that it attempts to round every column individually and then raise if there is a non-numeric column?  As opposed to looking at the `self.dtypes.values` ?
Ohh because `StringDtype` also exists? and other non-numeric dtypes outside of object? Could I use `pandas.api.types.is_numeric_dtype`?
> and other non-numeric dtypes outside of object? 

im specifically thinking of object dtype columns containing numeric entries
Ah okay, makes sense. 

I think the current behavior for `series.round()` is to raise when an object dtype column containing numeric entries is called though.

The `test_round_dtype_object()` test in `pandas/tests/series/methods/test_round.py` is this i think:
```
  def test_round_dtype_object(self):
        # GH#61206
        ser = Series([0.2], dtype="object")
        msg = "Expected numeric dtype, got object instead."
        with pytest.raises(TypeError, match=msg):
            ser.round()
```

Should I submit a PR to change this behavior first before implementing your pointwise solution?

@jbrockmendel Hi, no worries if too busy to look into this right now just curious if you had any insight on the above comment for making a different PR first, thanks!
This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.