-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add auto index column #106
Conversation
Codecov Report
@@ Coverage Diff @@
## master #106 +/- ##
==========================================
+ Coverage 87.68% 87.96% +0.27%
==========================================
Files 3 3
Lines 1535 1562 +27
==========================================
+ Hits 1346 1374 +28
+ Misses 189 188 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Should i add a test for this function? how should i handle those 5 failing checks? |
Thanks for the PR! Please could you add tests to We can ignore the 3.10-dev failures for now, it's unrelated and caused by pytest not yet supporting 3.10 beta. |
I will work on it, thank you! |
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
…ad of string matching as per jazzband#90
…ad of string matching as per jazzband#90
So this takes a table like this:
And adds an index to the right column:
However, @yanhuihang's example in #90 showed the index on the left column:
Would it be better on the left? And should it be possible to set the column's field name to something else via a parameter? It can default to "Index". |
Taking everything you said into consideration, I think i will remove valign and align as it is not necessary to have a separate formatting in the index column, i will add a parameter that represents the name of the index column and i will try to add the column on the left as I agree, this how it is normally done. Thank you very much for the guidance. |
…ft of the table as per jazzband#90
…ft of the table as per jazzband#90
I modified the function to add the column on the left, and added the def add_column(self, fieldname, column, align="c", valign="t"):
"""Add a column to the table.
Arguments:
fieldname - name of the field to contain the new column of data
column - column of data, should be a list with as many elements as the
table has rows
align - desired alignment for this column - "l" for left, "c" for centre and
"r" for right
valign - desired vertical alignment for new columns - "t" for top,
"m" for middle and "b" for bottom"""
if len(self._rows) in (0, len(column)):
self._validate_align(align)
self._validate_valign(valign)
self._field_names.append(fieldname)
self._align[fieldname] = align
self._valign[fieldname] = valign
for i in range(0, len(column)):
if len(self._rows) < i + 1:
self._rows.append([])
self._rows[i].append(column[i])
else:
raise Exception(
f"Column length {len(column)} does not match number of rows "
f"{len(self._rows)}"
) If that is ok please inform me so i can create a PR that also covers the |
…s for add_autoindex as per jazzband#90
Thank you very much! |
Is this index broken if you apply sort? |
It adds a column to the data, so if you sort after adding, yes. So it's best sort first and add the index last. |
Cool Is it possible to formatted index like 001, 002 etc ? |
No. |
No worries |
You can always manually add a column with whatever data you want, including numbers formatted however you like. |
Yes I have done exactly that. Thanks my_list.sort(key=lambda a: a[1])
for idx, val in enumerate(my_list):
val.insert(0, f"{(idx + 1):0>3}") |
Fixes #90.