From ff625555b3f3f97812040decbe7157d30b0926e3 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Tue, 12 Mar 2019 17:19:49 +0700 Subject: [PATCH] Use statistics backport Related to https://github.com/kennethreitz/tablib/issues/273 --- requirements.txt | 1 + setup.py | 1 + tablib/compat.py | 2 -- tablib/formats/_rst.py | 3 ++- tablib/packages/statistics.py | 24 ------------------------ 5 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 tablib/packages/statistics.py diff --git a/requirements.txt b/requirements.txt index e00b8d86..feac7787 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ backports.csv; python_version < '3.0' +statistics; python_version < '3.0' odfpy openpyxl>=2.4.0 pandas diff --git a/setup.py b/setup.py index 4e65dd2e..5c5b20c4 100755 --- a/setup.py +++ b/setup.py @@ -36,6 +36,7 @@ 'odfpy', 'openpyxl>=2.4.0', 'backports.csv;python_version<"3.0"', + 'statistics;python_version<"3.0"', 'xlrd', 'xlwt', 'pyyaml', diff --git a/tablib/compat.py b/tablib/compat.py index 660697d1..377dbfa2 100644 --- a/tablib/compat.py +++ b/tablib/compat.py @@ -17,7 +17,6 @@ from io import BytesIO from io import StringIO from tablib.packages import markup3 as markup - from statistics import median from itertools import zip_longest as izip_longest import csv import tablib.packages.dbfpy3 as dbfpy @@ -29,7 +28,6 @@ from cStringIO import StringIO as BytesIO from StringIO import StringIO from tablib.packages import markup - from tablib.packages.statistics import median from itertools import izip_longest from backports import csv import tablib.packages.dbfpy as dbfpy diff --git a/tablib/formats/_rst.py b/tablib/formats/_rst.py index 4b53ad7f..71c112f1 100644 --- a/tablib/formats/_rst.py +++ b/tablib/formats/_rst.py @@ -8,8 +8,9 @@ from textwrap import TextWrapper +from statistics import median + from tablib.compat import ( - median, unicode, izip_longest, ) diff --git a/tablib/packages/statistics.py b/tablib/packages/statistics.py deleted file mode 100644 index e97a6c93..00000000 --- a/tablib/packages/statistics.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import division - - -def median(data): - """ - Return the median (middle value) of numeric data, using the common - "mean of middle two" method. If data is empty, ValueError is raised. - - Mimics the behaviour of Python3's statistics.median - - >>> median([1, 3, 5]) - 3 - >>> median([1, 3, 5, 7]) - 4.0 - - """ - data = sorted(data) - n = len(data) - if not n: - raise ValueError("No median for empty data") - i = n // 2 - if n % 2: - return data[i] - return (data[i - 1] + data[i]) / 2