-
Notifications
You must be signed in to change notification settings - Fork 209
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
coerce float if string or tuple #569
Draft
dcolinmorgan
wants to merge
6
commits into
master
Choose a base branch
from
fix/hetero_feat2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7f6d31e
initial fix, need more robust synth data
dcolinmorgan 66a7bf2
explode adds node names -- need smart fix
dcolinmorgan 08b36b2
test_feat_type_edgecase passing
dcolinmorgan 99a1982
no explode, take first element in tuple as float
dcolinmorgan 05d0c8e
revert print in umap_utils
dcolinmorgan b21a0f0
lint
dcolinmorgan 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 |
---|---|---|
|
@@ -393,6 +393,28 @@ def convert_money_string_to_float(money: str): | |
mask = where_is_currency_column(df, col) | ||
df[col, mask] = df[col, mask].apply(convert_money_string_to_float) | ||
|
||
def try_coerce_to_numeric(ndf: pd.DataFrame): | ||
try: | ||
nndf = ndf.copy() | ||
object_columns = nndf.select_dtypes(include=['object']).columns | ||
for j in object_columns: | ||
num_floats = sum(isinstance(x, float) for x in nndf[j].dropna()) | ||
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. This is slow, and weird to check for floats in a col marked as object? |
||
if num_floats > len(nndf[j]) / 2: # most of column is float | ||
try: | ||
nndf[j] = [float(value) if not isinstance(value, float) else value for value in nndf[j]] | ||
logger.info("Coerced strings to floats") | ||
except: | ||
# nndf[j] = nndf[j].apply(lambda x: str(x).split() if isinstance(x, str) and ' ' in x else x) | ||
# nndf = nndf.explode(j) | ||
# logger.info("Exploded rows with multiple values in single cell") | ||
nndf[j] = nndf[j].apply(lambda x: str(x).split()[0] if isinstance(x, str) and ' ' in x else x) | ||
nndf[j] = nndf[j].astype(float) | ||
nndf.reset_index(drop=True, inplace=True) | ||
logger.info("took first float of tuple in single cell") | ||
|
||
except: | ||
pass | ||
return nndf | ||
|
||
def is_dataframe_all_numeric(df: pd.DataFrame) -> bool: | ||
is_all_numeric = True | ||
|
@@ -890,6 +912,7 @@ def process_dirty_dataframes( | |
from sklearn.preprocessing import FunctionTransformer | ||
t = time() | ||
|
||
ndf = try_coerce_to_numeric(ndf) | ||
all_numeric = is_dataframe_all_numeric(ndf) | ||
if not all_numeric and has_dirty_cat: | ||
data_encoder = SuperVectorizer( | ||
|
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
Oops, something went wrong.
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.
:(