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

[docs] tweak diet.jl tutorial to use more DataFrame logic #3213

Merged
merged 4 commits into from
Feb 11, 2023
Merged

Conversation

odow
Copy link
Member

@odow odow commented Feb 9, 2023

@codecov
Copy link

codecov bot commented Feb 9, 2023

Codecov Report

Base: 98.06% // Head: 97.93% // Decreases project coverage by -0.14% ⚠️

Coverage data is based on head (a7c2474) compared to base (451740a).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3213      +/-   ##
==========================================
- Coverage   98.06%   97.93%   -0.14%     
==========================================
  Files          34       34              
  Lines        4597     4597              
==========================================
- Hits         4508     4502       -6     
- Misses         89       95       +6     
Impacted Files Coverage Δ
src/solution_summary.jl 96.25% <0.00%> (-1.25%) ⬇️
src/sd.jl 99.30% <0.00%> (-0.70%) ⬇️
src/lp_sensitivity2.jl 97.20% <0.00%> (-0.56%) ⬇️
src/aff_expr.jl 96.86% <0.00%> (-0.40%) ⬇️
src/Containers/DenseAxisArray.jl 95.51% <0.00%> (-0.35%) ⬇️
src/print.jl 99.47% <0.00%> (-0.27%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jd-foster
Copy link
Collaborator

I think it improves the overall clarity. I added two comments that might help.


@variable(model, x[foods.name] >= 0);
@variable(model, x[foods.name] >= 0)
foods.x = Array(x)
Copy link
Member Author

Choose a reason for hiding this comment

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

@jd-foster: I changed it to this so that x has meaningful indices instead of x[1] through x[n]`. Too magical?

Copy link
Collaborator

@jd-foster jd-foster Feb 9, 2023

Choose a reason for hiding this comment

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

I thought about this change, and concluded it didn't matter if the index matched the name since it's row already has the key column. It matters if you split the JuMP variable column off the dataframe.

But personally prefer the way you've changed it to now.

@odow
Copy link
Member Author

odow commented Feb 9, 2023

Here's the preview: https://jump.dev/JuMP.jl/previews/PR3213/tutorials/linear/diet/. I think I need to show the data frame with the x as a column.

@odow
Copy link
Member Author

odow commented Feb 10, 2023

Hmm. The doc failure is problematic and has exposed a subtle bug. It's because of this:

julia> foods
9×7 DataFrame
 Row │ name       cost  calories  protein  fat  sodium  x            
     │ Any        Any   Any       Any      Any  Any     Variable    
─────┼───────────────────────────────────────────────────────────────
   1 │ hamburger  2.49  410       24       26   730     x[hamburger]
   2 │ chicken    2.89  420       32       10   1190    x[chicken]
   3 │ hot dog    1.5   560       20       32   1800    x[hot dog]
   4 │ fries      1.89  380       4        19   270     x[fries]
   5 │ macaroni   2.09  320       12       10   930     x[macaroni]
   6 │ pizza      1.99  320       15       12   820     x[pizza]
   7 │ salad      2.49  320       31       12   1230    x[salad]
   8 │ milk       0.89  100       8        2.5  125     x[milk]
   9 │ ice cream  1.59  330       8        10   180     x[ice cream]

julia> show(stdout, MIME("text/latex"), foods)
\begin{tabular}{r|ccccccc}
	& name & cost & calories & protein & fat & sodium & x\\
	\hline
	& Any & Any & Any & Any & Any & Any & Variable\\
	\hline
	1 & hamburger & 2.49 & 410 & 24 & 26 & 730 & $$ x_{hamburger} $$ \\
	2 & chicken & 2.89 & 420 & 32 & 10 & 1190 & $$ x_{chicken} $$ \\
	3 & hot dog & 1.5 & 560 & 20 & 32 & 1800 & $$ x_{hot dog} $$ \\
	4 & fries & 1.89 & 380 & 4 & 19 & 270 & $$ x_{fries} $$ \\
	5 & macaroni & 2.09 & 320 & 12 & 10 & 930 & $$ x_{macaroni} $$ \\
	6 & pizza & 1.99 & 320 & 15 & 12 & 820 & $$ x_{pizza} $$ \\
	7 & salad & 2.49 & 320 & 31 & 12 & 1230 & $$ x_{salad} $$ \\
	8 & milk & 0.89 & 100 & 8 & 2.5 & 125 & $$ x_{milk} $$ \\
	9 & ice cream & 1.59 & 330 & 8 & 10 & 180 & $$ x_{ice cream} $$ \\
\end{tabular}

The variable is being typeset as $$ x $$, but it's actually being used within a cell which doesn't support display equations.

I wonder what the impact is if we wrote everything as an inline equation.

@odow odow merged commit ceff7b2 into master Feb 11, 2023
@odow odow deleted the od/doc-df branch February 11, 2023 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants