Skip to content

Commit e31cf43

Browse files
committed
Merge branch 'braaannigan-master'
2 parents 3bd704a + 47c3b62 commit e31cf43

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Enhancements
6868

6969
Bug fixes
7070
~~~~~~~~~
71+
- Added warning in api.py of a netCDF4 bug that occurs when
72+
the filepath has 88 characters (:issue:`1745`).
73+
By `Liam Brannigan <https://github.com/braaannigan>` _.
7174
- Fixed encoding of multi-dimensional coordinates in
7275
:py:meth:`~Dataset.to_netcdf` (:issue:`1763`).
7376
By `Mike Neish <https://github.com/neishm>`_.

xarray/backends/netCDF4_.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from __future__ import print_function
44
import functools
55
import operator
6+
import warnings
7+
from distutils.version import LooseVersion
68

79
import numpy as np
810

@@ -244,6 +246,17 @@ def __init__(self, netcdf4_dataset, mode='r', writer=None, opener=None,
244246
def open(cls, filename, mode='r', format='NETCDF4', group=None,
245247
writer=None, clobber=True, diskless=False, persist=False,
246248
autoclose=False):
249+
import netCDF4 as nc4
250+
if (len(filename) == 88 and
251+
LooseVersion(nc4.__version__) < "1.3.1"):
252+
warnings.warn(
253+
'\nA segmentation fault may occur when the\n'
254+
'file path has exactly 88 characters as it does.\n'
255+
'in this case. The issue is known to occur with\n'
256+
'version 1.2.4 of netCDF4 and can be addressed by\n'
257+
'upgrading netCDF4 to at least version 1.3.1.\n'
258+
'More details can be found here:\n'
259+
'https://github.com/pydata/xarray/issues/1745 \n')
247260
if format is None:
248261
format = 'NETCDF4'
249262
opener = functools.partial(_open_netcdf4_group, filename, mode=mode,

xarray/tests/test_backends.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tempfile
1111
import unittest
1212
import sys
13+
import warnings
1314

1415
import numpy as np
1516
import pandas as pd
@@ -1056,6 +1057,15 @@ def test_unsorted_index_raises(self):
10561057
except IndexError as err:
10571058
self.assertIn('first by calling .load', str(err))
10581059

1060+
def test_88_character_filename_segmentation_fault(self):
1061+
# should be fixed in netcdf4 v1.3.1
1062+
with mock.patch('netCDF4.__version__', '1.2.4'):
1063+
with warnings.catch_warnings():
1064+
warnings.simplefilter("error")
1065+
with raises_regex(Warning, 'segmentation fault'):
1066+
# Need to construct 88 character filepath
1067+
xr.Dataset().to_netcdf('a' * (88 - len(os.getcwd()) - 1))
1068+
10591069

10601070
class NetCDF4DataStoreAutocloseTrue(NetCDF4DataTest):
10611071
autoclose = True

0 commit comments

Comments
 (0)