Skip to content

Commit

Permalink
feat: Change the default ellipsis_chars to … and use it when max_colu…
Browse files Browse the repository at this point in the history
…mn_width or max_precision is exceeded, #738
  • Loading branch information
jpmckinney committed Oct 18, 2023
1 parent d3bf621 commit b7b5dc1
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.9.0 - October 17, 2023
------------------------

* feat: Change the default ``ellipsis_chars`` configuration to ````, instead of ``...``.
* feat: Use the ``ellipsis_chars`` configuration when the ``max_column_width`` or ``max_precision`` is exceeded in :meth:`.Table.print_table` and :meth:`.Table.print_html`, instead of ``...``.

1.8.0 - October 10, 2023
------------------------

Expand Down
4 changes: 2 additions & 2 deletions agate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
+-------------------------+------------------------------------------+-----------------------------------------+
| tick_char | Character to render for axis ticks | '+' |
+-------------------------+------------------------------------------+-----------------------------------------+
| ellipsis_chars | Characters to render for ellipsis | '...' |
| ellipsis_chars | Characters to render for ellipsis | '…' |
+-------------------------+------------------------------------------+-----------------------------------------+
"""
Expand All @@ -49,7 +49,7 @@
#: Character to render for axis ticks
'tick_char': '+',
#: Characters to render for ellipsis
'ellipsis_chars': '...',
'ellipsis_chars': '',
}


Expand Down
2 changes: 1 addition & 1 deletion agate/table/denormalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def denormalize(self, key=None, property_column='property', value_column='value'
+---------+-----------+---------+
| Jane | age | 24 |
+---------+-----------+---------+
| ... | ... | ... |
| | … | … |
+---------+-----------+---------+
Can be denormalized so that each unique value in `field` becomes a
Expand Down
2 changes: 1 addition & 1 deletion agate/table/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def normalize(self, key, properties, property_column='property', value_column='v
+---------+-----------+---------+
| Jane | age | 24 |
+---------+-----------+---------+
| ... | ... | ... |
| | … | … |
+---------+-----------+---------+
This is the opposite of :meth:`.Table.denormalize`.
Expand Down
3 changes: 2 additions & 1 deletion agate/table/print_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def print_html(self, max_rows=20, max_columns=6, output=sys.stdout, max_column_w
max_precision = float('inf')

ellipsis = config.get_option('ellipsis_chars')
len_ellipsis = len(ellipsis)
locale = locale or config.get_option('default_locale')

rows_truncated = max_rows < len(self._rows)
Expand Down Expand Up @@ -93,7 +94,7 @@ def print_html(self, max_rows=20, max_columns=6, output=sys.stdout, max_column_w
v = str(v)

if max_column_width is not None and len(v) > max_column_width:
v = '%s...' % v[:max_column_width - 3]
v = '%s%s' % (v[:max_column_width - len_ellipsis], ellipsis)

formatted_row.append(v)

Expand Down
5 changes: 3 additions & 2 deletions agate/table/print_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def print_table(self, max_rows=20, max_columns=6, output=sys.stdout, max_column_
max_precision = float('inf')

ellipsis = config.get_option('ellipsis_chars')
len_ellipsis = len(ellipsis)
h_line = config.get_option('horizontal_line_char')
v_line = config.get_option('vertical_line_char')
locale = locale or config.get_option('default_locale')
Expand All @@ -54,7 +55,7 @@ def print_table(self, max_rows=20, max_columns=6, output=sys.stdout, max_column_
column_names = []
for column_name in self.column_names[:max_columns]:
if max_column_width is not None and len(column_name) > max_column_width:
column_names.append('%s...' % column_name[:max_column_width - 3])
column_names.append('%s%s' % (column_name[:max_column_width - len_ellipsis], ellipsis))
else:
column_names.append(column_name)

Expand Down Expand Up @@ -102,7 +103,7 @@ def print_table(self, max_rows=20, max_columns=6, output=sys.stdout, max_column_
v = str(v)

if max_column_width is not None and len(v) > max_column_width:
v = '%s...' % v[:max_column_width - 3]
v = '%s%s' % (v[:max_column_width - len_ellipsis], ellipsis)

if len(v) > widths[j]:
widths[j] = len(v)
Expand Down
3 changes: 2 additions & 1 deletion agate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from slugify import slugify as pslugify

from agate import config
from agate.warns import warn_duplicate_column, warn_unnamed_column

#: Sentinal for use when `None` is an valid argument value
Expand Down Expand Up @@ -161,7 +162,7 @@ def make_number_formatter(decimal_places, add_ellipsis=False):
Optionally add an ellipsis symbol at the end of a number
"""
fraction = '0' * decimal_places
ellipsis = '…' if add_ellipsis else ''
ellipsis = config.get_option('ellipsis_chars') if add_ellipsis else ''
return ''.join(['#,##0.', fraction, ellipsis, ';-#,##0.', fraction, ellipsis])


Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

project = 'agate'
copyright = '2017, Christopher Groskopf'
version = '1.8.0'
version = '1.9.0'
release = version

# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/cookbook/transform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ It's common for very large datasets to be distributed in a "normalized" format,
+---------+-----------+---------+
| Jane | age | 24 |
+---------+-----------+---------+
| ... | ... | ... |
| | | |
+---------+-----------+---------+

The :meth:`.Table.denormalize` method can be used to transform the table so that each unique property has its own column.
Expand Down Expand Up @@ -201,5 +201,5 @@ Result:
+---------+-----------+---------+
| Jane | age | 24 |
+---------+-----------+---------+
| ... | ... | ... |
| | | |
+---------+-----------+---------+
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='agate',
version='1.8.0',
version='1.9.0',
description='A data analysis library that is optimized for humans instead of machines.',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_table/test_print_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_print_table_max_columns(self):
lines = output.getvalue().split('\n')

self.assertEqual(len(lines), 6)
self.assertEqual(len(lines[0]), 23)
self.assertEqual(len(lines[0]), 21)

def test_print_table_max_precision(self):
rows = (
Expand Down Expand Up @@ -104,8 +104,8 @@ def test_print_table_max_column_width(self):
table.print_table(output=output, max_column_width=7)
lines = output.getvalue().split('\n')

self.assertIn(' also... ', lines[0])
self.assertIn(' this... ', lines[2])
self.assertIn(' also, … ', lines[0])
self.assertIn(' this i… ', lines[2])
self.assertIn(' nope ', lines[4])

def test_print_table_locale_american(self):
Expand Down
34 changes: 17 additions & 17 deletions tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -842,18 +842,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"| last_name | first_name | age | race | state | tags | crime | ... |\n",
"| --------- | ---------- | --- | --------- | ----- | ------- | ------- | --- |\n",
"| Murray | Lacresha | 11 | Black | TX | CV, F | Murder | ... |\n",
"| Adams | Johnathan | 12 | Caucasian | GA | CV, P | Murder | ... |\n",
"| Harris | Anthony | 12 | Black | OH | CV | Murder | ... |\n",
"| Edmonds | Tyler | 13 | Caucasian | MS | | Murder | ... |\n",
"| Handley | Zachary | 13 | Caucasian | PA | A, CV | Arson | ... |\n",
"| Jimenez | Thaddeus | 13 | Hispanic | IL | | Murder | ... |\n",
"| Pacek | Jerry | 13 | Caucasian | PA | | Murder | ... |\n",
"| Barr | Jonathan | 14 | Black | IL | CDC, CV | Murder | ... |\n",
"| Brim | Dominique | 14 | Black | MI | F | Assault | ... |\n",
"| Brown | Timothy | 14 | Black | FL | | Murder | ... |\n"
"| last_name | first_name | age | race | state | tags | crime | |\n",
"| --------- | ---------- | --- | --------- | ----- | ------- | ------- | - |\n",
"| Murray | Lacresha | 11 | Black | TX | CV, F | Murder | |\n",
"| Adams | Johnathan | 12 | Caucasian | GA | CV, P | Murder | |\n",
"| Harris | Anthony | 12 | Black | OH | CV | Murder | |\n",
"| Edmonds | Tyler | 13 | Caucasian | MS | | Murder | |\n",
"| Handley | Zachary | 13 | Caucasian | PA | A, CV | Arson | |\n",
"| Jimenez | Thaddeus | 13 | Hispanic | IL | | Murder | |\n",
"| Pacek | Jerry | 13 | Caucasian | PA | | Murder | |\n",
"| Barr | Jonathan | 14 | Black | IL | CDC, CV | Murder | |\n",
"| Brim | Dominique | 14 | Black | MI | F | Assault | |\n",
"| Brown | Timothy | 14 | Black | FL | | Murder | |\n"
]
}
],
Expand Down Expand Up @@ -966,7 +966,7 @@
"| CA | 164 |\n",
"| IL | 158 |\n",
"| MI | 63 |\n",
"| ... | ... |\n"
"| | |\n"
]
}
],
Expand Down Expand Up @@ -1002,14 +1002,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"| state | count | median_years_in_p... |\n",
"| state | count | median_years_in_pri. |\n",
"| ----- | ----- | -------------------- |\n",
"| DC | 15 | 27 |\n",
"| NE | 9 | 20 |\n",
"| ID | 2 | 19 |\n",
"| VT | 1 | 18 |\n",
"| LA | 45 | 16 |\n",
"| ... | ... | ... |\n"
"| | | |\n"
]
}
],
Expand Down Expand Up @@ -1068,7 +1068,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"| race | age_group | count | median_years_in_p... |\n",
"| race | age_group | count | median_years_in_pri… |\n",
"| --------------- | --------- | ----- | -------------------- |\n",
"| Native American | 20s | 2 | 21.5 |\n",
"| | 20s | 1 | 19.0 |\n",
Expand All @@ -1080,7 +1080,7 @@
"| Black | 30s | 156 | 10.0 |\n",
"| Caucasian | 10s | 76 | 8.0 |\n",
"| Caucasian | 20s | 255 | 8.0 |\n",
"| ... | ... | ... | ... |\n"
"| | … | | |\n"
]
}
],
Expand Down

0 comments on commit b7b5dc1

Please sign in to comment.