From 6813d84dcc733996ede489077a0c72fb5e734e9c Mon Sep 17 00:00:00 2001 From: afvincent Date: Wed, 17 Feb 2016 16:03:07 +0100 Subject: [PATCH 1/7] Update ticker.py --- lib/matplotlib/ticker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 782187cd09d1..4e4996807aa6 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1112,8 +1112,12 @@ def format_eng(self, num): format_str = ("%%.%if %%s" % self.places) formatted = format_str % (mant, prefix) - - return formatted.strip() + + formatted = formatted.strip() + if (self.unit is not "") and (prefix is self.ENG_PREFIXES[0]): + formatted = formatted + " " + + return formatted class PercentFormatter(Formatter): From 6f9bf5f68f7964143fde229a824f96f1705b4c0f Mon Sep 17 00:00:00 2001 From: afvincent Date: Wed, 17 Feb 2016 18:49:51 +0100 Subject: [PATCH 2/7] Unit test on strings coming out of EngFormatter Hope it is what was expected when asking for some unit (non image) test. --- lib/matplotlib/tests/test_ticker.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 94f66e8060e7..02ae8c9bb3ab 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -450,6 +450,26 @@ def test_percentformatter(): yield (_percent_format_helper,) + case +def test_EngFormatter_formatting(): + """ + Create two instances of EngFormatter with default parameters, with and + without a unit string ('s' for seconds). Test the formatting in some cases, + especially the case when no SI prefix is present, for values in [1, 1000). + + Should not exception. + """ + unitless = pef.EngFormatter() + nose.tools.assert_equal(unitless(0.1), u'100 m') + nose.tools.assert_equal(unitless(1), u'1') + nose.tools.assert_equal(unitless(999.9), u'999.9') + nose.tools.assert_equal(unitless(1001), u'1.001 k') + + with_unit = pef.EngFormatter(unit=u's') + nose.tools.assert_equal(with_unit(0.1), u'100 ms') + nose.tools.assert_equal(with_unit(1), u'1 s') + nose.tools.assert_equal(with_unit(999.9), u'999.9 s') + nose.tools.assert_equal(with_unit(1001), u'1.001 ks') + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) From ca341a5a813b3a76ce2fb51f6a7cd9ff9c3b7712 Mon Sep 17 00:00:00 2001 From: afvincent Date: Wed, 17 Feb 2016 19:00:00 +0100 Subject: [PATCH 3/7] Correct name for ticker in EngFormatter test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorry, I was using a different name than “mticker” to import the ticker module, and I had forgotten to change it when committing the new unit test test_EngFormatter_formatting()… --- lib/matplotlib/tests/test_ticker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 02ae8c9bb3ab..35614ff50f76 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -458,13 +458,13 @@ def test_EngFormatter_formatting(): Should not exception. """ - unitless = pef.EngFormatter() + unitless = mticker.EngFormatter() nose.tools.assert_equal(unitless(0.1), u'100 m') nose.tools.assert_equal(unitless(1), u'1') nose.tools.assert_equal(unitless(999.9), u'999.9') nose.tools.assert_equal(unitless(1001), u'1.001 k') - with_unit = pef.EngFormatter(unit=u's') + with_unit = mticker.EngFormatter(unit=u's') nose.tools.assert_equal(with_unit(0.1), u'100 ms') nose.tools.assert_equal(with_unit(1), u'1 s') nose.tools.assert_equal(with_unit(999.9), u'999.9 s') From cf201324e45fe64204a2ee561e9d6f99c9cac7cc Mon Sep 17 00:00:00 2001 From: afvincent Date: Wed, 17 Feb 2016 20:50:51 +0100 Subject: [PATCH 4/7] PEP8 compliance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now “All right” on pep8online.com for the method format_eng in the class EngFormatter. --- lib/matplotlib/ticker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 4e4996807aa6..2aa29eff652c 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1112,11 +1112,11 @@ def format_eng(self, num): format_str = ("%%.%if %%s" % self.places) formatted = format_str % (mant, prefix) - + formatted = formatted.strip() if (self.unit is not "") and (prefix is self.ENG_PREFIXES[0]): formatted = formatted + " " - + return formatted From 7724f0986a6f7e6ee64f153e3be13e485d6cfbea Mon Sep 17 00:00:00 2001 From: afvincent Date: Thu, 18 Feb 2016 08:49:55 +0100 Subject: [PATCH 5/7] New versions of (non) equality statements --- lib/matplotlib/ticker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 2aa29eff652c..cc3edda136de 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1114,7 +1114,7 @@ def format_eng(self, num): formatted = format_str % (mant, prefix) formatted = formatted.strip() - if (self.unit is not "") and (prefix is self.ENG_PREFIXES[0]): + if (self.unit != "") and (prefix == self.ENG_PREFIXES[0]): formatted = formatted + " " return formatted From 6d584adbf6b2ece0b3b17ffb40696bed5a2498a7 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Sun, 5 Jun 2016 10:34:10 +0200 Subject: [PATCH 6/7] Minor fix in the docstring. --- lib/matplotlib/tests/test_ticker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 35614ff50f76..b61345d37086 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -456,7 +456,7 @@ def test_EngFormatter_formatting(): without a unit string ('s' for seconds). Test the formatting in some cases, especially the case when no SI prefix is present, for values in [1, 1000). - Should not exception. + Should not raise exceptions. """ unitless = mticker.EngFormatter() nose.tools.assert_equal(unitless(0.1), u'100 m') From 2ab06c59f0687bbefee7387c23434724b159e8e8 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Mon, 6 Jun 2016 00:26:55 +0200 Subject: [PATCH 7/7] Fix a minor typo in EngFormatter docstring --- lib/matplotlib/ticker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index cc3edda136de..b878589ed051 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1033,7 +1033,7 @@ class EngFormatter(Formatter): suitable for use with single-letter representations of powers of 1000. For example, 'Hz' or 'm'. - `places` is the percision with which to display the number, + `places` is the precision with which to display the number, specified in digits after the decimal point (there will be between one and three digits before the decimal point). """ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy