Skip to content

Sourcery Starbot ⭐ refactored chip-felton-montage/sfguide-data-engineering-with-snowpark-python#1

Open
SourceryAI wants to merge 1 commit into
chip-felton:mainfrom
SourceryAI:main
Open

Sourcery Starbot ⭐ refactored chip-felton-montage/sfguide-data-engineering-with-snowpark-python#1
SourceryAI wants to merge 1 commit into
chip-felton:mainfrom
SourceryAI:main

Conversation

@SourceryAI
Copy link
Copy Markdown

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch https://github.com/sourcery-ai-bot/sfguide-data-engineering-with-snowpark-python main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment thread deploy_snowpark_apps.py
Comment on lines -25 to +31
if not "app.toml" in file_names:
if "app.toml" not in file_names:
# print(f"Skipping non-app folder {directory_path}")
continue

# Next determine what type of app it is
app_type = "unknown"
if "local_connection.py" in file_names:
app_type = "procedure"
else:
app_type = "function"

app_type = "procedure" if "local_connection.py" in file_names else "function"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 25-35 refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)
  • Replace if statement with if expression (assign-if-exp)

Comment thread steps/02_load_raw.py
Comment on lines -28 to +36
location = "@external.frostbyte_raw_stage/{}/{}".format(s3dir, tname)
location = f"@external.frostbyte_raw_stage/{s3dir}/{tname}"
else:
print('\tLoading year {}'.format(year))
location = "@external.frostbyte_raw_stage/{}/{}/year={}".format(s3dir, tname, year)
print(f'\tLoading year {year}')
location = f"@external.frostbyte_raw_stage/{s3dir}/{tname}/year={year}"

# we can infer schema using the parquet read option
df = session.read.option("compression", "snappy") \
.parquet(location)
df.copy_into_table("{}".format(tname))
df.copy_into_table(f"{tname}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function load_raw_table refactored with the following changes:

Comment thread steps/02_load_raw.py
schema = data['schema']
for tname in tnames:
print("Loading {}".format(tname))
print(f"Loading {tname}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function load_all_raw_tables refactored with the following changes:

Comment thread steps/02_load_raw.py
Comment on lines -61 to +64
print('{}: \n\t{}\n'.format(tname, session.table('RAW_POS.{}'.format(tname)).columns))
print(f"{tname}: \n\t{session.table(f'RAW_POS.{tname}').columns}\n")

for tname in CUSTOMER_TABLES:
print('{}: \n\t{}\n'.format(tname, session.table('RAW_CUSTOMER.{}'.format(tname)).columns))
print(f"{tname}: \n\t{session.table(f'RAW_CUSTOMER.{tname}').columns}\n")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function validate_raw_tables refactored with the following changes:


def main(temp_f: float) -> float:
return (float(temp_f) - 32) * (5/9)
return (temp_f - 32) * (5/9)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -15 to +17
exists = session.sql("SELECT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{}' AND TABLE_NAME = '{}') AS TABLE_EXISTS".format(schema, name)).collect()[0]['TABLE_EXISTS']
return exists
return session.sql(
f"SELECT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{schema}' AND TABLE_NAME = '{name}') AS TABLE_EXISTS"
).collect()[0]['TABLE_EXISTS']
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function table_exists refactored with the following changes:

Comment on lines -41 to +42
print("{} records in stream".format(session.table('HARMONIZED.ORDERS_STREAM').count()))
print(f"{session.table('HARMONIZED.ORDERS_STREAM').count()} records in stream")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function merge_daily_city_metrics refactored with the following changes:

Comment on lines -98 to +103

merge_daily_city_metrics(session)
# session.table('ANALYTICS.DAILY_CITY_METRICS').limit(5).show()

return f"Successfully processed DAILY_CITY_METRICS"
return "Successfully processed DAILY_CITY_METRICS"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

for k, v in session_config.items()
}
session_config_dict.update(app_config.get(environment)) # type: ignore
session_config_dict |= app_config.get(environment)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_dev_config refactored with the following changes:

This removes the following comments ( why? ):

# type: ignore

Comment thread utils/snowpark_utils.py
Comment on lines -71 to -80
connection_path = 'connections.' + connection_name
connection_path = f'connections.{connection_name}'

config.read(config_file_path)
session_config = config[connection_path]
# Convert snowsql connection variable names to snowcli ones
session_config_dict = {
return {
snowsql_to_snowpark_config_mapping[k]: v.strip('"')
for k, v in session_config.items()
}
return session_config_dict
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_snowsql_config refactored with the following changes:

This removes the following comments ( why? ):

# Convert snowsql connection variable names to snowcli ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant