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

update categorical profiler #1136

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions dataprofiler/profilers/categorical_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from typing import cast

import datasketches
from pandas import DataFrame, Series
import pandas as pd
import polars as pl
from polars import DataFrame, Series

from .. import dp_logging
from . import profiler_utils
Expand Down Expand Up @@ -601,7 +603,8 @@ def _get_categories_full(self, df_series) -> dict:
:return: dict of counts for each unique value
:rtype: dict
"""
category_count: dict = df_series.value_counts(dropna=False).to_dict()
value_counts = df_series.value_counts(sort=True)
category_count: dict = dict(value_counts.iter_rows())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value_counts = df_series.value_counts(sort=True)
category_count: dict = dict(value_counts.iter_rows())
category_count: dict = dict(df_series.value_counts(sort=True).iter_rows())

why not 1 line? Does this not run?

return category_count

@BaseColumnProfiler._timeit(name="categories")
Expand Down Expand Up @@ -678,6 +681,9 @@ def update(self, df_series: Series) -> CategoricalColumn:
:return: updated CategoricalColumn
:rtype: CategoricalColumn
"""
# TODO remove onces profiler builder is updated
if type(df_series) == pd.Series:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if type(df_series) == pd.Series:
if isinstance(df_series, pd.Series):

Copy link
Contributor

Choose a reason for hiding this comment

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

you'll want to validate but this is a bit cleaner

df_series = pl.from_pandas(df_series) # type: ignore
# If condition for limiting profile calculations
if len(df_series) == 0 or self._stop_condition_is_met:
return self
Expand Down
Loading