Skip to content

Commit

Permalink
Merge pull request #4 from znicholls/asavage
Browse files Browse the repository at this point in the history
Get tests passing again
  • Loading branch information
andrewgsavage authored Aug 28, 2018
2 parents cdbf864 + ad6deb3 commit 680ff04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install:
- if [ $NUMPY_VERSION != '0' ]; then conda install --yes numpy==$NUMPY_VERSION; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $NUMPY_VERSION == 1.11.2 && $UNCERTAINTIES == "Y" ]]; then pip install babel serialize pyyaml; fi
# this is superslow but suck it up until updates to pandas are made
- if [[ $PANDAS == '1' ]]; then pip install numpy cython pytest; pip install git+https://github.com/znicholls/pandas.git; fi
- if [[ $PANDAS == '1' ]]; then pip install numpy cython pytest; pip install git+https://github.com/pandas-dev/pandas.git; fi
- pip install coveralls

script:
Expand Down
27 changes: 18 additions & 9 deletions pint/pandas_interface/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,21 @@ def __repr__(self):
res = u("%s(%s%s)") % (klass, data, prepr)

return res

def __array__(self,dtype=None,copy=False):
# this is necessary to prevent for some pandas operations, eg transpose. Units will be lost though
if dtype==None:

def __array__(self, dtype=None, copy=False):
# this is necessary for some pandas operations, eg transpose
# note, units will be lost
if dtype == None:
dtype=object
if type(dtype)== str:
if type(dtype) == str:
dtype = getattr(np, dtype)
if dtype == object:
return np.array(list(self._data), dtype = dtype, copy = copy)
list_of_converteds= [ dtype(item) for item in self._data]
if not isinstance(dtype, np.dtype):
list_of_converteds = [dtype(item) for item in self._data]
else:
list_of_converteds = [dtype.type(item) for item in self._data]

return np.array(list_of_converteds)

def isna(self):
Expand All @@ -169,7 +174,7 @@ def isna(self):
missing : np.array
"""
return np.isnan(self._data.magnitude)

def astype(self, dtype, copy=True):
"""Cast to a NumPy array with 'dtype'.
Expand Down Expand Up @@ -275,10 +280,14 @@ def __setitem__(self, key, value):
def _concat_same_type(cls, to_concat):
# taken from Metpy, would be great to somehow include in pint...
for a in to_concat:
if all(np.isnan(a._data)):
continue
units = a._data.units

data = []
for a in to_concat:
if (all(np.isnan(a._data))) and (a._data.units != units):
a = a*units
mag_common_unit = a._data.to(units).magnitude
data.append(np.atleast_1d(mag_common_unit))

Expand Down Expand Up @@ -319,11 +328,11 @@ def value_counts(self, dropna=True):
data = self._data
if dropna:
data = data[~np.isnan(data.magnitude)]

data_list = data.tolist()
index = list(set(data))
array = [data_list.count(item) for item in index]

return Series(array, index=index)

def unique(self):
Expand Down

0 comments on commit 680ff04

Please sign in to comment.