Skip to content

Commit 5d8ae33

Browse files
authored
Removing the deprecated xarray_to_cdf flags (#286)
* Removing the deprecated xarray_to_cdf flags
1 parent b371a89 commit 5d8ae33

2 files changed

Lines changed: 4 additions & 62 deletions

File tree

cdflib/xarray/xarray_to_cdf.py

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
from datetime import datetime
44
from typing import Any, Dict, List, Tuple, Union, cast
5-
from warnings import warn
65

76
import numpy as np
87
import numpy.typing as npt
@@ -889,11 +888,6 @@ def xarray_to_cdf(
889888
record_dimensions: List[str] = ["record0"],
890889
compression: int = 0,
891890
nan_to_fillval: bool = True,
892-
from_unixtime: bool = False,
893-
from_datetime: bool = False,
894-
unixtime_to_cdftt2000: bool = False,
895-
datetime_to_cdftt2000: bool = True,
896-
datetime64_to_cdftt2000: bool = True,
897891
) -> None:
898892
"""
899893
This function converts XArray Dataset objects into CDF files.
@@ -908,11 +902,6 @@ def xarray_to_cdf(
908902
record_dimensions (list of str, optional): If the code cannot determine which dimensions should be made into CDF records, you may provide a list of them here
909903
compression (int, optional): The level of compression to gzip the data in the variables. Default is no compression, standard is 6.
910904
nan_to_fillval (bool, optional): Convert all np.nan and np.datetime64('NaT') to the standard CDF FILLVALs.
911-
from_datetime (bool, optional, deprecated): Same as the datetime_to_cdftt2000 option
912-
from_unixtime (bool, optional, deprecated): Same as the unixtime_to_cdftt2000 option
913-
datetime_to_cdftt2000 (bool, optional, deprecated): Whether or not to convert variables named "epoch" or "epoch_X" to CDF_TT2000 from datetime objects
914-
datetime64_to_cdftt2000 (bool, optional, deprecated): Whether or not to convert variables named "epoch" or "epoch_X" to CDF_TT2000 from the numpy datetime64
915-
unixtime_to_cdftt2000 (bool, optional, deprecated): Whether or not to convert variables named "epoch" or "epoch_X" to CDF_TT2000 from unixtime
916905
Returns:
917906
None, but generates a CDF file
918907
@@ -1041,30 +1030,6 @@ def xarray_to_cdf(
10411030
10421031
"""
10431032

1044-
if from_unixtime or unixtime_to_cdftt2000:
1045-
warn(
1046-
"from_unixtime and unixtime_to_cdftt2000 will eventually be phased out. Instead, use the more descriptive unix_time_to_cdf_time.",
1047-
DeprecationWarning,
1048-
stacklevel=2,
1049-
)
1050-
1051-
if from_datetime or datetime_to_cdftt2000:
1052-
warn(
1053-
"The from_datetime and datetime_to_cdftt2000 are obsolete. Python datetime objects are automatically converted to a CDF time. If you do not wish datetime objects to be converted, cast them to a different type prior to calling xarray_to_cdf()",
1054-
DeprecationWarning,
1055-
stacklevel=2,
1056-
)
1057-
1058-
if datetime64_to_cdftt2000:
1059-
warn(
1060-
"datetime64_to_cdftt2000 will eventually be phased out. Instead, datetime64 types will automatically be converted into a CDF time type. If you do not wish datetime64 arrays to be converted, cast them to a different type prior to calling xarray_to_cdf()",
1061-
DeprecationWarning,
1062-
stacklevel=2,
1063-
)
1064-
1065-
if unixtime_to_cdftt2000 or from_unixtime:
1066-
unix_time_to_cdf_time = True
1067-
10681033
if os.path.isfile(file_name):
10691034
_warn_or_except(f"{file_name} already exists, cannot create CDF file. Returning...", terminate_on_warning)
10701035
return
@@ -1153,9 +1118,7 @@ def xarray_to_cdf(
11531118
elif d[var].attrs["CDF_DATA_TYPE"] == "CDF_EPOCH16":
11541119
cdf_epoch16 = True
11551120

1156-
if (_is_datetime_array(d[var].data) and datetime_to_cdftt2000) or (
1157-
_is_datetime64_array(d[var].data) and datetime64_to_cdftt2000
1158-
):
1121+
if _is_datetime_array(d[var].data) or _is_datetime64_array(d[var].data):
11591122
var_data = _datetime_to_cdf_time(d[var], cdf_epoch=cdf_epoch, cdf_epoch16=cdf_epoch16)
11601123
elif unix_time_to_cdf_time:
11611124
if _is_istp_epoch_variable(var) or (
@@ -1167,9 +1130,7 @@ def xarray_to_cdf(
11671130
var_att_dict = {}
11681131
for att in d[var].attrs:
11691132
var_att_dict[att] = d[var].attrs[att]
1170-
if (_is_datetime_array(d[var].attrs[att]) and datetime_to_cdftt2000) or (
1171-
_is_datetime64_array(d[var].attrs[att]) and datetime64_to_cdftt2000
1172-
):
1133+
if _is_datetime_array(d[var].attrs[att]) or _is_datetime64_array(d[var].attrs[att]):
11731134
att_data = _datetime_to_cdf_time(d[var], cdf_epoch=cdf_epoch, cdf_epoch16=cdf_epoch16, attribute_name=att)
11741135
var_att_dict[att] = [att_data, DATATYPES_TO_STRINGS[cdf_data_type]]
11751136
elif unix_time_to_cdf_time:

tests/test_xarray_reader_writer.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ def test_smoke(cdf_path, tmp_path):
353353

354354

355355
def test_datetime64_conversion():
356-
# This tests out the datetime64_to_cdftt2000 conversion and then back again,
357356
# verifying that everything writes correctly
358357
pytest.importorskip("xarray")
359358
var_data = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
@@ -369,25 +368,7 @@ def test_datetime64_conversion():
369368
os.remove("hello.cdf")
370369

371370

372-
def test_datetime64_no_conversion():
373-
# This tests out the expected behavior when no datetime conversion is used,
374-
# even though datetime64 variables are being read into the CDF file
375-
pytest.importorskip("xarray")
376-
var_data = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
377-
var_dims = ["epoch", "direction"]
378-
data = xr.Variable(var_dims, var_data)
379-
epoch_data = [np.datetime64(1, "s"), np.datetime64(2, "s"), np.datetime64(3, "s")]
380-
epoch_dims = ["epoch"]
381-
epoch = xr.Variable(epoch_dims, epoch_data)
382-
ds = xr.Dataset(data_vars={"data": data, "epoch": epoch})
383-
xarray_to_cdf(ds, "hello.cdf", datetime64_to_cdftt2000=False)
384-
x = cdf_to_xarray("hello.cdf", to_datetime=False)
385-
assert x["epoch"][0] == 1000000000 # Seconds is converted to nanoseconds in the file, but otherwise left untouched
386-
os.remove("hello.cdf")
387-
388-
389371
def test_datetime64_conversion_odd_units():
390-
# This tests out the datetime64_to_cdftt2000 conversion and then back again,
391372
# verifying that everything writes correctly.
392373
# This time, it uses days as the base unit, and verifies that it comes back out again as days.
393374
pytest.importorskip("xarray")
@@ -398,7 +379,7 @@ def test_datetime64_conversion_odd_units():
398379
epoch_dims = ["epoch"]
399380
epoch = xr.Variable(epoch_dims, epoch_data)
400381
ds = xr.Dataset(data_vars={"data": data, "epoch": epoch})
401-
xarray_to_cdf(ds, "hello.cdf", datetime64_to_cdftt2000=True)
382+
xarray_to_cdf(ds, "hello.cdf")
402383
x = cdf_to_xarray("hello.cdf", to_datetime=True)
403384
assert x["epoch"][1] == np.datetime64("2000-01-02")
404385
os.remove("hello.cdf")
@@ -415,7 +396,7 @@ def test_numpy_string_array():
415396
epoch_dims = ["epoch"]
416397
epoch = xr.Variable(epoch_dims, epoch_data)
417398
ds = xr.Dataset(data_vars={"data": data, "epoch": epoch})
418-
xarray_to_cdf(ds, "hello.cdf", datetime64_to_cdftt2000=True)
399+
xarray_to_cdf(ds, "hello.cdf")
419400
x = cdf_to_xarray("hello.cdf", to_datetime=True)
420401
assert x["data"][2] == "c"
421402
os.remove("hello.cdf")

0 commit comments

Comments
 (0)