-
Notifications
You must be signed in to change notification settings - Fork 19
/
deprecations.py
1005 lines (774 loc) · 29.2 KB
/
deprecations.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from ...functions import (
_DEPRECATION_ERROR_ATTRIBUTE,
_DEPRECATION_ERROR_METHOD,
DeprecationError,
)
class DataClassDeprecationsMixin:
"""Deprecated attributes and methods for the Data class."""
def __hash__(self):
"""The built-in function `hash`.
Deprecated at version 3.14.0. Consider using the
`cf.hash_array` function instead.
Generating the hash temporarily realises the entire array in
memory, which may not be possible for large arrays.
The hash value is dependent on the data-type and shape of the data
array. If the array is a masked array then the hash value is
independent of the fill value and of data array values underlying
any masked elements.
The hash value may be different if regenerated after the data
array has been changed in place.
The hash value is not guaranteed to be portable across versions of
Python, numpy and cf.
:Returns:
`int`
The hash value.
**Examples**
>>> print(d.array)
[[0 1 2 3]]
>>> d.hash()
-8125230271916303273
>>> d[1, 0] = numpy.ma.masked
>>> print(d.array)
[[0 -- 2 3]]
>>> hash(d)
791917586613573563
>>> d.hardmask = False
>>> d[0, 1] = 999
>>> d[0, 1] = numpy.ma.masked
>>> d.hash()
791917586613573563
>>> d.squeeze()
>>> print(d.array)
[0 -- 2 3]
>>> hash(d)
-7007538450787927902
>>> d.dtype = float
>>> print(d.array)
[0.0 -- 2.0 3.0]
>>> hash(d)
-4816859207969696442
"""
_DEPRECATION_ERROR_METHOD(
self,
"__hash__",
message="Consider using 'cf.hash_array' function array instead.",
version="3.14.0",
removed_at="5.0.0",
)
@property
def _HDF_chunks(self):
"""The HDF chunksizes.
Deprecated at version 3.14.0.
DO NOT CHANGE IN PLACE.
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self, "_HDF_chunks", version="3.14.0", removed_at="5.0.0"
) # pragma: no cover
@_HDF_chunks.setter
def _HDF_chunks(self, value):
_DEPRECATION_ERROR_ATTRIBUTE(
self, "_HDF_chunks", version="3.14.0", removed_at="5.0.0"
) # pragma: no cover
@_HDF_chunks.deleter
def _HDF_chunks(self):
_DEPRECATION_ERROR_ATTRIBUTE(
self, "_HDF_chunks", version="3.14.0", removed_at="5.0.0"
) # pragma: no cover
@property
def Data(self):
"""Deprecated at version 3.0.0, use attribute `data` instead."""
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"Data",
"Use attribute 'data' instead.",
version="3.0.0",
removed_at="4.0.0",
) # pragma: no cover
@property
def dtvarray(self):
"""Deprecated at version 3.0.0."""
_DEPRECATION_ERROR_ATTRIBUTE(
self, "dtvarray", version="3.0.0", removed_at="4.0.0"
) # pragma: no cover
@property
def in_memory(self):
"""True if the array is retained in memory.
Deprecated at version 3.14.0.
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self, "in_memory", version="3.14.0", removed_at="5.0.0"
) # pragma: no cover
@property
def ismasked(self):
"""True if the data array has any masked values.
Deprecated at version 3.14.0. Use the `is_masked` attribute
instead.
**Examples**
>>> d = cf.Data([[1, 2, 3], [4, 5, 6]])
>>> print(d.ismasked)
False
>>> d[0, ...] = cf.masked
>>> d.ismasked
True
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"ismasked",
message="Use the 'is_masked' attribute instead",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
@property
def isscalar(self):
"""True if the data is a 0-d scalar array.
Deprecated at version 3.14.0. Use `d.ndim == 0`` instead.
**Examples**
>>> d = cf.Data(9, 'm')
>>> d.isscalar
True
>>> d = cf.Data([9], 'm')
>>> d.isscalar
False
>>> d = cf.Data([9, 10], 'm')
>>> d.isscalar
False
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"isscalar",
message="Use 'd.ndim == 0' instead",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
@property
def ispartitioned(self):
"""True if the data array is partitioned.
Deprecated at version 3.14.0 and is no longer available.
**Examples**
>>> d._pmsize
1
>>> d.ispartitioned
False
>>> d._pmsize
2
>>> d.ispartitioned
False
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self, "ispartitioned", version="3.14.0", removed_at="5.0.0"
) # pragma: no cover
@property
def unsafe_array(self):
"""Deprecated at version 3.0.0.
Use the `array` attribute instead.
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"unsafe_array",
message="Use the 'array' attribute instead.",
version="3.0.0",
removed_at="4.0.0",
) # pragma: no cover
@property
def varray(self):
"""A numpy array view of the data array.
Deprecated at version 3.14.0. Data are now stored as `dask`
arrays for which, in general, a numpy array view is not
robust.
Note that making changes to elements of the returned view changes
the underlying data.
.. seealso:: `array`, `to_dask_array`, `datetime_array`
**Examples**
>>> a = d.varray
>>> type(a)
<type 'numpy.ndarray'>
>>> a
array([0, 1, 2, 3, 4])
>>> a[0] = 999
>>> d.varray
array([999, 1, 2, 3, 4])
"""
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"varray",
message="Data are now stored as `dask` arrays for which, "
"in general, a numpy array view is not robust.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def expand_dims(self, position=0, i=False):
"""Deprecated at version 3.0.0, use method `insert_dimension`
instead.
May get re-instated at a later version.
"""
_DEPRECATION_ERROR_METHOD(
self,
"expand_dims",
"Use method 'insert_dimension' instead.",
version="3.0.0",
) # pragma: no cover
def files(self):
"""Deprecated at version 3.4.0, consider using method
`get_filenames` instead."""
_DEPRECATION_ERROR_METHOD(
self,
"files",
"Use method `get_filenames` instead.",
version="3.4.0",
removed_at="4.0.0",
) # pragma: no cover
def fits_in_one_chunk_in_memory(self, itemsize):
"""Return True if the master array is small enough to be
retained in memory.
Deprecated at version 3.14.0.
:Parameters:
itemsize: `int`
The number of bytes per word of the master data array.
:Returns:
`bool`
**Examples**
>>> print(d.fits_one_chunk_in_memory(8))
False
"""
_DEPRECATION_ERROR_METHOD(
self,
"fits_in_one_chunk_in_memory",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def close(self):
"""Close all files referenced by the data array.
Deprecated at version 3.14.0. All files are now automatically
closed when not being accessed.
"""
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def chunk(self, chunksize=None, total=None, omit_axes=None, pmshape=None):
"""Partition the data array.
Deprecated at version 3.14.0. Use the `rechunk` method
instead.
:Parameters:
chunksize: `int`, optional
The
total: sequence of `int`, optional
omit_axes: sequence of `int`, optional
pmshape: sequence of `int`, optional
:Returns:
`None`
**Examples**
>>> d.chunk()
>>> d.chunk(100000)
>>> d.chunk(100000, )
>>> d.chunk(100000, total=[2])
>>> d.chunk(100000, omit_axes=[3, 4])
"""
_DEPRECATION_ERROR_METHOD(
self,
"chunk",
message="Use the 'rechunk' method instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def dumpd(self):
"""Return a serialisation of the data array.
Deprecated at version 3.14.0. Consider inspecting the dask
array returned by `to_dask_array` instead.
.. seealso:: `loadd`, `loads`
:Returns:
`dict`
The serialisation.
**Examples**
>>> d = cf.Data([[1, 2, 3]], 'm')
>>> d.dumpd()
{'Partitions': [{'location': [(0, 1), (0, 3)],
'subarray': array([[1, 2, 3]])}],
'units': 'm',
'_axes': ['dim0', 'dim1'],
'_pmshape': (),
'dtype': dtype('int64'),
'shape': (1, 3)}
>>> d.flip(1)
>>> d.transpose()
>>> d.Units *= 1000
>>> d.dumpd()
{'Partitions': [{'units': 'm',
'axes': ['dim0', 'dim1'],
'location': [(0, 3), (0, 1)],
'subarray': array([[1, 2, 3]])}],
` 'units': '1000 m',
'_axes': ['dim1', 'dim0'],
'_flip': ['dim1'],
'_pmshape': (),
'dtype': dtype('int64'),
'shape': (3, 1)}
>>> d.dumpd()
{'Partitions': [{'units': 'm',
'location': [(0, 1), (0, 3)],
'subarray': array([[1, 2, 3]])}],
'units': '10000 m',
'_axes': ['dim0', 'dim1'],
'_flip': ['dim1'],
'_pmshape': (),
'dtype': dtype('int64'),
'shape': (1, 3)}
>>> e = cf.Data(loadd=d.dumpd())
>>> e.equals(d)
True
"""
_DEPRECATION_ERROR_METHOD(
self,
"dumpd",
message="Consider inspecting the dask array returned "
"by 'to_dask_array' instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def dumps(self):
"""Return a JSON string serialisation of the data array.
Deprecated at version 3.14.0. Consider inspecting the dask array
returned by `to_dask_array` instead.
"""
_DEPRECATION_ERROR_METHOD(
self,
"dumps",
message="Consider inspecting the dask array returned "
"by 'to_dask_array' instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def HDF_chunks(self, *chunks):
"""Get or set HDF chunk sizes.
The HDF chunk sizes may be used by external code that allows
`Data` objects to be written to netCDF files.
Deprecated at version 3.14.0 and is no longer available. Use
the methods `nc_clear_hdf5_chunksizes`, `nc_hdf5_chunksizes`,
and `nc_set_hdf5_chunksizes` instead.
.. seealso:: `nc_clear_hdf5_chunksizes`, `nc_hdf5_chunksizes`,
`nc_set_hdf5_chunksizes`
:Parameters:
chunks: `dict` or `None`, *optional*
Specify HDF chunk sizes.
When no positional argument is provided, the HDF chunk
sizes are unchanged.
If `None` then the HDF chunk sizes for each dimension
are cleared, so that the HDF default chunk size value
will be used when writing data to disk.
If a `dict` then it defines for a subset of the
dimensions, defined by their integer positions, the
corresponding HDF chunk sizes. The HDF chunk sizes are
set as a number of elements along the dimension.
:Returns:
`dict`
The HDF chunks for each dimension prior to the change,
or the current HDF chunks if no new values are
specified. A value of `None` is an indication that the
default chunk size should be used for that dimension.
**Examples**
>>> d = cf.Data(np.arange(30).reshape(5, 6))
>>> d.HDF_chunks()
{0: None, 1: None}
>>> d.HDF_chunks({1: 2})
{0: None, 1: None}
>>> d.HDF_chunks()
{0: None, 1: 2}
>>> d.HDF_chunks({1:None})
{0: None, 1: 2}
>>> d.HDF_chunks()
{0: None, 1: None}
>>> d.HDF_chunks({0: 3, 1: 6})
{0: None, 1: None}
>>> d.HDF_chunks()
{0: 3, 1: 6}
>>> d.HDF_chunks({1: 4})
{0: 3, 1: 6}
>>> d.HDF_chunks()
{0: 3, 1: 4}
>>> d.HDF_chunks({1: 999})
{0: 3, 1: 4}
>>> d.HDF_chunks()
{0: 3, 1: 999}
>>> d.HDF_chunks(None)
{0: 3, 1: 999}
>>> d.HDF_chunks()
{0: None, 1: None}
"""
_DEPRECATION_ERROR_METHOD(
self,
"HDF_chunks",
message="Use the methods 'nc_clear_hdf5_chunksizes', "
"'nc_hdf5_chunksizes', and 'nc_set_hdf5_chunksizes' "
"instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def loadd(self, d, chunk=True):
"""Reset the data in place from a dictionary serialisation.
Deprecated at version 3.14.0. Consider inspecting the dask
array returned by `to_dask_array` instead.
.. seealso:: `dumpd`, `loads`
:Parameters:
d: `dict`
A dictionary serialisation of a `cf.Data` object, such as
one as returned by the `dumpd` method.
chunk: `bool`, optional
If True (the default) then the reset data array will be
re-partitioned according the current chunk size, as
defined by the `cf.chunksize` function.
:Returns:
`None`
**Examples**
>>> d = Data([[1, 2, 3]], 'm')
>>> e = Data([6, 7, 8, 9], 's')
>>> e.loadd(d.dumpd())
>>> e.equals(d)
True
>>> e is d
False
>>> e = Data(loadd=d.dumpd())
>>> e.equals(d)
True
"""
_DEPRECATION_ERROR_METHOD(
self,
"loadd",
message="Consider inspecting the dask array returned "
"by 'to_dask_array' instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def loads(self, j, chunk=True):
"""Reset the data in place from a string serialisation.
Deprecated at version 3.14.0. Consider inspecting the dask
array returned by `to_dask_array` instead.
.. seealso:: `dumpd`, `loadd`
:Parameters:
j: `str`
A JSON document string serialisation of a `cf.Data` object.
chunk: `bool`, optional
If True (the default) then the reset data array will be
re-partitioned according the current chunk size, as defined
by the `cf.chunksize` function.
:Returns:
`None`
"""
_DEPRECATION_ERROR_METHOD(
self,
"loads",
message="Consider inspecting the dask array returned "
"by 'to_dask_array' instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def add_partitions(self, extra_boundaries, pdim):
"""Add partition boundaries.
Deprecated at version 3.14.0. Use the `rechunk` method
instead.
:Parameters:
extra_boundaries: `list` of `int`
The boundaries of the new partitions.
pdim: `str`
The name of the axis to have the new partitions.
:Returns:
`None`
**Examples**
>>> d.add_partitions( )
"""
_DEPRECATION_ERROR_METHOD(
self,
"add_partitions",
message="Use the 'rechunk' method instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
@staticmethod
def mask_fpe(*arg):
"""Masking of floating-point errors in the results of arithmetic
operations.
Deprecated at version 3.14.0. It is currently not possible
to control how floating-point errors are handled, due to the
use of `dask` for handling all array manipulations. This may
change in the future (see
https://github.com/dask/dask/issues/3245 for more details).
If masking is allowed then only floating-point errors which would
otherwise be raised as `FloatingPointError` exceptions are
masked. Whether `FloatingPointError` exceptions may be raised is
determined by `cf.Data.seterr`.
If called without an argument then the current behaviour is
returned.
Note that if the raising of `FloatingPointError` exceptions has
been suppressed then invalid values in the results of arithmetic
operations may be subsequently converted to masked values with the
`mask_invalid` method.
.. seealso:: `cf.Data.seterr`, `mask_invalid`
:Parameters:
arg: `bool`, optional
The new behaviour. True means that `FloatingPointError`
exceptions are suppressed and replaced with masked
values. False means that `FloatingPointError` exceptions
are raised. The default is not to change the current
behaviour.
:Returns:
`bool`
The behaviour prior to the change, or the current
behaviour if no new value was specified.
**Examples:**
>>> d = cf.Data([0., 1])
>>> e = cf.Data([1., 2])
>>> old = cf.Data.mask_fpe(False)
>>> old = cf.Data.seterr('raise')
>>> e/d
FloatingPointError: divide by zero encountered in divide
>>> e**123456
FloatingPointError: overflow encountered in power
>>> old = cf.Data.mask_fpe(True)
>>> old = cf.Data.seterr('raise')
>>> e/d
<CF Data: [--, 2.0] >
>>> e**123456
<CF Data: [1.0, --] >
>>> old = cf.Data.mask_fpe(True)
>>> old = cf.Data.seterr('ignore')
>>> e/d
<CF Data: [inf, 2.0] >
>>> e**123456
<CF Data: [1.0, inf] >
"""
raise DeprecationError(
"Data method 'mask_fpe' has been deprecated at version 3.14.0 "
"and is not available.\n\n"
"It is currently not possible to control how floating-point errors "
"are handled, due to the use of `dask` for handling all array "
"manipulations. This may change in the future (see "
"https://github.com/dask/dask/issues/3245 for more details)."
)
def mask_invalid(self, *args, **kwargs):
"""Mask the array where invalid values occur (NaN or inf).
Deprecated at version 3.14.0. Use the method
`masked_invalid` instead.
.. seealso:: `where`
:Parameters:
{{inplace: `bool`, optional}}
{{i: deprecated at version 3.0.0}}
:Returns:
`Data` or `None`
The masked data, or `None` if the operation was
in-place.
**Examples**
>>> d = cf.Data([0, 1, 2])
>>> e = cf.Data([0, 2, 0])
>>> f = d / e
>>> f
<CF Data(3): [nan, 0.5, inf]>
>>> f.mask_invalid()
<CF Data(3): [--, 0.5, --]>
"""
_DEPRECATION_ERROR_METHOD(
self,
"mask_invalid",
message="Use the method 'masked_invalid' instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def partition_boundaries(self):
"""Return the partition boundaries for each partition matrix
dimension.
Deprecated at version 3.14.0. Consider using the `chunks`
attribute instead.
:Returns:
`dict`
**Examples**
"""
_DEPRECATION_ERROR_METHOD(
self,
"partition_boundaries",
message="Consider using the 'chunks' attribute instead.",
version="3.14.0",
removed_at="5.0.0",
) # pragma: no cover
def save_to_disk(self, itemsize=None):
"""Deprecated."""
_DEPRECATION_ERROR_METHOD(
self, "save_to_disk", removed_at="4.0.0"
) # pragma: no cover
def to_disk(self):
"""Store the data array on disk.
Deprecated at version 3.14.0.
There is no change to partitions whose sub-arrays are already
on disk.
:Returns:
`None`
**Examples**
>>> d.to_disk()
"""
_DEPRECATION_ERROR_METHOD(
self, "to_disk", version="3.14.0", removed_at="5.0.0"
) # pragma: no cover
@staticmethod
def seterr(all=None, divide=None, over=None, under=None, invalid=None):
"""Set how floating-point errors in the results of arithmetic
operations are handled.
Deprecated at version 3.14.0. It is currently not possible
to control how floating-point errors are handled, due to the
use of `dask` for handling all array manipulations. This may
change in the future (see
https://github.com/dask/dask/issues/3245 for more details).
The options for handling floating-point errors are:
============ ========================================================
Treatment Action
============ ========================================================
``'ignore'`` Take no action. Allows invalid values to occur in the
result data array.
``'warn'`` Print a `RuntimeWarning` (via the Python `warnings`
module). Allows invalid values to occur in the result
data array.
``'raise'`` Raise a `FloatingPointError` exception.
============ ========================================================
The different types of floating-point errors are:
================= ================================= =================
Error Description Default treatment
================= ================================= =================
Division by zero Infinite result obtained from ``'warn'``
finite numbers.
Overflow Result too large to be expressed. ``'warn'``
Invalid operation Result is not an expressible ``'warn'``
number, typically indicates that
a NaN was produced.
Underflow Result so close to zero that some ``'ignore'``
precision was lost.
================= ================================= =================
Note that operations on integer scalar types (such as int16) are
handled like floating point, and are affected by these settings.
If called without any arguments then the current behaviour is
returned.
.. seealso:: `cf.Data.mask_fpe`, `mask_invalid`
:Parameters:
all: `str`, optional
Set the treatment for all types of floating-point errors
at once. The default is not to change the current
behaviour.
divide: `str`, optional
Set the treatment for division by zero. The default is not
to change the current behaviour.
over: `str`, optional
Set the treatment for floating-point overflow. The default
is not to change the current behaviour.
under: `str`, optional
Set the treatment for floating-point underflow. The
default is not to change the current behaviour.
invalid: `str`, optional
Set the treatment for invalid floating-point
operation. The default is not to change the current
behaviour.
:Returns:
`dict`
The behaviour prior to the change, or the current
behaviour if no new values are specified.
**Examples:**
Set treatment for all types of floating-point errors to
``'raise'`` and then reset to the previous behaviours:
>>> cf.Data.seterr()
{'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}
>>> old = cf.Data.seterr('raise')
>>> cf.Data.seterr(**old)
{'divide': 'raise', 'invalid': 'raise', 'over': 'raise', 'under': 'raise'}
>>> cf.Data.seterr()
{'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}
Set the treatment of division by zero to ``'ignore'`` and overflow
to ``'warn'`` without changing the treatment of underflow and
invalid operation:
>>> cf.Data.seterr(divide='ignore', over='warn')
{'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}
>>> cf.Data.seterr()
{'divide': 'ignore', 'invalid': 'warn', 'over': 'ignore', 'under': 'ignore'}
Some examples with data arrays:
>>> d = cf.Data([0., 1])
>>> e = cf.Data([1., 2])
>>> old = cf.Data.seterr('ignore')
>>> e/d
<CF Data: [inf, 2.0] >
>>> e**12345
<CF Data: [1.0, inf] >
>>> cf.Data.seterr(divide='warn')
{'divide': 'ignore', 'invalid': 'ignore', 'over': 'ignore', 'under': 'ignore'}
>>> e/d
RuntimeWarning: divide by zero encountered in divide
<CF Data: [inf, 2.0] >
>>> e**12345
<CF Data: [1.0, inf] >
>>> old = cf.Data.mask_fpe(False)
>>> cf.Data.seterr(over='raise')
{'divide': 'warn', 'invalid': 'ignore', 'over': 'ignore', 'under': 'ignore'}
>>> e/d
RuntimeWarning: divide by zero encountered in divide
<CF Data: [inf, 2.0] >
>>> e**12345
FloatingPointError: overflow encountered in power
>>> cf.Data.mask_fpe(True)
False
>>> cf.Data.seterr(divide='ignore')
{'divide': 'warn', 'invalid': 'ignore', 'over': 'raise', 'under': 'ignore'}
>>> e/d
<CF Data: [inf, 2.0] >
>>> e**12345
<CF Data: [1.0, --] >
"""
raise DeprecationError(
"Data method 'seterr' has been deprecated at version 3.14.0 "
"and is not available.\n\n"
"It is currently not possible to control how floating-point errors "
"are handled, due to the use of `dask` for handling all array "
"manipulations. This may change in the future (see "
"https://github.com/dask/dask/issues/3245 for more details)."
)
@classmethod
def reconstruct_sectioned_data(cls, sections, cyclic=(), hardmask=None):
"""Expects a dictionary of Data objects with ordering
information as keys, as output by the section method when called
with a Data object. Returns a reconstructed cf.Data object with
the sections in the original order.
Deprecated at version 3.14.0 and is no longer available.
:Parameters:
sections: `dict`
The dictionary of `Data` objects with ordering information
as keys.
:Returns:
`Data`
The resulting reconstructed Data object.
**Examples**
>>> d = cf.Data(numpy.arange(120).reshape(2, 3, 4, 5))
>>> x = d.section([1, 3])
>>> len(x)
8
>>> e = cf.Data.reconstruct_sectioned_data(x)
>>> e.equals(d)
True
"""
raise DeprecationError(
"Data method 'reconstruct_sectioned_data' has been deprecated "
"at version 3.14.0 and is no longer available"
)
@classmethod
def concatenate_data(cls, data_list, axis):
"""Concatenates a list of Data objects along the specified axis.
See cf.Data.concatenate for details.
In the case that the list contains only one element, that element
is simply returned.
:Parameters:
data_list: `list`
The list of data objects to concatenate.
axis: `int`
The axis along which to perform the concatenation.
:Returns:
`Data`
The resulting single `Data` object.
"""