Adapted from pandas.tseries.index._field_accessor

def _field_accessor(name, docstring=None, min_cftime_version='0.0'):
    """Adapted from pandas.tseries.index._field_accessor"""

    def f(self, min_cftime_version=min_cftime_version):
        import cftime

        version = cftime.__version__

        if LooseVersion(version) >= LooseVersion(min_cftime_version):
            return get_date_field(self._data, name)
        else:
            raise ImportError('The {!r} accessor requires a minimum '
                              'version of cftime of {}. Found an '
                              'installed version of {}.'.format(
                                  name, min_cftime_version, version))

    f.__name__ = name
    f.__doc__ = docstring
    return property(f)