-
Notifications
You must be signed in to change notification settings - Fork 2
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
Sourcery Starbot ⭐ refactored n8sty/policeShootings #1
base: master
Are you sure you want to change the base?
Conversation
check = df.shape[1] == cols | ||
return(check) | ||
return df.shape[1] == cols |
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.
Function shape_check
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
middle_name = names.map(lambda x: str(' '.join(x))) | ||
middle_name = names.map(lambda x: ' '.join(x)) | ||
|
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.
Function name_processor
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
|
||
cols_names = list(col_mappings[df_name].keys()) | ||
cols_select = list(col_mappings[df_name].values()) | ||
# create an empty dataframe as a destination for data | ||
df_output = pd.DataFrame(columns = col_mapping[df_name].keys()) | ||
|
||
cnt = 0 | ||
for col in cols_select: | ||
if col == None: | ||
col_values = [None] * length | ||
else: | ||
col_values = df[col] | ||
|
||
|
||
for cnt, col in enumerate(cols_select): | ||
col_values = [None] * length if col is None else df[col] | ||
df_output[cols_names[cnt]] = col_values | ||
cnt += 1 | ||
|
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.
Function shootings_df_process
refactored with the following changes:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate
) - Replace if statement with if expression (
assign-if-exp
) - Use x is None rather than x == None (
none-compare
)
|
||
timestamp = strftime("%Y-%m-%d-%H:%M:%S") | ||
|
||
# will create or add to the log file | ||
logging.basicConfig(filename = log_file, level = logging.DEBUG) | ||
logging.info(timestamp + ' ' + log_input) # add in a new line character for easier reading | ||
|
||
logging.info(f'{timestamp} {log_input}') |
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.
Function log_activity
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
# add in a new line character for easier reading
|
||
df = read_csv(url) | ||
|
||
if(df.shape[0] >= 0 and df.shape[1] == num_cols_check): | ||
outcome = log_str + ' success' | ||
if (df.shape[0] >= 0 and df.shape[1] == num_cols_check): | ||
outcome = f'{log_str} success' | ||
else: | ||
outcome = log_str + ' failure' | ||
outcome = f'{log_str} failure' | ||
|
||
log_activity(outcome, log_file) | ||
|
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.
Function load_google_shootings_csv
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
|
||
con = lite.connect(db_name) | ||
tbl_to_update.to_sql(name = tbl_to_update, con = con, flavor = 'sqlite', if_exists = if_exists, chunksize = 50) | ||
log_activity(tbl_to_update + ' updated using method ' + if_exists, log_file) | ||
log_activity(f'{tbl_to_update} updated using method {if_exists}', log_file) | ||
|
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.
Function update_db
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
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
master
branch, then run: