home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 959604710

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
959604710 MDU6SXNzdWU5NTk2MDQ3MTA= 5671 Fix typing for coords argument in DataArray 22784297 closed 0     3 2021-08-03T23:04:41Z 2021-12-23T19:54:57Z 2021-12-23T19:54:57Z NONE      

Problem

Mypy reports errors on anything other than a list of tuples passed to coords in xr.DataArray constructor even though xr.Variable and xr.DataArray are valid objects.

Code

Contained in file type_test.py. ```python import numpy as np import xarray as xr

t = np.linspace(0, 2*np.pi, 12) tv = xr.Variable('time', t) # line 5

d2sin = xr.DataArray(np.sin(2 * tv), coords=[('time', t)]) # using tuple

mypy column error detect here ----v

dsin = xr.DataArray(np.sin(tv), coords=[tv]) # using xr.Variable dcos = xr.DataArray(np.cos(tv), coords=[dsin['time']]) # using xr.DataArray

print(f"Types:\n\t{type(tv)=}\n\t{type(dsin['time'])=}") # line 12 print("d2sin:", d2sin) print("dsin:", dsin) print("dcos:", dcos) ```

Running Python

(jupyter) PS C:\Users\<USER>\Documents\Projects\Jupyter\sim_optical_disk> python .\type_test.py Types: type(tv)=<class 'xarray.core.variable.Variable'> type(dsin['time'])=<class 'xarray.core.dataarray.DataArray'> **d2sin**: <xarray.DataArray (time: 12)> array([ 0.00000000e+00, 9.09631995e-01, 7.55749574e-01, -2.81732557e-01, -9.89821442e-01, -5.40640817e-01, 5.40640817e-01, 9.89821442e-01, 2.81732557e-01, -7.55749574e-01, -9.09631995e-01, -4.89858720e-16]) Coordinates: * time (time) float64 0.0 0.5712 1.142 1.714 ... 4.57 5.141 5.712 6.283 **dsin**: <xarray.DataArray (time: 12)> array([ 0.00000000e+00, 5.40640817e-01, 9.09631995e-01, 9.89821442e-01, 7.55749574e-01, 2.81732557e-01, -2.81732557e-01, -7.55749574e-01, -9.89821442e-01, -9.09631995e-01, -5.40640817e-01, -2.44929360e-16]) Coordinates: * time (time) float64 0.0 0.5712 1.142 1.714 ... 4.57 5.141 5.712 6.283 **dcos**: <xarray.DataArray (time: 12)> array([ 1. , 0.84125353, 0.41541501, -0.14231484, -0.65486073, -0.95949297, -0.95949297, -0.65486073, -0.14231484, 0.41541501, 0.84125353, 1. ]) Coordinates: * time (time) float64 0.0 0.5712 1.142 1.714 ... 4.57 5.141 5.712 6.283

Running MyPy

(jupyter) PS C:\Users\<USER>\Documents\Projects\Jupyter\sim_optical_disk> mypy .\type_test.py type_test.py:9: error: List item 0 has incompatible type "Variable"; expected "Tuple[Any, ...]" type_test.py:10: error: List item 0 has incompatible type "DataArray"; expected "Tuple[Any, ...]" Found 2 errors in 1 file (checked 1 source file)

Environment

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.9.1 (default, Dec 11 2020, 09:29:25) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: English_United States.1252 libhdf5: 1.10.6 libnetcdf: 4.6.1 xarray: 0.18.0 pandas: 1.2.1 numpy: 1.20.2 scipy: 1.6.2 netCDF4: 1.5.7 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.5.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.3.2 cartopy: None seaborn: None numbagg: None pint: None setuptools: 52.0.0.post20210125 pip: 21.1.1 conda: None pytest: None IPython: 7.19.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5671/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 0.935ms · About: xarray-datasette