Skip to content

dtype kwargs of aggregation methods not passed to numpy function #1878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
loicdtx opened this issue Feb 1, 2018 · 3 comments
Closed

dtype kwargs of aggregation methods not passed to numpy function #1878

loicdtx opened this issue Feb 1, 2018 · 3 comments

Comments

@loicdtx
Copy link

loicdtx commented Feb 1, 2018

Hi,

I'm trying to pass dtype= as kwargs to some aggregation methods, but it seems that the argument is ignored. See the example below.

import xarray as xr
import numpy as np
from datetime import datetime
import datetime as dt

arr = np.random.randint(0, 10000, size=(20, 1000, 1000), dtype=np.int16)
date_list = [datetime(2018, 1, 1) + dt.timedelta(delta) for delta in range(20)]
xarr = xr.DataArray(arr, dims=['time', 'x', 'y'], coords={'time': date_list})
xset = xr.Dataset({'blue': xarr, 'green': xarr, 'red': xarr})
print(xset)

# <xarray.Dataset>
# Dimensions:  (time: 20, x: 1000, y: 1000)
# Coordinates:
#   * time     (time) datetime64[ns] 2018-01-01 2018-01-02 2018-01-03 ...
# Dimensions without coordinates: x, y
# Data variables:
#     blue     (time, x, y) int16 1946 9194 1563 8318 938 8498 7999 6609 6275 ...
#     red      (time, x, y) int16 1946 9194 1563 8318 938 8498 7999 6609 6275 ...
#     green    (time, x, y) int16 1946 9194 1563 8318 938 8498 7999 6609 6275 ...

xset_mean = xset.mean('time', keep_attrs=True, dtype=np.int16)
print(xset_mean)

# <xarray.Dataset>
# Dimensions:  (x: 1000, y: 1000)
# Dimensions without coordinates: x, y
# Data variables:
#     blue     (x, y) float64 5.46e+03 4.717e+03 5.959e+03 4.31e+03 4.865e+03 ...
#     red      (x, y) float64 5.46e+03 4.717e+03 5.959e+03 4.31e+03 4.865e+03 ...
#     green    (x, y) float64 5.46e+03 4.717e+03 5.959e+03 4.31e+03 4.865e+03 ...

# Pure numpy
arr_mean = arr.mean(axis=0, dtype=np.int16)
print(arr_mean.dtype)
# int16

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-104-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

xarray: 0.10.0
pandas: 0.22.0
numpy: 1.14.0
scipy: None
netCDF4: 1.3.1
h5netcdf: None
Nio: None
bottleneck: None
cyordereddict: None
dask: 0.16.0
matplotlib: None
cartopy: None
seaborn: None
setuptools: 38.4.0
pip: 9.0.1
conda: None
pytest: None
IPython: None
sphinx: None

@fujiisoup
Copy link
Member

Thanks for the report.
This bug was also reported in #1838, and was fixed by #1841.
I think the current master handles dtype argument for these aggregation methods.

@loicdtx
Copy link
Author

loicdtx commented Feb 1, 2018

Thanks @fujiisoup, indeed just saw #1838. Sorry for the duplicate 😬

@loicdtx loicdtx closed this as completed Feb 1, 2018
@loicdtx
Copy link
Author

loicdtx commented Feb 2, 2018

And I confirm that installing xarray from HEAD of the master branch fixes the issue described. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants