-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
PrettyTable 3.4.1 KeyError in _stringify_header + self._justify(fieldname, width, self._align[field]) #209
Comments
[I transferred this issue from https://github.com/jazzband/help to the PrettyTable repo] How are you calling |
Hi 👋 , this is the full code that produce the error. This method return a list with float valuesdef Euler_Method(function, x, y, max, h, d):
coordinates = []
while(Less_Than(x, max) or Equal_To(x, max)):
# Save values
coordinates.append(round(y,d))
# Update y value
y = y+h*function(x, y)
# Update x value
x = x+h
return coordinates I use this one as to process any function whit the selected method.
import numpy as np
def Calculate(function, y, min, max, h_values, method, d, n):
result = {}
# Calculate x values
x_values = np.linspace(min, max, num=n)
# Calculate y values
y_value = y
for x in x_values[1:]:
# Here will all pairs of y and h values
y_h_list = []
# Calculate y value of the current x value according to each one h vale
for h in h_values:
# Selecting the method to use
if method == Method.EULER:
y_value = Euler_Method(function, x, y, max, h, d)[-1]
elif method == Method.EULER_IMPROVED:
y_value = Euler_Method_Improved(function, x, y, max, h, d)[-1]
elif method == Method.RUNGE_KUTTA:
y_value = Runge_Kutta_Method(function, x, y, max, h, d)[-1]
y_h_list.append((y_value, h))
result[x] = y_h_list
return result And this is the method that I post before.I don't include anything related with the 'method' parameter, because I got the same error with or with out it. from prettytable import PrettyTable
def Create_Table(values: dict, method):
table = PrettyTable()
# Selecting table title
if method == Method.EULER:
table.title = "Euler Method"
elif method == Method.EULER_IMPROVED:
table.title = "Euler Improved Method"
elif method == Method.RUNGE_KUTTA:
table.title = "Runge-Kutta Method"
# Initialize the field names with x tag
table.field_names = ["x"]
# Adding a row for each x value, stored as keys
for x in values:
# The first value of the row will be always the x value
row_temp = [x]
for y_h in values[x]:
# Add y value
row_temp.append(y_h[0])
column_name = "y (h={})".format(str(y_h[1]))
# Check if I need to add the current y(h) to the columns
if column_name not in table.field_names:
table.field_names.append(column_name)
# Add the full row created to the table
table.add_row(row_temp)
print(table) I'm doing something like# Define function
def function(x, y):
return x/(1+y**2)
values = []
# Define initial values
x = -1
y = 1
max = 1
# Define h values
h_list = [0.1, 0.02, 0.004, 0.0008]
# Define number of decimals
d = 5
# Define number of equidistant points
n = 10
# Calculate values
values = Calculate(function, y, x, max, h_list, Method.EULER, d, n)
# Create table.
Create_Table(values, Method.EULER) |
There's no code there :) |
Sorry for that, my pc don't handle very well the web explorer open with the vscode at the same time, and I accidentally click Close with comment |
Is this my error or from PrettyTable?
What did you do?
What did you expect to happen?
What actually happened?
What versions are you using?
Please include code that reproduces the issue.
The best reproductions
are
self-contained scripts
with minimal dependencies.
The text was updated successfully, but these errors were encountered: