-
Notifications
You must be signed in to change notification settings - Fork 162
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
Add profiler option for column level invalid values #704
Merged
taylorfturner
merged 8 commits into
capitalone:main
from
tonywu315:column_invalid_values
Nov 4, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8314ae4
Add option for column level invalid values
tonywu315 d0a0894
Fix bug with changing null values for a column and fix test
tonywu315 8fc5386
Add tests
tonywu315 8d50f14
Fix test
tonywu315 b319755
Merge branch 'main' into column_invalid_values
tonywu315 8947ea5
Fix typos in tests
tonywu315 991b5ce
Merge branch 'main' into column_invalid_values
tonywu315 de9db62
Merge
tonywu315 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ def __init__( | |
min_true_samples: int = 0, | ||
sample_ids: np.ndarray = None, | ||
pool: Pool = None, | ||
column_index: int = None, | ||
options: StructuredOptions = None, | ||
) -> None: | ||
""" | ||
|
@@ -69,6 +70,8 @@ def __init__( | |
:type sample_ids: list(list) | ||
:param pool: pool utilized for multiprocessing | ||
:type pool: multiprocessing.Pool | ||
:param column_index: index of the given column | ||
:type column_index: int | ||
:param options: Options for the structured profiler. | ||
:type options: StructuredOptions Object | ||
""" | ||
|
@@ -100,10 +103,13 @@ def __init__( | |
} | ||
if options: | ||
if options.null_values is not None: | ||
self._null_values = options.null_values | ||
self._null_values = options.null_values.copy() | ||
if column_index is not None and options.column_null_values is not None: | ||
self._null_values.update( | ||
options.column_null_values.get(column_index, {}) | ||
) | ||
|
||
if df_series is not None and len(df_series) > 0: | ||
|
||
if not sample_size: | ||
sample_size = self._get_sample_size(df_series) | ||
if sample_size < len(df_series): | ||
|
@@ -497,7 +503,7 @@ def clean_data_and_get_base_stats( | |
:param null_values: Dictionary mapping null values to regex flag where | ||
the key represents the null value to remove from the data and the | ||
flag represents the regex flag to apply | ||
:type null_values: dict[str, re.FLAG] | ||
:type null_values: Dict[str, Union[re.RegexFlag, int]] | ||
:param min_true_samples: Minimum number of samples required for the | ||
profiler | ||
:type min_true_samples: int | ||
|
@@ -2418,7 +2424,10 @@ def _merge_null_replication_metrics(self, other: StructuredProfiler) -> Dict: | |
return merged_properties | ||
|
||
def _update_profile_from_chunk( | ||
self, data: pd.DataFrame, sample_size: int, min_true_samples: int = None | ||
self, | ||
data: Union[List, pd.Series, pd.DataFrame], | ||
sample_size: int, | ||
min_true_samples: int = None, | ||
) -> None: | ||
""" | ||
Iterate over the columns of a dataset and identify its parameters. | ||
|
@@ -2497,6 +2506,7 @@ def tqdm(level: Set[int]) -> Generator[int, None, None]: | |
sample_size=sample_size, | ||
min_true_samples=min_true_samples, # type: ignore | ||
sample_ids=sample_ids, # type: ignore | ||
column_index=col_idx, | ||
options=self.options, | ||
) | ||
) | ||
|
@@ -2536,7 +2546,12 @@ def tqdm(level: Set[int]) -> Generator[int, None, None]: | |
if min_true_samples is None: | ||
min_true_samples = self._profile[prof_idx]._min_true_samples | ||
try: | ||
null_values = self._profile[prof_idx]._null_values | ||
null_values: Dict = self._profile[prof_idx]._null_values.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
if self.options.column_null_values: | ||
null_values.update( | ||
self.options.column_null_values.get(col_idx, {}) | ||
) | ||
|
||
multi_process_dict[col_idx] = pool.apply_async( | ||
self._profile[prof_idx].clean_data_and_get_base_stats, | ||
( | ||
|
@@ -2576,7 +2591,13 @@ def tqdm(level: Set[int]) -> Generator[int, None, None]: | |
prof_idx = col_idx_to_prof_idx[col_idx] | ||
if min_true_samples is None: | ||
min_true_samples = self._profile[prof_idx]._min_true_samples | ||
null_values = self._profile[prof_idx]._null_values | ||
|
||
null_values = self._profile[prof_idx]._null_values.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
if self.options.column_null_values: | ||
null_values.update( | ||
self.options.column_null_values.get(col_idx, {}) | ||
) | ||
|
||
clean_sampled_dict[prof_idx], base_stats = self._profile[ | ||
prof_idx | ||
].clean_data_and_get_base_stats( | ||
|
@@ -2594,7 +2615,11 @@ def tqdm(level: Set[int]) -> Generator[int, None, None]: | |
prof_idx = col_idx_to_prof_idx[col_idx] | ||
if min_true_samples is None: | ||
min_true_samples = self._profile[prof_idx]._min_true_samples | ||
null_values = self._profile[prof_idx]._null_values | ||
|
||
null_values = self._profile[prof_idx]._null_values.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
if self.options.column_null_values: | ||
null_values.update(self.options.column_null_values.get(col_idx, {})) | ||
|
||
clean_sampled_dict[prof_idx], base_stats = self._profile[ | ||
prof_idx | ||
].clean_data_and_get_base_stats( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added copy