cf.PartitionArray

class cf.PartitionArray(array, **kwargs)

Bases: cf.utils.CfList

An N-dimensional partition array.

Initialization

Parameters :
array : list

A list of Partition objects.

kwargs :

Set attributes specified by the keywords and their values. Values are not deep copied.

Examples

>>> pa = PartitionArray(
        [Partition(location  = [(0,n) for n in shape],
                   shape     = shape[:],
                   order     = order[:],
                   direction = copy(direction),
                   Units     = units.copy(),
                   part      = [],
                   data      = data)
         ],
        order      = order,
        shape      = shape,
        size       = data.size,
        Units      = units.copy(),
        ndim       = ndim,
        direction  = direction,
        adims      = [],
        _FillValue = _FillValue)
add_partitions(extra_boundaries, adim, existing_boundaries=None)
change_dimension_names(dim_name_map)

dim_name_map should be a dictionary which maps each dimension names in self.order to its new dimension name. E.g. {‘dim0’:’dim1’, ‘dim1’:’dim0’}

copy(_copy_attr=True)

Return a deep copy.

Do not set the _copy_attr parameter. It is for internal use only.

Equivalent to copy.deepcopy(pa).

Returns :
out :

The deep copy.

Examples

>>> pa.copy()
count(value)

Return the number of occurrences of a given value.

Parameters :
value :

The value to count.

Returns :
out : int

The number of occurrences of value.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.count(1)
1
>>> s.count(2)
3
expand_dims(adim)
flat()

Return a flat iterator over the Partition objects in the partition array.

Returns :
out : generator

An iterator over the elements of the partition array.

Examples

>>> type(pa.flat())
<generator object flat at 0x145a0f0>
>>> for partition in pa.flat():
...     print partition.Units
index(value, start=0, stop=None)

Return the first index of a given value.

Parameters :

value :

start : int, optional

stop : int, optional

Returns :

out : int

Raises :
ValueError :

If the given value is not in the list.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.index(1)
1
>>> s.index(2, start=2)
3
>>> s.index(2, start=2, stop=4)
3
info(attr)
insert(index, object)

Insert an object before the given index in place.

Parameters :

index : int

object :

Returns :

None

Examples

>>> s
[1, 2, 3]
>>> s.insert(1, 'A')
>>> s
[1, 'A', 2, 3]
partition_boundaries()
ravel()

Return a flattened partition array as a built-in list.

Returns :
out : list of Partitions

A list containing the flattened partition array.

Examples

>>> x = partitions.ravel()
>>> type(x)
list
rollaxis(axis, start=0)

Roll the specified aggregating dimension backwards,in place until it lies in a given position.

This does not change the master array.

Parameters :
axis : int

The axis to roll backwards. The positions of the other axes do not change relative to one another.

start : int, optional

The axis is rolled until it lies before this position. The default, 0, results in a “complete” roll.

Returns :

None

Examples

>>> pa.rollaxis(2)
>>> pa.rollaxis(2, start=1)
save_to_disk(itemsize=None)
Parameters :itemsize : int, optional
Returns :out : bool
set_location_map()

Recalculate the location attribute of each Partition object in the partition array in place.

Examples

>>> pa.set_location_map()
to_disk()

Store each partition’s data on disk in place.

There is no change to partitions with data that are already on disk.

Returns :None

Examples

>>> pa.to_disk()
to_memory(regardless=False)

Store each partition’s data in memory in place if the master array is smaller than the chunk size.

There is no change to partitions with data that are already in memory.

Parameters :
regardless : bool, optional

If True then store all partitions’ data in memory regardless of the size of the master array. By default only store all partitions’ data in memory if the master array is smaller than the chunk size.

Returns :

None

Examples

>>> pa.to_memory()
>>> pa.to_memory(True)
transpose(axes)

Permute the aggregating dimensions of the partition array in-place.

This does not change the master array.

Parameters :
axes : sequence of ints

Permute the axes according to the values given.

Returns :

None

Examples

>>> pa.transpose((2,0,1))
dtype

Numpy data-type of the master array.

When there is more than one partition in the partition array, the normal data-type coercion rules apply. For example, if the partitions have data-types ‘int32’ and ‘float32’ then the master array’s data-type will be ‘float32’.

Examples

>>> pa.dtype
dtype('float64')
is_scalar

True if the master array is a 0-d scalar array.

Examples

>>> pa.ndim
0
>>> pa.is_scalar
True
>>> pa.ndim >= 1
True
>>> pa.is_scalar
False
npartitions

The number of partitions in the partition array.

Logically equivalent to len(pa.ravel()).

Examples

>>> pa.npartitions
7

Previous topic

cf.Partition

Next topic

cf.Filearray

This Page