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

Sourcery Starbot ⭐ refactored n8sty/policeShootings #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/policeShootings master
git merge --ff-only FETCH_HEAD
git reset HEAD^

check = df.shape[1] == cols
return(check)
return df.shape[1] == cols
Copy link
Author

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:

middle_name = names.map(lambda x: str(' '.join(x)))
middle_name = names.map(lambda x: ' '.join(x))

Copy link
Author

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:

Comment on lines -107 to -122

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

Copy link
Author

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:

Comment on lines -23 to +29

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}')
Copy link
Author

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:

This removes the following comments ( why? ):

# add in a new line character for easier reading

Comment on lines -34 to +43

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)

Copy link
Author

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:

Comment on lines -87 to +91

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)

Copy link
Author

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:

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