Repository: sdv-dev/RDT

Issue:
`learn_rounding_digits` should work for numerical data of `object` dtype
### Problem Description
The `learn_rounding_digits` method may raise the following error when running on numerical data of dtype `object`: ```TypeError: loop of ufunc does not support argument 0 of type float which has no callable rint method```.

This happens because pandas.Series doesn't support rounding when `dtype=object` for versions 2.1 or lower of pandas.

### Expected behavior
The `learn_rounding_digits` method should accept as input pandas.Series of numerical data with dtype `object`.

Hints from issue comments:

Solution patch:
diff --git a/rdt/transformers/utils.py b/rdt/transformers/utils.py
index 9e53662..868a3e6 100644
--- a/rdt/transformers/utils.py
+++ b/rdt/transformers/utils.py
@@ -274,6 +274,9 @@ def learn_rounding_digits(data):
     if len(roundable_data) == 0:
         return None
 
+    if roundable_data.dtype == 'object':
+        roundable_data = roundable_data.astype(float)
+
     # Try to round to fewer digits
     highest_int = int(np.max(np.abs(roundable_data)))
     most_digits = len(str(highest_int)) if highest_int != 0 else 0


Test patch:
diff --git a/tests/unit/transformers/test_utils.py b/tests/unit/transformers/test_utils.py
index 5c2c584..5b10d95 100644
--- a/tests/unit/transformers/test_utils.py
+++ b/tests/unit/transformers/test_utils.py
@@ -274,6 +274,18 @@ def test_learn_rounding_digits(test_data, expected_digits):
     assert result == expected_digits
 
 
+def test_learn_rounding_digits_object_dtype():
+    """Test learn_rounding_digits for object dtype."""
+    # Setup
+    data = pd.Series(['1.1', '1.11', np.nan], dtype='object')
+
+    # Run
+    result = learn_rounding_digits(data)
+
+    # Assert
+    assert result == 2
+
+
 def test_learn_rounding_digits_code_coverage():
     """Test learn_rounding_digits for code coverage."""
     # Setup