Skip to content

Commit 90c74c8

Browse files
bors[bot]znichollsandrewgsavage
committed
Merge #684
684: Add pandas support r=hgrecco a=znicholls This pull request adds pandas support to pint (hence is related to #645, #401 and pandas-dev/pandas#10349). An example can be seen in `example-notebooks/basic-example.ipynb`. It's a little bit hacksih, feedback would be greatly appreciated by me and @andrewgsavage. One obvious example is that we have to run all the interface tests with `pytest` to fit with `pandas` test suite, which introduces a dependency for the CI and currently gives us this awkward testing setup (see the alterations we had to make to `testsuite`). This also means that our code coverage tests are fiddly too. If you'd like us to squash the commits, that can be done. If pint has a linter, it would be good to run that over this pull request too as we're a little bit all over the place re style. Things to discuss: - [x] general feedback and changes - [x] test setup, especially need for pytest for pandas tests and hackish way to get around automatic discovery - [x] squashing/rebasing - [x] linting/other code style (related to #664 and #628: we're happy with whatever, I've found using an automatic linter e.g. black and/or flake8 has made things much simpler in other projects) - [x] including notebooks in the repo (if we want to, I'm happy to put them under CI so we can make sure they run) - [x] setting up the docs correctly Co-authored-by: Zebedee Nicholls <[email protected]> Co-authored-by: andrewgsavage <[email protected]>
2 parents 62f0c00 + d17c745 commit 90c74c8

File tree

11 files changed

+2942
-20
lines changed

11 files changed

+2942
-20
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build/
99
dist/
1010
MANIFEST
1111
.tox
12+
*pytest_cache*
1213

1314
# WebDAV file system cache files
1415
.DAV/
@@ -18,3 +19,9 @@ tags
1819

1920
test/
2021
.coverage*
22+
23+
# notebook stuff
24+
*.ipynb_checkpoints*
25+
26+
# test csv which should be user generated
27+
notebooks/pandas_test.csv

.travis.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ branches:
77
- trying.tmp
88

99
env:
10-
- UNCERTAINTIES="N" PYTHON="3.3" NUMPY_VERSION=1.9.2
11-
- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.11.2
12-
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=1.11.2
13-
- UNCERTAINTIES="Y" PYTHON="3.5" NUMPY_VERSION=1.11.2
14-
- UNCERTAINTIES="N" PYTHON="3.6" NUMPY_VERSION=1.11.2
15-
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=0
16-
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=0
10+
- UNCERTAINTIES="N" PYTHON="3.6" NUMPY_VERSION=1.14 PANDAS=1
11+
- UNCERTAINTIES="N" PYTHON="3.3" NUMPY_VERSION=1.9.2 PANDAS=0
12+
- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.11.2 PANDAS=0
13+
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=1.11.2 PANDAS=0
14+
- UNCERTAINTIES="Y" PYTHON="3.5" NUMPY_VERSION=1.11.2 PANDAS=0
15+
- UNCERTAINTIES="N" PYTHON="3.6" NUMPY_VERSION=1.11.2 PANDAS=0
16+
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=0 PANDAS=0
17+
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=0 PANDAS=0
1718
# Test with the latest numpy version
18-
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=1.14
19-
- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.14
20-
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=1.14
21-
- UNCERTAINTIES="Y" PYTHON="3.5" NUMPY_VERSION=1.14
22-
- UNCERTAINTIES="N" PYTHON="3.6" NUMPY_VERSION=1.14
19+
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=1.14 PANDAS=0
20+
- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.14 PANDAS=0
21+
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=1.14 PANDAS=0
22+
- UNCERTAINTIES="Y" PYTHON="3.5" NUMPY_VERSION=1.14 PANDAS=0
23+
- UNCERTAINTIES="N" PYTHON="3.6" NUMPY_VERSION=1.14 PANDAS=0
2324

2425
before_install:
2526
- sudo apt-get update
@@ -48,10 +49,17 @@ install:
4849
- if [ $UNCERTAINTIES == 'Y' ]; then pip install 'uncertainties==2.4.7.1'; fi
4950
- if [ $NUMPY_VERSION != '0' ]; then conda install --yes numpy==$NUMPY_VERSION; fi
5051
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $NUMPY_VERSION == 1.11.2 && $UNCERTAINTIES == "Y" ]]; then pip install babel serialize pyyaml; fi
52+
# this is superslow but suck it up until updates to pandas are made
53+
- if [[ $PANDAS == '1' ]]; then pip install numpy cython pytest pytest-cov nbval; pip install git+https://github.com/pandas-dev/pandas.git; fi
5154
- pip install coveralls
5255

5356
script:
54-
- python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" setup.py test
57+
# if we're doing the pandas tests and hence have pytest available, we can
58+
# simply use it to run all the tests
59+
- if [[ $PANDAS == '1' ]]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" -m py.test; fi
60+
# test notebooks too if pandas available
61+
- if [[ $PANDAS == '1' ]]; then pip install -e .; pytest --nbval notebooks/*; fi
62+
- if [[ $PANDAS == '0' ]]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*","*pandas*" setup.py test; fi
5563
- coverage combine
5664
- coverage report -m
5765

docs/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ points, like positions on a map or absolute temperature scales.
102102
**Python 2 and 3**: a single codebase that runs unchanged in Python 2.7+ and
103103
Python 3.3+.
104104

105+
**Pandas integration**: Thanks to `Pandas Extension Types`_ it is now possible to use Pint with Pandas. Operations on DataFrames and between columns are units aware, providing even more convenience for users of Pandas DataFrames. For full details, see the `Pandas Support Documentation`_.
106+
107+
108+
When you choose to use a NumPy_ ndarray, its methods and
109+
ufuncs are supported including automatic conversion of units. For example
110+
`numpy.arccos(q)` will require a dimensionless `q` and the units of the output
111+
quantity will be radian.
105112

106113

107114
User Guide
@@ -152,3 +159,5 @@ One last thing
152159
.. _`NumPy`: http://www.numpy.org/
153160
.. _`PEP 3101`: https://www.python.org/dev/peps/pep-3101/
154161
.. _`Babel`: http://babel.pocoo.org/
162+
.. _`Pandas Extension Types`: https://pandas.pydata.org/pandas-docs/stable/extending.html#extension-types
163+
.. _`Pandas Support Documentation`: ./pandas.rst

0 commit comments

Comments
 (0)