From cc3dabba6034b70152d676cbbbbb5ddca192a60c Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:48:17 -0400 Subject: [PATCH] csvstat: Add a "Most decimal places" statistic and --max-precision option, wireservice/agate-sql#43 --- CHANGELOG.rst | 2 ++ csvkit/utilities/csvstat.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6871480b7..472244090 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,9 @@ Unreleased * :doc:`/scripts/csvstat` adds a :code:`--json` option to output results as JSON text. * :doc:`/scripts/csvstat` adds an :code:`--indent` option to indent the JSON text when :code:`--json` is set. * :doc:`/scripts/csvstat` reports a "Non-null values" statistic (or a :code:`nonnulls` column when :code:`--csv` is set). +* :doc:`/scripts/csvstat` reports a "Most decimal places" statistic (or a :code:`maxprecision` column when :code:`--csv` is set). * :doc:`/scripts/csvstat` adds a :code:`--non-nulls` option to only output counts of non-null values. +* :doc:`/scripts/csvstat` adds a :code:`--max-precision` option to only output the most decimal places. * feat: Add a :code:`--null-value` option to commands with the :code:`--blanks` option, to convert additional values to NULL. * Add Python 3.12 support. diff --git a/csvkit/utilities/csvstat.py b/csvkit/utilities/csvstat.py index a21ac64a9..2d0a93f71 100644 --- a/csvkit/utilities/csvstat.py +++ b/csvkit/utilities/csvstat.py @@ -56,6 +56,10 @@ 'aggregation': agate.MaxLength, 'label': 'Longest value: ', }), + ('maxprecision', { + 'aggregation': agate.MaxPrecision, + 'label': 'Most decimal places: ', + }), ('freq', { 'aggregation': None, 'label': 'Most common values: ', @@ -117,6 +121,9 @@ def add_arguments(self): self.argparser.add_argument( '--len', dest='len_only', action='store_true', help='Only output the length of the longest values.') + self.argparser.add_argument( + '--max-precision', dest='maxprecision_only', action='store_true', + help='Only output the most decimal places.') self.argparser.add_argument( '--freq', dest='freq_only', action='store_true', help='Only output lists of frequent values.')