Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fealho committed Oct 16, 2024
1 parent a28f04a commit dd0eff2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 4 additions & 5 deletions rdt/transformers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ def learn_rounding_digits(data):
int or None:
Number of digits to round to.
"""
# check it ends with pyarrow
if str(data.dtype).endswith("[pyarrow]"):
data = data.to_numpy()

# check if data has any decimals
name = data.name
if str(data.dtype).endswith('[pyarrow]'):
data = data.to_numpy()
roundable_data = data[~(np.isinf(data.astype(float)) | pd.isna(data))]

# Doesn't contain numbers
Expand All @@ -276,7 +275,7 @@ def learn_rounding_digits(data):
# Can't round, not equal after MAX_DECIMALS digits of precision
LOGGER.info(
"No rounding scheme detected for column '%s'. Data will not be rounded.",
data.name,
name,
)
return None

Expand Down
16 changes: 15 additions & 1 deletion tests/unit/transformers/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sre_parse
import warnings
from sre_constants import MAXREPEAT
from unittest.mock import patch
from unittest.mock import Mock, patch

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -329,6 +329,20 @@ def test_learn_rounding_digits_nullable_numerical_pandas_dtypes():
assert output == expected_output[column]


def test_learn_rounding_digits_pyarrow_to_numpy():
"""Test that ``learn_rounding_digits`` works with pyarrow to numpy conversion."""
# Setup
data = Mock()
data.dtype = 'int64[pyarrow]'
data.to_numpy.return_value = np.array()

# Run
learn_rounding_digits(data)

# Assert
assert data.to_numpy.called


def test_warn_dict():
"""Test that ``WarnDict`` will raise a warning when called with `text`."""
# Setup
Expand Down

0 comments on commit dd0eff2

Please sign in to comment.