Skip to content
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

Bug fix for float precision calculation using categorical data with trailing 0s #1125

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion dataprofiler/profilers/float_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ def _get_float_precision(

# length of sampled cells after all punctuation removed
len_per_float = (
df_series_clean.sample(sample_size).replace(to_replace=r, value="").map(len)
df_series_clean.sample(sample_size)
.astype(object)
.replace(to_replace=r, value="")
.map(len)
).astype(float)

# Determine statistics precision
Expand Down
7 changes: 7 additions & 0 deletions dataprofiler/tests/profilers/test_float_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ def test_profiled_precision(self):
msg=f"Errored for: {sample[0]}",
)

# Validate categorical series with trailing zeros supported
categorical_series = pd.Series(
[202209, 202210, 202211], dtype="category"
).apply(str)
float_profiler = FloatColumn("Name")
float_profiler.update(categorical_series)
Comment on lines +215 to +219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing this locally so may have some additional comments, but initial thought is that there should definitely be some assert statements here to validate this is actually working as intended post-change @SchadtJ @scottiegarcia

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def test_profiled_min(self):
# test with multiple values
data = np.linspace(-5, 5, 11)
Expand Down