File: unstacking.py

package info (click to toggle)
python-xarray 0.11.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,476 kB
  • sloc: python: 37,552; makefile: 231; sh: 1
file content (26 lines) | stat: -rw-r--r-- 665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ import absolute_import, division, print_function

import numpy as np

import xarray as xr

from . import requires_dask


class Unstacking(object):
    def setup(self):
        data = np.random.RandomState(0).randn(1, 1000, 500)
        self.ds = xr.DataArray(data).stack(flat_dim=['dim_1', 'dim_2'])

    def time_unstack_fast(self):
        self.ds.unstack('flat_dim')

    def time_unstack_slow(self):
        self.ds[:, ::-1].unstack('flat_dim')


class UnstackingDask(Unstacking):
    def setup(self, *args, **kwargs):
        requires_dask()
        super(UnstackingDask, self).setup(**kwargs)
        self.ds = self.ds.chunk({'flat_dim': 50})