Skip to content

Commit

Permalink
Merge branch 'master' into 765-print_structure-nested-tableset
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney authored Apr 27, 2024
2 parents cfdc90f + 8eee14a commit 72e83ef
Show file tree
Hide file tree
Showing 34 changed files with 140 additions and 67 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
11 changes: 3 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', pypy-3.7]
exclude:
- os: windows-latest
python-version: 3.7
- os: windows-latest
python-version: pypy-3.7
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', pypy-3.9]
steps:
- if: matrix.os == 'ubuntu-latest'
name: Install UTF-8 locales and lxml requirements
Expand All @@ -22,8 +17,8 @@ jobs:
sudo locale-gen en_US.UTF-8
sudo locale-gen ko_KR.UTF-8
sudo update-locale
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: Lint
on: [push, pull_request]
env:
BASEDIR: https://raw.githubusercontent.com/open-contracting/standard-maintenance-scripts/main
jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ on: push
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install --upgrade build
- run: python -m build --sdist --wheel
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ agate is made by a community. The following individuals have contributed code, d
* `mathdesc <https://github.com/mathdesc>`_
* `Tim Gates <https://github.com/timgates42>`_
* `castorf <https://github.com/castorf>`_
* `Julien Enselme <https://github.com/Jenselme>`__

41 changes: 28 additions & 13 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
Unreleased
----------
1.11.0 - April 27. 2024
-----------------------

* fix: Fix :meth:`.TableSet.print_structure` for nested tablesets. (#765)

1.9.1 - December 21, 2023
-------------------------

* Add Babel 2.14 support.

1.9.0 - October 17, 2023
------------------------

* feat: Add a ``text_truncation_chars`` configuration for values that exceed ``max_column_width`` in :meth:`.Table.print_table` and :meth:`.Table.print_html`.
* feat: Add a ``number_truncation_chars`` configuration for values that exceed ``max_precision`` in :meth:`.Table.print_table` and :meth:`.Table.print_html`.

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

* feat: Lowercase the ``null_values`` provided to individual data types, since all comparisons to ``null_values`` are case-insensitive. (#770)
* feat: :class:`.Mean` works with :class:`.TimeDelta`. (#761)
* fix: Fix :meth:`.TableSet.print_structure` for nested tablesets. (#765)
* Switch from ``pytz`` to ``ZoneInfo``.
* Add Python 3.12 support.
* Drop Python 3.7 support (end-of-life was June 27, 2023).

1.7.1 - Jan 4, 2023
-------------------
1.7.1 - January 4, 2023
-----------------------

* Allow parsedatetime 2.6.

1.7.0 - Jan 3, 2023
-------------------
1.7.0 - January 3, 2023
-----------------------

* Add Python 3.11 support.
* Add Python 3.10 support.
* Drop Python 3.6 support (end-of-life was December 23, 2021).
* Drop Python 2.7 support (end-of-life was January 1, 2020).
* Add Python 3.10 and 3.11 support.
* Drop support for Python 2.7 (EOL 2020-01-01), 3.6 (2021-12-23).

1.6.3 - July 15, 2021
---------------------
Expand All @@ -37,8 +53,7 @@ Unreleased
* fix: Aggregations return ``None`` if all values are ``None``, instead of raising an error. Note that ``Sum``, ``MaxLength`` and ``MaxPrecision`` continue to return ``0`` if all values are ``None``. (#706)
* fix: Ensure files are closed when errors occur. (#734)
* build: Make PyICU an optional dependency.
* Drop Python 3.5 support (end-of-life was September 13, 2020).
* Drop Python 3.4 support (end-of-life was March 18, 2019).
* Drop support for Python 3.4 (2019-03-18), 3.5 (2020-09-13).

1.6.2 - March 10, 2021
----------------------
Expand Down
1 change: 0 additions & 1 deletion agate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import agate.csv_py3 as csv
from agate.aggregations import *
from agate.columns import Column
Expand Down
1 change: 0 additions & 1 deletion agate/aggregations/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from agate.exceptions import UnsupportedAggregationError


Expand Down
1 change: 0 additions & 1 deletion agate/computations/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Computation: # pragma: no cover
"""
Computations produce a new column by performing a calculation on each row.
Expand Down
1 change: 0 additions & 1 deletion agate/computations/percent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from agate.aggregations.has_nulls import HasNulls
from agate.aggregations.sum import Sum
from agate.computations.base import Computation
Expand Down
8 changes: 8 additions & 0 deletions agate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
+-------------------------+------------------------------------------+-----------------------------------------+
| ellipsis_chars | Characters to render for ellipsis | '...' |
+-------------------------+------------------------------------------+-----------------------------------------+
| text_truncation_chars | Characters for truncated text values | '...' |
+-------------------------+------------------------------------------+-----------------------------------------+
| number_truncation_chars | Characters for truncated number values | '…' |
+-------------------------+------------------------------------------+-----------------------------------------+
"""

Expand All @@ -50,6 +54,10 @@
'tick_char': '+',
#: Characters to render for ellipsis
'ellipsis_chars': '...',
#: Characters for truncated text values
'text_truncation_chars': '...',
#: Characters for truncated number values
'number_truncation_chars': '…',
}


Expand Down
1 change: 0 additions & 1 deletion agate/data_types/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from agate.exceptions import CastError

#: Default values which will be automatically cast to :code:`None`
Expand Down
3 changes: 1 addition & 2 deletions agate/data_types/date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class DateTime(DataType):
A formatting string for :meth:`datetime.datetime.strptime` to use
instead of using regex-based parsing.
:param timezone:
A `pytz <https://pytz.sourceforge.net/>`_ timezone to apply to each
parsed date.
A ``ZoneInfo`` timezone to apply to each parsed date.
:param locale:
A locale specification such as :code:`en_US` or :code:`de_DE` to use
for parsing formatted datetimes.
Expand Down
7 changes: 5 additions & 2 deletions agate/data_types/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def __init__(self, locale='en_US', group_symbol=None, decimal_symbol=None,
with warnings.catch_warnings():
warnings.simplefilter("ignore")

self.group_symbol = group_symbol or self.locale.number_symbols.get('group', ',')
self.decimal_symbol = decimal_symbol or self.locale.number_symbols.get('decimal', '.')
# Babel 2.14 support.
# https://babel.pocoo.org/en/latest/changelog.html#possibly-backwards-incompatible-changes
number_symbols = self.locale.number_symbols.get('latn', self.locale.number_symbols)
self.group_symbol = group_symbol or number_symbols.get('group', ',')
self.decimal_symbol = decimal_symbol or number_symbols.get('decimal', '.')

def cast(self, d):
"""
Expand Down
1 change: 0 additions & 1 deletion agate/data_types/text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from agate.data_types.base import DataType


Expand Down
1 change: 0 additions & 1 deletion agate/table/find.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def find(self, test):
"""
Find the first row that passes a test.
Expand Down
19 changes: 19 additions & 0 deletions agate/table/from_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ def from_object(cls, obj, row_names=None, column_types=None):
Not all rows are required to have the same keys. Missing elements will
be filled in with null values.
Keys containing a slash (``/``) can collide with other keys. For example:
.. code-block:: python
{
'a/b': 2,
'a': {
'b': False
}
}
Would generate:
.. code-block:: python
{
'a/b': false
}
:param obj:
Filepath or file-like object from which to read JSON data.
:param row_names:
Expand Down
1 change: 0 additions & 1 deletion agate/table/limit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def limit(self, start_or_stop=None, stop=None, step=None):
"""
Create a new table with fewer rows.
Expand Down
1 change: 0 additions & 1 deletion agate/table/pivot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from agate import utils
from agate.aggregations import Count

Expand Down
4 changes: 3 additions & 1 deletion agate/table/print_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ 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')
truncation = config.get_option('text_truncation_chars')
len_truncation = len(truncation)
locale = locale or config.get_option('default_locale')

rows_truncated = max_rows < len(self._rows)
Expand Down Expand Up @@ -93,7 +95,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_truncation], truncation)

formatted_row.append(v)

Expand Down
6 changes: 4 additions & 2 deletions agate/table/print_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ 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')
truncation = config.get_option('text_truncation_chars')
len_truncation = len(truncation)
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 +56,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_truncation], truncation))
else:
column_names.append(column_name)

Expand Down Expand Up @@ -102,7 +104,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_truncation], truncation)

if len(v) > widths[j]:
widths[j] = len(v)
Expand Down
4 changes: 3 additions & 1 deletion agate/table/to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def to_csv(self, path, **kwargs):
Write this table to a CSV. This method uses agate's builtin CSV writer,
which supports unicode on both Python 2 and Python 3.
`kwargs` will be passed through to the CSV writer.
``kwargs`` will be passed through to the CSV writer.
The ``lineterminator`` defaults to the newline character (LF, ``\\n``).
:param path:
Filepath or file-like object to write to.
Expand Down
1 change: 0 additions & 1 deletion agate/table/where.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def where(self, test):
"""
Create a new :class:`.Table` with only those rows that pass a test.
Expand Down
1 change: 0 additions & 1 deletion agate/tableset/having.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def having(self, aggregations, test):
"""
Create a new :class:`.TableSet` with only those tables that pass a test.
Expand Down
1 change: 0 additions & 1 deletion agate/tableset/proxy_methods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def bins(self, *args, **kwargs):
"""
Calls :meth:`.Table.bins` on each table in the TableSet.
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('number_truncation_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.7.1'
version = '1.9.1'
release = version

# -- General configuration ---------------------------------------------------
Expand Down
18 changes: 13 additions & 5 deletions docs/cookbook/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ The second way is to specify a timezone as an argument to the type constructor:

.. code-block:: python
import pytz
try:
from zoneinfo import ZoneInfo
except ImportError:
# Fallback for Python < 3.9
from backports.zoneinfo import ZoneInfo
eastern = pytz.timezone('US/Eastern')
eastern = ZoneInfo('US/Eastern')
datetime_type = agate.DateTime(timezone=eastern)
In this case all timezones that are processed will be set to have the Eastern timezone. Note, the timezone will be **set**, not converted. You cannot use this method to convert your timezones from UTC to another timezone. To do that see :ref:`convert_timezones`.
Expand All @@ -60,17 +64,21 @@ If you load data from a spreadsheet in one timezone and you need to convert it t

.. code-block:: python
import pytz
try:
from zoneinfo import ZoneInfo
except ImportError:
# Fallback for Python < 3.9
from backports.zoneinfo import ZoneInfo
us_eastern = pytz.timezone('US/Eastern')
us_eastern = ZoneInfo('US/Eastern')
datetime_type = agate.DateTime(timezone=us_eastern)
column_names = ['what', 'when']
column_types = [text_type, datetime_type]
table = agate.Table.from_csv('events.csv', columns)
rome = timezone('Europe/Rome')
rome = ZoneInfo('Europe/Rome')
timezone_shifter = agate.Formula(lambda r: r['when'].astimezone(rome))
table = agate.Table.compute([
Expand Down
Loading

0 comments on commit 72e83ef

Please sign in to comment.