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

build_code_export does not escape curly brackets that are used as part of syntax code #669

Closed
lironle6 opened this issue May 24, 2022 · 3 comments

Comments

@lironle6
Copy link

lironle6 commented May 24, 2022

dtale version: 2.4.0

Hi,
Just started using this wonderful package a few days ago and ran into this issue.
replication:

df = pd.read_csv('https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')
dtale.show(df)

then on the website use replacements and
search for: male replace with 0 and click +
search for: female replace with 1 and click +
click replace
now click on "correlations" and it shows:

Traceback (most recent call last):
  File "/home/sta/miniconda3/envs/JLab/lib/python3.9/site-packages/dtale/views.py", line 120, in _handle_exceptions
    return func(*args, **kwargs)
  File "/home/sta/miniconda3/envs/JLab/lib/python3.9/site-packages/dtale/views.py", line 2815, in get_correlations
    matrix_data = build_correlations_matrix(
  File "/home/sta/miniconda3/envs/JLab/lib/python3.9/site-packages/dtale/views.py", line 2749, in build_correlations_matrix
    matrix_code.format(
KeyError: "\n\t'male'"

This happens because the replace code has curly brackets and this wasn't escaped so the next format breaks.
This is the matrix_code before the format breaks:

s = df['Sex']
s = s.replace({
	'male': '0',
	'female': '1'})
df.loc[:, 'Sex'] = s
s = df['Sex']
s = s.replace({
	'male': '0',
	'female': '1'})
df.loc[:, 'Sex'] = s
corr_cols = [
	'{corr_cols}'
]
corr_data = df[corr_cols]
{str_encodings}corr_data = corr_data.corr(method='pearson')

The second line has curly brackets so python tries to format it but doesn't find the relevant key and errors out.
I would suggest either escaping prior code curly brackets, or better yet format the code before joining.

Thanks and keep up the good work!

@aschonfeld
Copy link
Collaborator

@shnitzel6 thanks for bringing this to my attention. I just committed a fix and will let you know when a new version is available

@lironle6
Copy link
Author

Thanks @aschonfeld
Looking forward to it

@aschonfeld
Copy link
Collaborator

@shnitzel6 just released v2.5.1 with this fix. Also, if you haven't already, please toss your ⭐ on the repo. Thanks 🙏

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

No branches or pull requests

2 participants