issue_comments: 426689282
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/2459#issuecomment-426689282 | https://api.github.com/repos/pydata/xarray/issues/2459 | 426689282 | MDEyOklzc3VlQ29tbWVudDQyNjY4OTI4Mg== | 1217238 | 2018-10-03T15:50:32Z | 2018-10-03T15:50:32Z | MEMBER | The vast majority of the time in xarray's current implementation seems to be spent in See these results from line-profiler: ``` In [8]: %lprun -f xarray.Dataset.from_dataframe cropped.to_xarray() Timer unit: 1e-06 s Total time: 0.727191 s File: /Users/shoyer/dev/xarray/xarray/core/dataset.py Function: from_dataframe at line 3094 Line # Hits Time Per Hit % Time Line Contents3094 @classmethod 3095 def from_dataframe(cls, dataframe): 3096 """Convert a pandas.DataFrame into an xarray.Dataset 3097 3098 Each column will be converted into an independent variable in the 3099 Dataset. If the dataframe's index is a MultiIndex, it will be expanded 3100 into a tensor product of one-dimensional indices (filling in missing 3101 values with NaN). This method will produce a Dataset very similar to 3102 that on which the 'to_dataframe' method was called, except with 3103 possibly redundant dimensions (since all dataset variables will have 3104 the same dimensionality). 3105 """ 3106 # TODO: Add an option to remove dimensions along which the variables 3107 # are constant, to enable consistent serialization to/from a dataframe, 3108 # even if some variables have different dimensionality. 3109 3110 1 352.0 352.0 0.0 if not dataframe.columns.is_unique: 3111 raise ValueError( 3112 'cannot convert DataFrame with non-unique columns') 3113 3114 1 3.0 3.0 0.0 idx = dataframe.index 3115 1 356.0 356.0 0.0 obj = cls() 3116 3117 1 2.0 2.0 0.0 if isinstance(idx, pd.MultiIndex): 3118 # it's a multi-index 3119 # expand the DataFrame to include the product of all levels 3120 1 4524.0 4524.0 0.6 full_idx = pd.MultiIndex.from_product(idx.levels, names=idx.names) 3121 1 717008.0 717008.0 98.6 dataframe = dataframe.reindex(full_idx) 3122 1 3.0 3.0 0.0 dims = [name if name is not None else 'level_%i' % n 3123 1 20.0 20.0 0.0 for n, name in enumerate(idx.names)] 3124 4 9.0 2.2 0.0 for dim, lev in zip(dims, idx.levels): 3125 3 2973.0 991.0 0.4 obj[dim] = (dim, lev) 3126 1 37.0 37.0 0.0 shape = [lev.size for lev in idx.levels] 3127 else: 3128 dims = (idx.name if idx.name is not None else 'index',) 3129 obj[dims[0]] = (dims, idx) 3130 shape = -1 3131 3132 2 350.0 175.0 0.0 for name, series in iteritems(dataframe): 3133 1 33.0 33.0 0.0 data = np.asarray(series).reshape(shape) 3134 1 1520.0 1520.0 0.2 obj[name] = (dims, data) 3135 1 1.0 1.0 0.0 return obj ``` |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
365973662 |