• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hgrecco / pint / 1879 / 10
91%
master: 91%

Build:
DEFAULT BRANCH: master
Ran 19 Aug 2020 01:39AM UTC
Files 18
Run time 1s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

19 Aug 2020 01:23AM UTC coverage: 87.365% (+0.006%) from 87.359%
PKGS="python=3.8 numpy=1.17 matplotlib"

push

travis-ci

web-flow
Merge #1150

1150: Add option to disable sorting of formatted unit components r=hgrecco a=lukelbd

- [ ] Closes # (insert issue number) (*n/a*)
- [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors
- [ ] The change is fully covered by automated unit tests (*do I need to address this?*)
- [x] Documented in docs/ as appropriate
- [x] Added an entry to the CHANGES file

This is a very simple PR that adds a `sort` keyword argument to `pint.formatting.formatter`. The `sort` keyword can be set to `False` to optionally disable alphabetical sorting of the component units. This can be useful if your units are conventionally placed in a particular order, or conceptually easier to understand in a particular order.

Also, since preserving the dictionary insertion order is [an explicit python 3.6+ feature](https://docs.python.org/3/whatsnew/3.6.html#new-dict-implementation), the `unit: exponent` pairs in the `UnitsContainer` dictionaries can be reliably expected to preserve their original order, making this feature practically useful for formatting existing `Units` objects.

Here's a quick example with the conventional [specific heat capacity](https://en.wikipedia.org/wiki/Specific_heat_capacity) units:

```python

In  [1]: import pint
    ...: ureg = pint.UnitRegistry()
    ...: units = ureg.parse_units('J kg^-1 K^-1') 

In [2]: units.format_babel('C~', sort=True, as_ratio=False, product_fmt=' ')
Out[2]: 'J K**-1 kg**-1'

In [3]: units.format_babel('C~', sort=False, as_ratio=False, product_fmt=' ')
Out[3]: 'J kg**-1 K**-1'
```

Co-authored-by: Luke Davis <lukelbd@gmail.com>

3644 of 4171 relevant lines covered (87.37%)

0.87 hits per line

Source Files on job 1879.10 (PKGS="python=3.8 numpy=1.17 matplotlib")
  • Tree
  • List 0
  • Changed 1
  • Source Changed 1
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 1745
  • Travis Job 1879.10
  • adcb08a3 on github
  • Prev Job for PKGS="python=3.8 numpy=1.17 matplotlib" on master (#1875.10)
  • Next Job for PKGS="python=3.8 numpy=1.17 matplotlib" on master (#1882.10)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc