/* Generated by Cython 3.0.0 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "pyreadstat/conditional_includes.h",
            "src/readstat.h",
            "src/readstat_io_unistd.h"
        ],
        "extra_compile_args": [
            "-Ireadstat",
            "-DHAVE_ZLIB=1"
        ],
        "include_dirs": [
            "pyreadstat",
            "src",
            "src/stata",
            "src/spss",
            "src/sas",
            "."
        ],
        "libraries": [
            "m",
            "z"
        ],
        "name": "pyreadstat._readstat_writer",
        "sources": [
            "pyreadstat/_readstat_writer.pyx",
            "./src/CKHashTable.c",
            "./src/readstat_bits.c",
            "./src/readstat_convert.c",
            "./src/readstat_error.c",
            "./src/readstat_io_unistd.c",
            "./src/readstat_malloc.c",
            "./src/readstat_metadata.c",
            "./src/readstat_parser.c",
            "./src/readstat_value.c",
            "./src/readstat_variable.c",
            "./src/readstat_writer.c",
            "./src/sas/ieee.c",
            "./src/sas/readstat_sas.c",
            "./src/sas/readstat_sas7bcat_read.c",
            "./src/sas/readstat_sas7bcat_write.c",
            "./src/sas/readstat_sas7bdat_read.c",
            "./src/sas/readstat_sas7bdat_write.c",
            "./src/sas/readstat_sas_rle.c",
            "./src/sas/readstat_xport.c",
            "./src/sas/readstat_xport_parse_format.c",
            "./src/sas/readstat_xport_read.c",
            "./src/sas/readstat_xport_write.c",
            "./src/spss/readstat_por.c",
            "./src/spss/readstat_por_parse.c",
            "./src/spss/readstat_por_read.c",
            "./src/spss/readstat_por_write.c",
            "./src/spss/readstat_sav.c",
            "./src/spss/readstat_sav_compress.c",
            "./src/spss/readstat_sav_parse.c",
            "./src/spss/readstat_sav_parse_timestamp.c",
            "./src/spss/readstat_sav_read.c",
            "./src/spss/readstat_sav_write.c",
            "./src/spss/readstat_spss.c",
            "./src/spss/readstat_spss_parse.c",
            "./src/spss/readstat_zsav_compress.c",
            "./src/spss/readstat_zsav_read.c",
            "./src/spss/readstat_zsav_write.c",
            "./src/stata/readstat_dta.c",
            "./src/stata/readstat_dta_parse_timestamp.c",
            "./src/stata/readstat_dta_read.c",
            "./src/stata/readstat_dta_write.c"
        ]
    },
    "module_name": "pyreadstat._readstat_writer"
}
END: Cython Metadata */

#ifndef PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */
#if defined(CYTHON_LIMITED_API) && 0
  #ifndef Py_LIMITED_API
    #if CYTHON_LIMITED_API+0 > 0x03030000
      #define Py_LIMITED_API CYTHON_LIMITED_API
    #else
      #define Py_LIMITED_API 0x03030000
    #endif
  #endif
#endif

#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.7+ or Python 3.3+.
#else
#define CYTHON_ABI "3_0_0"
#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
#define CYTHON_HEX_VERSION 0x030000F0
#define CYTHON_FUTURE_DIVISION 0
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #define HAVE_LONG_LONG
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#if defined(GRAALVM_PYTHON)
  /* For very preliminary testing purposes. Most variables are set the same as PyPy.
     The existence of this section does not imply that anything works or is even tested */
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 1
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_TYPE_SPECS
  #define CYTHON_USE_TYPE_SPECS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #undef CYTHON_METH_FASTCALL
  #define CYTHON_METH_FASTCALL 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3)
  #endif
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(PYPY_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_TYPE_SPECS
  #define CYTHON_USE_TYPE_SPECS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #undef CYTHON_METH_FASTCALL
  #define CYTHON_METH_FASTCALL 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3)
  #endif
  #if PY_VERSION_HEX < 0x03090000
    #undef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT)
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00)
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(CYTHON_LIMITED_API)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 1
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_CLINE_IN_TRACEBACK
  #define CYTHON_CLINE_IN_TRACEBACK 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_TYPE_SPECS
  #define CYTHON_USE_TYPE_SPECS 1
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #endif
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #undef CYTHON_METH_FASTCALL
  #define CYTHON_METH_FASTCALL 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 1
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(PY_NOGIL)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #ifndef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #ifndef CYTHON_USE_TYPE_SPECS
    #define CYTHON_USE_TYPE_SPECS 0
  #endif
  #ifndef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #ifndef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_GIL
    #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6)
  #endif
  #ifndef CYTHON_METH_FASTCALL
    #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1)
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT)
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_MODULE_STATE
    #define CYTHON_USE_MODULE_STATE 0
  #endif
  #if PY_VERSION_HEX < 0x030400a1
    #undef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 0
  #elif !defined(CYTHON_USE_TP_FINALIZE)
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #if PY_VERSION_HEX < 0x030600B1
    #undef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS 0
  #elif !defined(CYTHON_USE_DICT_VERSIONS)
    #define CYTHON_USE_DICT_VERSIONS  (PY_VERSION_HEX < 0x030C00A5)
  #endif
  #if PY_VERSION_HEX < 0x030700A3
    #undef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK 0
  #elif !defined(CYTHON_USE_EXC_INFO_STACK)
    #define CYTHON_USE_EXC_INFO_STACK 1
  #endif
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if !defined(CYTHON_VECTORCALL)
#define CYTHON_VECTORCALL  (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1)
#endif
#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1)
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_MAJOR_VERSION < 3
    #include "longintrepr.h"
  #endif
  #undef SHIFT
  #undef BASE
  #undef MASK
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifndef CYTHON_UNUSED
  #if defined(__cplusplus)
    /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17
     * but leads to warnings with -pedantic, since it is a C++17 feature */
    #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
      #if __has_cpp_attribute(maybe_unused)
        #define CYTHON_UNUSED [[maybe_unused]]
      #endif
    #endif
  #endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
  #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x)
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
            typedef unsigned char     uint8_t;
            typedef unsigned short    uint16_t;
            typedef unsigned int      uint32_t;
        #else
            typedef unsigned __int8   uint8_t;
            typedef unsigned __int16  uint16_t;
            typedef unsigned __int32  uint32_t;
        #endif
    #endif
    #if _MSC_VER < 1300
        #ifdef _WIN64
            typedef unsigned long long  __pyx_uintptr_t;
        #else
            typedef unsigned int        __pyx_uintptr_t;
        #endif
    #else
        #ifdef _WIN64
            typedef unsigned __int64    __pyx_uintptr_t;
        #else
            typedef unsigned __int32    __pyx_uintptr_t;
        #endif
    #endif
#else
    #include <stdint.h>
    typedef uintptr_t  __pyx_uintptr_t;
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus)
    /* for clang __has_cpp_attribute(fallthrough) is true even before C++17
     * but leads to warnings with -pedantic, since it is a C++17 feature */
    #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
      #if __has_cpp_attribute(fallthrough)
        #define CYTHON_FALLTHROUGH [[fallthrough]]
      #endif
    #endif
    #ifndef CYTHON_FALLTHROUGH
      #if __has_cpp_attribute(clang::fallthrough)
        #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
      #elif __has_cpp_attribute(gnu::fallthrough)
        #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
      #endif
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif
#ifdef __cplusplus
  template <typename T>
  struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);};
  #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL<type>::value)
#else
  #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0)
#endif
#if CYTHON_COMPILING_IN_PYPY == 1
  #define __PYX_NEED_TP_PRINT_SLOT  (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000)
#else
  #define __PYX_NEED_TP_PRINT_SLOT  (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000)
#endif
#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer))

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_DefaultClassType PyClass_Type
  #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_DefaultClassType PyType_Type
#if PY_VERSION_HEX >= 0x030B00A1
    static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
        PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
        PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *empty=NULL;
        const char *fn_cstr=NULL;
        const char *name_cstr=NULL;
        PyCodeObject *co=NULL, *result=NULL;
        PyObject *type, *value, *traceback;
        PyErr_Fetch(&type, &value, &traceback);
        if (!(kwds=PyDict_New())) goto end;
        if (!(argcount=PyLong_FromLong(a))) goto end;
        if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end;
        if (!(posonlyargcount=PyLong_FromLong(p))) goto end;
        if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end;
        if (!(kwonlyargcount=PyLong_FromLong(k))) goto end;
        if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end;
        if (!(nlocals=PyLong_FromLong(l))) goto end;
        if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end;
        if (!(stacksize=PyLong_FromLong(s))) goto end;
        if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end;
        if (!(flags=PyLong_FromLong(f))) goto end;
        if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end;
        if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end;
        if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
        if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
        if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto end;
        if (!(empty = PyTuple_New(0))) goto end;
        result = (PyCodeObject*) PyObject_Call(replace, empty, kwds);
    end:
        Py_XDECREF((PyObject*) co);
        Py_XDECREF(kwds);
        Py_XDECREF(argcount);
        Py_XDECREF(posonlyargcount);
        Py_XDECREF(kwonlyargcount);
        Py_XDECREF(nlocals);
        Py_XDECREF(stacksize);
        Py_XDECREF(replace);
        Py_XDECREF(empty);
        if (type) {
            PyErr_Restore(type, value, traceback);
        }
        return result;
    }
#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif
#endif
#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE)
  #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type)
#else
  #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type))
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is)
  #define __Pyx_Py_Is(x, y)  Py_Is(x, y)
#else
  #define __Pyx_Py_Is(x, y) ((x) == (y))
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone)
  #define __Pyx_Py_IsNone(ob) Py_IsNone(ob)
#else
  #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None)
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue)
  #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob)
#else
  #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True)
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse)
  #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob)
#else
  #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False)
#endif
#define __Pyx_NoneAsNull(obj)  (__Pyx_Py_IsNone(obj) ? NULL : (obj))
#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o)
#else
  #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o)
#endif
#ifndef CO_COROUTINE
  #define CO_COROUTINE 0x80
#endif
#ifndef CO_ASYNC_GENERATOR
  #define CO_ASYNC_GENERATOR 0x200
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef Py_TPFLAGS_SEQUENCE
  #define Py_TPFLAGS_SEQUENCE 0
#endif
#ifndef Py_TPFLAGS_MAPPING
  #define Py_TPFLAGS_MAPPING 0
#endif
#ifndef METH_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_METH_FASTCALL
  #define __Pyx_METH_FASTCALL METH_FASTCALL
  #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast
  #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords
#else
  #define __Pyx_METH_FASTCALL METH_VARARGS
  #define __Pyx_PyCFunction_FastCall PyCFunction
  #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords
#endif
#if CYTHON_VECTORCALL
  #define __pyx_vectorcallfunc vectorcallfunc
  #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET  PY_VECTORCALL_ARGUMENTS_OFFSET
  #define __Pyx_PyVectorcall_NARGS(n)  PyVectorcall_NARGS((size_t)(n))
#elif CYTHON_BACKPORT_VECTORCALL
  typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args,
                                            size_t nargsf, PyObject *kwnames);
  #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET  ((size_t)1 << (8 * sizeof(size_t) - 1))
  #define __Pyx_PyVectorcall_NARGS(n)  ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET))
#else
  #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET  0
  #define __Pyx_PyVectorcall_NARGS(n)  ((Py_ssize_t)(n))
#endif
#if PY_VERSION_HEX < 0x030900B1
  #define __Pyx_PyType_FromModuleAndSpec(m, s, b)  ((void)m, PyType_FromSpecWithBases(s, b))
  typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *);
#else
  #define __Pyx_PyType_FromModuleAndSpec(m, s, b)  PyType_FromModuleAndSpec(m, s, b)
  #define __Pyx_PyCMethod  PyCMethod
#endif
#ifndef METH_METHOD
  #define METH_METHOD 0x200
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_PyThreadState_Current PyThreadState_Get()
#elif !CYTHON_FAST_THREAD_STATE
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op)
{
    void *result;
    result = PyModule_GetState(op);
    if (!result)
        Py_FatalError("Couldn't find the module state");
    return result;
}
#endif
#define __Pyx_PyObject_GetSlot(obj, name, func_ctype)  __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype)
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_PyType_GetSlot(type, name, func_ctype)  ((func_ctype) PyType_GetSlot((type), Py_##name))
#else
  #define __Pyx_PyType_GetSlot(type, name, func_ctype)  ((type)->name)
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if PY_MAJOR_VERSION < 3
    #if CYTHON_COMPILING_IN_PYPY
        #if PYPY_VERSION_NUM < 0x07030600
            #if defined(__cplusplus) && __cplusplus >= 201402L
                [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]]
            #elif defined(__GNUC__) || defined(__clang__)
                __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")))
            #elif defined(_MSC_VER)
                __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))
            #endif
            static CYTHON_INLINE int PyGILState_Check(void) {
                return 0;
            }
        #else  // PYPY_VERSION_NUM < 0x07030600
        #endif  // PYPY_VERSION_NUM < 0x07030600
    #else
        static CYTHON_INLINE int PyGILState_Check(void) {
            PyThreadState * tstate = _PyThreadState_Current;
            return tstate && (tstate == PyGILState_GetThisThreadState());
        }
    #endif
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStrWithError(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) {
    PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name);
    if (res == NULL) PyErr_Clear();
    return res;
}
#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000)
#define __Pyx_PyDict_GetItemStrWithError  PyDict_GetItemWithError
#define __Pyx_PyDict_GetItemStr           PyDict_GetItem
#else
static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) {
#if CYTHON_COMPILING_IN_PYPY
    return PyDict_GetItem(dict, name);
#else
    PyDictEntry *ep;
    PyDictObject *mp = (PyDictObject*) dict;
    long hash = ((PyStringObject *) name)->ob_shash;
    assert(hash != -1);
    ep = (mp->ma_lookup)(mp, name, hash);
    if (ep == NULL) {
        return NULL;
    }
    return ep->me_value;
#endif
}
#define __Pyx_PyDict_GetItemStr           PyDict_GetItem
#endif
#if CYTHON_USE_TYPE_SLOTS
  #define __Pyx_PyType_GetFlags(tp)   (((PyTypeObject *)tp)->tp_flags)
  #define __Pyx_PyType_HasFeature(type, feature)  ((__Pyx_PyType_GetFlags(type) & (feature)) != 0)
  #define __Pyx_PyObject_GetIterNextFunc(obj)  (Py_TYPE(obj)->tp_iternext)
#else
  #define __Pyx_PyType_GetFlags(tp)   (PyType_GetFlags((PyTypeObject *)tp))
  #define __Pyx_PyType_HasFeature(type, feature)  PyType_HasFeature(type, feature)
  #define __Pyx_PyObject_GetIterNextFunc(obj)  PyIter_Next
#endif
#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000
#define __Pyx_PyHeapTypeObject_GC_Del(obj)  {\
    PyTypeObject *type = Py_TYPE(obj);\
    assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\
    PyObject_GC_Del(obj);\
    Py_DECREF(type);\
}
#else
#define __Pyx_PyHeapTypeObject_GC_Del(obj)  PyObject_GC_Del(obj)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GetLength(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((void)u, 1114111U)
  #define __Pyx_PyUnicode_KIND(u)         ((void)u, (0))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)u)
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)k, PyUnicode_ReadChar((PyObject*)(d), i))
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GetLength(u))
#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #if PY_VERSION_HEX >= 0x030C0000
    #define __Pyx_PyUnicode_READY(op)       (0)
  #else
    #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                                0 : _PyUnicode_Ready((PyObject *)(op)))
  #endif
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         ((int)PyUnicode_KIND(u))
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, (Py_UCS4) ch)
  #if PY_VERSION_HEX >= 0x030C0000
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #else
    #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
    #else
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    #endif
  #endif
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U)
  #define __Pyx_PyUnicode_KIND(u)         ((int)sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #if !defined(PyUnicode_DecodeUnicodeEscape)
    #define PyUnicode_DecodeUnicodeEscape(s, size, errors)  PyUnicode_Decode(s, size, "unicode_escape", errors)
  #endif
  #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500)
    #undef PyUnicode_Contains
    #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
  #endif
  #if !defined(PyByteArray_Check)
    #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
  #endif
  #if !defined(PyObject_Format)
    #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
  #endif
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#if CYTHON_COMPILING_IN_CPYTHON
  #define __Pyx_PySequence_ListKeepNew(obj)\
    (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj))
#else
  #define __Pyx_PySequence_ListKeepNew(obj)  PySequence_List(obj)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        __Pyx_IS_TYPE(obj, &PySet_Type)
#endif
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define __Pyx_Py3Int_Check(op)       PyLong_Check(op)
  #define __Pyx_Py3Int_CheckExact(op)  PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#else
  #define __Pyx_Py3Int_Check(op)       (PyLong_Check(op) || PyInt_Check(op))
  #define __Pyx_Py3Int_CheckExact(op)  (PyLong_CheckExact(op) || PyInt_CheckExact(op))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsHash_t
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsSsize_t
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
  #if !defined(_USE_MATH_DEFINES)
    #define _USE_MATH_DEFINES
  #endif
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif

#define __PYX_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

#ifdef CYTHON_EXTERN_C
    #undef __PYX_EXTERN_C
    #define __PYX_EXTERN_C CYTHON_EXTERN_C
#elif defined(__PYX_EXTERN_C)
    #ifdef _MSC_VER
    #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.")
    #else
    #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.
    #endif
#else
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__pyreadstat___readstat_writer
#define __PYX_HAVE_API__pyreadstat___readstat_writer
/* Early includes */
#include <stddef.h>
#include <sys/types.h>
#include <stdint.h>
#include "readstat.h"
#include "readstat_io_unistd.h"
#include "conditional_includes.h"
#include <math.h>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 1
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING "utf8"
#define __Pyx_PyObject_FromString __Pyx_PyUnicode_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#if CYTHON_COMPILING_IN_LIMITED_API
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const wchar_t *u)
{
    const wchar_t *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#endif
#define __Pyx_PyUnicode_FromOrdinal(o)       PyUnicode_FromOrdinal((int)o)
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_VERSION_HEX >= 0x030C00A7
  #ifndef _PyLong_SIGN_MASK
    #define _PyLong_SIGN_MASK 3
  #endif
  #ifndef _PyLong_NON_SIZE_BITS
    #define _PyLong_NON_SIZE_BITS 3
  #endif
  #define __Pyx_PyLong_Sign(x)  (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK)
  #define __Pyx_PyLong_IsNeg(x)  ((__Pyx_PyLong_Sign(x) & 2) != 0)
  #define __Pyx_PyLong_IsNonNeg(x)  (!__Pyx_PyLong_IsNeg(x))
  #define __Pyx_PyLong_IsZero(x)  (__Pyx_PyLong_Sign(x) & 1)
  #define __Pyx_PyLong_IsPos(x)  (__Pyx_PyLong_Sign(x) == 0)
  #define __Pyx_PyLong_CompactValueUnsigned(x)  (__Pyx_PyLong_Digits(x)[0])
  #define __Pyx_PyLong_DigitCount(x)  ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS))
  #define __Pyx_PyLong_SignedDigitCount(x)\
        ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x))
  #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
    #define __Pyx_PyLong_IsCompact(x)     PyUnstable_Long_IsCompact((PyLongObject*) x)
    #define __Pyx_PyLong_CompactValue(x)  PyUnstable_Long_CompactValue((PyLongObject*) x)
  #else
    #define __Pyx_PyLong_IsCompact(x)     (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS))
    #define __Pyx_PyLong_CompactValue(x)  ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0])
  #endif
  typedef Py_ssize_t  __Pyx_compact_pylong;
  typedef size_t  __Pyx_compact_upylong;
  #else  // Py < 3.12
  #define __Pyx_PyLong_IsNeg(x)  (Py_SIZE(x) < 0)
  #define __Pyx_PyLong_IsNonNeg(x)  (Py_SIZE(x) >= 0)
  #define __Pyx_PyLong_IsZero(x)  (Py_SIZE(x) == 0)
  #define __Pyx_PyLong_IsPos(x)  (Py_SIZE(x) > 0)
  #define __Pyx_PyLong_CompactValueUnsigned(x)  ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0])
  #define __Pyx_PyLong_DigitCount(x)  __Pyx_sst_abs(Py_SIZE(x))
  #define __Pyx_PyLong_SignedDigitCount(x)  Py_SIZE(x)
  #define __Pyx_PyLong_IsCompact(x)  (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
  #define __Pyx_PyLong_CompactValue(x)\
        ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0]))
  typedef sdigit  __Pyx_compact_pylong;
  typedef digit  __Pyx_compact_upylong;
  #endif
  #if PY_VERSION_HEX >= 0x030C00A5
  #define __Pyx_PyLong_Digits(x)  (((PyLongObject*)x)->long_value.ob_digit)
  #else
  #define __Pyx_PyLong_Digits(x)  (((PyLongObject*)x)->ob_digit)
  #endif
#endif
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = (char) c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

#if !CYTHON_USE_MODULE_STATE
static PyObject *__pyx_m = NULL;
#endif
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm = __FILE__;
static const char *__pyx_filename;

/* #### Code section: filename_table ### */

static const char *__pyx_f[] = {
  "pyreadstat/_readstat_writer.pyx",
  "pyreadstat/_readstat_parser.pxd",
};
/* #### Code section: utility_code_proto_before_types ### */
/* #### Code section: numeric_typedefs ### */
/* #### Code section: complex_type_declarations ### */
/* #### Code section: type_declarations ### */

/*--- Type declarations ---*/
struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container;

/* "_readstat_parser.pxd":22
 * 
 * # Definitions of enum types
 * ctypedef enum py_file_extension:             # <<<<<<<<<<<<<<
 *     FILE_EXT_SAV
 *     FILE_EXT_SAS7BDAT
 */
enum __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension {
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAV,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAS7BDAT,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_DTA,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_XPORT,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_POR,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAS7BCAT
};
typedef enum __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension;

/* "_readstat_parser.pxd":30
 *     FILE_EXT_SAS7BCAT
 * 
 * ctypedef enum py_file_format:             # <<<<<<<<<<<<<<
 *     FILE_FORMAT_SAS
 *     FILE_FORMAT_SPSS
 */
enum __pyx_t_10pyreadstat_16_readstat_parser_py_file_format {
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS,
  __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA
};
typedef enum __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_t_10pyreadstat_16_readstat_parser_py_file_format;

/* "_readstat_parser.pxd":35
 *     FILE_FORMAT_STATA
 * 
 * ctypedef enum py_datetime_format:             # <<<<<<<<<<<<<<
 *     DATE_FORMAT_NOTADATE
 *     DATE_FORMAT_DATE
 */
enum __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format {
  __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE,
  __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE,
  __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME,
  __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_TIME
};
typedef enum __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format;

/* "_readstat_parser.pxd":41
 *     DATE_FORMAT_TIME
 * 
 * ctypedef enum py_variable_format:             # <<<<<<<<<<<<<<
 *     VAR_FORMAT_STRING
 *     VAR_FORMAT_LONG
 */
enum __pyx_t_10pyreadstat_16_readstat_parser_py_variable_format {
  __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_STRING,
  __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG,
  __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT,
  __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_MISSING
};
typedef enum __pyx_t_10pyreadstat_16_readstat_parser_py_variable_format __pyx_t_10pyreadstat_16_readstat_parser_py_variable_format;

/* "pyreadstat/_readstat_writer.pxd":56
 *     ssize_t write(int fd, const void *buf, size_t nbyte)
 * 
 * ctypedef enum dst_file_format:             # <<<<<<<<<<<<<<
 *     FILE_FORMAT_SAS7BDAT
 *     FILE_FORMAT_SAS7BCAT
 */
enum __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format {
  __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BDAT,
  __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BCAT,
  __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_XPORT,
  __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAV,
  __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA,
  __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR
};
typedef enum __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format;

/* "pyreadstat/_readstat_writer.pxd":64
 *     FILE_FORMAT_POR
 * 
 * ctypedef enum pywriter_variable_type:             # <<<<<<<<<<<<<<
 *     PYWRITER_DOUBLE
 *     PYWRITER_INTEGER
 */
enum __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type {
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US
};
typedef enum __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type;

/* "_readstat_parser.pxd":49
 * # Definitions of extension types
 * 
 * cdef class data_container:             # <<<<<<<<<<<<<<
 *     """
 *     This extension type holds all the data we need to get from our file from
 */
struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container {
  PyObject_HEAD
  int n_obs;
  int n_vars;
  int max_n_obs;
  PyObject *col_data;
  PyObject *col_data_len;
  PyObject *col_names;
  PyObject *col_labels;
  PyObject *col_dtypes;
  PyObject *col_numpy_dtypes;
  PyObject *col_dtypes_isobject;
  PyObject *col_dytpes_isfloat;
  PyObject *col_formats;
  PyObject *col_formats_original;
  PyObject *origin;
  __pyx_t_10pyreadstat_16_readstat_parser_py_file_format file_format;
  int is_unkown_number_rows;
  PyObject *file_label;
  PyObject *file_encoding;
  int metaonly;
  int dates_as_pandas;
  PyObject *label_to_var_name;
  PyObject *labels_raw;
  PyObject *notes;
  PyObject *user_encoding;
  PyObject *table_name;
  int filter_cols;
  PyObject *use_cols;
  int usernan;
  PyObject *missing_ranges;
  PyObject *missing_user_values;
  PyObject *variable_storage_width;
  PyObject *variable_display_width;
  PyObject *variable_alignment;
  PyObject *variable_measure;
  int no_datetime_conversion;
  int ctime;
  int mtime;
};

/* #### Code section: utility_code_proto ### */

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, Py_ssize_t);
    void (*DECREF)(void*, PyObject*, Py_ssize_t);
    void (*GOTREF)(void*, PyObject*, Py_ssize_t);
    void (*GIVEREF)(void*, PyObject*, Py_ssize_t);
    void* (*SetupContext)(const char*, Py_ssize_t, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\
          }
  #define __Pyx_RefNannyFinishContextNogil() {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __Pyx_RefNannyFinishContext();\
              PyGILState_Release(__pyx_gilstate_save);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__))
  #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext()
#endif
  #define __Pyx_RefNannyFinishContextNogil() {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __Pyx_RefNannyFinishContext();\
              PyGILState_Release(__pyx_gilstate_save);\
          }
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_XINCREF(r)  do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContextNogil()
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_Py_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; Py_XDECREF(tmp);\
    } while (0)
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#if PY_VERSION_HEX >= 0x030C00A6
#define __Pyx_PyErr_Occurred()  (__pyx_tstate->current_exception != NULL)
#define __Pyx_PyErr_CurrentExceptionType()  (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL)
#else
#define __Pyx_PyErr_Occurred()  (__pyx_tstate->curexc_type != NULL)
#define __Pyx_PyErr_CurrentExceptionType()  (__pyx_tstate->curexc_type)
#endif
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  (PyErr_Occurred() != NULL)
#define __Pyx_PyErr_CurrentExceptionType()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* PyObjectGetAttrStrNoError.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  do {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
} while(0)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  do {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
} while(0)
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#if !CYTHON_VECTORCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
#if !CYTHON_VECTORCALL
#if PY_VERSION_HEX >= 0x03080000
  #include "frameobject.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #define __Pxy_PyFrame_Initialize_Offsets()
  #define __Pyx_PyFrame_GetLocalsplus(frame)  ((frame)->f_localsplus)
#else
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#endif
#endif
#endif

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectFastCall.proto */
#define __Pyx_PyObject_FastCall(func, args, nargs)  __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL)
static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs);

/* IncludeStringH.proto */
#include <string.h>

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* RaiseUnexpectedTypeError.proto */
static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj);

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod1.proto */
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#else
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg)  __Pyx__CallUnboundCMethod1(cfunc, self, arg)
#endif

/* py_dict_keys.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d);

/* CallUnboundCMethod0.proto */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    (likely((cfunc)->func) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\
            (PY_VERSION_HEX >= 0x030700A0 ?\
                (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\
                (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\
          (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\
            (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\
            (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
               ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) :\
               __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

/* PyObject_Str.proto */
#define __Pyx_PyObject_Str(obj)\
    (likely(PyString_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj))

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject *key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* dict_getitem_default.proto */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value);

/* CallUnboundCMethod2.proto */
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2);
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2);
#else
#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2)  __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
#endif

/* pyfrozenset_new.proto */
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it);

/* PySetContains.proto */
static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq);

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
#define __Pyx_PyObject_Dict_GetItem(obj, name)\
    (likely(PyDict_CheckExact(obj)) ?\
     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
#endif

/* py_dict_items.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d);

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* UnicodeAsUCS4.proto */
static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);

/* object_ord.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyObject_Ord(c)\
    (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
#else
#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c)
#endif
static long __Pyx__PyObject_Ord(PyObject* c);

/* PyIntCompare.proto */
static CYTHON_INLINE int __Pyx_PyInt_BoolNeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* RaiseUnboundLocalError.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* HasAttr.proto */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);

/* GetTopmostException.proto */
#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* PyFloatBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_DivideObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyFloat_DivideObjC(op1, op2, floatval, inplace, zerodivision_check)\
    ((inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2)))
    #endif

/* SwapException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* TypeImport.proto */
#ifndef __PYX_HAVE_RT_ImportType_proto_3_0_0
#define __PYX_HAVE_RT_ImportType_proto_3_0_0
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#include <stdalign.h>
#endif
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || __cplusplus >= 201103L
#define __PYX_GET_STRUCT_ALIGNMENT_3_0_0(s) alignof(s)
#else
#define __PYX_GET_STRUCT_ALIGNMENT_3_0_0(s) sizeof(void*)
#endif
enum __Pyx_ImportType_CheckSize_3_0_0 {
   __Pyx_ImportType_CheckSize_Error_3_0_0 = 0,
   __Pyx_ImportType_CheckSize_Warn_3_0_0 = 1,
   __Pyx_ImportType_CheckSize_Ignore_3_0_0 = 2
};
static PyTypeObject *__Pyx_ImportType_3_0_0(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_0 check_size);
#endif

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportDottedModule.proto */
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple);
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple);
#endif

/* ImportDottedModuleRelFirst.proto */
static PyObject *__Pyx_ImportDottedModuleRelFirst(PyObject *name, PyObject *parts_tuple);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* PyObjectCallNoArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
#if !CYTHON_COMPILING_IN_LIMITED_API
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
#endif

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* GCCDiagnostics.proto */
#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define __Pyx_HAS_GCC_DIAGNOSTIC
#endif

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_readstat_type_t(readstat_type_t value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntFromPy.proto */
static CYTHON_INLINE readstat_type_t __Pyx_PyInt_As_readstat_type_t(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __Pyx_PyInt_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(PyObject *);

/* FormatTypeName.proto */
#if CYTHON_COMPILING_IN_LIMITED_API
typedef PyObject *__Pyx_TypeName;
#define __Pyx_FMT_TYPENAME "%U"
static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp);
#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj)
#else
typedef const char *__Pyx_TypeName;
#define __Pyx_FMT_TYPENAME "%.200s"
#define __Pyx_PyType_GetName(tp) ((tp)->tp_name)
#define __Pyx_DECREF_TypeName(obj)
#endif

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2))
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyErr_ExceptionMatches2(err1, err2)  __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2)
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* FunctionExport.proto */
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);

/* VoidPtrImport.proto */
static int __Pyx_ImportVoidPtr_3_0_0(PyObject *module, const char *name, void **p, const char *sig);

/* FunctionImport.proto */
static int __Pyx_ImportFunction_3_0_0(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

/* #### Code section: module_declarations ### */

/* Module declarations from "libc.stddef" */

/* Module declarations from "pyreadstat.readstat_api" */

/* Module declarations from "libc.math" */

/* Module declarations from "pyreadstat._readstat_parser" */
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_readstat_to_numpy_types = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types (*__pyx_vp_10pyreadstat_16_readstat_parser_readstat_to_numpy_types)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_sas_date_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_sas_date_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_sas_datetime_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_sas_datetime_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_sas_time_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_sas_time_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_sas_all_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_sas_all_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_sas_origin = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_sas_origin (*__pyx_vp_10pyreadstat_16_readstat_parser_sas_origin)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_spss_datetime_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_spss_datetime_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_spss_date_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_spss_date_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_spss_time_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_spss_time_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_spss_all_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_spss_all_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_spss_origin = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_spss_origin (*__pyx_vp_10pyreadstat_16_readstat_parser_spss_origin)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_stata_datetime_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_stata_datetime_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_stata_date_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_stata_date_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_stata_time_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_stata_time_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_stata_all_formats = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats (*__pyx_vp_10pyreadstat_16_readstat_parser_stata_all_formats)
static PyObject **__pyx_vp_10pyreadstat_16_readstat_parser_stata_origin = 0;
#define __pyx_v_10pyreadstat_16_readstat_parser_stata_origin (*__pyx_vp_10pyreadstat_16_readstat_parser_stata_origin)
static void (*__pyx_f_10pyreadstat_16_readstat_parser_check_exit_status)(readstat_error_t); /*proto*/

/* Module declarations from "pyreadstat._readstat_writer" */
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_int_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_float_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_numeric_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_datetime_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_nat_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types = 0;
static double __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_secs;
static double __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_secs;
static double __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_days;
static double __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_days;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_date_0 = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas = 0;
static PyObject *__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata = 0;
static double __pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number(__pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, PyObject *); /*proto*/
static char *__pyx_f_10pyreadstat_16_readstat_writer_get_datetimelike_format_for_readstat(__pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type); /*proto*/
static int __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(PyObject *, PyObject *); /*proto*/
static int __pyx_f_10pyreadstat_16_readstat_writer_check_series_all_same_types(PyObject *, PyObject *); /*proto*/
static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_get_pandas_column_types(PyObject *, PyObject *, PyObject *); /*proto*/
static Py_ssize_t __pyx_f_10pyreadstat_16_readstat_writer_write_bytes(void const *, size_t, void *); /*proto*/
static int __pyx_f_10pyreadstat_16_readstat_writer_open_file(PyObject *); /*proto*/
static int __pyx_f_10pyreadstat_16_readstat_writer_close_file(int); /*proto*/
static readstat_label_set_t *__pyx_f_10pyreadstat_16_readstat_writer_set_value_label(readstat_writer_t *, PyObject *, PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *); /*proto*/
static void __pyx_f_10pyreadstat_16_readstat_writer_add_missing_ranges(PyObject *, readstat_variable_t *, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, PyObject *); /*proto*/
static void __pyx_f_10pyreadstat_16_readstat_writer_set_variable_alignment(readstat_variable_t *, PyObject *, PyObject *); /*proto*/
static void __pyx_f_10pyreadstat_16_readstat_writer_set_variable_display_width(readstat_variable_t *, int, PyObject *); /*proto*/
static void __pyx_f_10pyreadstat_16_readstat_writer_set_variable_measure(readstat_variable_t *, PyObject *, PyObject *); /*proto*/
/* #### Code section: typeinfo ### */
/* #### Code section: before_global_var ### */
#define __Pyx_MODULE_NAME "pyreadstat._readstat_writer"
extern int __pyx_module_is_main_pyreadstat___readstat_writer;
int __pyx_module_is_main_pyreadstat___readstat_writer = 0;

/* Implementation of "pyreadstat._readstat_writer" */
/* #### Code section: global_var ### */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_UnicodeError;
/* #### Code section: string_decls ### */
static const char __pyx_k_x[] = "x";
static const char __pyx_k__2[] = " ";
static const char __pyx_k__4[] = "*";
static const char __pyx_k__5[] = ".";
static const char __pyx_k_hi[] = "hi";
static const char __pyx_k_lo[] = "lo";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_nt[] = "nt";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_pd[] = "pd";
static const char __pyx_k__17[] = "_";
static const char __pyx_k__18[] = "?";
static const char __pyx_k_any[] = "any";
static const char __pyx_k_chr[] = "chr";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_loc[] = "loc";
static const char __pyx_k_min[] = "min";
static const char __pyx_k_nan[] = "nan";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_utc[] = "utc";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_asm8[] = "asm8";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_core[] = "core";
static const char __pyx_k_date[] = "date";
static const char __pyx_k_days[] = "days";
static const char __pyx_k_drop[] = "drop";
static const char __pyx_k_iloc[] = "iloc";
static const char __pyx_k_int8[] = "int8";
static const char __pyx_k_isin[] = "isin";
static const char __pyx_k_isna[] = "isna";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_left[] = "left";
static const char __pyx_k_libs[] = "_libs";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "name";
static const char __pyx_k_path[] = "path";
static const char __pyx_k_spec[] = "__spec__";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_time[] = "time";
static const char __pyx_k_warn[] = "warn";
static const char __pyx_k_M8_ns[] = "<M8[ns]";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_float[] = "float";
static const char __pyx_k_int16[] = "int16";
static const char __pyx_k_int32[] = "int32";
static const char __pyx_k_int64[] = "int64";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_right[] = "right";
static const char __pyx_k_round[] = "round";
static const char __pyx_k_scale[] = "scale";
static const char __pyx_k_uint8[] = "uint8";
static const char __pyx_k_union[] = "union";
static const char __pyx_k_upper[] = "upper";
static const char __pyx_k_utf_8[] = "utf-8";
static const char __pyx_k_astype[] = "astype";
static const char __pyx_k_center[] = "center";
static const char __pyx_k_dropna[] = "dropna";
static const char __pyx_k_dtypes[] = "dtypes";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_name_2[] = "__name__";
static const char __pyx_k_object[] = "object";
static const char __pyx_k_pandas[] = "pandas";
static const char __pyx_k_string[] = "string";
static const char __pyx_k_timegm[] = "timegm";
static const char __pyx_k_tolist[] = "tolist";
static const char __pyx_k_tslibs[] = "tslibs";
static const char __pyx_k_tzinfo[] = "tzinfo";
static const char __pyx_k_uint16[] = "uint16";
static const char __pyx_k_uint32[] = "uint32";
static const char __pyx_k_uint64[] = "uint64";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_asarray[] = "asarray";
static const char __pyx_k_columns[] = "columns";
static const char __pyx_k_combine[] = "combine";
static const char __pyx_k_float32[] = "float32";
static const char __pyx_k_float64[] = "float64";
static const char __pyx_k_isalpha[] = "isalpha";
static const char __pyx_k_nominal[] = "nominal";
static const char __pyx_k_ordinal[] = "ordinal";
static const char __pyx_k_replace[] = "replace";
static const char __pyx_k_unknown[] = "unknown";
static const char __pyx_k_calendar[] = "calendar";
static const char __pyx_k_datetime[] = "datetime";
static const char __pyx_k_fsdecode[] = "fsdecode";
static const char __pyx_k_fsencode[] = "fsencode";
static const char __pyx_k_timezone[] = "_timezone";
static const char __pyx_k_warnings[] = "warnings";
static const char __pyx_k_DataFrame[] = "DataFrame";
static const char __pyx_k_Int8Dtype[] = "Int8Dtype";
static const char __pyx_k_Timestamp[] = "Timestamp";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_timetuple[] = "timetuple";
static const char __pyx_k_Int16Dtype[] = "Int16Dtype";
static const char __pyx_k_Int32Dtype[] = "Int32Dtype";
static const char __pyx_k_Int64Dtype[] = "Int64Dtype";
static const char __pyx_k_UInt8Dtype[] = "UInt8Dtype";
static const char __pyx_k_datetime64[] = "datetime64";
static const char __pyx_k_expanduser[] = "expanduser";
static const char __pyx_k_startswith[] = "startswith";
static const char __pyx_k_timestamps[] = "timestamps";
static const char __pyx_k_timezone_2[] = "timezone";
static const char __pyx_k_UInt16Dtype[] = "UInt16Dtype";
static const char __pyx_k_UInt32Dtype[] = "UInt32Dtype";
static const char __pyx_k_UInt64Dtype[] = "UInt64Dtype";
static const char __pyx_k_reset_index[] = "reset_index";
static const char __pyx_k_Float32Dtype[] = "Float32Dtype";
static const char __pyx_k_Float64Dtype[] = "Float64Dtype";
static const char __pyx_k_UnicodeError[] = "UnicodeError";
static const char __pyx_k_initializing[] = "_initializing";
static const char __pyx_k_ReadstatError[] = "ReadstatError";
static const char __pyx_k_class_getitem[] = "__class_getitem__";
static const char __pyx_k_datetime64_ms[] = "datetime64[ms]";
static const char __pyx_k_datetime64_ns[] = "datetime64[ns]";
static const char __pyx_k_datetime64_us[] = "datetime64[us]";
static const char __pyx_k_total_seconds[] = "total_seconds";
static const char __pyx_k_PyreadstatError[] = "PyreadstatError";
static const char __pyx_k_datetime64_us_2[] = "datetime64[us";
static const char __pyx_k_readstat_parser[] = "_readstat_parser";
static const char __pyx_k_surrogateescape[] = "surrogateescape";
static const char __pyx_k_CategoricalDtype[] = "CategoricalDtype";
static const char __pyx_k_pandas_api_types[] = "pandas.api.types";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_unknown_file_format[] = "unknown file format";
static const char __pyx_k_getfilesystemencoding[] = "getfilesystemencoding";
static const char __pyx_k_is_datetime64_ns_dtype[] = "is_datetime64_ns_dtype";
static const char __pyx_k_is_datetime64_any_dtype[] = "is_datetime64_any_dtype";
static const char __pyx_k_Column_labels_must_be_strings[] = "Column labels must be strings";
static const char __pyx_k_Unknown_data_format_to_insert[] = "Unknown data format to insert";
static const char __pyx_k_first_argument_must_be_a_pandas[] = "first argument must be a pandas data frame";
static const char __pyx_k_length_of_column_labels_must_be[] = "length of column labels must be the same as number of columns";
static const char __pyx_k_missing_ranges_hi_and_lo_values[] = "missing_ranges: hi and lo values must be both the same for string type";
static const char __pyx_k_missing_user_values_not_allowed[] = "missing_user_values not allowed for character variable %s";
static const char __pyx_k_variable_value_labels_value_for[] = "variable_value_labels: value for key %s must be dict, got %s";
static const char __pyx_k_Non_unique_column_names_detected[] = "Non unique column names detected in the dataframe!";
static const char __pyx_k_Unknown_pywriter_variable_format[] = "Unknown pywriter variable format";
static const char __pyx_k_alignment_for_variable_s_must_be[] = "alignment for variable %s must be either right, center, left or unknown got %s instead";
static const char __pyx_k_character_missing_ranges_value_g[] = "character missing_ranges value given for non character variable %s";
static const char __pyx_k_column_labels_must_be_either_lis[] = "column_labels must be either list or dict!";
static const char __pyx_k_dictionaries_in_missing_ranges_m[] = "dictionaries in missing_ranges must have the keys hi and lo";
static const char __pyx_k_file_path_could_not_be_encoded_w[] = "file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly.";
static const char __pyx_k_measure_for_variable_s_must_be_e[] = "measure for variable %s must be either nominal, ordinal, scale or unknown got %s instead";
static const char __pyx_k_missing_ranges_max_1_discrete_nu[] = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed";
static const char __pyx_k_missing_ranges_max_1_range_value[] = "missing_ranges: max 1 range value per variable allowed";
static const char __pyx_k_missing_ranges_max_3_discrete_nu[] = "missing_ranges: max 3 discrete numeric values per variable allowed";
static const char __pyx_k_missing_ranges_max_3_string_valu[] = "missing_ranges: max 3 string values per variable allowed";
static const char __pyx_k_missing_ranges_string_values_len[] = "missing_ranges: string values length must not be larger than 8";
static const char __pyx_k_missing_ranges_values_in_diction[] = "missing_ranges: values in dictionary must be list";
static const char __pyx_k_missing_ranges_values_must_be_bo[] = "missing_ranges: values must be both either of numeric or string type";
static const char __pyx_k_missing_user_values_supports_val[] = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead";
static const char __pyx_k_missing_user_values_values_in_di[] = "missing_user_values: values in dictionary must be list";
static const char __pyx_k_numeric_missing_ranges_value_giv[] = "numeric missing_ranges value given for non numeric variable %s";
static const char __pyx_k_path_must_be_either_str_or_bytes[] = "path must be either str or bytes";
static const char __pyx_k_variable_name_s_contains_a_space[] = "variable name '%s' contains a space, which is not allowed";
static const char __pyx_k_variable_name_s_is_of_type_s_and[] = "variable name '%s' is of type %s and it must be str (not starting with numbers!)";
static const char __pyx_k_variable_name_s_starts_with_an_i[] = "variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)";
static const char __pyx_k_variable_value_labels_type_of_La[] = "variable_value_labels: type of Label %s in variable %s must be string";
static const char __pyx_k_variable_value_labels_type_of_Va[] = "variable_value_labels: type of Value %s in variable %s must be numeric";
static const char __pyx_k_missing_ranges_hi_and_lo_values_2[] = "missing_ranges: hi and lo values must be both either of numeric or string type";
static const char __pyx_k_variable_value_labels_type_of_Va_2[] = "variable_value_labels: type of Value %s in variable %s must be int";
static const char __pyx_k_variable_value_labels_type_of_Va_3[] = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0";
static const char __pyx_k_variable_value_labels_type_of_Va_4[] = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time";
/* #### Code section: decls ### */
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, 0, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, 0, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_keys = {0, 0, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PySet_Type_union = {0, 0, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyString_Type_encode = {0, 0, 0, 0, 0};
/* #### Code section: late_includes ### */
/* #### Code section: module_state ### */
typedef struct {
  PyObject *__pyx_d;
  PyObject *__pyx_b;
  PyObject *__pyx_cython_runtime;
  PyObject *__pyx_empty_tuple;
  PyObject *__pyx_empty_bytes;
  PyObject *__pyx_empty_unicode;
  #ifdef __Pyx_CyFunction_USED
  PyTypeObject *__pyx_CyFunctionType;
  #endif
  #ifdef __Pyx_FusedFunction_USED
  PyTypeObject *__pyx_FusedFunctionType;
  #endif
  #ifdef __Pyx_Generator_USED
  PyTypeObject *__pyx_GeneratorType;
  #endif
  #ifdef __Pyx_IterableCoroutine_USED
  PyTypeObject *__pyx_IterableCoroutineType;
  #endif
  #ifdef __Pyx_Coroutine_USED
  PyTypeObject *__pyx_CoroutineAwaitType;
  #endif
  #ifdef __Pyx_Coroutine_USED
  PyTypeObject *__pyx_CoroutineType;
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_10pyreadstat_16_readstat_parser_data_container;
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyObject *__pyx_n_s_CategoricalDtype;
  PyObject *__pyx_kp_s_Column_labels_must_be_strings;
  PyObject *__pyx_n_s_DataFrame;
  PyObject *__pyx_n_s_Float32Dtype;
  PyObject *__pyx_n_s_Float64Dtype;
  PyObject *__pyx_n_s_Int16Dtype;
  PyObject *__pyx_n_s_Int32Dtype;
  PyObject *__pyx_n_s_Int64Dtype;
  PyObject *__pyx_n_s_Int8Dtype;
  PyObject *__pyx_kp_s_M8_ns;
  PyObject *__pyx_kp_s_Non_unique_column_names_detected;
  PyObject *__pyx_n_s_PyreadstatError;
  PyObject *__pyx_n_s_ReadstatError;
  PyObject *__pyx_n_s_Timestamp;
  PyObject *__pyx_n_s_UInt16Dtype;
  PyObject *__pyx_n_s_UInt32Dtype;
  PyObject *__pyx_n_s_UInt64Dtype;
  PyObject *__pyx_n_s_UInt8Dtype;
  PyObject *__pyx_n_s_UnicodeError;
  PyObject *__pyx_kp_s_Unknown_data_format_to_insert;
  PyObject *__pyx_kp_s_Unknown_pywriter_variable_format;
  PyObject *__pyx_n_s__17;
  PyObject *__pyx_n_s__18;
  PyObject *__pyx_kp_s__2;
  PyObject *__pyx_n_s__4;
  PyObject *__pyx_kp_u__5;
  PyObject *__pyx_kp_s_alignment_for_variable_s_must_be;
  PyObject *__pyx_n_s_any;
  PyObject *__pyx_n_s_asarray;
  PyObject *__pyx_n_s_asm8;
  PyObject *__pyx_n_s_astype;
  PyObject *__pyx_n_s_calendar;
  PyObject *__pyx_n_s_center;
  PyObject *__pyx_kp_s_character_missing_ranges_value_g;
  PyObject *__pyx_n_s_chr;
  PyObject *__pyx_n_s_class_getitem;
  PyObject *__pyx_n_s_cline_in_traceback;
  PyObject *__pyx_kp_s_column_labels_must_be_either_lis;
  PyObject *__pyx_n_s_columns;
  PyObject *__pyx_n_s_combine;
  PyObject *__pyx_n_s_copy;
  PyObject *__pyx_n_s_core;
  PyObject *__pyx_n_s_date;
  PyObject *__pyx_n_s_datetime;
  PyObject *__pyx_n_s_datetime64;
  PyObject *__pyx_kp_s_datetime64_ms;
  PyObject *__pyx_kp_s_datetime64_ns;
  PyObject *__pyx_kp_s_datetime64_us;
  PyObject *__pyx_kp_s_datetime64_us_2;
  PyObject *__pyx_n_s_days;
  PyObject *__pyx_kp_s_dictionaries_in_missing_ranges_m;
  PyObject *__pyx_n_s_drop;
  PyObject *__pyx_n_s_dropna;
  PyObject *__pyx_n_s_dtype;
  PyObject *__pyx_n_s_dtypes;
  PyObject *__pyx_n_s_encode;
  PyObject *__pyx_n_s_enumerate;
  PyObject *__pyx_n_s_expanduser;
  PyObject *__pyx_kp_s_file_path_could_not_be_encoded_w;
  PyObject *__pyx_kp_s_first_argument_must_be_a_pandas;
  PyObject *__pyx_n_s_float;
  PyObject *__pyx_n_s_float32;
  PyObject *__pyx_n_s_float64;
  PyObject *__pyx_n_s_fsdecode;
  PyObject *__pyx_n_s_fsencode;
  PyObject *__pyx_n_s_get;
  PyObject *__pyx_n_s_getfilesystemencoding;
  PyObject *__pyx_n_s_hi;
  PyObject *__pyx_n_s_iloc;
  PyObject *__pyx_n_s_import;
  PyObject *__pyx_n_s_initializing;
  PyObject *__pyx_n_s_int16;
  PyObject *__pyx_n_s_int32;
  PyObject *__pyx_n_s_int64;
  PyObject *__pyx_n_s_int8;
  PyObject *__pyx_n_s_is_datetime64_any_dtype;
  PyObject *__pyx_n_s_is_datetime64_ns_dtype;
  PyObject *__pyx_n_s_isalpha;
  PyObject *__pyx_n_s_isin;
  PyObject *__pyx_n_s_isna;
  PyObject *__pyx_n_s_items;
  PyObject *__pyx_n_s_keys;
  PyObject *__pyx_n_s_left;
  PyObject *__pyx_kp_s_length_of_column_labels_must_be;
  PyObject *__pyx_n_s_libs;
  PyObject *__pyx_n_s_lo;
  PyObject *__pyx_n_s_loc;
  PyObject *__pyx_n_s_main;
  PyObject *__pyx_kp_s_measure_for_variable_s_must_be_e;
  PyObject *__pyx_n_s_min;
  PyObject *__pyx_kp_s_missing_ranges_hi_and_lo_values;
  PyObject *__pyx_kp_s_missing_ranges_hi_and_lo_values_2;
  PyObject *__pyx_kp_s_missing_ranges_max_1_discrete_nu;
  PyObject *__pyx_kp_s_missing_ranges_max_1_range_value;
  PyObject *__pyx_kp_s_missing_ranges_max_3_discrete_nu;
  PyObject *__pyx_kp_s_missing_ranges_max_3_string_valu;
  PyObject *__pyx_kp_s_missing_ranges_string_values_len;
  PyObject *__pyx_kp_s_missing_ranges_values_in_diction;
  PyObject *__pyx_kp_s_missing_ranges_values_must_be_bo;
  PyObject *__pyx_kp_s_missing_user_values_not_allowed;
  PyObject *__pyx_kp_s_missing_user_values_supports_val;
  PyObject *__pyx_kp_s_missing_user_values_values_in_di;
  PyObject *__pyx_n_s_name;
  PyObject *__pyx_n_s_name_2;
  PyObject *__pyx_n_s_nan;
  PyObject *__pyx_n_s_nominal;
  PyObject *__pyx_n_s_np;
  PyObject *__pyx_n_s_nt;
  PyObject *__pyx_kp_s_numeric_missing_ranges_value_giv;
  PyObject *__pyx_n_s_numpy;
  PyObject *__pyx_n_s_object;
  PyObject *__pyx_n_s_ordinal;
  PyObject *__pyx_n_s_os;
  PyObject *__pyx_n_s_pandas;
  PyObject *__pyx_n_s_pandas_api_types;
  PyObject *__pyx_n_s_path;
  PyObject *__pyx_kp_s_path_must_be_either_str_or_bytes;
  PyObject *__pyx_n_s_pd;
  PyObject *__pyx_n_s_range;
  PyObject *__pyx_n_s_readstat_parser;
  PyObject *__pyx_n_s_replace;
  PyObject *__pyx_n_s_reset_index;
  PyObject *__pyx_n_s_right;
  PyObject *__pyx_n_s_round;
  PyObject *__pyx_n_s_scale;
  PyObject *__pyx_n_s_spec;
  PyObject *__pyx_n_s_startswith;
  PyObject *__pyx_n_s_string;
  PyObject *__pyx_n_s_surrogateescape;
  PyObject *__pyx_n_s_sys;
  PyObject *__pyx_n_s_test;
  PyObject *__pyx_n_s_time;
  PyObject *__pyx_n_s_timegm;
  PyObject *__pyx_n_s_timestamps;
  PyObject *__pyx_n_s_timetuple;
  PyObject *__pyx_n_s_timezone;
  PyObject *__pyx_n_s_timezone_2;
  PyObject *__pyx_n_s_tolist;
  PyObject *__pyx_n_s_total_seconds;
  PyObject *__pyx_n_s_tslibs;
  PyObject *__pyx_n_s_tzinfo;
  PyObject *__pyx_n_s_uint16;
  PyObject *__pyx_n_s_uint32;
  PyObject *__pyx_n_s_uint64;
  PyObject *__pyx_n_s_uint8;
  PyObject *__pyx_n_s_union;
  PyObject *__pyx_n_s_unknown;
  PyObject *__pyx_kp_s_unknown_file_format;
  PyObject *__pyx_n_s_upper;
  PyObject *__pyx_n_s_utc;
  PyObject *__pyx_kp_s_utf_8;
  PyObject *__pyx_n_s_values;
  PyObject *__pyx_kp_s_variable_name_s_contains_a_space;
  PyObject *__pyx_kp_s_variable_name_s_is_of_type_s_and;
  PyObject *__pyx_kp_s_variable_name_s_starts_with_an_i;
  PyObject *__pyx_kp_s_variable_value_labels_type_of_La;
  PyObject *__pyx_kp_s_variable_value_labels_type_of_Va;
  PyObject *__pyx_kp_s_variable_value_labels_type_of_Va_2;
  PyObject *__pyx_kp_s_variable_value_labels_type_of_Va_3;
  PyObject *__pyx_kp_s_variable_value_labels_type_of_Va_4;
  PyObject *__pyx_kp_s_variable_value_labels_value_for;
  PyObject *__pyx_n_s_warn;
  PyObject *__pyx_n_s_warnings;
  PyObject *__pyx_n_s_x;
  PyObject *__pyx_n_s_zip;
  PyObject *__pyx_float_1e6;
  PyObject *__pyx_float_1e9;
  PyObject *__pyx_int_0;
  PyObject *__pyx_int_1;
  PyObject *__pyx_int_65;
  PyObject *__pyx_int_97;
  PyObject *__pyx_int_1970;
  PyObject *__pyx_int_neg_9223056417655;
  PyObject *__pyx_slice_;
  PyObject *__pyx_tuple__3;
  PyObject *__pyx_tuple__6;
  PyObject *__pyx_tuple__7;
  PyObject *__pyx_tuple__8;
  PyObject *__pyx_tuple__9;
  PyObject *__pyx_tuple__10;
  PyObject *__pyx_tuple__11;
  PyObject *__pyx_tuple__12;
  PyObject *__pyx_tuple__13;
  PyObject *__pyx_tuple__14;
  PyObject *__pyx_tuple__15;
  PyObject *__pyx_tuple__16;
} __pyx_mstate;

#if CYTHON_USE_MODULE_STATE
#ifdef __cplusplus
namespace {
  extern struct PyModuleDef __pyx_moduledef;
} /* anonymous namespace */
#else
static struct PyModuleDef __pyx_moduledef;
#endif

#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o))

#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef)))

#define __pyx_m (PyState_FindModule(&__pyx_moduledef))
#else
static __pyx_mstate __pyx_mstate_global_static =
#ifdef __cplusplus
    {};
#else
    {0};
#endif
static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static;
#endif
/* #### Code section: module_state_clear ### */
#if CYTHON_USE_MODULE_STATE
static int __pyx_m_clear(PyObject *m) {
  __pyx_mstate *clear_module_state = __pyx_mstate(m);
  if (!clear_module_state) return 0;
  Py_CLEAR(clear_module_state->__pyx_d);
  Py_CLEAR(clear_module_state->__pyx_b);
  Py_CLEAR(clear_module_state->__pyx_cython_runtime);
  Py_CLEAR(clear_module_state->__pyx_empty_tuple);
  Py_CLEAR(clear_module_state->__pyx_empty_bytes);
  Py_CLEAR(clear_module_state->__pyx_empty_unicode);
  #ifdef __Pyx_CyFunction_USED
  Py_CLEAR(clear_module_state->__pyx_CyFunctionType);
  #endif
  #ifdef __Pyx_FusedFunction_USED
  Py_CLEAR(clear_module_state->__pyx_FusedFunctionType);
  #endif
  Py_CLEAR(clear_module_state->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container);
  Py_CLEAR(clear_module_state->__pyx_n_s_CategoricalDtype);
  Py_CLEAR(clear_module_state->__pyx_kp_s_Column_labels_must_be_strings);
  Py_CLEAR(clear_module_state->__pyx_n_s_DataFrame);
  Py_CLEAR(clear_module_state->__pyx_n_s_Float32Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_Float64Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_Int16Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_Int32Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_Int64Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_Int8Dtype);
  Py_CLEAR(clear_module_state->__pyx_kp_s_M8_ns);
  Py_CLEAR(clear_module_state->__pyx_kp_s_Non_unique_column_names_detected);
  Py_CLEAR(clear_module_state->__pyx_n_s_PyreadstatError);
  Py_CLEAR(clear_module_state->__pyx_n_s_ReadstatError);
  Py_CLEAR(clear_module_state->__pyx_n_s_Timestamp);
  Py_CLEAR(clear_module_state->__pyx_n_s_UInt16Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_UInt32Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_UInt64Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_UInt8Dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_UnicodeError);
  Py_CLEAR(clear_module_state->__pyx_kp_s_Unknown_data_format_to_insert);
  Py_CLEAR(clear_module_state->__pyx_kp_s_Unknown_pywriter_variable_format);
  Py_CLEAR(clear_module_state->__pyx_n_s__17);
  Py_CLEAR(clear_module_state->__pyx_n_s__18);
  Py_CLEAR(clear_module_state->__pyx_kp_s__2);
  Py_CLEAR(clear_module_state->__pyx_n_s__4);
  Py_CLEAR(clear_module_state->__pyx_kp_u__5);
  Py_CLEAR(clear_module_state->__pyx_kp_s_alignment_for_variable_s_must_be);
  Py_CLEAR(clear_module_state->__pyx_n_s_any);
  Py_CLEAR(clear_module_state->__pyx_n_s_asarray);
  Py_CLEAR(clear_module_state->__pyx_n_s_asm8);
  Py_CLEAR(clear_module_state->__pyx_n_s_astype);
  Py_CLEAR(clear_module_state->__pyx_n_s_calendar);
  Py_CLEAR(clear_module_state->__pyx_n_s_center);
  Py_CLEAR(clear_module_state->__pyx_kp_s_character_missing_ranges_value_g);
  Py_CLEAR(clear_module_state->__pyx_n_s_chr);
  Py_CLEAR(clear_module_state->__pyx_n_s_class_getitem);
  Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback);
  Py_CLEAR(clear_module_state->__pyx_kp_s_column_labels_must_be_either_lis);
  Py_CLEAR(clear_module_state->__pyx_n_s_columns);
  Py_CLEAR(clear_module_state->__pyx_n_s_combine);
  Py_CLEAR(clear_module_state->__pyx_n_s_copy);
  Py_CLEAR(clear_module_state->__pyx_n_s_core);
  Py_CLEAR(clear_module_state->__pyx_n_s_date);
  Py_CLEAR(clear_module_state->__pyx_n_s_datetime);
  Py_CLEAR(clear_module_state->__pyx_n_s_datetime64);
  Py_CLEAR(clear_module_state->__pyx_kp_s_datetime64_ms);
  Py_CLEAR(clear_module_state->__pyx_kp_s_datetime64_ns);
  Py_CLEAR(clear_module_state->__pyx_kp_s_datetime64_us);
  Py_CLEAR(clear_module_state->__pyx_kp_s_datetime64_us_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_days);
  Py_CLEAR(clear_module_state->__pyx_kp_s_dictionaries_in_missing_ranges_m);
  Py_CLEAR(clear_module_state->__pyx_n_s_drop);
  Py_CLEAR(clear_module_state->__pyx_n_s_dropna);
  Py_CLEAR(clear_module_state->__pyx_n_s_dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_dtypes);
  Py_CLEAR(clear_module_state->__pyx_n_s_encode);
  Py_CLEAR(clear_module_state->__pyx_n_s_enumerate);
  Py_CLEAR(clear_module_state->__pyx_n_s_expanduser);
  Py_CLEAR(clear_module_state->__pyx_kp_s_file_path_could_not_be_encoded_w);
  Py_CLEAR(clear_module_state->__pyx_kp_s_first_argument_must_be_a_pandas);
  Py_CLEAR(clear_module_state->__pyx_n_s_float);
  Py_CLEAR(clear_module_state->__pyx_n_s_float32);
  Py_CLEAR(clear_module_state->__pyx_n_s_float64);
  Py_CLEAR(clear_module_state->__pyx_n_s_fsdecode);
  Py_CLEAR(clear_module_state->__pyx_n_s_fsencode);
  Py_CLEAR(clear_module_state->__pyx_n_s_get);
  Py_CLEAR(clear_module_state->__pyx_n_s_getfilesystemencoding);
  Py_CLEAR(clear_module_state->__pyx_n_s_hi);
  Py_CLEAR(clear_module_state->__pyx_n_s_iloc);
  Py_CLEAR(clear_module_state->__pyx_n_s_import);
  Py_CLEAR(clear_module_state->__pyx_n_s_initializing);
  Py_CLEAR(clear_module_state->__pyx_n_s_int16);
  Py_CLEAR(clear_module_state->__pyx_n_s_int32);
  Py_CLEAR(clear_module_state->__pyx_n_s_int64);
  Py_CLEAR(clear_module_state->__pyx_n_s_int8);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_datetime64_any_dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_datetime64_ns_dtype);
  Py_CLEAR(clear_module_state->__pyx_n_s_isalpha);
  Py_CLEAR(clear_module_state->__pyx_n_s_isin);
  Py_CLEAR(clear_module_state->__pyx_n_s_isna);
  Py_CLEAR(clear_module_state->__pyx_n_s_items);
  Py_CLEAR(clear_module_state->__pyx_n_s_keys);
  Py_CLEAR(clear_module_state->__pyx_n_s_left);
  Py_CLEAR(clear_module_state->__pyx_kp_s_length_of_column_labels_must_be);
  Py_CLEAR(clear_module_state->__pyx_n_s_libs);
  Py_CLEAR(clear_module_state->__pyx_n_s_lo);
  Py_CLEAR(clear_module_state->__pyx_n_s_loc);
  Py_CLEAR(clear_module_state->__pyx_n_s_main);
  Py_CLEAR(clear_module_state->__pyx_kp_s_measure_for_variable_s_must_be_e);
  Py_CLEAR(clear_module_state->__pyx_n_s_min);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_hi_and_lo_values);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_hi_and_lo_values_2);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_max_1_discrete_nu);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_max_1_range_value);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_max_3_discrete_nu);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_max_3_string_valu);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_string_values_len);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_values_in_diction);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_ranges_values_must_be_bo);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_user_values_not_allowed);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_user_values_supports_val);
  Py_CLEAR(clear_module_state->__pyx_kp_s_missing_user_values_values_in_di);
  Py_CLEAR(clear_module_state->__pyx_n_s_name);
  Py_CLEAR(clear_module_state->__pyx_n_s_name_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_nan);
  Py_CLEAR(clear_module_state->__pyx_n_s_nominal);
  Py_CLEAR(clear_module_state->__pyx_n_s_np);
  Py_CLEAR(clear_module_state->__pyx_n_s_nt);
  Py_CLEAR(clear_module_state->__pyx_kp_s_numeric_missing_ranges_value_giv);
  Py_CLEAR(clear_module_state->__pyx_n_s_numpy);
  Py_CLEAR(clear_module_state->__pyx_n_s_object);
  Py_CLEAR(clear_module_state->__pyx_n_s_ordinal);
  Py_CLEAR(clear_module_state->__pyx_n_s_os);
  Py_CLEAR(clear_module_state->__pyx_n_s_pandas);
  Py_CLEAR(clear_module_state->__pyx_n_s_pandas_api_types);
  Py_CLEAR(clear_module_state->__pyx_n_s_path);
  Py_CLEAR(clear_module_state->__pyx_kp_s_path_must_be_either_str_or_bytes);
  Py_CLEAR(clear_module_state->__pyx_n_s_pd);
  Py_CLEAR(clear_module_state->__pyx_n_s_range);
  Py_CLEAR(clear_module_state->__pyx_n_s_readstat_parser);
  Py_CLEAR(clear_module_state->__pyx_n_s_replace);
  Py_CLEAR(clear_module_state->__pyx_n_s_reset_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_right);
  Py_CLEAR(clear_module_state->__pyx_n_s_round);
  Py_CLEAR(clear_module_state->__pyx_n_s_scale);
  Py_CLEAR(clear_module_state->__pyx_n_s_spec);
  Py_CLEAR(clear_module_state->__pyx_n_s_startswith);
  Py_CLEAR(clear_module_state->__pyx_n_s_string);
  Py_CLEAR(clear_module_state->__pyx_n_s_surrogateescape);
  Py_CLEAR(clear_module_state->__pyx_n_s_sys);
  Py_CLEAR(clear_module_state->__pyx_n_s_test);
  Py_CLEAR(clear_module_state->__pyx_n_s_time);
  Py_CLEAR(clear_module_state->__pyx_n_s_timegm);
  Py_CLEAR(clear_module_state->__pyx_n_s_timestamps);
  Py_CLEAR(clear_module_state->__pyx_n_s_timetuple);
  Py_CLEAR(clear_module_state->__pyx_n_s_timezone);
  Py_CLEAR(clear_module_state->__pyx_n_s_timezone_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_tolist);
  Py_CLEAR(clear_module_state->__pyx_n_s_total_seconds);
  Py_CLEAR(clear_module_state->__pyx_n_s_tslibs);
  Py_CLEAR(clear_module_state->__pyx_n_s_tzinfo);
  Py_CLEAR(clear_module_state->__pyx_n_s_uint16);
  Py_CLEAR(clear_module_state->__pyx_n_s_uint32);
  Py_CLEAR(clear_module_state->__pyx_n_s_uint64);
  Py_CLEAR(clear_module_state->__pyx_n_s_uint8);
  Py_CLEAR(clear_module_state->__pyx_n_s_union);
  Py_CLEAR(clear_module_state->__pyx_n_s_unknown);
  Py_CLEAR(clear_module_state->__pyx_kp_s_unknown_file_format);
  Py_CLEAR(clear_module_state->__pyx_n_s_upper);
  Py_CLEAR(clear_module_state->__pyx_n_s_utc);
  Py_CLEAR(clear_module_state->__pyx_kp_s_utf_8);
  Py_CLEAR(clear_module_state->__pyx_n_s_values);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_name_s_contains_a_space);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_name_s_is_of_type_s_and);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_name_s_starts_with_an_i);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_value_labels_type_of_La);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_value_labels_type_of_Va);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_value_labels_type_of_Va_2);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_value_labels_type_of_Va_3);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_value_labels_type_of_Va_4);
  Py_CLEAR(clear_module_state->__pyx_kp_s_variable_value_labels_value_for);
  Py_CLEAR(clear_module_state->__pyx_n_s_warn);
  Py_CLEAR(clear_module_state->__pyx_n_s_warnings);
  Py_CLEAR(clear_module_state->__pyx_n_s_x);
  Py_CLEAR(clear_module_state->__pyx_n_s_zip);
  Py_CLEAR(clear_module_state->__pyx_float_1e6);
  Py_CLEAR(clear_module_state->__pyx_float_1e9);
  Py_CLEAR(clear_module_state->__pyx_int_0);
  Py_CLEAR(clear_module_state->__pyx_int_1);
  Py_CLEAR(clear_module_state->__pyx_int_65);
  Py_CLEAR(clear_module_state->__pyx_int_97);
  Py_CLEAR(clear_module_state->__pyx_int_1970);
  Py_CLEAR(clear_module_state->__pyx_int_neg_9223056417655);
  Py_CLEAR(clear_module_state->__pyx_slice_);
  Py_CLEAR(clear_module_state->__pyx_tuple__3);
  Py_CLEAR(clear_module_state->__pyx_tuple__6);
  Py_CLEAR(clear_module_state->__pyx_tuple__7);
  Py_CLEAR(clear_module_state->__pyx_tuple__8);
  Py_CLEAR(clear_module_state->__pyx_tuple__9);
  Py_CLEAR(clear_module_state->__pyx_tuple__10);
  Py_CLEAR(clear_module_state->__pyx_tuple__11);
  Py_CLEAR(clear_module_state->__pyx_tuple__12);
  Py_CLEAR(clear_module_state->__pyx_tuple__13);
  Py_CLEAR(clear_module_state->__pyx_tuple__14);
  Py_CLEAR(clear_module_state->__pyx_tuple__15);
  Py_CLEAR(clear_module_state->__pyx_tuple__16);
  return 0;
}
#endif
/* #### Code section: module_state_traverse ### */
#if CYTHON_USE_MODULE_STATE
static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) {
  __pyx_mstate *traverse_module_state = __pyx_mstate(m);
  if (!traverse_module_state) return 0;
  Py_VISIT(traverse_module_state->__pyx_d);
  Py_VISIT(traverse_module_state->__pyx_b);
  Py_VISIT(traverse_module_state->__pyx_cython_runtime);
  Py_VISIT(traverse_module_state->__pyx_empty_tuple);
  Py_VISIT(traverse_module_state->__pyx_empty_bytes);
  Py_VISIT(traverse_module_state->__pyx_empty_unicode);
  #ifdef __Pyx_CyFunction_USED
  Py_VISIT(traverse_module_state->__pyx_CyFunctionType);
  #endif
  #ifdef __Pyx_FusedFunction_USED
  Py_VISIT(traverse_module_state->__pyx_FusedFunctionType);
  #endif
  Py_VISIT(traverse_module_state->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container);
  Py_VISIT(traverse_module_state->__pyx_n_s_CategoricalDtype);
  Py_VISIT(traverse_module_state->__pyx_kp_s_Column_labels_must_be_strings);
  Py_VISIT(traverse_module_state->__pyx_n_s_DataFrame);
  Py_VISIT(traverse_module_state->__pyx_n_s_Float32Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_Float64Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_Int16Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_Int32Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_Int64Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_Int8Dtype);
  Py_VISIT(traverse_module_state->__pyx_kp_s_M8_ns);
  Py_VISIT(traverse_module_state->__pyx_kp_s_Non_unique_column_names_detected);
  Py_VISIT(traverse_module_state->__pyx_n_s_PyreadstatError);
  Py_VISIT(traverse_module_state->__pyx_n_s_ReadstatError);
  Py_VISIT(traverse_module_state->__pyx_n_s_Timestamp);
  Py_VISIT(traverse_module_state->__pyx_n_s_UInt16Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_UInt32Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_UInt64Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_UInt8Dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_UnicodeError);
  Py_VISIT(traverse_module_state->__pyx_kp_s_Unknown_data_format_to_insert);
  Py_VISIT(traverse_module_state->__pyx_kp_s_Unknown_pywriter_variable_format);
  Py_VISIT(traverse_module_state->__pyx_n_s__17);
  Py_VISIT(traverse_module_state->__pyx_n_s__18);
  Py_VISIT(traverse_module_state->__pyx_kp_s__2);
  Py_VISIT(traverse_module_state->__pyx_n_s__4);
  Py_VISIT(traverse_module_state->__pyx_kp_u__5);
  Py_VISIT(traverse_module_state->__pyx_kp_s_alignment_for_variable_s_must_be);
  Py_VISIT(traverse_module_state->__pyx_n_s_any);
  Py_VISIT(traverse_module_state->__pyx_n_s_asarray);
  Py_VISIT(traverse_module_state->__pyx_n_s_asm8);
  Py_VISIT(traverse_module_state->__pyx_n_s_astype);
  Py_VISIT(traverse_module_state->__pyx_n_s_calendar);
  Py_VISIT(traverse_module_state->__pyx_n_s_center);
  Py_VISIT(traverse_module_state->__pyx_kp_s_character_missing_ranges_value_g);
  Py_VISIT(traverse_module_state->__pyx_n_s_chr);
  Py_VISIT(traverse_module_state->__pyx_n_s_class_getitem);
  Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback);
  Py_VISIT(traverse_module_state->__pyx_kp_s_column_labels_must_be_either_lis);
  Py_VISIT(traverse_module_state->__pyx_n_s_columns);
  Py_VISIT(traverse_module_state->__pyx_n_s_combine);
  Py_VISIT(traverse_module_state->__pyx_n_s_copy);
  Py_VISIT(traverse_module_state->__pyx_n_s_core);
  Py_VISIT(traverse_module_state->__pyx_n_s_date);
  Py_VISIT(traverse_module_state->__pyx_n_s_datetime);
  Py_VISIT(traverse_module_state->__pyx_n_s_datetime64);
  Py_VISIT(traverse_module_state->__pyx_kp_s_datetime64_ms);
  Py_VISIT(traverse_module_state->__pyx_kp_s_datetime64_ns);
  Py_VISIT(traverse_module_state->__pyx_kp_s_datetime64_us);
  Py_VISIT(traverse_module_state->__pyx_kp_s_datetime64_us_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_days);
  Py_VISIT(traverse_module_state->__pyx_kp_s_dictionaries_in_missing_ranges_m);
  Py_VISIT(traverse_module_state->__pyx_n_s_drop);
  Py_VISIT(traverse_module_state->__pyx_n_s_dropna);
  Py_VISIT(traverse_module_state->__pyx_n_s_dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_dtypes);
  Py_VISIT(traverse_module_state->__pyx_n_s_encode);
  Py_VISIT(traverse_module_state->__pyx_n_s_enumerate);
  Py_VISIT(traverse_module_state->__pyx_n_s_expanduser);
  Py_VISIT(traverse_module_state->__pyx_kp_s_file_path_could_not_be_encoded_w);
  Py_VISIT(traverse_module_state->__pyx_kp_s_first_argument_must_be_a_pandas);
  Py_VISIT(traverse_module_state->__pyx_n_s_float);
  Py_VISIT(traverse_module_state->__pyx_n_s_float32);
  Py_VISIT(traverse_module_state->__pyx_n_s_float64);
  Py_VISIT(traverse_module_state->__pyx_n_s_fsdecode);
  Py_VISIT(traverse_module_state->__pyx_n_s_fsencode);
  Py_VISIT(traverse_module_state->__pyx_n_s_get);
  Py_VISIT(traverse_module_state->__pyx_n_s_getfilesystemencoding);
  Py_VISIT(traverse_module_state->__pyx_n_s_hi);
  Py_VISIT(traverse_module_state->__pyx_n_s_iloc);
  Py_VISIT(traverse_module_state->__pyx_n_s_import);
  Py_VISIT(traverse_module_state->__pyx_n_s_initializing);
  Py_VISIT(traverse_module_state->__pyx_n_s_int16);
  Py_VISIT(traverse_module_state->__pyx_n_s_int32);
  Py_VISIT(traverse_module_state->__pyx_n_s_int64);
  Py_VISIT(traverse_module_state->__pyx_n_s_int8);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_datetime64_any_dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_datetime64_ns_dtype);
  Py_VISIT(traverse_module_state->__pyx_n_s_isalpha);
  Py_VISIT(traverse_module_state->__pyx_n_s_isin);
  Py_VISIT(traverse_module_state->__pyx_n_s_isna);
  Py_VISIT(traverse_module_state->__pyx_n_s_items);
  Py_VISIT(traverse_module_state->__pyx_n_s_keys);
  Py_VISIT(traverse_module_state->__pyx_n_s_left);
  Py_VISIT(traverse_module_state->__pyx_kp_s_length_of_column_labels_must_be);
  Py_VISIT(traverse_module_state->__pyx_n_s_libs);
  Py_VISIT(traverse_module_state->__pyx_n_s_lo);
  Py_VISIT(traverse_module_state->__pyx_n_s_loc);
  Py_VISIT(traverse_module_state->__pyx_n_s_main);
  Py_VISIT(traverse_module_state->__pyx_kp_s_measure_for_variable_s_must_be_e);
  Py_VISIT(traverse_module_state->__pyx_n_s_min);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_hi_and_lo_values);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_hi_and_lo_values_2);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_max_1_discrete_nu);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_max_1_range_value);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_max_3_discrete_nu);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_max_3_string_valu);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_string_values_len);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_values_in_diction);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_ranges_values_must_be_bo);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_user_values_not_allowed);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_user_values_supports_val);
  Py_VISIT(traverse_module_state->__pyx_kp_s_missing_user_values_values_in_di);
  Py_VISIT(traverse_module_state->__pyx_n_s_name);
  Py_VISIT(traverse_module_state->__pyx_n_s_name_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_nan);
  Py_VISIT(traverse_module_state->__pyx_n_s_nominal);
  Py_VISIT(traverse_module_state->__pyx_n_s_np);
  Py_VISIT(traverse_module_state->__pyx_n_s_nt);
  Py_VISIT(traverse_module_state->__pyx_kp_s_numeric_missing_ranges_value_giv);
  Py_VISIT(traverse_module_state->__pyx_n_s_numpy);
  Py_VISIT(traverse_module_state->__pyx_n_s_object);
  Py_VISIT(traverse_module_state->__pyx_n_s_ordinal);
  Py_VISIT(traverse_module_state->__pyx_n_s_os);
  Py_VISIT(traverse_module_state->__pyx_n_s_pandas);
  Py_VISIT(traverse_module_state->__pyx_n_s_pandas_api_types);
  Py_VISIT(traverse_module_state->__pyx_n_s_path);
  Py_VISIT(traverse_module_state->__pyx_kp_s_path_must_be_either_str_or_bytes);
  Py_VISIT(traverse_module_state->__pyx_n_s_pd);
  Py_VISIT(traverse_module_state->__pyx_n_s_range);
  Py_VISIT(traverse_module_state->__pyx_n_s_readstat_parser);
  Py_VISIT(traverse_module_state->__pyx_n_s_replace);
  Py_VISIT(traverse_module_state->__pyx_n_s_reset_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_right);
  Py_VISIT(traverse_module_state->__pyx_n_s_round);
  Py_VISIT(traverse_module_state->__pyx_n_s_scale);
  Py_VISIT(traverse_module_state->__pyx_n_s_spec);
  Py_VISIT(traverse_module_state->__pyx_n_s_startswith);
  Py_VISIT(traverse_module_state->__pyx_n_s_string);
  Py_VISIT(traverse_module_state->__pyx_n_s_surrogateescape);
  Py_VISIT(traverse_module_state->__pyx_n_s_sys);
  Py_VISIT(traverse_module_state->__pyx_n_s_test);
  Py_VISIT(traverse_module_state->__pyx_n_s_time);
  Py_VISIT(traverse_module_state->__pyx_n_s_timegm);
  Py_VISIT(traverse_module_state->__pyx_n_s_timestamps);
  Py_VISIT(traverse_module_state->__pyx_n_s_timetuple);
  Py_VISIT(traverse_module_state->__pyx_n_s_timezone);
  Py_VISIT(traverse_module_state->__pyx_n_s_timezone_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_tolist);
  Py_VISIT(traverse_module_state->__pyx_n_s_total_seconds);
  Py_VISIT(traverse_module_state->__pyx_n_s_tslibs);
  Py_VISIT(traverse_module_state->__pyx_n_s_tzinfo);
  Py_VISIT(traverse_module_state->__pyx_n_s_uint16);
  Py_VISIT(traverse_module_state->__pyx_n_s_uint32);
  Py_VISIT(traverse_module_state->__pyx_n_s_uint64);
  Py_VISIT(traverse_module_state->__pyx_n_s_uint8);
  Py_VISIT(traverse_module_state->__pyx_n_s_union);
  Py_VISIT(traverse_module_state->__pyx_n_s_unknown);
  Py_VISIT(traverse_module_state->__pyx_kp_s_unknown_file_format);
  Py_VISIT(traverse_module_state->__pyx_n_s_upper);
  Py_VISIT(traverse_module_state->__pyx_n_s_utc);
  Py_VISIT(traverse_module_state->__pyx_kp_s_utf_8);
  Py_VISIT(traverse_module_state->__pyx_n_s_values);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_name_s_contains_a_space);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_name_s_is_of_type_s_and);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_name_s_starts_with_an_i);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_value_labels_type_of_La);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_value_labels_type_of_Va);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_value_labels_type_of_Va_2);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_value_labels_type_of_Va_3);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_value_labels_type_of_Va_4);
  Py_VISIT(traverse_module_state->__pyx_kp_s_variable_value_labels_value_for);
  Py_VISIT(traverse_module_state->__pyx_n_s_warn);
  Py_VISIT(traverse_module_state->__pyx_n_s_warnings);
  Py_VISIT(traverse_module_state->__pyx_n_s_x);
  Py_VISIT(traverse_module_state->__pyx_n_s_zip);
  Py_VISIT(traverse_module_state->__pyx_float_1e6);
  Py_VISIT(traverse_module_state->__pyx_float_1e9);
  Py_VISIT(traverse_module_state->__pyx_int_0);
  Py_VISIT(traverse_module_state->__pyx_int_1);
  Py_VISIT(traverse_module_state->__pyx_int_65);
  Py_VISIT(traverse_module_state->__pyx_int_97);
  Py_VISIT(traverse_module_state->__pyx_int_1970);
  Py_VISIT(traverse_module_state->__pyx_int_neg_9223056417655);
  Py_VISIT(traverse_module_state->__pyx_slice_);
  Py_VISIT(traverse_module_state->__pyx_tuple__3);
  Py_VISIT(traverse_module_state->__pyx_tuple__6);
  Py_VISIT(traverse_module_state->__pyx_tuple__7);
  Py_VISIT(traverse_module_state->__pyx_tuple__8);
  Py_VISIT(traverse_module_state->__pyx_tuple__9);
  Py_VISIT(traverse_module_state->__pyx_tuple__10);
  Py_VISIT(traverse_module_state->__pyx_tuple__11);
  Py_VISIT(traverse_module_state->__pyx_tuple__12);
  Py_VISIT(traverse_module_state->__pyx_tuple__13);
  Py_VISIT(traverse_module_state->__pyx_tuple__14);
  Py_VISIT(traverse_module_state->__pyx_tuple__15);
  Py_VISIT(traverse_module_state->__pyx_tuple__16);
  return 0;
}
#endif
/* #### Code section: module_state_defines ### */
#define __pyx_d __pyx_mstate_global->__pyx_d
#define __pyx_b __pyx_mstate_global->__pyx_b
#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime
#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple
#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes
#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode
#ifdef __Pyx_CyFunction_USED
#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType
#endif
#ifdef __Pyx_FusedFunction_USED
#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType
#endif
#ifdef __Pyx_Generator_USED
#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType
#endif
#ifdef __Pyx_IterableCoroutine_USED
#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType
#endif
#ifdef __Pyx_Coroutine_USED
#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType
#endif
#ifdef __Pyx_Coroutine_USED
#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_10pyreadstat_16_readstat_parser_data_container __pyx_mstate_global->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_n_s_CategoricalDtype __pyx_mstate_global->__pyx_n_s_CategoricalDtype
#define __pyx_kp_s_Column_labels_must_be_strings __pyx_mstate_global->__pyx_kp_s_Column_labels_must_be_strings
#define __pyx_n_s_DataFrame __pyx_mstate_global->__pyx_n_s_DataFrame
#define __pyx_n_s_Float32Dtype __pyx_mstate_global->__pyx_n_s_Float32Dtype
#define __pyx_n_s_Float64Dtype __pyx_mstate_global->__pyx_n_s_Float64Dtype
#define __pyx_n_s_Int16Dtype __pyx_mstate_global->__pyx_n_s_Int16Dtype
#define __pyx_n_s_Int32Dtype __pyx_mstate_global->__pyx_n_s_Int32Dtype
#define __pyx_n_s_Int64Dtype __pyx_mstate_global->__pyx_n_s_Int64Dtype
#define __pyx_n_s_Int8Dtype __pyx_mstate_global->__pyx_n_s_Int8Dtype
#define __pyx_kp_s_M8_ns __pyx_mstate_global->__pyx_kp_s_M8_ns
#define __pyx_kp_s_Non_unique_column_names_detected __pyx_mstate_global->__pyx_kp_s_Non_unique_column_names_detected
#define __pyx_n_s_PyreadstatError __pyx_mstate_global->__pyx_n_s_PyreadstatError
#define __pyx_n_s_ReadstatError __pyx_mstate_global->__pyx_n_s_ReadstatError
#define __pyx_n_s_Timestamp __pyx_mstate_global->__pyx_n_s_Timestamp
#define __pyx_n_s_UInt16Dtype __pyx_mstate_global->__pyx_n_s_UInt16Dtype
#define __pyx_n_s_UInt32Dtype __pyx_mstate_global->__pyx_n_s_UInt32Dtype
#define __pyx_n_s_UInt64Dtype __pyx_mstate_global->__pyx_n_s_UInt64Dtype
#define __pyx_n_s_UInt8Dtype __pyx_mstate_global->__pyx_n_s_UInt8Dtype
#define __pyx_n_s_UnicodeError __pyx_mstate_global->__pyx_n_s_UnicodeError
#define __pyx_kp_s_Unknown_data_format_to_insert __pyx_mstate_global->__pyx_kp_s_Unknown_data_format_to_insert
#define __pyx_kp_s_Unknown_pywriter_variable_format __pyx_mstate_global->__pyx_kp_s_Unknown_pywriter_variable_format
#define __pyx_n_s__17 __pyx_mstate_global->__pyx_n_s__17
#define __pyx_n_s__18 __pyx_mstate_global->__pyx_n_s__18
#define __pyx_kp_s__2 __pyx_mstate_global->__pyx_kp_s__2
#define __pyx_n_s__4 __pyx_mstate_global->__pyx_n_s__4
#define __pyx_kp_u__5 __pyx_mstate_global->__pyx_kp_u__5
#define __pyx_kp_s_alignment_for_variable_s_must_be __pyx_mstate_global->__pyx_kp_s_alignment_for_variable_s_must_be
#define __pyx_n_s_any __pyx_mstate_global->__pyx_n_s_any
#define __pyx_n_s_asarray __pyx_mstate_global->__pyx_n_s_asarray
#define __pyx_n_s_asm8 __pyx_mstate_global->__pyx_n_s_asm8
#define __pyx_n_s_astype __pyx_mstate_global->__pyx_n_s_astype
#define __pyx_n_s_calendar __pyx_mstate_global->__pyx_n_s_calendar
#define __pyx_n_s_center __pyx_mstate_global->__pyx_n_s_center
#define __pyx_kp_s_character_missing_ranges_value_g __pyx_mstate_global->__pyx_kp_s_character_missing_ranges_value_g
#define __pyx_n_s_chr __pyx_mstate_global->__pyx_n_s_chr
#define __pyx_n_s_class_getitem __pyx_mstate_global->__pyx_n_s_class_getitem
#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback
#define __pyx_kp_s_column_labels_must_be_either_lis __pyx_mstate_global->__pyx_kp_s_column_labels_must_be_either_lis
#define __pyx_n_s_columns __pyx_mstate_global->__pyx_n_s_columns
#define __pyx_n_s_combine __pyx_mstate_global->__pyx_n_s_combine
#define __pyx_n_s_copy __pyx_mstate_global->__pyx_n_s_copy
#define __pyx_n_s_core __pyx_mstate_global->__pyx_n_s_core
#define __pyx_n_s_date __pyx_mstate_global->__pyx_n_s_date
#define __pyx_n_s_datetime __pyx_mstate_global->__pyx_n_s_datetime
#define __pyx_n_s_datetime64 __pyx_mstate_global->__pyx_n_s_datetime64
#define __pyx_kp_s_datetime64_ms __pyx_mstate_global->__pyx_kp_s_datetime64_ms
#define __pyx_kp_s_datetime64_ns __pyx_mstate_global->__pyx_kp_s_datetime64_ns
#define __pyx_kp_s_datetime64_us __pyx_mstate_global->__pyx_kp_s_datetime64_us
#define __pyx_kp_s_datetime64_us_2 __pyx_mstate_global->__pyx_kp_s_datetime64_us_2
#define __pyx_n_s_days __pyx_mstate_global->__pyx_n_s_days
#define __pyx_kp_s_dictionaries_in_missing_ranges_m __pyx_mstate_global->__pyx_kp_s_dictionaries_in_missing_ranges_m
#define __pyx_n_s_drop __pyx_mstate_global->__pyx_n_s_drop
#define __pyx_n_s_dropna __pyx_mstate_global->__pyx_n_s_dropna
#define __pyx_n_s_dtype __pyx_mstate_global->__pyx_n_s_dtype
#define __pyx_n_s_dtypes __pyx_mstate_global->__pyx_n_s_dtypes
#define __pyx_n_s_encode __pyx_mstate_global->__pyx_n_s_encode
#define __pyx_n_s_enumerate __pyx_mstate_global->__pyx_n_s_enumerate
#define __pyx_n_s_expanduser __pyx_mstate_global->__pyx_n_s_expanduser
#define __pyx_kp_s_file_path_could_not_be_encoded_w __pyx_mstate_global->__pyx_kp_s_file_path_could_not_be_encoded_w
#define __pyx_kp_s_first_argument_must_be_a_pandas __pyx_mstate_global->__pyx_kp_s_first_argument_must_be_a_pandas
#define __pyx_n_s_float __pyx_mstate_global->__pyx_n_s_float
#define __pyx_n_s_float32 __pyx_mstate_global->__pyx_n_s_float32
#define __pyx_n_s_float64 __pyx_mstate_global->__pyx_n_s_float64
#define __pyx_n_s_fsdecode __pyx_mstate_global->__pyx_n_s_fsdecode
#define __pyx_n_s_fsencode __pyx_mstate_global->__pyx_n_s_fsencode
#define __pyx_n_s_get __pyx_mstate_global->__pyx_n_s_get
#define __pyx_n_s_getfilesystemencoding __pyx_mstate_global->__pyx_n_s_getfilesystemencoding
#define __pyx_n_s_hi __pyx_mstate_global->__pyx_n_s_hi
#define __pyx_n_s_iloc __pyx_mstate_global->__pyx_n_s_iloc
#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import
#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing
#define __pyx_n_s_int16 __pyx_mstate_global->__pyx_n_s_int16
#define __pyx_n_s_int32 __pyx_mstate_global->__pyx_n_s_int32
#define __pyx_n_s_int64 __pyx_mstate_global->__pyx_n_s_int64
#define __pyx_n_s_int8 __pyx_mstate_global->__pyx_n_s_int8
#define __pyx_n_s_is_datetime64_any_dtype __pyx_mstate_global->__pyx_n_s_is_datetime64_any_dtype
#define __pyx_n_s_is_datetime64_ns_dtype __pyx_mstate_global->__pyx_n_s_is_datetime64_ns_dtype
#define __pyx_n_s_isalpha __pyx_mstate_global->__pyx_n_s_isalpha
#define __pyx_n_s_isin __pyx_mstate_global->__pyx_n_s_isin
#define __pyx_n_s_isna __pyx_mstate_global->__pyx_n_s_isna
#define __pyx_n_s_items __pyx_mstate_global->__pyx_n_s_items
#define __pyx_n_s_keys __pyx_mstate_global->__pyx_n_s_keys
#define __pyx_n_s_left __pyx_mstate_global->__pyx_n_s_left
#define __pyx_kp_s_length_of_column_labels_must_be __pyx_mstate_global->__pyx_kp_s_length_of_column_labels_must_be
#define __pyx_n_s_libs __pyx_mstate_global->__pyx_n_s_libs
#define __pyx_n_s_lo __pyx_mstate_global->__pyx_n_s_lo
#define __pyx_n_s_loc __pyx_mstate_global->__pyx_n_s_loc
#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main
#define __pyx_kp_s_measure_for_variable_s_must_be_e __pyx_mstate_global->__pyx_kp_s_measure_for_variable_s_must_be_e
#define __pyx_n_s_min __pyx_mstate_global->__pyx_n_s_min
#define __pyx_kp_s_missing_ranges_hi_and_lo_values __pyx_mstate_global->__pyx_kp_s_missing_ranges_hi_and_lo_values
#define __pyx_kp_s_missing_ranges_hi_and_lo_values_2 __pyx_mstate_global->__pyx_kp_s_missing_ranges_hi_and_lo_values_2
#define __pyx_kp_s_missing_ranges_max_1_discrete_nu __pyx_mstate_global->__pyx_kp_s_missing_ranges_max_1_discrete_nu
#define __pyx_kp_s_missing_ranges_max_1_range_value __pyx_mstate_global->__pyx_kp_s_missing_ranges_max_1_range_value
#define __pyx_kp_s_missing_ranges_max_3_discrete_nu __pyx_mstate_global->__pyx_kp_s_missing_ranges_max_3_discrete_nu
#define __pyx_kp_s_missing_ranges_max_3_string_valu __pyx_mstate_global->__pyx_kp_s_missing_ranges_max_3_string_valu
#define __pyx_kp_s_missing_ranges_string_values_len __pyx_mstate_global->__pyx_kp_s_missing_ranges_string_values_len
#define __pyx_kp_s_missing_ranges_values_in_diction __pyx_mstate_global->__pyx_kp_s_missing_ranges_values_in_diction
#define __pyx_kp_s_missing_ranges_values_must_be_bo __pyx_mstate_global->__pyx_kp_s_missing_ranges_values_must_be_bo
#define __pyx_kp_s_missing_user_values_not_allowed __pyx_mstate_global->__pyx_kp_s_missing_user_values_not_allowed
#define __pyx_kp_s_missing_user_values_supports_val __pyx_mstate_global->__pyx_kp_s_missing_user_values_supports_val
#define __pyx_kp_s_missing_user_values_values_in_di __pyx_mstate_global->__pyx_kp_s_missing_user_values_values_in_di
#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name
#define __pyx_n_s_name_2 __pyx_mstate_global->__pyx_n_s_name_2
#define __pyx_n_s_nan __pyx_mstate_global->__pyx_n_s_nan
#define __pyx_n_s_nominal __pyx_mstate_global->__pyx_n_s_nominal
#define __pyx_n_s_np __pyx_mstate_global->__pyx_n_s_np
#define __pyx_n_s_nt __pyx_mstate_global->__pyx_n_s_nt
#define __pyx_kp_s_numeric_missing_ranges_value_giv __pyx_mstate_global->__pyx_kp_s_numeric_missing_ranges_value_giv
#define __pyx_n_s_numpy __pyx_mstate_global->__pyx_n_s_numpy
#define __pyx_n_s_object __pyx_mstate_global->__pyx_n_s_object
#define __pyx_n_s_ordinal __pyx_mstate_global->__pyx_n_s_ordinal
#define __pyx_n_s_os __pyx_mstate_global->__pyx_n_s_os
#define __pyx_n_s_pandas __pyx_mstate_global->__pyx_n_s_pandas
#define __pyx_n_s_pandas_api_types __pyx_mstate_global->__pyx_n_s_pandas_api_types
#define __pyx_n_s_path __pyx_mstate_global->__pyx_n_s_path
#define __pyx_kp_s_path_must_be_either_str_or_bytes __pyx_mstate_global->__pyx_kp_s_path_must_be_either_str_or_bytes
#define __pyx_n_s_pd __pyx_mstate_global->__pyx_n_s_pd
#define __pyx_n_s_range __pyx_mstate_global->__pyx_n_s_range
#define __pyx_n_s_readstat_parser __pyx_mstate_global->__pyx_n_s_readstat_parser
#define __pyx_n_s_replace __pyx_mstate_global->__pyx_n_s_replace
#define __pyx_n_s_reset_index __pyx_mstate_global->__pyx_n_s_reset_index
#define __pyx_n_s_right __pyx_mstate_global->__pyx_n_s_right
#define __pyx_n_s_round __pyx_mstate_global->__pyx_n_s_round
#define __pyx_n_s_scale __pyx_mstate_global->__pyx_n_s_scale
#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec
#define __pyx_n_s_startswith __pyx_mstate_global->__pyx_n_s_startswith
#define __pyx_n_s_string __pyx_mstate_global->__pyx_n_s_string
#define __pyx_n_s_surrogateescape __pyx_mstate_global->__pyx_n_s_surrogateescape
#define __pyx_n_s_sys __pyx_mstate_global->__pyx_n_s_sys
#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test
#define __pyx_n_s_time __pyx_mstate_global->__pyx_n_s_time
#define __pyx_n_s_timegm __pyx_mstate_global->__pyx_n_s_timegm
#define __pyx_n_s_timestamps __pyx_mstate_global->__pyx_n_s_timestamps
#define __pyx_n_s_timetuple __pyx_mstate_global->__pyx_n_s_timetuple
#define __pyx_n_s_timezone __pyx_mstate_global->__pyx_n_s_timezone
#define __pyx_n_s_timezone_2 __pyx_mstate_global->__pyx_n_s_timezone_2
#define __pyx_n_s_tolist __pyx_mstate_global->__pyx_n_s_tolist
#define __pyx_n_s_total_seconds __pyx_mstate_global->__pyx_n_s_total_seconds
#define __pyx_n_s_tslibs __pyx_mstate_global->__pyx_n_s_tslibs
#define __pyx_n_s_tzinfo __pyx_mstate_global->__pyx_n_s_tzinfo
#define __pyx_n_s_uint16 __pyx_mstate_global->__pyx_n_s_uint16
#define __pyx_n_s_uint32 __pyx_mstate_global->__pyx_n_s_uint32
#define __pyx_n_s_uint64 __pyx_mstate_global->__pyx_n_s_uint64
#define __pyx_n_s_uint8 __pyx_mstate_global->__pyx_n_s_uint8
#define __pyx_n_s_union __pyx_mstate_global->__pyx_n_s_union
#define __pyx_n_s_unknown __pyx_mstate_global->__pyx_n_s_unknown
#define __pyx_kp_s_unknown_file_format __pyx_mstate_global->__pyx_kp_s_unknown_file_format
#define __pyx_n_s_upper __pyx_mstate_global->__pyx_n_s_upper
#define __pyx_n_s_utc __pyx_mstate_global->__pyx_n_s_utc
#define __pyx_kp_s_utf_8 __pyx_mstate_global->__pyx_kp_s_utf_8
#define __pyx_n_s_values __pyx_mstate_global->__pyx_n_s_values
#define __pyx_kp_s_variable_name_s_contains_a_space __pyx_mstate_global->__pyx_kp_s_variable_name_s_contains_a_space
#define __pyx_kp_s_variable_name_s_is_of_type_s_and __pyx_mstate_global->__pyx_kp_s_variable_name_s_is_of_type_s_and
#define __pyx_kp_s_variable_name_s_starts_with_an_i __pyx_mstate_global->__pyx_kp_s_variable_name_s_starts_with_an_i
#define __pyx_kp_s_variable_value_labels_type_of_La __pyx_mstate_global->__pyx_kp_s_variable_value_labels_type_of_La
#define __pyx_kp_s_variable_value_labels_type_of_Va __pyx_mstate_global->__pyx_kp_s_variable_value_labels_type_of_Va
#define __pyx_kp_s_variable_value_labels_type_of_Va_2 __pyx_mstate_global->__pyx_kp_s_variable_value_labels_type_of_Va_2
#define __pyx_kp_s_variable_value_labels_type_of_Va_3 __pyx_mstate_global->__pyx_kp_s_variable_value_labels_type_of_Va_3
#define __pyx_kp_s_variable_value_labels_type_of_Va_4 __pyx_mstate_global->__pyx_kp_s_variable_value_labels_type_of_Va_4
#define __pyx_kp_s_variable_value_labels_value_for __pyx_mstate_global->__pyx_kp_s_variable_value_labels_value_for
#define __pyx_n_s_warn __pyx_mstate_global->__pyx_n_s_warn
#define __pyx_n_s_warnings __pyx_mstate_global->__pyx_n_s_warnings
#define __pyx_n_s_x __pyx_mstate_global->__pyx_n_s_x
#define __pyx_n_s_zip __pyx_mstate_global->__pyx_n_s_zip
#define __pyx_float_1e6 __pyx_mstate_global->__pyx_float_1e6
#define __pyx_float_1e9 __pyx_mstate_global->__pyx_float_1e9
#define __pyx_int_0 __pyx_mstate_global->__pyx_int_0
#define __pyx_int_1 __pyx_mstate_global->__pyx_int_1
#define __pyx_int_65 __pyx_mstate_global->__pyx_int_65
#define __pyx_int_97 __pyx_mstate_global->__pyx_int_97
#define __pyx_int_1970 __pyx_mstate_global->__pyx_int_1970
#define __pyx_int_neg_9223056417655 __pyx_mstate_global->__pyx_int_neg_9223056417655
#define __pyx_slice_ __pyx_mstate_global->__pyx_slice_
#define __pyx_tuple__3 __pyx_mstate_global->__pyx_tuple__3
#define __pyx_tuple__6 __pyx_mstate_global->__pyx_tuple__6
#define __pyx_tuple__7 __pyx_mstate_global->__pyx_tuple__7
#define __pyx_tuple__8 __pyx_mstate_global->__pyx_tuple__8
#define __pyx_tuple__9 __pyx_mstate_global->__pyx_tuple__9
#define __pyx_tuple__10 __pyx_mstate_global->__pyx_tuple__10
#define __pyx_tuple__11 __pyx_mstate_global->__pyx_tuple__11
#define __pyx_tuple__12 __pyx_mstate_global->__pyx_tuple__12
#define __pyx_tuple__13 __pyx_mstate_global->__pyx_tuple__13
#define __pyx_tuple__14 __pyx_mstate_global->__pyx_tuple__14
#define __pyx_tuple__15 __pyx_mstate_global->__pyx_tuple__15
#define __pyx_tuple__16 __pyx_mstate_global->__pyx_tuple__16
/* #### Code section: module_code ### */

/* "pyreadstat/_readstat_writer.pyx":62
 * 
 * 
 * cdef double convert_datetimelike_to_number(dst_file_format file_format, pywriter_variable_type curtype, object curval) except *:             # <<<<<<<<<<<<<<
 *     """
 *     converts a datime like python/pandas object to a float
 */

static double __pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number(__pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_v_curtype, PyObject *__pyx_v_curval) {
  double __pyx_v_offset_days;
  double __pyx_v_tstamp;
  double __pyx_v_offset_secs;
  PyObject *__pyx_v_days = NULL;
  PyObject *__pyx_v_tdelta = NULL;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  double __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_datetimelike_to_number", 0);
  __Pyx_INCREF(__pyx_v_curval);

  /* "pyreadstat/_readstat_writer.pyx":69
 *     cdef double offset_days, tstamp
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         offset_days = spss_offset_days
 *         offset_secs = spss_offset_secs
 */
  switch (__pyx_v_file_format) {
    case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAV:
    case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR:

    /* "pyreadstat/_readstat_writer.pyx":70
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *         offset_days = spss_offset_days             # <<<<<<<<<<<<<<
 *         offset_secs = spss_offset_secs
 *     else:
 */
    __pyx_v_offset_days = __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_days;

    /* "pyreadstat/_readstat_writer.pyx":71
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *         offset_days = spss_offset_days
 *         offset_secs = spss_offset_secs             # <<<<<<<<<<<<<<
 *     else:
 *         offset_days = sas_offset_days
 */
    __pyx_v_offset_secs = __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_secs;

    /* "pyreadstat/_readstat_writer.pyx":69
 *     cdef double offset_days, tstamp
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         offset_days = spss_offset_days
 *         offset_secs = spss_offset_secs
 */
    break;
    default:

    /* "pyreadstat/_readstat_writer.pyx":73
 *         offset_secs = spss_offset_secs
 *     else:
 *         offset_days = sas_offset_days             # <<<<<<<<<<<<<<
 *         offset_secs = sas_offset_secs
 * 
 */
    __pyx_v_offset_days = __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_days;

    /* "pyreadstat/_readstat_writer.pyx":74
 *     else:
 *         offset_days = sas_offset_days
 *         offset_secs = sas_offset_secs             # <<<<<<<<<<<<<<
 * 
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS:
 */
    __pyx_v_offset_secs = __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_secs;
    break;
  }

  /* "pyreadstat/_readstat_writer.pyx":76
 *         offset_secs = sas_offset_secs
 * 
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS:             # <<<<<<<<<<<<<<
 *         # get timestamp in seconds
 *         if type(curval) == pd._libs.tslibs.timestamps.Timestamp:
 */
  switch (__pyx_v_curtype) {
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME:
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS:

    /* "pyreadstat/_readstat_writer.pyx":78
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS:
 *         # get timestamp in seconds
 *         if type(curval) == pd._libs.tslibs.timestamps.Timestamp:             # <<<<<<<<<<<<<<
 *             curval = curval.asm8
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_libs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_tslibs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_timestamps); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Timestamp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":79
 *         # get timestamp in seconds
 *         if type(curval) == pd._libs.tslibs.timestamps.Timestamp:
 *             curval = curval.asm8             # <<<<<<<<<<<<<<
 * 
 *         if type(curval) == datetime.datetime:
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_asm8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF_SET(__pyx_v_curval, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":78
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS:
 *         # get timestamp in seconds
 *         if type(curval) == pd._libs.tslibs.timestamps.Timestamp:             # <<<<<<<<<<<<<<
 *             curval = curval.asm8
 * 
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":81
 *             curval = curval.asm8
 * 
 *         if type(curval) == datetime.datetime:             # <<<<<<<<<<<<<<
 *             #tstamp = curval.replace(tzinfo=timezone.utc).timestamp() # works only in python 3
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 81, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":83
 *         if type(curval) == datetime.datetime:
 *             #tstamp = curval.replace(tzinfo=timezone.utc).timestamp() # works only in python 3
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())             # <<<<<<<<<<<<<<
 *         elif type(curval) == np.datetime64:
 *             if curval.dtype.name == "datetime64[ns]":
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_calendar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_timegm); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_replace); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_timezone); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_utc); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_tzinfo, __pyx_t_8) < 0) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_timetuple); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_9 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[1] = {__pyx_t_8, };
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 83, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __pyx_t_6 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_9 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_1};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 83, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 83, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_tstamp = __pyx_t_10;

      /* "pyreadstat/_readstat_writer.pyx":81
 *             curval = curval.asm8
 * 
 *         if type(curval) == datetime.datetime:             # <<<<<<<<<<<<<<
 *             #tstamp = curval.replace(tzinfo=timezone.utc).timestamp() # works only in python 3
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 */
      goto __pyx_L4;
    }

    /* "pyreadstat/_readstat_writer.pyx":84
 *             #tstamp = curval.replace(tzinfo=timezone.utc).timestamp() # works only in python 3
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 *         elif type(curval) == np.datetime64:             # <<<<<<<<<<<<<<
 *             if curval.dtype.name == "datetime64[ns]":
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":85
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 *         elif type(curval) == np.datetime64:
 *             if curval.dtype.name == "datetime64[ns]":             # <<<<<<<<<<<<<<
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 *             elif curval.dtype.name == "datetime64[us]":
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 85, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_kp_s_datetime64_ns, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 85, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_3) {

        /* "pyreadstat/_readstat_writer.pyx":86
 *         elif type(curval) == np.datetime64:
 *             if curval.dtype.name == "datetime64[ns]":
 *                 tstamp = round(<double>curval.astype(float)/1e9)             # <<<<<<<<<<<<<<
 *             elif curval.dtype.name == "datetime64[us]":
 *                 tstamp = round(<double>curval.astype(float)/1e6)
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_9 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_1, ((PyObject *)(&PyFloat_Type))};
          __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 86, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_tstamp = round((((double)__pyx_t_10) / 1e9));

        /* "pyreadstat/_readstat_writer.pyx":85
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 *         elif type(curval) == np.datetime64:
 *             if curval.dtype.name == "datetime64[ns]":             # <<<<<<<<<<<<<<
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 *             elif curval.dtype.name == "datetime64[us]":
 */
        goto __pyx_L5;
      }

      /* "pyreadstat/_readstat_writer.pyx":87
 *             if curval.dtype.name == "datetime64[ns]":
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 *             elif curval.dtype.name == "datetime64[us]":             # <<<<<<<<<<<<<<
 *                 tstamp = round(<double>curval.astype(float)/1e6)
 *             elif curval.dtype.name == "datetime64[ms]":
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_dtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s_datetime64_us, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 87, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_3) {

        /* "pyreadstat/_readstat_writer.pyx":88
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 *             elif curval.dtype.name == "datetime64[us]":
 *                 tstamp = round(<double>curval.astype(float)/1e6)             # <<<<<<<<<<<<<<
 *             elif curval.dtype.name == "datetime64[ms]":
 *                 tstamp = round(<double>curval.astype(float)/1e3)
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_astype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 88, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_1 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_9 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_1, ((PyObject *)(&PyFloat_Type))};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 88, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        }
        __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 88, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_tstamp = round((((double)__pyx_t_10) / 1e6));

        /* "pyreadstat/_readstat_writer.pyx":87
 *             if curval.dtype.name == "datetime64[ns]":
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 *             elif curval.dtype.name == "datetime64[us]":             # <<<<<<<<<<<<<<
 *                 tstamp = round(<double>curval.astype(float)/1e6)
 *             elif curval.dtype.name == "datetime64[ms]":
 */
        goto __pyx_L5;
      }

      /* "pyreadstat/_readstat_writer.pyx":89
 *             elif curval.dtype.name == "datetime64[us]":
 *                 tstamp = round(<double>curval.astype(float)/1e6)
 *             elif curval.dtype.name == "datetime64[ms]":             # <<<<<<<<<<<<<<
 *                 tstamp = round(<double>curval.astype(float)/1e3)
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_kp_s_datetime64_ms, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_3) {

        /* "pyreadstat/_readstat_writer.pyx":90
 *                 tstamp = round(<double>curval.astype(float)/1e6)
 *             elif curval.dtype.name == "datetime64[ms]":
 *                 tstamp = round(<double>curval.astype(float)/1e3)             # <<<<<<<<<<<<<<
 * 
 *         tstamp += offset_secs
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_9 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_1, ((PyObject *)(&PyFloat_Type))};
          __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 90, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 90, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_tstamp = round((((double)__pyx_t_10) / 1e3));

        /* "pyreadstat/_readstat_writer.pyx":89
 *             elif curval.dtype.name == "datetime64[us]":
 *                 tstamp = round(<double>curval.astype(float)/1e6)
 *             elif curval.dtype.name == "datetime64[ms]":             # <<<<<<<<<<<<<<
 *                 tstamp = round(<double>curval.astype(float)/1e3)
 * 
 */
      }
      __pyx_L5:;

      /* "pyreadstat/_readstat_writer.pyx":84
 *             #tstamp = curval.replace(tzinfo=timezone.utc).timestamp() # works only in python 3
 *             tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 *         elif type(curval) == np.datetime64:             # <<<<<<<<<<<<<<
 *             if curval.dtype.name == "datetime64[ns]":
 *                 tstamp = round(<double>curval.astype(float)/1e9)
 */
    }
    __pyx_L4:;

    /* "pyreadstat/_readstat_writer.pyx":92
 *                 tstamp = round(<double>curval.astype(float)/1e3)
 * 
 *         tstamp += offset_secs             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             # stata stores in milliseconds
 */
    __pyx_v_tstamp = (__pyx_v_tstamp + __pyx_v_offset_secs);

    /* "pyreadstat/_readstat_writer.pyx":93
 * 
 *         tstamp += offset_secs
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             # stata stores in milliseconds
 *             tstamp *= 1000
 */
    __pyx_t_3 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":95
 *         if file_format == FILE_FORMAT_DTA:
 *             # stata stores in milliseconds
 *             tstamp *= 1000             # <<<<<<<<<<<<<<
 * 
 *     elif curtype == PYWRITER_DATE:
 */
      __pyx_v_tstamp = (__pyx_v_tstamp * 1000.0);

      /* "pyreadstat/_readstat_writer.pyx":93
 * 
 *         tstamp += offset_secs
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             # stata stores in milliseconds
 *             tstamp *= 1000
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":76
 *         offset_secs = sas_offset_secs
 * 
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS:             # <<<<<<<<<<<<<<
 *         # get timestamp in seconds
 *         if type(curval) == pd._libs.tslibs.timestamps.Timestamp:
 */
    break;
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE:

    /* "pyreadstat/_readstat_writer.pyx":98
 * 
 *     elif curtype == PYWRITER_DATE:
 *         if type(curval) == datetime.date:             # <<<<<<<<<<<<<<
 *             days = curval - date_0
 *             tstamp = days.days
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_date); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 98, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 98, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":99
 *     elif curtype == PYWRITER_DATE:
 *         if type(curval) == datetime.date:
 *             days = curval - date_0             # <<<<<<<<<<<<<<
 *             tstamp = days.days
 *             tstamp += offset_days
 */
      __pyx_t_4 = PyNumber_Subtract(__pyx_v_curval, __pyx_v_10pyreadstat_16_readstat_writer_date_0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_v_days = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "pyreadstat/_readstat_writer.pyx":100
 *         if type(curval) == datetime.date:
 *             days = curval - date_0
 *             tstamp = days.days             # <<<<<<<<<<<<<<
 *             tstamp += offset_days
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_days, __pyx_n_s_days); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 100, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 100, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_tstamp = __pyx_t_10;

      /* "pyreadstat/_readstat_writer.pyx":101
 *             days = curval - date_0
 *             tstamp = days.days
 *             tstamp += offset_days             # <<<<<<<<<<<<<<
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *                 # spss stores in seconds
 */
      __pyx_v_tstamp = (__pyx_v_tstamp + __pyx_v_offset_days);

      /* "pyreadstat/_readstat_writer.pyx":102
 *             tstamp = days.days
 *             tstamp += offset_days
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *                 # spss stores in seconds
 *                 tstamp *= 86400
 */
      switch (__pyx_v_file_format) {
        case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAV:
        case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR:

        /* "pyreadstat/_readstat_writer.pyx":104
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *                 # spss stores in seconds
 *                 tstamp *= 86400             # <<<<<<<<<<<<<<
 * 
 *     elif curtype == PYWRITER_TIME:
 */
        __pyx_v_tstamp = (__pyx_v_tstamp * 86400.0);

        /* "pyreadstat/_readstat_writer.pyx":102
 *             tstamp = days.days
 *             tstamp += offset_days
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *                 # spss stores in seconds
 *                 tstamp *= 86400
 */
        break;
        default: break;
      }

      /* "pyreadstat/_readstat_writer.pyx":98
 * 
 *     elif curtype == PYWRITER_DATE:
 *         if type(curval) == datetime.date:             # <<<<<<<<<<<<<<
 *             days = curval - date_0
 *             tstamp = days.days
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":97
 *             tstamp *= 1000
 * 
 *     elif curtype == PYWRITER_DATE:             # <<<<<<<<<<<<<<
 *         if type(curval) == datetime.date:
 *             days = curval - date_0
 */
    break;
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME:

    /* "pyreadstat/_readstat_writer.pyx":107
 * 
 *     elif curtype == PYWRITER_TIME:
 *         if type(curval) == datetime.time:             # <<<<<<<<<<<<<<
 *             tdelta = datetime.datetime.combine(datetime.date.min, curval) - datetime.datetime.min
 *             tstamp = tdelta.total_seconds()
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":108
 *     elif curtype == PYWRITER_TIME:
 *         if type(curval) == datetime.time:
 *             tdelta = datetime.datetime.combine(datetime.date.min, curval) - datetime.datetime.min             # <<<<<<<<<<<<<<
 *             tstamp = tdelta.total_seconds()
 *             #tstamp += offset * 86400
 */
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_combine); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_date); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_min); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_9 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_6, __pyx_t_1, __pyx_v_curval};
        __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 108, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_min); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Subtract(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_tdelta = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pyreadstat/_readstat_writer.pyx":109
 *         if type(curval) == datetime.time:
 *             tdelta = datetime.datetime.combine(datetime.date.min, curval) - datetime.datetime.min
 *             tstamp = tdelta.total_seconds()             # <<<<<<<<<<<<<<
 *             #tstamp += offset * 86400
 *             if file_format == FILE_FORMAT_DTA:
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tdelta, __pyx_n_s_total_seconds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_9 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[1] = {__pyx_t_4, };
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_tstamp = __pyx_t_10;

      /* "pyreadstat/_readstat_writer.pyx":111
 *             tstamp = tdelta.total_seconds()
 *             #tstamp += offset * 86400
 *             if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *                 # stata stores in milliseconds
 *                 tstamp *= 1000
 */
      __pyx_t_3 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
      if (__pyx_t_3) {

        /* "pyreadstat/_readstat_writer.pyx":113
 *             if file_format == FILE_FORMAT_DTA:
 *                 # stata stores in milliseconds
 *                 tstamp *= 1000             # <<<<<<<<<<<<<<
 * 
 *     return tstamp
 */
        __pyx_v_tstamp = (__pyx_v_tstamp * 1000.0);

        /* "pyreadstat/_readstat_writer.pyx":111
 *             tstamp = tdelta.total_seconds()
 *             #tstamp += offset * 86400
 *             if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *                 # stata stores in milliseconds
 *                 tstamp *= 1000
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":107
 * 
 *     elif curtype == PYWRITER_TIME:
 *         if type(curval) == datetime.time:             # <<<<<<<<<<<<<<
 *             tdelta = datetime.datetime.combine(datetime.date.min, curval) - datetime.datetime.min
 *             tstamp = tdelta.total_seconds()
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":106
 *                 tstamp *= 86400
 * 
 *     elif curtype == PYWRITER_TIME:             # <<<<<<<<<<<<<<
 *         if type(curval) == datetime.time:
 *             tdelta = datetime.datetime.combine(datetime.date.min, curval) - datetime.datetime.min
 */
    break;
    default: break;
  }

  /* "pyreadstat/_readstat_writer.pyx":115
 *                 tstamp *= 1000
 * 
 *     return tstamp             # <<<<<<<<<<<<<<
 * 
 * cdef char * get_datetimelike_format_for_readstat(dst_file_format file_format, pywriter_variable_type curtype):
 */
  __pyx_r = __pyx_v_tstamp;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":62
 * 
 * 
 * cdef double convert_datetimelike_to_number(dst_file_format file_format, pywriter_variable_type curtype, object curval) except *:             # <<<<<<<<<<<<<<
 *     """
 *     converts a datime like python/pandas object to a float
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.convert_datetimelike_to_number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_days);
  __Pyx_XDECREF(__pyx_v_tdelta);
  __Pyx_XDECREF(__pyx_v_curval);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":117
 *     return tstamp
 * 
 * cdef char * get_datetimelike_format_for_readstat(dst_file_format file_format, pywriter_variable_type curtype):             # <<<<<<<<<<<<<<
 *     """
 *     gives back a string with the format of the variable (according to the final application) to be used by readstat
 */

static char *__pyx_f_10pyreadstat_16_readstat_writer_get_datetimelike_format_for_readstat(__pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_v_curtype) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_datetimelike_format_for_readstat", 0);

  /* "pyreadstat/_readstat_writer.pyx":122
 *     """
 * 
 *     if curtype == PYWRITER_DATE:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%td"
 */
  switch (__pyx_v_curtype) {
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE:

    /* "pyreadstat/_readstat_writer.pyx":123
 * 
 *     if curtype == PYWRITER_DATE:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%td"
 *         #elif file_format == FILE_FORMAT_SAV:
 */
    __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
    if (__pyx_t_1) {

      /* "pyreadstat/_readstat_writer.pyx":124
 *     if curtype == PYWRITER_DATE:
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%td"             # <<<<<<<<<<<<<<
 *         #elif file_format == FILE_FORMAT_SAV:
 *         #    return "DATE11"
 */
      __pyx_r = ((char *)"%td");
      goto __pyx_L0;

      /* "pyreadstat/_readstat_writer.pyx":123
 * 
 *     if curtype == PYWRITER_DATE:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%td"
 *         #elif file_format == FILE_FORMAT_SAV:
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":128
 *         #    return "DATE11"
 *         else:
 *             return "DATE"             # <<<<<<<<<<<<<<
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US:
 *         if file_format == FILE_FORMAT_DTA:
 */
    /*else*/ {
      __pyx_r = ((char *)"DATE");
      goto __pyx_L0;
    }

    /* "pyreadstat/_readstat_writer.pyx":122
 *     """
 * 
 *     if curtype == PYWRITER_DATE:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%td"
 */
    break;
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME:

    /* "pyreadstat/_readstat_writer.pyx":129
 *         else:
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tc"
 */
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS:
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US:

    /* "pyreadstat/_readstat_writer.pyx":130
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%tc"
 *         #elif file_format == FILE_FORMAT_SAV:
 */
    __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
    if (__pyx_t_1) {

      /* "pyreadstat/_readstat_writer.pyx":131
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US:
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tc"             # <<<<<<<<<<<<<<
 *         #elif file_format == FILE_FORMAT_SAV:
 *         #    return "DATETIME20"
 */
      __pyx_r = ((char *)"%tc");
      goto __pyx_L0;

      /* "pyreadstat/_readstat_writer.pyx":130
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%tc"
 *         #elif file_format == FILE_FORMAT_SAV:
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":135
 *         #    return "DATETIME20"
 *         else:
 *             return "DATETIME"             # <<<<<<<<<<<<<<
 *     elif curtype == PYWRITER_TIME:
 *         if file_format == FILE_FORMAT_DTA:
 */
    /*else*/ {
      __pyx_r = ((char *)"DATETIME");
      goto __pyx_L0;
    }

    /* "pyreadstat/_readstat_writer.pyx":129
 *         else:
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tc"
 */
    break;
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME:

    /* "pyreadstat/_readstat_writer.pyx":137
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%tcHH:MM:SS"
 *         else:
 */
    __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
    if (__pyx_t_1) {

      /* "pyreadstat/_readstat_writer.pyx":138
 *     elif curtype == PYWRITER_TIME:
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tcHH:MM:SS"             # <<<<<<<<<<<<<<
 *         else:
 *             return "TIME"
 */
      __pyx_r = ((char *)"%tcHH:MM:SS");
      goto __pyx_L0;

      /* "pyreadstat/_readstat_writer.pyx":137
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%tcHH:MM:SS"
 *         else:
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":140
 *             return "%tcHH:MM:SS"
 *         else:
 *             return "TIME"             # <<<<<<<<<<<<<<
 *     else:
 *         raise PyreadstatError("Unknown pywriter variable format")
 */
    /*else*/ {
      __pyx_r = ((char *)"TIME");
      goto __pyx_L0;
    }

    /* "pyreadstat/_readstat_writer.pyx":136
 *         else:
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tcHH:MM:SS"
 */
    break;
    default:

    /* "pyreadstat/_readstat_writer.pyx":142
 *             return "TIME"
 *     else:
 *         raise PyreadstatError("Unknown pywriter variable format")             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_5 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_kp_s_Unknown_pywriter_variable_format};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 142, __pyx_L1_error)
    break;
  }

  /* "pyreadstat/_readstat_writer.pyx":117
 *     return tstamp
 * 
 * cdef char * get_datetimelike_format_for_readstat(dst_file_format file_format, pywriter_variable_type curtype):             # <<<<<<<<<<<<<<
 *     """
 *     gives back a string with the format of the variable (according to the final application) to be used by readstat
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.get_datetimelike_format_for_readstat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":145
 * 
 * 
 * cdef int get_pandas_str_series_max_length(object series, dict value_labels):             # <<<<<<<<<<<<<<
 *     """ For a pandas string series get the max length of the strings. Assumes there is no NaN among the elements.
 *     """
 */

static int __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(PyObject *__pyx_v_series, PyObject *__pyx_v_value_labels) {
  PyObject *__pyx_v_values = NULL;
  PyObject *__pyx_v_val = 0;
  PyObject *__pyx_v_temp = 0;
  int __pyx_v_max_length;
  int __pyx_v_curlen;
  PyObject *__pyx_v_labels = 0;
  PyObject *__pyx_v_lab = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_pandas_str_series_max_length", 0);

  /* "pyreadstat/_readstat_writer.pyx":148
 *     """ For a pandas string series get the max length of the strings. Assumes there is no NaN among the elements.
 *     """
 *     values = series.values             # <<<<<<<<<<<<<<
 *     cdef str val
 *     cdef bytes temp
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_series, __pyx_n_s_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_values = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":151
 *     cdef str val
 *     cdef bytes temp
 *     cdef int max_length = 1             # <<<<<<<<<<<<<<
 *     cdef int curlen
 *     cdef list labels
 */
  __pyx_v_max_length = 1;

  /* "pyreadstat/_readstat_writer.pyx":154
 *     cdef int curlen
 *     cdef list labels
 *     for val in values:             # <<<<<<<<<<<<<<
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)
 */
  if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) {
    __pyx_t_1 = __pyx_v_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 154, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 154, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 154, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (!(likely(PyString_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_4))) __PYX_ERR(0, 154, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_val, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":155
 *     cdef list labels
 *     for val in values:
 *         temp = val.encode("utf-8")             # <<<<<<<<<<<<<<
 *         curlen = len(temp)
 *         if curlen > max_length:
 */
    __pyx_t_4 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_val, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 155, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_4))) __PYX_ERR(0, 155, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_temp, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":156
 *     for val in values:
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)             # <<<<<<<<<<<<<<
 *         if curlen > max_length:
 *             max_length = curlen
 */
    if (unlikely(__pyx_v_temp == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 156, __pyx_L1_error)
    }
    __pyx_t_5 = PyBytes_GET_SIZE(__pyx_v_temp); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 156, __pyx_L1_error)
    __pyx_v_curlen = __pyx_t_5;

    /* "pyreadstat/_readstat_writer.pyx":157
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)
 *         if curlen > max_length:             # <<<<<<<<<<<<<<
 *             max_length = curlen
 *     if value_labels:
 */
    __pyx_t_6 = (__pyx_v_curlen > __pyx_v_max_length);
    if (__pyx_t_6) {

      /* "pyreadstat/_readstat_writer.pyx":158
 *         curlen = len(temp)
 *         if curlen > max_length:
 *             max_length = curlen             # <<<<<<<<<<<<<<
 *     if value_labels:
 *         labels = list(value_labels.keys())
 */
      __pyx_v_max_length = __pyx_v_curlen;

      /* "pyreadstat/_readstat_writer.pyx":157
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)
 *         if curlen > max_length:             # <<<<<<<<<<<<<<
 *             max_length = curlen
 *     if value_labels:
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":154
 *     cdef int curlen
 *     cdef list labels
 *     for val in values:             # <<<<<<<<<<<<<<
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":159
 *         if curlen > max_length:
 *             max_length = curlen
 *     if value_labels:             # <<<<<<<<<<<<<<
 *         labels = list(value_labels.keys())
 *         for lab in labels:
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_value_labels); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 159, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "pyreadstat/_readstat_writer.pyx":160
 *             max_length = curlen
 *     if value_labels:
 *         labels = list(value_labels.keys())             # <<<<<<<<<<<<<<
 *         for lab in labels:
 *             curlen = len(str(lab))
 */
    if (unlikely(__pyx_v_value_labels == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "keys");
      __PYX_ERR(0, 160, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_Keys(__pyx_v_value_labels); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PySequence_ListKeepNew(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_labels = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":161
 *     if value_labels:
 *         labels = list(value_labels.keys())
 *         for lab in labels:             # <<<<<<<<<<<<<<
 *             curlen = len(str(lab))
 *             if curlen > max_length:
 */
    __pyx_t_4 = __pyx_v_labels; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0;
    for (;;) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 161, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_lab, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pyreadstat/_readstat_writer.pyx":162
 *         labels = list(value_labels.keys())
 *         for lab in labels:
 *             curlen = len(str(lab))             # <<<<<<<<<<<<<<
 *             if curlen > max_length:
 *                 max_length = curlen
 */
      __pyx_t_1 = __Pyx_PyObject_Str(__pyx_v_lab); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_curlen = __pyx_t_5;

      /* "pyreadstat/_readstat_writer.pyx":163
 *         for lab in labels:
 *             curlen = len(str(lab))
 *             if curlen > max_length:             # <<<<<<<<<<<<<<
 *                 max_length = curlen
 * 
 */
      __pyx_t_6 = (__pyx_v_curlen > __pyx_v_max_length);
      if (__pyx_t_6) {

        /* "pyreadstat/_readstat_writer.pyx":164
 *             curlen = len(str(lab))
 *             if curlen > max_length:
 *                 max_length = curlen             # <<<<<<<<<<<<<<
 * 
 *     return max_length
 */
        __pyx_v_max_length = __pyx_v_curlen;

        /* "pyreadstat/_readstat_writer.pyx":163
 *         for lab in labels:
 *             curlen = len(str(lab))
 *             if curlen > max_length:             # <<<<<<<<<<<<<<
 *                 max_length = curlen
 * 
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":161
 *     if value_labels:
 *         labels = list(value_labels.keys())
 *         for lab in labels:             # <<<<<<<<<<<<<<
 *             curlen = len(str(lab))
 *             if curlen > max_length:
 */
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":159
 *         if curlen > max_length:
 *             max_length = curlen
 *     if value_labels:             # <<<<<<<<<<<<<<
 *         labels = list(value_labels.keys())
 *         for lab in labels:
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":166
 *                 max_length = curlen
 * 
 *     return max_length             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_max_length;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":145
 * 
 * 
 * cdef int get_pandas_str_series_max_length(object series, dict value_labels):             # <<<<<<<<<<<<<<
 *     """ For a pandas string series get the max length of the strings. Assumes there is no NaN among the elements.
 *     """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.get_pandas_str_series_max_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XDECREF(__pyx_v_val);
  __Pyx_XDECREF(__pyx_v_temp);
  __Pyx_XDECREF(__pyx_v_labels);
  __Pyx_XDECREF(__pyx_v_lab);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":169
 * 
 * 
 * cdef int check_series_all_same_types(object series, object type_to_check):             # <<<<<<<<<<<<<<
 *     """
 *     1 if all elements in a series are of type type_to_check, 0 otherwise
 */

static int __pyx_f_10pyreadstat_16_readstat_writer_check_series_all_same_types(PyObject *__pyx_v_series, PyObject *__pyx_v_type_to_check) {
  PyObject *__pyx_v_values = NULL;
  PyObject *__pyx_v_val = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check_series_all_same_types", 0);

  /* "pyreadstat/_readstat_writer.pyx":174
 *     """
 * 
 *     values = series.values             # <<<<<<<<<<<<<<
 *     for val in values:
 *         if type(val) != type_to_check:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_series, __pyx_n_s_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_values = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":175
 * 
 *     values = series.values
 *     for val in values:             # <<<<<<<<<<<<<<
 *         if type(val) != type_to_check:
 *             return 0
 */
  if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) {
    __pyx_t_1 = __pyx_v_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 175, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 175, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 175, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 175, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 175, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":176
 *     values = series.values
 *     for val in values:
 *         if type(val) != type_to_check:             # <<<<<<<<<<<<<<
 *             return 0
 *     return 1
 */
    __pyx_t_4 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_val)), __pyx_v_type_to_check, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":177
 *     for val in values:
 *         if type(val) != type_to_check:
 *             return 0             # <<<<<<<<<<<<<<
 *     return 1
 * 
 */
      __pyx_r = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "pyreadstat/_readstat_writer.pyx":176
 *     values = series.values
 *     for val in values:
 *         if type(val) != type_to_check:             # <<<<<<<<<<<<<<
 *             return 0
 *     return 1
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":175
 * 
 *     values = series.values
 *     for val in values:             # <<<<<<<<<<<<<<
 *         if type(val) != type_to_check:
 *             return 0
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":178
 *         if type(val) != type_to_check:
 *             return 0
 *     return 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":169
 * 
 * 
 * cdef int check_series_all_same_types(object series, object type_to_check):             # <<<<<<<<<<<<<<
 *     """
 *     1 if all elements in a series are of type type_to_check, 0 otherwise
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.check_series_all_same_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XDECREF(__pyx_v_val);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":181
 * 
 * 
 * cdef list get_pandas_column_types(object df, dict missing_user_values, dict variable_value_labels):             # <<<<<<<<<<<<<<
 *     """
 *     From a pandas data frame, get a list with tuples column types as first element, max_length as second and is_missing
 */

static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_get_pandas_column_types(PyObject *__pyx_v_df, PyObject *__pyx_v_missing_user_values, PyObject *__pyx_v_variable_value_labels) {
  int __pyx_v_max_length;
  PyObject *__pyx_v_types = 0;
  PyObject *__pyx_v_columns = 0;
  PyObject *__pyx_v_result = 0;
  int __pyx_v_equal;
  int __pyx_v_is_missing;
  PyObject *__pyx_v_indx = NULL;
  PyObject *__pyx_v_col_name = NULL;
  PyObject *__pyx_v_col_type = NULL;
  PyObject *__pyx_v_curseries = NULL;
  PyObject *__pyx_v_curuser_missing = NULL;
  PyObject *__pyx_v_col = NULL;
  PyTypeObject *__pyx_v_curtype = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  int __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  long __pyx_t_17;
  long __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_pandas_column_types", 0);
  __Pyx_INCREF(__pyx_v_variable_value_labels);

  /* "pyreadstat/_readstat_writer.pyx":191
 *     cdef int max_length
 * 
 *     cdef list types = df.dtypes.values.tolist()             # <<<<<<<<<<<<<<
 *     cdef list columns = df.columns.values.tolist()
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_n_s_dtypes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_tolist); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  {
    PyObject *__pyx_callargs[1] = {__pyx_t_3, };
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_1))) __PYX_ERR(0, 191, __pyx_L1_error)
  __pyx_v_types = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":192
 * 
 *     cdef list types = df.dtypes.values.tolist()
 *     cdef list columns = df.columns.values.tolist()             # <<<<<<<<<<<<<<
 * 
 *     cdef list result = list()
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_n_s_columns); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_tolist); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  {
    PyObject *__pyx_callargs[1] = {__pyx_t_3, };
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_1))) __PYX_ERR(0, 192, __pyx_L1_error)
  __pyx_v_columns = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":194
 *     cdef list columns = df.columns.values.tolist()
 * 
 *     cdef list result = list()             # <<<<<<<<<<<<<<
 *     cdef int equal, is_missing
 *     if variable_value_labels is None:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":196
 *     cdef list result = list()
 *     cdef int equal, is_missing
 *     if variable_value_labels is None:             # <<<<<<<<<<<<<<
 *         variable_value_labels = dict()
 * 
 */
  __pyx_t_5 = (__pyx_v_variable_value_labels == ((PyObject*)Py_None));
  if (__pyx_t_5) {

    /* "pyreadstat/_readstat_writer.pyx":197
 *     cdef int equal, is_missing
 *     if variable_value_labels is None:
 *         variable_value_labels = dict()             # <<<<<<<<<<<<<<
 * 
 *     for indx, (col_name, col_type) in enumerate(zip(columns, types)):
 */
    __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_variable_value_labels, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":196
 *     cdef list result = list()
 *     cdef int equal, is_missing
 *     if variable_value_labels is None:             # <<<<<<<<<<<<<<
 *         variable_value_labels = dict()
 * 
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":199
 *         variable_value_labels = dict()
 * 
 *     for indx, (col_name, col_type) in enumerate(zip(columns, types)):             # <<<<<<<<<<<<<<
 * 
 *         max_length = 0
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_1 = __pyx_int_0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_columns);
  __Pyx_GIVEREF(__pyx_v_columns);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_columns);
  __Pyx_INCREF(__pyx_v_types);
  __Pyx_GIVEREF(__pyx_v_types);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_types);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 199, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 199, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely((0 < 0))) __PYX_ERR(0, 199, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 199, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely((0 < 0))) __PYX_ERR(0, 199, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 199, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_7(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 199, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 199, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
      index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 199, __pyx_L1_error)
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 199, __pyx_L1_error)
      __pyx_L7_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_col_name, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_col_type, __pyx_t_9);
    __pyx_t_9 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_indx, __pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 199, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pyreadstat/_readstat_writer.pyx":201
 *     for indx, (col_name, col_type) in enumerate(zip(columns, types)):
 * 
 *         max_length = 0             # <<<<<<<<<<<<<<
 *         curseries = df.iloc[:, indx]
 *         curuser_missing = None
 */
    __pyx_v_max_length = 0;

    /* "pyreadstat/_readstat_writer.pyx":202
 * 
 *         max_length = 0
 *         curseries = df.iloc[:, indx]             # <<<<<<<<<<<<<<
 *         curuser_missing = None
 *         if missing_user_values:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_n_s_iloc); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 202, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 202, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_slice_);
    __Pyx_GIVEREF(__pyx_slice_);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_slice_);
    __Pyx_INCREF(__pyx_v_indx);
    __Pyx_GIVEREF(__pyx_v_indx);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_indx);
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 202, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF_SET(__pyx_v_curseries, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "pyreadstat/_readstat_writer.pyx":203
 *         max_length = 0
 *         curseries = df.iloc[:, indx]
 *         curuser_missing = None             # <<<<<<<<<<<<<<
 *         if missing_user_values:
 *             curuser_missing = missing_user_values.get(col_name)
 */
    __Pyx_INCREF(Py_None);
    __Pyx_XDECREF_SET(__pyx_v_curuser_missing, Py_None);

    /* "pyreadstat/_readstat_writer.pyx":204
 *         curseries = df.iloc[:, indx]
 *         curuser_missing = None
 *         if missing_user_values:             # <<<<<<<<<<<<<<
 *             curuser_missing = missing_user_values.get(col_name)
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 204, __pyx_L1_error)
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":205
 *         curuser_missing = None
 *         if missing_user_values:
 *             curuser_missing = missing_user_values.get(col_name)             # <<<<<<<<<<<<<<
 * 
 *         # recover original type for categories
 */
      if (unlikely(__pyx_v_missing_user_values == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 205, __pyx_L1_error)
      }
      __pyx_t_8 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_user_values, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF_SET(__pyx_v_curuser_missing, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":204
 *         curseries = df.iloc[:, indx]
 *         curuser_missing = None
 *         if missing_user_values:             # <<<<<<<<<<<<<<
 *             curuser_missing = missing_user_values.get(col_name)
 * 
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":208
 * 
 *         # recover original type for categories
 *         if type(col_type) is pd.core.dtypes.dtypes.CategoricalDtype:             # <<<<<<<<<<<<<<
 *             col_type = np.asarray(curseries).dtype
 *         if col_type in int_types:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pd); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_core); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_dtypes); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_dtypes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_CategoricalDtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_v_col_type)) == __pyx_t_8);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":209
 *         # recover original type for categories
 *         if type(col_type) is pd.core.dtypes.dtypes.CategoricalDtype:
 *             col_type = np.asarray(curseries).dtype             # <<<<<<<<<<<<<<
 *         if col_type in int_types:
 *             result.append((PYWRITER_INTEGER, 0,0))
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 209, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_asarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_curseries};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 209, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF_SET(__pyx_v_col_type, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyreadstat/_readstat_writer.pyx":208
 * 
 *         # recover original type for categories
 *         if type(col_type) is pd.core.dtypes.dtypes.CategoricalDtype:             # <<<<<<<<<<<<<<
 *             col_type = np.asarray(curseries).dtype
 *         if col_type in int_types:
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":210
 *         if type(col_type) is pd.core.dtypes.dtypes.CategoricalDtype:
 *             col_type = np.asarray(curseries).dtype
 *         if col_type in int_types:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_INTEGER, 0,0))
 *         elif col_type in float_types:
 */
    if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 210, __pyx_L1_error)
    }
    __pyx_t_5 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_int_types, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 210, __pyx_L1_error)
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":211
 *             col_type = np.asarray(curseries).dtype
 *         if col_type in int_types:
 *             result.append((PYWRITER_INTEGER, 0,0))             # <<<<<<<<<<<<<<
 *         elif col_type in float_types:
 *             if np.any(pd.isna(curseries)):
 */
      __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 211, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_0);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_0);
      __pyx_t_3 = 0;
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 211, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":210
 *         if type(col_type) is pd.core.dtypes.dtypes.CategoricalDtype:
 *             col_type = np.asarray(curseries).dtype
 *         if col_type in int_types:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_INTEGER, 0,0))
 *         elif col_type in float_types:
 */
      goto __pyx_L10;
    }

    /* "pyreadstat/_readstat_writer.pyx":212
 *         if col_type in int_types:
 *             result.append((PYWRITER_INTEGER, 0,0))
 *         elif col_type in float_types:             # <<<<<<<<<<<<<<
 *             if np.any(pd.isna(curseries)):
 *                 result.append((PYWRITER_DOUBLE, 0, 1))
 */
    if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_float_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 212, __pyx_L1_error)
    }
    __pyx_t_5 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_float_types, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 212, __pyx_L1_error)
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":213
 *             result.append((PYWRITER_INTEGER, 0,0))
 *         elif col_type in float_types:
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DOUBLE, 0, 1))
 *             else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_any); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pd); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_isna); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_v_curseries};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __pyx_t_13 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_3};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 213, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":214
 *         elif col_type in float_types:
 *             if np.any(pd.isna(curseries)):
 *                 result.append((PYWRITER_DOUBLE, 0, 1))             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append((PYWRITER_DOUBLE, 0, 0))
 */
        __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 214, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 214, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_0);
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_int_1);
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 214, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pyreadstat/_readstat_writer.pyx":213
 *             result.append((PYWRITER_INTEGER, 0,0))
 *         elif col_type in float_types:
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DOUBLE, 0, 1))
 *             else:
 */
        goto __pyx_L11;
      }

      /* "pyreadstat/_readstat_writer.pyx":216
 *                 result.append((PYWRITER_DOUBLE, 0, 1))
 *             else:
 *                 result.append((PYWRITER_DOUBLE, 0, 0))             # <<<<<<<<<<<<<<
 *         elif col_type == bool:
 *             result.append((PYWRITER_LOGICAL, 0,0))
 */
      /*else*/ {
        __pyx_t_9 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 216, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 216, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_0);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_0);
        __pyx_t_9 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 216, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_L11:;

      /* "pyreadstat/_readstat_writer.pyx":212
 *         if col_type in int_types:
 *             result.append((PYWRITER_INTEGER, 0,0))
 *         elif col_type in float_types:             # <<<<<<<<<<<<<<
 *             if np.any(pd.isna(curseries)):
 *                 result.append((PYWRITER_DOUBLE, 0, 1))
 */
      goto __pyx_L10;
    }

    /* "pyreadstat/_readstat_writer.pyx":217
 *             else:
 *                 result.append((PYWRITER_DOUBLE, 0, 0))
 *         elif col_type == bool:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_LOGICAL, 0,0))
 *         # np.datetime64[ns]
 */
    __pyx_t_8 = PyObject_RichCompare(__pyx_v_col_type, ((PyObject*)&PyBool_Type), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 217, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 217, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":218
 *                 result.append((PYWRITER_DOUBLE, 0, 0))
 *         elif col_type == bool:
 *             result.append((PYWRITER_LOGICAL, 0,0))             # <<<<<<<<<<<<<<
 *         # np.datetime64[ns]
 *         elif is_datetime64_ns_dtype(df[col_name]):
 */
      __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 218, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 218, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_0);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_int_0);
      __pyx_t_8 = 0;
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 218, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":217
 *             else:
 *                 result.append((PYWRITER_DOUBLE, 0, 0))
 *         elif col_type == bool:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_LOGICAL, 0,0))
 *         # np.datetime64[ns]
 */
      goto __pyx_L10;
    }

    /* "pyreadstat/_readstat_writer.pyx":220
 *             result.append((PYWRITER_LOGICAL, 0,0))
 *         # np.datetime64[ns]
 *         elif is_datetime64_ns_dtype(df[col_name]):             # <<<<<<<<<<<<<<
 *             if np.any(pd.isna(curseries)):
 *                 result.append((PYWRITER_DATETIME64_NS, 0,1))
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_is_datetime64_ns_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_df, __pyx_v_col_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_13 = NULL;
    __pyx_t_4 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_4 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_3};
      __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 220, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":221
 *         # np.datetime64[ns]
 *         elif is_datetime64_ns_dtype(df[col_name]):
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64_NS, 0,1))
 *             else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_any); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_pd); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_isna); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_v_curseries};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 221, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __pyx_t_10 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_8};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 221, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":222
 *         elif is_datetime64_ns_dtype(df[col_name]):
 *             if np.any(pd.isna(curseries)):
 *                 result.append((PYWRITER_DATETIME64_NS, 0,1))             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append((PYWRITER_DATETIME64_NS, 0,0))
 */
        __pyx_t_9 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 222, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_1);
        __pyx_t_9 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 222, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":221
 *         # np.datetime64[ns]
 *         elif is_datetime64_ns_dtype(df[col_name]):
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64_NS, 0,1))
 *             else:
 */
        goto __pyx_L12;
      }

      /* "pyreadstat/_readstat_writer.pyx":224
 *                 result.append((PYWRITER_DATETIME64_NS, 0,1))
 *             else:
 *                 result.append((PYWRITER_DATETIME64_NS, 0,0))             # <<<<<<<<<<<<<<
 *         elif col_type == np.dtype('<M8[ns]') or col_type in datetime_types or is_datetime64_any_dtype(df[col_name]):
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0
 */
      /*else*/ {
        __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 224, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_0);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_int_0);
        __pyx_t_3 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 224, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_L12:;

      /* "pyreadstat/_readstat_writer.pyx":220
 *             result.append((PYWRITER_LOGICAL, 0,0))
 *         # np.datetime64[ns]
 *         elif is_datetime64_ns_dtype(df[col_name]):             # <<<<<<<<<<<<<<
 *             if np.any(pd.isna(curseries)):
 *                 result.append((PYWRITER_DATETIME64_NS, 0,1))
 */
      goto __pyx_L10;
    }

    /* "pyreadstat/_readstat_writer.pyx":225
 *             else:
 *                 result.append((PYWRITER_DATETIME64_NS, 0,0))
 *         elif col_type == np.dtype('<M8[ns]') or col_type in datetime_types or is_datetime64_any_dtype(df[col_name]):             # <<<<<<<<<<<<<<
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0
 *             if str(col_type).startswith('datetime64[us'):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    __pyx_t_4 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_4 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_kp_s_M8_ns};
      __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __pyx_t_8 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_9, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (!__pyx_t_14) {
    } else {
      __pyx_t_5 = __pyx_t_14;
      goto __pyx_L13_bool_binop_done;
    }
    if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_datetime_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 225, __pyx_L1_error)
    }
    __pyx_t_14 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_datetime_types, Py_EQ)); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 225, __pyx_L1_error)
    if (!__pyx_t_14) {
    } else {
      __pyx_t_5 = __pyx_t_14;
      goto __pyx_L13_bool_binop_done;
    }
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_is_datetime64_any_dtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_df, __pyx_v_col_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = NULL;
    __pyx_t_4 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
        __pyx_t_4 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_3};
      __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_5 = __pyx_t_14;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":226
 *                 result.append((PYWRITER_DATETIME64_NS, 0,0))
 *         elif col_type == np.dtype('<M8[ns]') or col_type in datetime_types or is_datetime64_any_dtype(df[col_name]):
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0             # <<<<<<<<<<<<<<
 *             if str(col_type).startswith('datetime64[us'):
 *                 result.append((PYWRITER_DATETIME64_US, 0, is_missing))
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_any); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pd); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_isna); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
          __pyx_t_15 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_v_curseries};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_15, 1+__pyx_t_15);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 226, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __pyx_t_13 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_15 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_9};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_15, 1+__pyx_t_15);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 226, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_5) {
        __pyx_t_4 = 1;
      } else {
        __pyx_t_4 = 0;
      }
      __pyx_v_is_missing = __pyx_t_4;

      /* "pyreadstat/_readstat_writer.pyx":227
 *         elif col_type == np.dtype('<M8[ns]') or col_type in datetime_types or is_datetime64_any_dtype(df[col_name]):
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0
 *             if str(col_type).startswith('datetime64[us'):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64_US, 0, is_missing))
 *             else:
 */
      __pyx_t_3 = __Pyx_PyObject_Str(__pyx_v_col_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_kp_s_datetime64_us_2};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 227, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":228
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0
 *             if str(col_type).startswith('datetime64[us'):
 *                 result.append((PYWRITER_DATETIME64_US, 0, is_missing))             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 */
        __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 228, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 228, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 228, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_9);
        __pyx_t_8 = 0;
        __pyx_t_9 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 228, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":227
 *         elif col_type == np.dtype('<M8[ns]') or col_type in datetime_types or is_datetime64_any_dtype(df[col_name]):
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0
 *             if str(col_type).startswith('datetime64[us'):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64_US, 0, is_missing))
 *             else:
 */
        goto __pyx_L16;
      }

      /* "pyreadstat/_readstat_writer.pyx":230
 *                 result.append((PYWRITER_DATETIME64_US, 0, is_missing))
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))             # <<<<<<<<<<<<<<
 *         elif col_type == object or col_type == 'string' or col_type in int_mixed_types:
 *             is_missing = 0
 */
      /*else*/ {
        __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 230, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 230, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 230, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_9);
        __pyx_t_3 = 0;
        __pyx_t_9 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 230, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_L16:;

      /* "pyreadstat/_readstat_writer.pyx":225
 *             else:
 *                 result.append((PYWRITER_DATETIME64_NS, 0,0))
 *         elif col_type == np.dtype('<M8[ns]') or col_type in datetime_types or is_datetime64_any_dtype(df[col_name]):             # <<<<<<<<<<<<<<
 *             is_missing = 1 if np.any(pd.isna(curseries)) else 0
 *             if str(col_type).startswith('datetime64[us'):
 */
      goto __pyx_L10;
    }

    /* "pyreadstat/_readstat_writer.pyx":231
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *         elif col_type == object or col_type == 'string' or col_type in int_mixed_types:             # <<<<<<<<<<<<<<
 *             is_missing = 0
 *             if curuser_missing:
 */
    __pyx_t_8 = PyObject_RichCompare(__pyx_v_col_type, __pyx_builtin_object, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 231, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 231, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (!__pyx_t_14) {
    } else {
      __pyx_t_5 = __pyx_t_14;
      goto __pyx_L17_bool_binop_done;
    }
    __pyx_t_14 = (__Pyx_PyString_Equals(__pyx_v_col_type, __pyx_n_s_string, Py_EQ)); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 231, __pyx_L1_error)
    if (!__pyx_t_14) {
    } else {
      __pyx_t_5 = __pyx_t_14;
      goto __pyx_L17_bool_binop_done;
    }
    if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 231, __pyx_L1_error)
    }
    __pyx_t_14 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types, Py_EQ)); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 231, __pyx_L1_error)
    __pyx_t_5 = __pyx_t_14;
    __pyx_L17_bool_binop_done:;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":232
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *         elif col_type == object or col_type == 'string' or col_type in int_mixed_types:
 *             is_missing = 0             # <<<<<<<<<<<<<<
 *             if curuser_missing:
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)
 */
      __pyx_v_is_missing = 0;

      /* "pyreadstat/_readstat_writer.pyx":233
 *         elif col_type == object or col_type == 'string' or col_type in int_mixed_types:
 *             is_missing = 0
 *             if curuser_missing:             # <<<<<<<<<<<<<<
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)
 *                 if not len(curseries):
 */
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_curuser_missing); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 233, __pyx_L1_error)
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":234
 *             is_missing = 0
 *             if curuser_missing:
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)             # <<<<<<<<<<<<<<
 *                 if not len(curseries):
 *                     result.append((PYWRITER_DOUBLE, 0, 1))
 */
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_isin); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 234, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = NULL;
        __pyx_t_4 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
            __pyx_t_4 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_curuser_missing};
          __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 234, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __pyx_t_9 = PyNumber_Invert(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 234, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_curseries, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 234, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_reset_index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 234, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 234, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_drop, Py_True) < 0) __PYX_ERR(0, 234, __pyx_L1_error)
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_empty_tuple, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF_SET(__pyx_v_curseries, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":235
 *             if curuser_missing:
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)
 *                 if not len(curseries):             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_DOUBLE, 0, 1))
 *                     continue
 */
        __pyx_t_16 = PyObject_Length(__pyx_v_curseries); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 235, __pyx_L1_error)
        __pyx_t_5 = (!(__pyx_t_16 != 0));
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":236
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)
 *                 if not len(curseries):
 *                     result.append((PYWRITER_DOUBLE, 0, 1))             # <<<<<<<<<<<<<<
 *                     continue
 *             if np.any(pd.isna(curseries)):
 */
          __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 236, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 236, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_0);
          __Pyx_INCREF(__pyx_int_1);
          __Pyx_GIVEREF(__pyx_int_1);
          PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1);
          __pyx_t_3 = 0;
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 236, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

          /* "pyreadstat/_readstat_writer.pyx":237
 *                 if not len(curseries):
 *                     result.append((PYWRITER_DOUBLE, 0, 1))
 *                     continue             # <<<<<<<<<<<<<<
 *             if np.any(pd.isna(curseries)):
 *                 if col_type in int_mixed_types:
 */
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":235
 *             if curuser_missing:
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)
 *                 if not len(curseries):             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_DOUBLE, 0, 1))
 *                     continue
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":233
 *         elif col_type == object or col_type == 'string' or col_type in int_mixed_types:
 *             is_missing = 0
 *             if curuser_missing:             # <<<<<<<<<<<<<<
 *                 curseries = curseries[~curseries.isin(curuser_missing)].reset_index(drop=True)
 *                 if not len(curseries):
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":238
 *                     result.append((PYWRITER_DOUBLE, 0, 1))
 *                     continue
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 if col_type in int_mixed_types:
 *                     result.append((PYWRITER_INTEGER, 0, 1))
 */
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_any); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_pd); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_isna); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_v_curseries};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __pyx_t_10 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_3};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 238, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":239
 *                     continue
 *             if np.any(pd.isna(curseries)):
 *                 if col_type in int_mixed_types:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_INTEGER, 0, 1))
 *                     continue
 */
        if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 239, __pyx_L1_error)
        }
        __pyx_t_5 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 239, __pyx_L1_error)
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":240
 *             if np.any(pd.isna(curseries)):
 *                 if col_type in int_mixed_types:
 *                     result.append((PYWRITER_INTEGER, 0, 1))             # <<<<<<<<<<<<<<
 *                     continue
 *                 col = curseries.dropna().reset_index(drop=True)
 */
          __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 240, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 240, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_0);
          __Pyx_INCREF(__pyx_int_1);
          __Pyx_GIVEREF(__pyx_int_1);
          PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_int_1);
          __pyx_t_8 = 0;
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 240, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "pyreadstat/_readstat_writer.pyx":241
 *                 if col_type in int_mixed_types:
 *                     result.append((PYWRITER_INTEGER, 0, 1))
 *                     continue             # <<<<<<<<<<<<<<
 *                 col = curseries.dropna().reset_index(drop=True)
 *                 is_missing = 1
 */
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":239
 *                     continue
 *             if np.any(pd.isna(curseries)):
 *                 if col_type in int_mixed_types:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_INTEGER, 0, 1))
 *                     continue
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":242
 *                     result.append((PYWRITER_INTEGER, 0, 1))
 *                     continue
 *                 col = curseries.dropna().reset_index(drop=True)             # <<<<<<<<<<<<<<
 *                 is_missing = 1
 *                 if len(col):
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_dropna); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 242, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = NULL;
        __pyx_t_4 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_4 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[1] = {__pyx_t_3, };
          __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 242, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_reset_index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 242, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 242, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_drop, Py_True) < 0) __PYX_ERR(0, 242, __pyx_L1_error)
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 242, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF_SET(__pyx_v_col, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":243
 *                     continue
 *                 col = curseries.dropna().reset_index(drop=True)
 *                 is_missing = 1             # <<<<<<<<<<<<<<
 *                 if len(col):
 *                     curtype = type(col[0])
 */
        __pyx_v_is_missing = 1;

        /* "pyreadstat/_readstat_writer.pyx":244
 *                 col = curseries.dropna().reset_index(drop=True)
 *                 is_missing = 1
 *                 if len(col):             # <<<<<<<<<<<<<<
 *                     curtype = type(col[0])
 *                     equal = check_series_all_same_types(col, curtype)
 */
        __pyx_t_16 = PyObject_Length(__pyx_v_col); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 244, __pyx_L1_error)
        __pyx_t_5 = (__pyx_t_16 != 0);
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":245
 *                 is_missing = 1
 *                 if len(col):
 *                     curtype = type(col[0])             # <<<<<<<<<<<<<<
 *                     equal = check_series_all_same_types(col, curtype)
 *                     #equal = col.apply(lambda x: type(x) == curtype)
 */
          __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_col, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 245, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_3)));
          __Pyx_XDECREF_SET(__pyx_v_curtype, ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_t_3))));
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":246
 *                 if len(col):
 *                     curtype = type(col[0])
 *                     equal = check_series_all_same_types(col, curtype)             # <<<<<<<<<<<<<<
 *                     #equal = col.apply(lambda x: type(x) == curtype)
 *                     #if not np.all(equal):
 */
          __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_check_series_all_same_types(__pyx_v_col, ((PyObject *)__pyx_v_curtype)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 246, __pyx_L1_error)
          __pyx_v_equal = __pyx_t_4;

          /* "pyreadstat/_readstat_writer.pyx":249
 *                     #equal = col.apply(lambda x: type(x) == curtype)
 *                     #if not np.all(equal):
 *                     if not equal:             # <<<<<<<<<<<<<<
 *                         max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 *                         result.append((PYWRITER_OBJECT, max_length, 1))
 */
          __pyx_t_5 = (!(__pyx_v_equal != 0));
          if (__pyx_t_5) {

            /* "pyreadstat/_readstat_writer.pyx":250
 *                     #if not np.all(equal):
 *                     if not equal:
 *                         max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *                         result.append((PYWRITER_OBJECT, max_length, 1))
 *                         continue
 */
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_col, __pyx_n_s_astype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 250, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_8 = NULL;
            __pyx_t_4 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
              __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
              if (likely(__pyx_t_8)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                __Pyx_INCREF(__pyx_t_8);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_9, function);
                __pyx_t_4 = 1;
              }
            }
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_8, ((PyObject *)(&PyString_Type))};
              __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
            if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 250, __pyx_L1_error)
            }
            __pyx_t_9 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 250, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            if (!(likely(PyDict_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_9))) __PYX_ERR(0, 250, __pyx_L1_error)
            __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_t_3, ((PyObject*)__pyx_t_9)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 250, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_v_max_length = __pyx_t_4;

            /* "pyreadstat/_readstat_writer.pyx":251
 *                     if not equal:
 *                         max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 *                         result.append((PYWRITER_OBJECT, max_length, 1))             # <<<<<<<<<<<<<<
 *                         continue
 *                 else:
 */
            __pyx_t_9 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 251, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 251, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_GIVEREF(__pyx_t_9);
            PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3);
            __Pyx_INCREF(__pyx_int_1);
            __Pyx_GIVEREF(__pyx_int_1);
            PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1);
            __pyx_t_9 = 0;
            __pyx_t_3 = 0;
            __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 251, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

            /* "pyreadstat/_readstat_writer.pyx":252
 *                         max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 *                         result.append((PYWRITER_OBJECT, max_length, 1))
 *                         continue             # <<<<<<<<<<<<<<
 *                 else:
 *                     if curuser_missing:
 */
            goto __pyx_L4_continue;

            /* "pyreadstat/_readstat_writer.pyx":249
 *                     #equal = col.apply(lambda x: type(x) == curtype)
 *                     #if not np.all(equal):
 *                     if not equal:             # <<<<<<<<<<<<<<
 *                         max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 *                         result.append((PYWRITER_OBJECT, max_length, 1))
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":244
 *                 col = curseries.dropna().reset_index(drop=True)
 *                 is_missing = 1
 *                 if len(col):             # <<<<<<<<<<<<<<
 *                     curtype = type(col[0])
 *                     equal = check_series_all_same_types(col, curtype)
 */
          goto __pyx_L24;
        }

        /* "pyreadstat/_readstat_writer.pyx":254
 *                         continue
 *                 else:
 *                     if curuser_missing:             # <<<<<<<<<<<<<<
 *                         result.append((PYWRITER_DOUBLE, 0, 1))
 *                     else:
 */
        /*else*/ {
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_curuser_missing); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 254, __pyx_L1_error)
          if (__pyx_t_5) {

            /* "pyreadstat/_readstat_writer.pyx":255
 *                 else:
 *                     if curuser_missing:
 *                         result.append((PYWRITER_DOUBLE, 0, 1))             # <<<<<<<<<<<<<<
 *                     else:
 *                         result.append((PYWRITER_LOGICAL, 0, 1))
 */
            __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 255, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_8);
            PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
            __Pyx_INCREF(__pyx_int_0);
            __Pyx_GIVEREF(__pyx_int_0);
            PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
            __Pyx_INCREF(__pyx_int_1);
            __Pyx_GIVEREF(__pyx_int_1);
            PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_1);
            __pyx_t_8 = 0;
            __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 255, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

            /* "pyreadstat/_readstat_writer.pyx":254
 *                         continue
 *                 else:
 *                     if curuser_missing:             # <<<<<<<<<<<<<<
 *                         result.append((PYWRITER_DOUBLE, 0, 1))
 *                     else:
 */
            goto __pyx_L26;
          }

          /* "pyreadstat/_readstat_writer.pyx":257
 *                         result.append((PYWRITER_DOUBLE, 0, 1))
 *                     else:
 *                         result.append((PYWRITER_LOGICAL, 0, 1))             # <<<<<<<<<<<<<<
 *                     continue
 *             else:
 */
          /*else*/ {
            __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 257, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
            __Pyx_INCREF(__pyx_int_0);
            __Pyx_GIVEREF(__pyx_int_0);
            PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_0);
            __Pyx_INCREF(__pyx_int_1);
            __Pyx_GIVEREF(__pyx_int_1);
            PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1);
            __pyx_t_3 = 0;
            __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 257, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          }
          __pyx_L26:;

          /* "pyreadstat/_readstat_writer.pyx":258
 *                     else:
 *                         result.append((PYWRITER_LOGICAL, 0, 1))
 *                     continue             # <<<<<<<<<<<<<<
 *             else:
 *                 if col_type in int_mixed_types:
 */
          goto __pyx_L4_continue;
        }
        __pyx_L24:;

        /* "pyreadstat/_readstat_writer.pyx":238
 *                     result.append((PYWRITER_DOUBLE, 0, 1))
 *                     continue
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 if col_type in int_mixed_types:
 *                     result.append((PYWRITER_INTEGER, 0, 1))
 */
        goto __pyx_L22;
      }

      /* "pyreadstat/_readstat_writer.pyx":260
 *                     continue
 *             else:
 *                 if col_type in int_mixed_types:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_INTEGER, 0, 0))
 *                     continue
 */
      /*else*/ {
        if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 260, __pyx_L1_error)
        }
        __pyx_t_5 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 260, __pyx_L1_error)
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":261
 *             else:
 *                 if col_type in int_mixed_types:
 *                     result.append((PYWRITER_INTEGER, 0, 0))             # <<<<<<<<<<<<<<
 *                     continue
 *                 curtype = type(curseries.iloc[0])
 */
          __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 261, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 261, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0);
          __pyx_t_8 = 0;
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 261, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":262
 *                 if col_type in int_mixed_types:
 *                     result.append((PYWRITER_INTEGER, 0, 0))
 *                     continue             # <<<<<<<<<<<<<<
 *                 curtype = type(curseries.iloc[0])
 *                 equal = check_series_all_same_types(curseries, curtype)
 */
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":260
 *                     continue
 *             else:
 *                 if col_type in int_mixed_types:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_INTEGER, 0, 0))
 *                     continue
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":263
 *                     result.append((PYWRITER_INTEGER, 0, 0))
 *                     continue
 *                 curtype = type(curseries.iloc[0])             # <<<<<<<<<<<<<<
 *                 equal = check_series_all_same_types(curseries, curtype)
 *                 #equal = curseries.apply(lambda x: type(x) == curtype)
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_iloc); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 263, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_8)));
        __Pyx_XDECREF_SET(__pyx_v_curtype, ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_t_8))));
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pyreadstat/_readstat_writer.pyx":264
 *                     continue
 *                 curtype = type(curseries.iloc[0])
 *                 equal = check_series_all_same_types(curseries, curtype)             # <<<<<<<<<<<<<<
 *                 #equal = curseries.apply(lambda x: type(x) == curtype)
 *                 #if not np.all(equal):
 */
        __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_check_series_all_same_types(__pyx_v_curseries, ((PyObject *)__pyx_v_curtype)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L1_error)
        __pyx_v_equal = __pyx_t_4;

        /* "pyreadstat/_readstat_writer.pyx":267
 *                 #equal = curseries.apply(lambda x: type(x) == curtype)
 *                 #if not np.all(equal):
 *                 if not equal:             # <<<<<<<<<<<<<<
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *                     result.append((PYWRITER_OBJECT, max_length, 0))
 */
        __pyx_t_5 = (!(__pyx_v_equal != 0));
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":268
 *                 #if not np.all(equal):
 *                 if not equal:
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_OBJECT, max_length, 0))
 *                     continue
 */
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_astype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_9 = NULL;
          __pyx_t_4 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_3, function);
              __pyx_t_4 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_9, ((PyObject *)(&PyString_Type))};
            __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
            if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 268, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
          if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 268, __pyx_L1_error)
          }
          __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_3))) __PYX_ERR(0, 268, __pyx_L1_error)
          __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_t_8, ((PyObject*)__pyx_t_3)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 268, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_v_max_length = __pyx_t_4;

          /* "pyreadstat/_readstat_writer.pyx":269
 *                 if not equal:
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *                     result.append((PYWRITER_OBJECT, max_length, 0))             # <<<<<<<<<<<<<<
 *                     continue
 *             if curtype in int_types:
 */
          __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 269, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 269, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_int_0);
          __pyx_t_3 = 0;
          __pyx_t_8 = 0;
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 269, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "pyreadstat/_readstat_writer.pyx":270
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *                     result.append((PYWRITER_OBJECT, max_length, 0))
 *                     continue             # <<<<<<<<<<<<<<
 *             if curtype in int_types:
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))
 */
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":267
 *                 #equal = curseries.apply(lambda x: type(x) == curtype)
 *                 #if not np.all(equal):
 *                 if not equal:             # <<<<<<<<<<<<<<
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *                     result.append((PYWRITER_OBJECT, max_length, 0))
 */
        }
      }
      __pyx_L22:;

      /* "pyreadstat/_readstat_writer.pyx":271
 *                     result.append((PYWRITER_OBJECT, max_length, 0))
 *                     continue
 *             if curtype in int_types:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))
 *             elif curtype in float_types:
 */
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 271, __pyx_L1_error)
      }
      __pyx_t_5 = (__Pyx_PySet_ContainsTF(((PyObject *)__pyx_v_curtype), __pyx_v_10pyreadstat_16_readstat_writer_int_types, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 271, __pyx_L1_error)
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":272
 *                     continue
 *             if curtype in int_types:
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))             # <<<<<<<<<<<<<<
 *             elif curtype in float_types:
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))
 */
        __pyx_t_9 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 272, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 272, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
        __pyx_t_9 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 272, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":271
 *                     result.append((PYWRITER_OBJECT, max_length, 0))
 *                     continue
 *             if curtype in int_types:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))
 *             elif curtype in float_types:
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":273
 *             if curtype in int_types:
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))
 *             elif curtype in float_types:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))
 *             elif curtype == bool:
 */
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_float_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 273, __pyx_L1_error)
      }
      __pyx_t_5 = (__Pyx_PySet_ContainsTF(((PyObject *)__pyx_v_curtype), __pyx_v_10pyreadstat_16_readstat_writer_float_types, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 273, __pyx_L1_error)
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":274
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))
 *             elif curtype in float_types:
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))             # <<<<<<<<<<<<<<
 *             elif curtype == bool:
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 */
        __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_8);
        __pyx_t_3 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pyreadstat/_readstat_writer.pyx":273
 *             if curtype in int_types:
 *                 result.append((PYWRITER_INTEGER, 0, is_missing))
 *             elif curtype in float_types:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))
 *             elif curtype == bool:
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":275
 *             elif curtype in float_types:
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))
 *             elif curtype == bool:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 *             elif curtype == str:
 */
      __pyx_t_9 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), ((PyObject*)&PyBool_Type), Py_EQ); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 275, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 275, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":276
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))
 *             elif curtype == bool:
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))             # <<<<<<<<<<<<<<
 *             elif curtype == str:
 *                 if is_missing:
 */
        __pyx_t_9 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 276, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 276, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 276, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
        __pyx_t_9 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 276, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":275
 *             elif curtype in float_types:
 *                 result.append((PYWRITER_DOUBLE, 0, is_missing))
 *             elif curtype == bool:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 *             elif curtype == str:
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":277
 *             elif curtype == bool:
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 *             elif curtype == str:             # <<<<<<<<<<<<<<
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)
 */
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 277, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 277, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":278
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 *             elif curtype == str:
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col, variable_value_labels.get(col_name))
 */
        __pyx_t_5 = (__pyx_v_is_missing != 0);
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":279
 *             elif curtype == str:
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)             # <<<<<<<<<<<<<<
 *                     max_length = get_pandas_str_series_max_length(col, variable_value_labels.get(col_name))
 *                     max_length = max(1, max_length)
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_dropna); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 279, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = NULL;
          __pyx_t_4 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
              __pyx_t_4 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[1] = {__pyx_t_9, };
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 279, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          }
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_reset_index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 279, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 279, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_drop, Py_True) < 0) __PYX_ERR(0, 279, __pyx_L1_error)
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 279, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF_SET(__pyx_v_col, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "pyreadstat/_readstat_writer.pyx":280
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col, variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *                     max_length = max(1, max_length)
 *                 else:
 */
          if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 280, __pyx_L1_error)
          }
          __pyx_t_9 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 280, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (!(likely(PyDict_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_9))) __PYX_ERR(0, 280, __pyx_L1_error)
          __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_v_col, ((PyObject*)__pyx_t_9)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 280, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_v_max_length = __pyx_t_4;

          /* "pyreadstat/_readstat_writer.pyx":281
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col, variable_value_labels.get(col_name))
 *                     max_length = max(1, max_length)             # <<<<<<<<<<<<<<
 *                 else:
 *                     max_length = get_pandas_str_series_max_length(curseries, variable_value_labels.get(col_name))
 */
          __pyx_t_4 = __pyx_v_max_length;
          __pyx_t_17 = 1;
          if ((__pyx_t_4 > __pyx_t_17)) {
            __pyx_t_18 = __pyx_t_4;
          } else {
            __pyx_t_18 = __pyx_t_17;
          }
          __pyx_v_max_length = __pyx_t_18;

          /* "pyreadstat/_readstat_writer.pyx":278
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 *             elif curtype == str:
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col, variable_value_labels.get(col_name))
 */
          goto __pyx_L30;
        }

        /* "pyreadstat/_readstat_writer.pyx":283
 *                     max_length = max(1, max_length)
 *                 else:
 *                     max_length = get_pandas_str_series_max_length(curseries, variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_CHARACTER, max_length, is_missing))
 *             elif curtype == datetime.date:
 */
        /*else*/ {
          if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 283, __pyx_L1_error)
          }
          __pyx_t_9 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 283, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (!(likely(PyDict_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_9))) __PYX_ERR(0, 283, __pyx_L1_error)
          __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_v_curseries, ((PyObject*)__pyx_t_9)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 283, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_v_max_length = __pyx_t_4;
        }
        __pyx_L30:;

        /* "pyreadstat/_readstat_writer.pyx":284
 *                 else:
 *                     max_length = get_pandas_str_series_max_length(curseries, variable_value_labels.get(col_name))
 *                 result.append((PYWRITER_CHARACTER, max_length, is_missing))             # <<<<<<<<<<<<<<
 *             elif curtype == datetime.date:
 *                 result.append((PYWRITER_DATE, 0, is_missing))
 */
        __pyx_t_9 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_8);
        __pyx_t_9 = 0;
        __pyx_t_3 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "pyreadstat/_readstat_writer.pyx":277
 *             elif curtype == bool:
 *                 result.append((PYWRITER_LOGICAL, 0, is_missing))
 *             elif curtype == str:             # <<<<<<<<<<<<<<
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":285
 *                     max_length = get_pandas_str_series_max_length(curseries, variable_value_labels.get(col_name))
 *                 result.append((PYWRITER_CHARACTER, max_length, is_missing))
 *             elif curtype == datetime.date:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATE, 0, is_missing))
 *             elif curtype == datetime.datetime:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_datetime); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_date); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":286
 *                 result.append((PYWRITER_CHARACTER, max_length, is_missing))
 *             elif curtype == datetime.date:
 *                 result.append((PYWRITER_DATE, 0, is_missing))             # <<<<<<<<<<<<<<
 *             elif curtype == datetime.datetime:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 */
        __pyx_t_10 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 286, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 286, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
        __pyx_t_10 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 286, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":285
 *                     max_length = get_pandas_str_series_max_length(curseries, variable_value_labels.get(col_name))
 *                 result.append((PYWRITER_CHARACTER, max_length, is_missing))
 *             elif curtype == datetime.date:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATE, 0, is_missing))
 *             elif curtype == datetime.datetime:
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":287
 *             elif curtype == datetime.date:
 *                 result.append((PYWRITER_DATE, 0, is_missing))
 *             elif curtype == datetime.datetime:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *             elif curtype == datetime.time:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":288
 *                 result.append((PYWRITER_DATE, 0, is_missing))
 *             elif curtype == datetime.datetime:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))             # <<<<<<<<<<<<<<
 *             elif curtype == datetime.time:
 *                 result.append((PYWRITER_TIME, 0, is_missing))
 */
        __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 288, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 288, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_8);
        __pyx_t_3 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 288, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "pyreadstat/_readstat_writer.pyx":287
 *             elif curtype == datetime.date:
 *                 result.append((PYWRITER_DATE, 0, is_missing))
 *             elif curtype == datetime.datetime:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *             elif curtype == datetime.time:
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":289
 *             elif curtype == datetime.datetime:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *             elif curtype == datetime.time:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_TIME, 0, is_missing))
 *             else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_datetime); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":290
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *             elif curtype == datetime.time:
 *                 result.append((PYWRITER_TIME, 0, is_missing))             # <<<<<<<<<<<<<<
 *             else:
 *                 curseries = curseries.astype(str)
 */
        __pyx_t_10 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
        __pyx_t_10 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":289
 *             elif curtype == datetime.datetime:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *             elif curtype == datetime.time:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_TIME, 0, is_missing))
 *             else:
 */
        goto __pyx_L29;
      }

      /* "pyreadstat/_readstat_writer.pyx":292
 *                 result.append((PYWRITER_TIME, 0, is_missing))
 *             else:
 *                 curseries = curseries.astype(str)             # <<<<<<<<<<<<<<
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)
 */
      /*else*/ {
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_astype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_10 = NULL;
        __pyx_t_4 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_4 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_10, ((PyObject *)(&PyString_Type))};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_DECREF_SET(__pyx_v_curseries, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":293
 *             else:
 *                 curseries = curseries.astype(str)
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 */
        __pyx_t_5 = (__pyx_v_is_missing != 0);
        if (__pyx_t_5) {

          /* "pyreadstat/_readstat_writer.pyx":294
 *                 curseries = curseries.astype(str)
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)             # <<<<<<<<<<<<<<
 *                     max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 *                 else:
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_dropna); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 294, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_10 = NULL;
          __pyx_t_4 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
              __pyx_t_4 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[1] = {__pyx_t_10, };
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          }
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_reset_index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 294, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_drop, Py_True) < 0) __PYX_ERR(0, 294, __pyx_L1_error)
          __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 294, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF_SET(__pyx_v_col, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "pyreadstat/_readstat_writer.pyx":295
 *                 if is_missing:
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *                 else:
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 */
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_col, __pyx_n_s_astype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_8 = NULL;
          __pyx_t_4 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_3, function);
              __pyx_t_4 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_8, ((PyObject *)(&PyString_Type))};
            __pyx_t_10 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 295, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
          if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 295, __pyx_L1_error)
          }
          __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_3))) __PYX_ERR(0, 295, __pyx_L1_error)
          __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_t_10, ((PyObject*)__pyx_t_3)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 295, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_v_max_length = __pyx_t_4;

          /* "pyreadstat/_readstat_writer.pyx":293
 *             else:
 *                 curseries = curseries.astype(str)
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     col = curseries.dropna().reset_index(drop=True)
 *                     max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 */
          goto __pyx_L31;
        }

        /* "pyreadstat/_readstat_writer.pyx":297
 *                     max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name))
 *                 else:
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_OBJECT, max_length, is_missing))
 * 
 */
        /*else*/ {
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_astype); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 297, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_8 = NULL;
          __pyx_t_4 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
              __pyx_t_4 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_8, ((PyObject *)(&PyString_Type))};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 297, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          }
          if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 297, __pyx_L1_error)
          }
          __pyx_t_10 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 297, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          if (!(likely(PyDict_CheckExact(__pyx_t_10))||((__pyx_t_10) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_10))) __PYX_ERR(0, 297, __pyx_L1_error)
          __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_t_3, ((PyObject*)__pyx_t_10)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 297, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_v_max_length = __pyx_t_4;
        }
        __pyx_L31:;

        /* "pyreadstat/_readstat_writer.pyx":298
 *                 else:
 *                     max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *                 result.append((PYWRITER_OBJECT, max_length, is_missing))             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
        __pyx_t_10 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_8);
        __pyx_t_10 = 0;
        __pyx_t_3 = 0;
        __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_L29:;

      /* "pyreadstat/_readstat_writer.pyx":231
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, is_missing))
 *         elif col_type == object or col_type == 'string' or col_type in int_mixed_types:             # <<<<<<<<<<<<<<
 *             is_missing = 0
 *             if curuser_missing:
 */
      goto __pyx_L10;
    }

    /* "pyreadstat/_readstat_writer.pyx":302
 *         else:
 *             # generic object
 *             max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))             # <<<<<<<<<<<<<<
 *             is_missing = 0
 *             if np.any(pd.isna(curseries)):
 */
    /*else*/ {
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_n_s_astype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_3, ((PyObject *)(&PyString_Type))};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 302, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 302, __pyx_L1_error)
      }
      __pyx_t_8 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (!(likely(PyDict_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_8))) __PYX_ERR(0, 302, __pyx_L1_error)
      __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length(__pyx_t_9, ((PyObject*)__pyx_t_8)); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_v_max_length = __pyx_t_4;

      /* "pyreadstat/_readstat_writer.pyx":303
 *             # generic object
 *             max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *             is_missing = 0             # <<<<<<<<<<<<<<
 *             if np.any(pd.isna(curseries)):
 *                 is_missing = 1
 */
      __pyx_v_is_missing = 0;

      /* "pyreadstat/_readstat_writer.pyx":304
 *             max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *             is_missing = 0
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 is_missing = 1
 *             result.append((PYWRITER_OBJECT, max_length, is_missing))
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 304, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_any); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 304, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pd); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 304, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_isna); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 304, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_v_curseries};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 304, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __pyx_t_13 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_4 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_9};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 304, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 304, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_5) {

        /* "pyreadstat/_readstat_writer.pyx":305
 *             is_missing = 0
 *             if np.any(pd.isna(curseries)):
 *                 is_missing = 1             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_OBJECT, max_length, is_missing))
 *     return result
 */
        __pyx_v_is_missing = 1;

        /* "pyreadstat/_readstat_writer.pyx":304
 *             max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name))
 *             is_missing = 0
 *             if np.any(pd.isna(curseries)):             # <<<<<<<<<<<<<<
 *                 is_missing = 1
 *             result.append((PYWRITER_OBJECT, max_length, is_missing))
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":306
 *             if np.any(pd.isna(curseries)):
 *                 is_missing = 1
 *             result.append((PYWRITER_OBJECT, max_length, is_missing))             # <<<<<<<<<<<<<<
 *     return result
 * 
 */
      __pyx_t_8 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 306, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 306, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_is_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 306, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 306, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_9);
      __pyx_t_8 = 0;
      __pyx_t_3 = 0;
      __pyx_t_9 = 0;
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 306, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    }
    __pyx_L10:;

    /* "pyreadstat/_readstat_writer.pyx":199
 *         variable_value_labels = dict()
 * 
 *     for indx, (col_name, col_type) in enumerate(zip(columns, types)):             # <<<<<<<<<<<<<<
 * 
 *         max_length = 0
 */
    __pyx_L4_continue:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":307
 *                 is_missing = 1
 *             result.append((PYWRITER_OBJECT, max_length, is_missing))
 *     return result             # <<<<<<<<<<<<<<
 * 
 * cdef readstat_label_set_t *set_value_label(readstat_writer_t *writer, dict value_labels, str labelset_name,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":181
 * 
 * 
 * cdef list get_pandas_column_types(object df, dict missing_user_values, dict variable_value_labels):             # <<<<<<<<<<<<<<
 *     """
 *     From a pandas data frame, get a list with tuples column types as first element, max_length as second and is_missing
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.get_pandas_column_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_types);
  __Pyx_XDECREF(__pyx_v_columns);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_indx);
  __Pyx_XDECREF(__pyx_v_col_name);
  __Pyx_XDECREF(__pyx_v_col_type);
  __Pyx_XDECREF(__pyx_v_curseries);
  __Pyx_XDECREF(__pyx_v_curuser_missing);
  __Pyx_XDECREF(__pyx_v_col);
  __Pyx_XDECREF((PyObject *)__pyx_v_curtype);
  __Pyx_XDECREF(__pyx_v_variable_value_labels);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":309
 *     return result
 * 
 * cdef readstat_label_set_t *set_value_label(readstat_writer_t *writer, dict value_labels, str labelset_name,             # <<<<<<<<<<<<<<
 *                         pywriter_variable_type curpytype, dst_file_format file_format, str variable_name,
 *                         list user_missing_tags) except *:
 */

static readstat_label_set_t *__pyx_f_10pyreadstat_16_readstat_writer_set_value_label(readstat_writer_t *__pyx_v_writer, PyObject *__pyx_v_value_labels, PyObject *__pyx_v_labelset_name, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_v_curpytype, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, PyObject *__pyx_v_variable_name, PyObject *__pyx_v_user_missing_tags) {
  readstat_label_set_t *__pyx_v_label_set;
  readstat_type_t __pyx_v_curtype;
  double __pyx_v_double_val;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_label = NULL;
  PyObject *__pyx_v_msg = NULL;
  readstat_label_set_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  readstat_type_t __pyx_t_3;
  char const *__pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  long __pyx_t_14;
  char const *__pyx_t_15;
  double __pyx_t_16;
  char const *__pyx_t_17;
  int32_t __pyx_t_18;
  char const *__pyx_t_19;
  char const *__pyx_t_20;
  char const *__pyx_t_21;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_value_label", 0);

  /* "pyreadstat/_readstat_writer.pyx":320
 *     cdef double double_val
 * 
 *     curtype = pandas_to_readstat_types[curpytype]             # <<<<<<<<<<<<<<
 *     label_set = readstat_add_label_set(writer, curtype, labelset_name.encode("utf-8"))
 * 
 */
  if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 320, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curpytype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((readstat_type_t)__Pyx_PyInt_As_readstat_type_t(__pyx_t_2)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_curtype = __pyx_t_3;

  /* "pyreadstat/_readstat_writer.pyx":321
 * 
 *     curtype = pandas_to_readstat_types[curpytype]
 *     label_set = readstat_add_label_set(writer, curtype, labelset_name.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *     for value, label in value_labels.items():
 */
  __pyx_t_2 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_labelset_name, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L1_error)
  __pyx_v_label_set = readstat_add_label_set(__pyx_v_writer, __pyx_v_curtype, __pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":323
 *     label_set = readstat_add_label_set(writer, curtype, labelset_name.encode("utf-8"))
 * 
 *     for value, label in value_labels.items():             # <<<<<<<<<<<<<<
 * 
 *         if type(label) != str:
 */
  if (unlikely(__pyx_v_value_labels == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items");
    __PYX_ERR(0, 323, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_value_labels); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 323, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 323, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 323, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 323, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 323, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      #else
      __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_9);
      index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 323, __pyx_L1_error)
      __pyx_t_10 = NULL;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 323, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_label, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "pyreadstat/_readstat_writer.pyx":325
 *     for value, label in value_labels.items():
 * 
 *         if type(label) != str:             # <<<<<<<<<<<<<<
 *             msg = "variable_value_labels: type of Label %s in variable %s must be string" % (str(label), variable_name)
 *             raise PyreadstatError(msg)
 */
    __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_label)), ((PyObject *)(&PyString_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error)
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 325, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(__pyx_t_11)) {

      /* "pyreadstat/_readstat_writer.pyx":326
 * 
 *         if type(label) != str:
 *             msg = "variable_value_labels: type of Label %s in variable %s must be string" % (str(label), variable_name)             # <<<<<<<<<<<<<<
 *             raise PyreadstatError(msg)
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_Str(__pyx_v_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
      __Pyx_INCREF(__pyx_v_variable_name);
      __Pyx_GIVEREF(__pyx_v_variable_name);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_variable_name);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_variable_value_labels_type_of_La, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_v_msg = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":327
 *         if type(label) != str:
 *             msg = "variable_value_labels: type of Label %s in variable %s must be string" % (str(label), variable_name)
 *             raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *         if user_missing_tags and value in user_missing_tags:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 327, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_ERR(0, 327, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":325
 *     for value, label in value_labels.items():
 * 
 *         if type(label) != str:             # <<<<<<<<<<<<<<
 *             msg = "variable_value_labels: type of Label %s in variable %s must be string" % (str(label), variable_name)
 *             raise PyreadstatError(msg)
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":329
 *             raise PyreadstatError(msg)
 * 
 *         if user_missing_tags and value in user_missing_tags:             # <<<<<<<<<<<<<<
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name
 */
    __pyx_t_13 = (__pyx_v_user_missing_tags != Py_None)&&(PyList_GET_SIZE(__pyx_v_user_missing_tags) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_11 = __pyx_t_13;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_13 = (__Pyx_PySequence_ContainsTF(__pyx_v_value, __pyx_v_user_missing_tags, Py_EQ)); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 329, __pyx_L1_error)
    __pyx_t_11 = __pyx_t_13;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_11) {

      /* "pyreadstat/_readstat_writer.pyx":330
 * 
 *         if user_missing_tags and value in user_missing_tags:
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name
 *                 raise PyreadstatError(msg)
 */
      switch (__pyx_v_curpytype) {
        case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER:
        case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT:

        /* "pyreadstat/_readstat_writer.pyx":331
 *         if user_missing_tags and value in user_missing_tags:
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 * 
 */
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_missing_user_values_not_allowed, __pyx_v_variable_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 331, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_v_msg = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":332
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *             readstat_label_tagged_value(label_set, ord(value), label.encode("utf-8"))
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 332, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_12 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 332, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 332, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":330
 * 
 *         if user_missing_tags and value in user_missing_tags:
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name
 *                 raise PyreadstatError(msg)
 */
        break;
        default: break;
      }

      /* "pyreadstat/_readstat_writer.pyx":334
 *                 raise PyreadstatError(msg)
 * 
 *             readstat_label_tagged_value(label_set, ord(value), label.encode("utf-8"))             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
      __pyx_t_14 = __Pyx_PyObject_Ord(__pyx_v_value); if (unlikely(__pyx_t_14 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 334, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_label, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 334, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_s_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_t_15 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) __PYX_ERR(0, 334, __pyx_L1_error)
      readstat_label_tagged_value(__pyx_v_label_set, __pyx_t_14, __pyx_t_15);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":335
 * 
 *             readstat_label_tagged_value(label_set, ord(value), label.encode("utf-8"))
 *             continue             # <<<<<<<<<<<<<<
 * 
 * 
 */
      goto __pyx_L3_continue;

      /* "pyreadstat/_readstat_writer.pyx":329
 *             raise PyreadstatError(msg)
 * 
 *         if user_missing_tags and value in user_missing_tags:             # <<<<<<<<<<<<<<
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":338
 * 
 * 
 *         if curpytype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *             if type(value) not in numeric_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 */
    switch (__pyx_v_curpytype) {
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE:

      /* "pyreadstat/_readstat_writer.pyx":339
 * 
 *         if curpytype == PYWRITER_DOUBLE:
 *             if type(value) not in numeric_types:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_numeric_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 339, __pyx_L1_error)
      }
      __pyx_t_11 = (__Pyx_PySet_ContainsTF(((PyObject *)Py_TYPE(__pyx_v_value)), __pyx_v_10pyreadstat_16_readstat_writer_numeric_types, Py_NE)); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 339, __pyx_L1_error)
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":340
 *         if curpytype == PYWRITER_DOUBLE:
 *             if type(value) not in numeric_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             readstat_label_double_value(label_set, value, label.encode("utf-8"))
 */
        __pyx_t_2 = __Pyx_PyObject_Str(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 340, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
        __Pyx_INCREF(__pyx_v_variable_name);
        __Pyx_GIVEREF(__pyx_v_variable_name);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_variable_name);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_variable_value_labels_type_of_Va, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_v_msg = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":341
 *             if type(value) not in numeric_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             readstat_label_double_value(label_set, value, label.encode("utf-8"))
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 341, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_12 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 341, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":339
 * 
 *         if curpytype == PYWRITER_DOUBLE:
 *             if type(value) not in numeric_types:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":342
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 *             readstat_label_double_value(label_set, value, label.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *         elif curpytype == PYWRITER_INTEGER:
 */
      __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 342, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_label, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 342, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_s_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 342, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_t_17 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 342, __pyx_L1_error)
      readstat_label_double_value(__pyx_v_label_set, __pyx_t_16, __pyx_t_17);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":338
 * 
 * 
 *         if curpytype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *             if type(value) not in numeric_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 */
      break;
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER:

      /* "pyreadstat/_readstat_writer.pyx":345
 * 
 *         elif curpytype == PYWRITER_INTEGER:
 *             if type(value) not in int_types:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 345, __pyx_L1_error)
      }
      __pyx_t_11 = (__Pyx_PySet_ContainsTF(((PyObject *)Py_TYPE(__pyx_v_value)), __pyx_v_10pyreadstat_16_readstat_writer_int_types, Py_NE)); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 345, __pyx_L1_error)
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":346
 *         elif curpytype == PYWRITER_INTEGER:
 *             if type(value) not in int_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name)             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             readstat_label_int32_value(label_set, value, label.encode("utf-8"))
 */
        __pyx_t_2 = __Pyx_PyObject_Str(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
        __Pyx_INCREF(__pyx_v_variable_name);
        __Pyx_GIVEREF(__pyx_v_variable_name);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_variable_name);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_variable_value_labels_type_of_Va_2, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_v_msg = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":347
 *             if type(value) not in int_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             readstat_label_int32_value(label_set, value, label.encode("utf-8"))
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_12 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 347, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":345
 * 
 *         elif curpytype == PYWRITER_INTEGER:
 *             if type(value) not in int_types:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":348
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 *             readstat_label_int32_value(label_set, value, label.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *         elif curpytype == PYWRITER_LOGICAL:
 */
      __pyx_t_18 = __Pyx_PyInt_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_18 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_label, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 348, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_s_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 348, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error)
      readstat_label_int32_value(__pyx_v_label_set, __pyx_t_18, __pyx_t_19);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":344
 *             readstat_label_double_value(label_set, value, label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_INTEGER:             # <<<<<<<<<<<<<<
 *             if type(value) not in int_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name)
 */
      break;
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL:

      /* "pyreadstat/_readstat_writer.pyx":351
 * 
 *         elif curpytype == PYWRITER_LOGICAL:
 *             if type(value) != bool and (value != 0 and value != 1):             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_value)), ((PyObject*)&PyBool_Type), Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error)
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 351, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_13) {
      } else {
        __pyx_t_11 = __pyx_t_13;
        goto __pyx_L14_bool_binop_done;
      }
      __pyx_t_13 = (__Pyx_PyInt_BoolNeObjC(__pyx_v_value, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 351, __pyx_L1_error)
      if (__pyx_t_13) {
      } else {
        __pyx_t_11 = __pyx_t_13;
        goto __pyx_L14_bool_binop_done;
      }
      __pyx_t_13 = (__Pyx_PyInt_BoolNeObjC(__pyx_v_value, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 351, __pyx_L1_error)
      __pyx_t_11 = __pyx_t_13;
      __pyx_L14_bool_binop_done:;
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":352
 *         elif curpytype == PYWRITER_LOGICAL:
 *             if type(value) != bool and (value != 0 and value != 1):
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0" % (str(value), variable_name)             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))
 */
        __pyx_t_2 = __Pyx_PyObject_Str(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
        __Pyx_INCREF(__pyx_v_variable_name);
        __Pyx_GIVEREF(__pyx_v_variable_name);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_variable_name);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_variable_value_labels_type_of_Va_3, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_v_msg = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":353
 *             if type(value) != bool and (value != 0 and value != 1):
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 353, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_12 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 353, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":351
 * 
 *         elif curpytype == PYWRITER_LOGICAL:
 *             if type(value) != bool and (value != 0 and value != 1):             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":354
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 */
      __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_18 = __Pyx_PyInt_As_int32_t(__pyx_t_2); if (unlikely((__pyx_t_18 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 354, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_label, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 354, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_s_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 354, __pyx_L1_error)
      readstat_label_int32_value(__pyx_v_label_set, __pyx_t_18, __pyx_t_19);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":350
 *             readstat_label_int32_value(label_set, value, label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_LOGICAL:             # <<<<<<<<<<<<<<
 *             if type(value) != bool and (value != 0 and value != 1):
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be boolean or be 1 or 0" % (str(value), variable_name)
 */
      break;
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER:

      /* "pyreadstat/_readstat_writer.pyx":356
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *             value = str(value)
 *             readstat_label_string_value(label_set, value.encode("utf-8"), label.encode("utf-8"))
 */
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT:

      /* "pyreadstat/_readstat_writer.pyx":357
 * 
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 *             value = str(value)             # <<<<<<<<<<<<<<
 *             readstat_label_string_value(label_set, value.encode("utf-8"), label.encode("utf-8"))
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_Str(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":358
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:
 *             value = str(value)
 *             readstat_label_string_value(label_set, value.encode("utf-8"), label.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US):
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_s_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __pyx_t_20 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) __PYX_ERR(0, 358, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_label, __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_kp_s_utf_8};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_t_21 = __Pyx_PyObject_AsString(__pyx_t_8); if (unlikely((!__pyx_t_21) && PyErr_Occurred())) __PYX_ERR(0, 358, __pyx_L1_error)
      readstat_label_string_value(__pyx_v_label_set, __pyx_t_20, __pyx_t_21);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":356
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *             value = str(value)
 *             readstat_label_string_value(label_set, value.encode("utf-8"), label.encode("utf-8"))
 */
      break;
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE:

      /* "pyreadstat/_readstat_writer.pyx":360
 *             readstat_label_string_value(label_set, value.encode("utf-8"), label.encode("utf-8"))
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US):             # <<<<<<<<<<<<<<
 *             if type(value) not in nat_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)
 */
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME:
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME:
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS:
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US:

      /* "pyreadstat/_readstat_writer.pyx":361
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US):
 *             if type(value) not in nat_types:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_nat_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 361, __pyx_L1_error)
      }
      __pyx_t_11 = (__Pyx_PySet_ContainsTF(((PyObject *)Py_TYPE(__pyx_v_value)), __pyx_v_10pyreadstat_16_readstat_writer_nat_types, Py_NE)); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 361, __pyx_L1_error)
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":362
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US):
 *             if type(value) not in nat_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             double_val = convert_datetimelike_to_number(file_format, curpytype, value)
 */
        __pyx_t_8 = __Pyx_PyObject_Str(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8);
        __Pyx_INCREF(__pyx_v_variable_name);
        __Pyx_GIVEREF(__pyx_v_variable_name);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_variable_name);
        __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_variable_value_labels_type_of_Va_4, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_msg = __pyx_t_8;
        __pyx_t_8 = 0;

        /* "pyreadstat/_readstat_writer.pyx":363
 *             if type(value) not in nat_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             double_val = convert_datetimelike_to_number(file_format, curpytype, value)
 *             readstat_label_double_value(label_set, double_val, label.encode("utf-8"))
 */
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_12 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 363, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __PYX_ERR(0, 363, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":361
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US):
 *             if type(value) not in nat_types:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":364
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
 *             double_val = convert_datetimelike_to_number(file_format, curpytype, value)             # <<<<<<<<<<<<<<
 *             readstat_label_double_value(label_set, double_val, label.encode("utf-8"))
 * 
 */
      __pyx_t_16 = __pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number(__pyx_v_file_format, __pyx_v_curpytype, __pyx_v_value); if (unlikely(__pyx_t_16 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 364, __pyx_L1_error)
      __pyx_v_double_val = __pyx_t_16;

      /* "pyreadstat/_readstat_writer.pyx":365
 *                 raise PyreadstatError(msg)
 *             double_val = convert_datetimelike_to_number(file_format, curpytype, value)
 *             readstat_label_double_value(label_set, double_val, label.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *     return label_set
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_label, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_12 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_s_utf_8};
        __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 365, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __pyx_t_17 = __Pyx_PyObject_AsString(__pyx_t_8); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 365, __pyx_L1_error)
      readstat_label_double_value(__pyx_v_label_set, __pyx_v_double_val, __pyx_t_17);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":360
 *             readstat_label_string_value(label_set, value.encode("utf-8"), label.encode("utf-8"))
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US):             # <<<<<<<<<<<<<<
 *             if type(value) not in nat_types:
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name)
 */
      break;
      default: break;
    }

    /* "pyreadstat/_readstat_writer.pyx":323
 *     label_set = readstat_add_label_set(writer, curtype, labelset_name.encode("utf-8"))
 * 
 *     for value, label in value_labels.items():             # <<<<<<<<<<<<<<
 * 
 *         if type(label) != str:
 */
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":367
 *             readstat_label_double_value(label_set, double_val, label.encode("utf-8"))
 * 
 *     return label_set             # <<<<<<<<<<<<<<
 * 
 * cdef void add_missing_ranges(list cur_ranges, readstat_variable_t *variable, pywriter_variable_type vartype, str variablename) except *:
 */
  __pyx_r = __pyx_v_label_set;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":309
 *     return result
 * 
 * cdef readstat_label_set_t *set_value_label(readstat_writer_t *writer, dict value_labels, str labelset_name,             # <<<<<<<<<<<<<<
 *                         pywriter_variable_type curpytype, dst_file_format file_format, str variable_name,
 *                         list user_missing_tags) except *:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.set_value_label", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_label);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":369
 *     return label_set
 * 
 * cdef void add_missing_ranges(list cur_ranges, readstat_variable_t *variable, pywriter_variable_type vartype, str variablename) except *:             # <<<<<<<<<<<<<<
 *     """
 *     Adding missing ranges, user defined missing discrete values both numeric and character,
 */

static void __pyx_f_10pyreadstat_16_readstat_writer_add_missing_ranges(PyObject *__pyx_v_cur_ranges, readstat_variable_t *__pyx_v_variable, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_v_vartype, PyObject *__pyx_v_variablename) {
  int __pyx_v_range_values;
  int __pyx_v_discrete_values;
  int __pyx_v_discrete_strings;
  PyObject *__pyx_v_cur_range = NULL;
  PyObject *__pyx_v_hi = NULL;
  PyObject *__pyx_v_lo = NULL;
  PyObject *__pyx_v_msg = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  double __pyx_t_9;
  double __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  char const *__pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_missing_ranges", 0);

  /* "pyreadstat/_readstat_writer.pyx":375
 *     """
 * 
 *     cdef int range_values = 0             # <<<<<<<<<<<<<<
 *     cdef int discrete_values = 0
 *     cdef int discrete_strings = 0
 */
  __pyx_v_range_values = 0;

  /* "pyreadstat/_readstat_writer.pyx":376
 * 
 *     cdef int range_values = 0
 *     cdef int discrete_values = 0             # <<<<<<<<<<<<<<
 *     cdef int discrete_strings = 0
 * 
 */
  __pyx_v_discrete_values = 0;

  /* "pyreadstat/_readstat_writer.pyx":377
 *     cdef int range_values = 0
 *     cdef int discrete_values = 0
 *     cdef int discrete_strings = 0             # <<<<<<<<<<<<<<
 * 
 *     for cur_range in cur_ranges:
 */
  __pyx_v_discrete_strings = 0;

  /* "pyreadstat/_readstat_writer.pyx":379
 *     cdef int discrete_strings = 0
 * 
 *     for cur_range in cur_ranges:             # <<<<<<<<<<<<<<
 *         if isinstance(cur_range, dict):
 *             hi = cur_range.get("hi")
 */
  if (unlikely(__pyx_v_cur_ranges == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 379, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_cur_ranges; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 379, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_cur_range, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyreadstat/_readstat_writer.pyx":380
 * 
 *     for cur_range in cur_ranges:
 *         if isinstance(cur_range, dict):             # <<<<<<<<<<<<<<
 *             hi = cur_range.get("hi")
 *             lo = cur_range.get("lo")
 */
    __pyx_t_4 = PyDict_Check(__pyx_v_cur_range); 
    if (__pyx_t_4) {

      /* "pyreadstat/_readstat_writer.pyx":381
 *     for cur_range in cur_ranges:
 *         if isinstance(cur_range, dict):
 *             hi = cur_range.get("hi")             # <<<<<<<<<<<<<<
 *             lo = cur_range.get("lo")
 *             if hi is None or lo is None:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_cur_range, __pyx_n_s_get); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 381, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      __pyx_t_7 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_7 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_n_s_hi};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_XDECREF_SET(__pyx_v_hi, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyreadstat/_readstat_writer.pyx":382
 *         if isinstance(cur_range, dict):
 *             hi = cur_range.get("hi")
 *             lo = cur_range.get("lo")             # <<<<<<<<<<<<<<
 *             if hi is None or lo is None:
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_cur_range, __pyx_n_s_get); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 382, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      __pyx_t_7 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_7 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_n_s_lo};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_XDECREF_SET(__pyx_v_lo, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyreadstat/_readstat_writer.pyx":383
 *             hi = cur_range.get("hi")
 *             lo = cur_range.get("lo")
 *             if hi is None or lo is None:             # <<<<<<<<<<<<<<
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)
 */
      __pyx_t_8 = (__pyx_v_hi == Py_None);
      if (!__pyx_t_8) {
      } else {
        __pyx_t_4 = __pyx_t_8;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_8 = (__pyx_v_lo == Py_None);
      __pyx_t_4 = __pyx_t_8;
      __pyx_L7_bool_binop_done:;
      if (unlikely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":384
 *             lo = cur_range.get("lo")
 *             if hi is None or lo is None:
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:
 */
        __Pyx_INCREF(__pyx_kp_s_dictionaries_in_missing_ranges_m);
        __pyx_v_msg = __pyx_kp_s_dictionaries_in_missing_ranges_m;

        /* "pyreadstat/_readstat_writer.pyx":385
 *             if hi is None or lo is None:
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 385, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_7 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 385, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 385, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":383
 *             hi = cur_range.get("hi")
 *             lo = cur_range.get("lo")
 *             if hi is None or lo is None:             # <<<<<<<<<<<<<<
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":386
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:             # <<<<<<<<<<<<<<
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 */
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_numeric_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 386, __pyx_L1_error)
      }
      __pyx_t_8 = (__Pyx_PySet_ContainsTF(((PyObject *)Py_TYPE(__pyx_v_hi)), __pyx_v_10pyreadstat_16_readstat_writer_numeric_types, Py_EQ)); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 386, __pyx_L1_error)
      if (__pyx_t_8) {
      } else {
        __pyx_t_4 = __pyx_t_8;
        goto __pyx_L10_bool_binop_done;
      }
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_numeric_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 386, __pyx_L1_error)
      }
      __pyx_t_8 = (__Pyx_PySet_ContainsTF(((PyObject *)Py_TYPE(__pyx_v_lo)), __pyx_v_10pyreadstat_16_readstat_writer_numeric_types, Py_EQ)); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 386, __pyx_L1_error)
      __pyx_t_4 = __pyx_t_8;
      __pyx_L10_bool_binop_done:;
      if (__pyx_t_4) {

        /* "pyreadstat/_readstat_writer.pyx":387
 *                 raise PyreadstatError(msg)
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:             # <<<<<<<<<<<<<<
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_vartype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 387, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 387, __pyx_L1_error)
        }
        __pyx_t_4 = (__Pyx_PySet_ContainsTF(__pyx_t_3, __pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types, Py_NE)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 387, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":388
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename             # <<<<<<<<<<<<<<
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:
 */
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_numeric_missing_ranges_value_giv, __pyx_v_variablename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_msg = __pyx_t_3;
          __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":389
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                 if hi == lo:
 *                     check_exit_status(readstat_variable_add_missing_double_value(variable, hi))
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 389, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = NULL;
          __pyx_t_7 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_7 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 389, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 389, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":387
 *                 raise PyreadstatError(msg)
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:             # <<<<<<<<<<<<<<
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":390
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_variable_add_missing_double_value(variable, hi))
 *                     discrete_values += 1
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_hi, __pyx_v_lo, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":391
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:
 *                     check_exit_status(readstat_variable_add_missing_double_value(variable, hi))             # <<<<<<<<<<<<<<
 *                     discrete_values += 1
 *                 else:
 */
          __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_hi); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 391, __pyx_L1_error)
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_double_value(__pyx_v_variable, __pyx_t_9)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 391, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":392
 *                 if hi == lo:
 *                     check_exit_status(readstat_variable_add_missing_double_value(variable, hi))
 *                     discrete_values += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     check_exit_status(readstat_variable_add_missing_double_range(variable, lo, hi))
 */
          __pyx_v_discrete_values = (__pyx_v_discrete_values + 1);

          /* "pyreadstat/_readstat_writer.pyx":390
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_variable_add_missing_double_value(variable, hi))
 *                     discrete_values += 1
 */
          goto __pyx_L13;
        }

        /* "pyreadstat/_readstat_writer.pyx":394
 *                     discrete_values += 1
 *                 else:
 *                     check_exit_status(readstat_variable_add_missing_double_range(variable, lo, hi))             # <<<<<<<<<<<<<<
 *                     range_values += 1
 *             elif type(hi) == str and type(lo) == str:
 */
        /*else*/ {
          __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_lo); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L1_error)
          __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_hi); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L1_error)
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_double_range(__pyx_v_variable, __pyx_t_9, __pyx_t_10)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":395
 *                 else:
 *                     check_exit_status(readstat_variable_add_missing_double_range(variable, lo, hi))
 *                     range_values += 1             # <<<<<<<<<<<<<<
 *             elif type(hi) == str and type(lo) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 */
          __pyx_v_range_values = (__pyx_v_range_values + 1);
        }
        __pyx_L13:;

        /* "pyreadstat/_readstat_writer.pyx":386
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)
 *             if type(hi) in numeric_types  and type(lo) in numeric_types:             # <<<<<<<<<<<<<<
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 */
        goto __pyx_L9;
      }

      /* "pyreadstat/_readstat_writer.pyx":396
 *                     check_exit_status(readstat_variable_add_missing_double_range(variable, lo, hi))
 *                     range_values += 1
 *             elif type(hi) == str and type(lo) == str:             # <<<<<<<<<<<<<<
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 */
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_hi)), ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 396, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 396, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_8) {
      } else {
        __pyx_t_4 = __pyx_t_8;
        goto __pyx_L14_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_lo)), ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 396, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 396, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_4 = __pyx_t_8;
      __pyx_L14_bool_binop_done:;
      if (likely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":397
 *                     range_values += 1
 *             elif type(hi) == str and type(lo) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        switch (__pyx_v_vartype) {
          case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER:
          case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT:
          __pyx_t_4 = 0;
          break;
          default:
          __pyx_t_4 = 1;
          break;
        }
        if (unlikely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":398
 *             elif type(hi) == str and type(lo) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename             # <<<<<<<<<<<<<<
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:
 */
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_character_missing_ranges_value_g, __pyx_v_variablename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_msg = __pyx_t_3;
          __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":399
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                 if hi == lo:
 *                     if len(hi) > 8:
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 399, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = NULL;
          __pyx_t_7 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_7 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 399, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 399, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":397
 *                     range_values += 1
 *             elif type(hi) == str and type(lo) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":400
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:             # <<<<<<<<<<<<<<
 *                     if len(hi) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_hi, __pyx_v_lo, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 400, __pyx_L1_error)
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 400, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (likely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":401
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:
 *                     if len(hi) > 8:             # <<<<<<<<<<<<<<
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)
 */
          __pyx_t_11 = PyObject_Length(__pyx_v_hi); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 401, __pyx_L1_error)
          __pyx_t_4 = (__pyx_t_11 > 8);
          if (unlikely(__pyx_t_4)) {

            /* "pyreadstat/_readstat_writer.pyx":402
 *                 if hi == lo:
 *                     if len(hi) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"             # <<<<<<<<<<<<<<
 *                         raise PyreadstatError(msg)
 *                     check_exit_status(readstat_variable_add_missing_string_value(variable, hi))#.encode("utf-8")))
 */
            __Pyx_INCREF(__pyx_kp_s_missing_ranges_string_values_len);
            __pyx_v_msg = __pyx_kp_s_missing_ranges_string_values_len;

            /* "pyreadstat/_readstat_writer.pyx":403
 *                     if len(hi) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_variable_add_missing_string_value(variable, hi))#.encode("utf-8")))
 *                     discrete_strings += 1
 */
            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 403, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_6 = NULL;
            __pyx_t_7 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_6)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_6);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
                __pyx_t_7 = 1;
              }
            }
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
              __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 403, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            }
            __Pyx_Raise(__pyx_t_3, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __PYX_ERR(0, 403, __pyx_L1_error)

            /* "pyreadstat/_readstat_writer.pyx":401
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:
 *                     if len(hi) > 8:             # <<<<<<<<<<<<<<
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":404
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)
 *                     check_exit_status(readstat_variable_add_missing_string_value(variable, hi))#.encode("utf-8")))             # <<<<<<<<<<<<<<
 *                     discrete_strings += 1
 *                 else:
 */
          __pyx_t_12 = __Pyx_PyObject_AsString(__pyx_v_hi); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 404, __pyx_L1_error)
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_string_value(__pyx_v_variable, __pyx_t_12)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 404, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":405
 *                         raise PyreadstatError(msg)
 *                     check_exit_status(readstat_variable_add_missing_string_value(variable, hi))#.encode("utf-8")))
 *                     discrete_strings += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     #check_exit_status(readstat_variable_add_missing_string_range(variable, lo, hi))
 */
          __pyx_v_discrete_strings = (__pyx_v_discrete_strings + 1);

          /* "pyreadstat/_readstat_writer.pyx":400
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:             # <<<<<<<<<<<<<<
 *                     if len(hi) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 */
          goto __pyx_L17;
        }

        /* "pyreadstat/_readstat_writer.pyx":408
 *                 else:
 *                     #check_exit_status(readstat_variable_add_missing_string_range(variable, lo, hi))
 *                     msg = "missing_ranges: hi and lo values must be both the same for string type"             # <<<<<<<<<<<<<<
 *                     raise PyreadstatError(msg)
 *             else:
 */
        /*else*/ {
          __Pyx_INCREF(__pyx_kp_s_missing_ranges_hi_and_lo_values);
          __pyx_v_msg = __pyx_kp_s_missing_ranges_hi_and_lo_values;

          /* "pyreadstat/_readstat_writer.pyx":409
 *                     #check_exit_status(readstat_variable_add_missing_string_range(variable, lo, hi))
 *                     msg = "missing_ranges: hi and lo values must be both the same for string type"
 *                     raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             else:
 *                 msg = "missing_ranges: hi and lo values must be both either of numeric or string type"
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 409, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = NULL;
          __pyx_t_7 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_7 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 409, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 409, __pyx_L1_error)
        }
        __pyx_L17:;

        /* "pyreadstat/_readstat_writer.pyx":396
 *                     check_exit_status(readstat_variable_add_missing_double_range(variable, lo, hi))
 *                     range_values += 1
 *             elif type(hi) == str and type(lo) == str:             # <<<<<<<<<<<<<<
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 */
        goto __pyx_L9;
      }

      /* "pyreadstat/_readstat_writer.pyx":411
 *                     raise PyreadstatError(msg)
 *             else:
 *                 msg = "missing_ranges: hi and lo values must be both either of numeric or string type"             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *         else:
 */
      /*else*/ {
        __Pyx_INCREF(__pyx_kp_s_missing_ranges_hi_and_lo_values_2);
        __pyx_v_msg = __pyx_kp_s_missing_ranges_hi_and_lo_values_2;

        /* "pyreadstat/_readstat_writer.pyx":412
 *             else:
 *                 msg = "missing_ranges: hi and lo values must be both either of numeric or string type"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *         else:
 *             if type(cur_range) in numeric_types:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_7 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 412, __pyx_L1_error)
      }
      __pyx_L9:;

      /* "pyreadstat/_readstat_writer.pyx":380
 * 
 *     for cur_range in cur_ranges:
 *         if isinstance(cur_range, dict):             # <<<<<<<<<<<<<<
 *             hi = cur_range.get("hi")
 *             lo = cur_range.get("lo")
 */
      goto __pyx_L5;
    }

    /* "pyreadstat/_readstat_writer.pyx":414
 *                 raise PyreadstatError(msg)
 *         else:
 *             if type(cur_range) in numeric_types:             # <<<<<<<<<<<<<<
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 */
    /*else*/ {
      if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_numeric_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 414, __pyx_L1_error)
      }
      __pyx_t_4 = (__Pyx_PySet_ContainsTF(((PyObject *)Py_TYPE(__pyx_v_cur_range)), __pyx_v_10pyreadstat_16_readstat_writer_numeric_types, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 414, __pyx_L1_error)
      if (__pyx_t_4) {

        /* "pyreadstat/_readstat_writer.pyx":415
 *         else:
 *             if type(cur_range) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:             # <<<<<<<<<<<<<<
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_vartype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 415, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 415, __pyx_L1_error)
        }
        __pyx_t_4 = (__Pyx_PySet_ContainsTF(__pyx_t_3, __pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types, Py_NE)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 415, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":416
 *             if type(cur_range) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename             # <<<<<<<<<<<<<<
 *                     raise PyreadstatError(msg)
 *                 check_exit_status(readstat_variable_add_missing_double_value(variable, cur_range))
 */
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_numeric_missing_ranges_value_giv, __pyx_v_variablename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 416, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_msg = __pyx_t_3;
          __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":417
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                 check_exit_status(readstat_variable_add_missing_double_value(variable, cur_range))
 *                 discrete_values += 1
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 417, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = NULL;
          __pyx_t_7 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_7 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 417, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 417, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":415
 *         else:
 *             if type(cur_range) in numeric_types:
 *                 if vartype not in pywriter_numeric_types:             # <<<<<<<<<<<<<<
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":418
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 check_exit_status(readstat_variable_add_missing_double_value(variable, cur_range))             # <<<<<<<<<<<<<<
 *                 discrete_values += 1
 *             elif type(cur_range) == str:
 */
        __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_cur_range); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 418, __pyx_L1_error)
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_double_value(__pyx_v_variable, __pyx_t_10)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 418, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":419
 *                     raise PyreadstatError(msg)
 *                 check_exit_status(readstat_variable_add_missing_double_value(variable, cur_range))
 *                 discrete_values += 1             # <<<<<<<<<<<<<<
 *             elif type(cur_range) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 */
        __pyx_v_discrete_values = (__pyx_v_discrete_values + 1);

        /* "pyreadstat/_readstat_writer.pyx":414
 *                 raise PyreadstatError(msg)
 *         else:
 *             if type(cur_range) in numeric_types:             # <<<<<<<<<<<<<<
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
 */
        goto __pyx_L19;
      }

      /* "pyreadstat/_readstat_writer.pyx":420
 *                 check_exit_status(readstat_variable_add_missing_double_value(variable, cur_range))
 *                 discrete_values += 1
 *             elif type(cur_range) == str:             # <<<<<<<<<<<<<<
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 */
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_cur_range)), ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 420, __pyx_L1_error)
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 420, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":421
 *                 discrete_values += 1
 *             elif type(cur_range) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        switch (__pyx_v_vartype) {
          case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER:
          case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT:
          __pyx_t_4 = 0;
          break;
          default:
          __pyx_t_4 = 1;
          break;
        }
        if (unlikely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":422
 *             elif type(cur_range) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename             # <<<<<<<<<<<<<<
 *                     raise PyreadstatError(msg)
 *                 if len(cur_range) > 8:
 */
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_character_missing_ranges_value_g, __pyx_v_variablename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 422, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_msg = __pyx_t_3;
          __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":423
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                 if len(cur_range) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 423, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = NULL;
          __pyx_t_7 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_7 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 423, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 423, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":421
 *                 discrete_values += 1
 *             elif type(cur_range) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":424
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 if len(cur_range) > 8:             # <<<<<<<<<<<<<<
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)
 */
        __pyx_t_11 = PyObject_Length(__pyx_v_cur_range); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 424, __pyx_L1_error)
        __pyx_t_4 = (__pyx_t_11 > 8);
        if (unlikely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":425
 *                     raise PyreadstatError(msg)
 *                 if len(cur_range) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"             # <<<<<<<<<<<<<<
 *                         raise PyreadstatError(msg)
 *                 check_exit_status(readstat_variable_add_missing_string_value(variable, cur_range))#.encode("utf-8")))
 */
          __Pyx_INCREF(__pyx_kp_s_missing_ranges_string_values_len);
          __pyx_v_msg = __pyx_kp_s_missing_ranges_string_values_len;

          /* "pyreadstat/_readstat_writer.pyx":426
 *                 if len(cur_range) > 8:
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                 check_exit_status(readstat_variable_add_missing_string_value(variable, cur_range))#.encode("utf-8")))
 *                 discrete_strings += 1
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 426, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = NULL;
          __pyx_t_7 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_7 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 426, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 426, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":424
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 *                     raise PyreadstatError(msg)
 *                 if len(cur_range) > 8:             # <<<<<<<<<<<<<<
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":427
 *                         msg = "missing_ranges: string values length must not be larger than 8"
 *                         raise PyreadstatError(msg)
 *                 check_exit_status(readstat_variable_add_missing_string_value(variable, cur_range))#.encode("utf-8")))             # <<<<<<<<<<<<<<
 *                 discrete_strings += 1
 *             else:
 */
        __pyx_t_12 = __Pyx_PyObject_AsString(__pyx_v_cur_range); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 427, __pyx_L1_error)
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_string_value(__pyx_v_variable, __pyx_t_12)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 427, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":428
 *                         raise PyreadstatError(msg)
 *                 check_exit_status(readstat_variable_add_missing_string_value(variable, cur_range))#.encode("utf-8")))
 *                 discrete_strings += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 msg = "missing_ranges: values must be both either of numeric or string type"
 */
        __pyx_v_discrete_strings = (__pyx_v_discrete_strings + 1);

        /* "pyreadstat/_readstat_writer.pyx":420
 *                 check_exit_status(readstat_variable_add_missing_double_value(variable, cur_range))
 *                 discrete_values += 1
 *             elif type(cur_range) == str:             # <<<<<<<<<<<<<<
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
 */
        goto __pyx_L19;
      }

      /* "pyreadstat/_readstat_writer.pyx":430
 *                 discrete_strings += 1
 *             else:
 *                 msg = "missing_ranges: values must be both either of numeric or string type"             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 * 
 */
      /*else*/ {
        __Pyx_INCREF(__pyx_kp_s_missing_ranges_values_must_be_bo);
        __pyx_v_msg = __pyx_kp_s_missing_ranges_values_must_be_bo;

        /* "pyreadstat/_readstat_writer.pyx":431
 *             else:
 *                 msg = "missing_ranges: values must be both either of numeric or string type"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *         if discrete_strings > 3:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_7 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 431, __pyx_L1_error)
      }
      __pyx_L19:;
    }
    __pyx_L5:;

    /* "pyreadstat/_readstat_writer.pyx":433
 *                 raise PyreadstatError(msg)
 * 
 *         if discrete_strings > 3:             # <<<<<<<<<<<<<<
 *             msg = "missing_ranges: max 3 string values per variable allowed"
 *             raise PyreadstatError(msg)
 */
    __pyx_t_4 = (__pyx_v_discrete_strings > 3);
    if (unlikely(__pyx_t_4)) {

      /* "pyreadstat/_readstat_writer.pyx":434
 * 
 *         if discrete_strings > 3:
 *             msg = "missing_ranges: max 3 string values per variable allowed"             # <<<<<<<<<<<<<<
 *             raise PyreadstatError(msg)
 *         if range_values:
 */
      __Pyx_INCREF(__pyx_kp_s_missing_ranges_max_3_string_valu);
      __pyx_v_msg = __pyx_kp_s_missing_ranges_max_3_string_valu;

      /* "pyreadstat/_readstat_writer.pyx":435
 *         if discrete_strings > 3:
 *             msg = "missing_ranges: max 3 string values per variable allowed"
 *             raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *         if range_values:
 *             if range_values > 1:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      __pyx_t_7 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_7 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 435, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":433
 *                 raise PyreadstatError(msg)
 * 
 *         if discrete_strings > 3:             # <<<<<<<<<<<<<<
 *             msg = "missing_ranges: max 3 string values per variable allowed"
 *             raise PyreadstatError(msg)
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":436
 *             msg = "missing_ranges: max 3 string values per variable allowed"
 *             raise PyreadstatError(msg)
 *         if range_values:             # <<<<<<<<<<<<<<
 *             if range_values > 1:
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 */
    __pyx_t_4 = (__pyx_v_range_values != 0);
    if (__pyx_t_4) {

      /* "pyreadstat/_readstat_writer.pyx":437
 *             raise PyreadstatError(msg)
 *         if range_values:
 *             if range_values > 1:             # <<<<<<<<<<<<<<
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 */
      __pyx_t_4 = (__pyx_v_range_values > 1);
      if (unlikely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":438
 *         if range_values:
 *             if range_values > 1:
 *                 msg = "missing_ranges: max 1 range value per variable allowed"             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             if discrete_values > 1:
 */
        __Pyx_INCREF(__pyx_kp_s_missing_ranges_max_1_range_value);
        __pyx_v_msg = __pyx_kp_s_missing_ranges_max_1_range_value;

        /* "pyreadstat/_readstat_writer.pyx":439
 *             if range_values > 1:
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             if discrete_values > 1:
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 439, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_7 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 439, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":437
 *             raise PyreadstatError(msg)
 *         if range_values:
 *             if range_values > 1:             # <<<<<<<<<<<<<<
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":440
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 *             if discrete_values > 1:             # <<<<<<<<<<<<<<
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 */
      __pyx_t_4 = (__pyx_v_discrete_values > 1);
      if (unlikely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":441
 *                 raise PyreadstatError(msg)
 *             if discrete_values > 1:
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *         if discrete_values >3:
 */
        __Pyx_INCREF(__pyx_kp_s_missing_ranges_max_1_discrete_nu);
        __pyx_v_msg = __pyx_kp_s_missing_ranges_max_1_discrete_nu;

        /* "pyreadstat/_readstat_writer.pyx":442
 *             if discrete_values > 1:
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *         if discrete_values >3:
 *             msg = "missing_ranges: max 3 discrete numeric values per variable allowed"
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 442, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_7 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 442, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 442, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":440
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 *             if discrete_values > 1:             # <<<<<<<<<<<<<<
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":436
 *             msg = "missing_ranges: max 3 string values per variable allowed"
 *             raise PyreadstatError(msg)
 *         if range_values:             # <<<<<<<<<<<<<<
 *             if range_values > 1:
 *                 msg = "missing_ranges: max 1 range value per variable allowed"
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":443
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 *         if discrete_values >3:             # <<<<<<<<<<<<<<
 *             msg = "missing_ranges: max 3 discrete numeric values per variable allowed"
 *             raise PyreadstatError(msg)
 */
    __pyx_t_4 = (__pyx_v_discrete_values > 3);
    if (unlikely(__pyx_t_4)) {

      /* "pyreadstat/_readstat_writer.pyx":444
 *                 raise PyreadstatError(msg)
 *         if discrete_values >3:
 *             msg = "missing_ranges: max 3 discrete numeric values per variable allowed"             # <<<<<<<<<<<<<<
 *             raise PyreadstatError(msg)
 * 
 */
      __Pyx_INCREF(__pyx_kp_s_missing_ranges_max_3_discrete_nu);
      __pyx_v_msg = __pyx_kp_s_missing_ranges_max_3_discrete_nu;

      /* "pyreadstat/_readstat_writer.pyx":445
 *         if discrete_values >3:
 *             msg = "missing_ranges: max 3 discrete numeric values per variable allowed"
 *             raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 * cdef void set_variable_alignment(readstat_variable_t *variable, str alignment_str, str var_name) except *:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      __pyx_t_7 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_7 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_msg};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 445, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 445, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":443
 *                 msg = "missing_ranges: max 1 discrete numeric value if combined with 1 range value per variable allowed"
 *                 raise PyreadstatError(msg)
 *         if discrete_values >3:             # <<<<<<<<<<<<<<
 *             msg = "missing_ranges: max 3 discrete numeric values per variable allowed"
 *             raise PyreadstatError(msg)
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":379
 *     cdef int discrete_strings = 0
 * 
 *     for cur_range in cur_ranges:             # <<<<<<<<<<<<<<
 *         if isinstance(cur_range, dict):
 *             hi = cur_range.get("hi")
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":369
 *     return label_set
 * 
 * cdef void add_missing_ranges(list cur_ranges, readstat_variable_t *variable, pywriter_variable_type vartype, str variablename) except *:             # <<<<<<<<<<<<<<
 *     """
 *     Adding missing ranges, user defined missing discrete values both numeric and character,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.add_missing_ranges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cur_range);
  __Pyx_XDECREF(__pyx_v_hi);
  __Pyx_XDECREF(__pyx_v_lo);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_RefNannyFinishContext();
}

/* "pyreadstat/_readstat_writer.pyx":447
 *             raise PyreadstatError(msg)
 * 
 * cdef void set_variable_alignment(readstat_variable_t *variable, str alignment_str, str var_name) except *:             # <<<<<<<<<<<<<<
 *     """
 *     Sets the variable alignment, ineffective on SPSS, STATA and XPORT (what about SAS7bdat?)
 */

static void __pyx_f_10pyreadstat_16_readstat_writer_set_variable_alignment(readstat_variable_t *__pyx_v_variable, PyObject *__pyx_v_alignment_str, PyObject *__pyx_v_var_name) {
  readstat_alignment_t __pyx_v_alignment;
  PyObject *__pyx_v_msg = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_variable_alignment", 0);

  /* "pyreadstat/_readstat_writer.pyx":454
 *     cdef readstat_alignment_t alignment
 * 
 *     if alignment_str == "right":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_alignment_str, __pyx_n_s_right, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 454, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":455
 * 
 *     if alignment_str == "right":
 *         alignment = READSTAT_ALIGNMENT_RIGHT             # <<<<<<<<<<<<<<
 *     elif alignment_str == "left":
 *         alignment = READSTAT_ALIGNMENT_LEFT
 */
    __pyx_v_alignment = READSTAT_ALIGNMENT_RIGHT;

    /* "pyreadstat/_readstat_writer.pyx":454
 *     cdef readstat_alignment_t alignment
 * 
 *     if alignment_str == "right":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":456
 *     if alignment_str == "right":
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_alignment_str, __pyx_n_s_left, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 456, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":457
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":
 *         alignment = READSTAT_ALIGNMENT_LEFT             # <<<<<<<<<<<<<<
 *     elif alignment_str == "center":
 *         alignment = READSTAT_ALIGNMENT_CENTER
 */
    __pyx_v_alignment = READSTAT_ALIGNMENT_LEFT;

    /* "pyreadstat/_readstat_writer.pyx":456
 *     if alignment_str == "right":
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":458
 *     elif alignment_str == "left":
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_alignment_str, __pyx_n_s_center, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 458, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":459
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":
 *         alignment = READSTAT_ALIGNMENT_CENTER             # <<<<<<<<<<<<<<
 *     elif alignment_str == "unknown":
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN
 */
    __pyx_v_alignment = READSTAT_ALIGNMENT_CENTER;

    /* "pyreadstat/_readstat_writer.pyx":458
 *     elif alignment_str == "left":
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":460
 *     elif alignment_str == "center":
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN
 *     else:
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_alignment_str, __pyx_n_s_unknown, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 460, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":461
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN             # <<<<<<<<<<<<<<
 *     else:
 *         msg = "alignment for variable %s must be either right, center, left or unknown got %s instead" % (var_name, alignment_str)
 */
    __pyx_v_alignment = READSTAT_ALIGNMENT_UNKNOWN;

    /* "pyreadstat/_readstat_writer.pyx":460
 *     elif alignment_str == "center":
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN
 *     else:
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":463
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN
 *     else:
 *         msg = "alignment for variable %s must be either right, center, left or unknown got %s instead" % (var_name, alignment_str)             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(msg)
 * 
 */
  /*else*/ {
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 463, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_var_name);
    __Pyx_GIVEREF(__pyx_v_var_name);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_var_name);
    __Pyx_INCREF(__pyx_v_alignment_str);
    __Pyx_GIVEREF(__pyx_v_alignment_str);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_alignment_str);
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_alignment_for_variable_s_must_be, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_msg = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyreadstat/_readstat_writer.pyx":464
 *     else:
 *         msg = "alignment for variable %s must be either right, center, left or unknown got %s instead" % (var_name, alignment_str)
 *         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     readstat_variable_set_alignment(variable, alignment)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 464, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_5 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_msg};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 464, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 464, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "pyreadstat/_readstat_writer.pyx":466
 *         raise PyreadstatError(msg)
 * 
 *     readstat_variable_set_alignment(variable, alignment)             # <<<<<<<<<<<<<<
 * 
 * cdef void set_variable_display_width(readstat_variable_t *variable, int display_width, str var_name) except *:
 */
  readstat_variable_set_alignment(__pyx_v_variable, __pyx_v_alignment);

  /* "pyreadstat/_readstat_writer.pyx":447
 *             raise PyreadstatError(msg)
 * 
 * cdef void set_variable_alignment(readstat_variable_t *variable, str alignment_str, str var_name) except *:             # <<<<<<<<<<<<<<
 *     """
 *     Sets the variable alignment, ineffective on SPSS, STATA and XPORT (what about SAS7bdat?)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.set_variable_alignment", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_RefNannyFinishContext();
}

/* "pyreadstat/_readstat_writer.pyx":468
 *     readstat_variable_set_alignment(variable, alignment)
 * 
 * cdef void set_variable_display_width(readstat_variable_t *variable, int display_width, str var_name) except *:             # <<<<<<<<<<<<<<
 *     """
 *     Sets the variable display width (SPSS). Not effective on STATA. (what about SAS7BDAT?)
 */

static void __pyx_f_10pyreadstat_16_readstat_writer_set_variable_display_width(readstat_variable_t *__pyx_v_variable, int __pyx_v_display_width, CYTHON_UNUSED PyObject *__pyx_v_var_name) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_variable_display_width", 0);

  /* "pyreadstat/_readstat_writer.pyx":473
 *     """
 * 
 *     readstat_variable_set_display_width(variable, display_width)             # <<<<<<<<<<<<<<
 * 
 * cdef void set_variable_measure(readstat_variable_t *variable, str measure_str, str var_name) except *:
 */
  readstat_variable_set_display_width(__pyx_v_variable, __pyx_v_display_width);

  /* "pyreadstat/_readstat_writer.pyx":468
 *     readstat_variable_set_alignment(variable, alignment)
 * 
 * cdef void set_variable_display_width(readstat_variable_t *variable, int display_width, str var_name) except *:             # <<<<<<<<<<<<<<
 *     """
 *     Sets the variable display width (SPSS). Not effective on STATA. (what about SAS7BDAT?)
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "pyreadstat/_readstat_writer.pyx":475
 *     readstat_variable_set_display_width(variable, display_width)
 * 
 * cdef void set_variable_measure(readstat_variable_t *variable, str measure_str, str var_name) except *:             # <<<<<<<<<<<<<<
 *     """
 *     sets the variable measure type (SPSS). Not effective on STATA.
 */

static void __pyx_f_10pyreadstat_16_readstat_writer_set_variable_measure(readstat_variable_t *__pyx_v_variable, PyObject *__pyx_v_measure_str, PyObject *__pyx_v_var_name) {
  readstat_measure_t __pyx_v_measure;
  PyObject *__pyx_v_msg = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_variable_measure", 0);

  /* "pyreadstat/_readstat_writer.pyx":482
 *     cdef readstat_measure_t measure
 * 
 *     if measure_str == "nominal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_measure_str, __pyx_n_s_nominal, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 482, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":483
 * 
 *     if measure_str == "nominal":
 *         measure = READSTAT_MEASURE_NOMINAL             # <<<<<<<<<<<<<<
 *     elif measure_str == "ordinal":
 *         measure = READSTAT_MEASURE_ORDINAL
 */
    __pyx_v_measure = READSTAT_MEASURE_NOMINAL;

    /* "pyreadstat/_readstat_writer.pyx":482
 *     cdef readstat_measure_t measure
 * 
 *     if measure_str == "nominal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":484
 *     if measure_str == "nominal":
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_measure_str, __pyx_n_s_ordinal, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 484, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":485
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":
 *         measure = READSTAT_MEASURE_ORDINAL             # <<<<<<<<<<<<<<
 *     elif measure_str == "scale":
 *         measure = READSTAT_MEASURE_SCALE
 */
    __pyx_v_measure = READSTAT_MEASURE_ORDINAL;

    /* "pyreadstat/_readstat_writer.pyx":484
 *     if measure_str == "nominal":
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":486
 *     elif measure_str == "ordinal":
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_measure_str, __pyx_n_s_scale, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 486, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":487
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":
 *         measure = READSTAT_MEASURE_SCALE             # <<<<<<<<<<<<<<
 *     elif measure_str == "unknown":
 *         measure = READSTAT_MEASURE_UNKNOWN
 */
    __pyx_v_measure = READSTAT_MEASURE_SCALE;

    /* "pyreadstat/_readstat_writer.pyx":486
 *     elif measure_str == "ordinal":
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":488
 *     elif measure_str == "scale":
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_UNKNOWN
 *     else:
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_measure_str, __pyx_n_s_unknown, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 488, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":489
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":
 *         measure = READSTAT_MEASURE_UNKNOWN             # <<<<<<<<<<<<<<
 *     else:
 *         msg = "measure for variable %s must be either nominal, ordinal, scale or unknown got %s instead" % (var_name, measure_str)
 */
    __pyx_v_measure = READSTAT_MEASURE_UNKNOWN;

    /* "pyreadstat/_readstat_writer.pyx":488
 *     elif measure_str == "scale":
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_UNKNOWN
 *     else:
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":491
 *         measure = READSTAT_MEASURE_UNKNOWN
 *     else:
 *         msg = "measure for variable %s must be either nominal, ordinal, scale or unknown got %s instead" % (var_name, measure_str)             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(msg)
 * 
 */
  /*else*/ {
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 491, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_var_name);
    __Pyx_GIVEREF(__pyx_v_var_name);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_var_name);
    __Pyx_INCREF(__pyx_v_measure_str);
    __Pyx_GIVEREF(__pyx_v_measure_str);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_measure_str);
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_measure_for_variable_s_must_be_e, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 491, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_msg = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyreadstat/_readstat_writer.pyx":492
 *     else:
 *         msg = "measure for variable %s must be either nominal, ordinal, scale or unknown got %s instead" % (var_name, measure_str)
 *         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     readstat_variable_set_measure(variable, measure);
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_5 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_msg};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 492, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "pyreadstat/_readstat_writer.pyx":494
 *         raise PyreadstatError(msg)
 * 
 *     readstat_variable_set_measure(variable, measure);             # <<<<<<<<<<<<<<
 * 
 * 
 */
  readstat_variable_set_measure(__pyx_v_variable, __pyx_v_measure);

  /* "pyreadstat/_readstat_writer.pyx":475
 *     readstat_variable_set_display_width(variable, display_width)
 * 
 * cdef void set_variable_measure(readstat_variable_t *variable, str measure_str, str var_name) except *:             # <<<<<<<<<<<<<<
 *     """
 *     sets the variable measure type (SPSS). Not effective on STATA.
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.set_variable_measure", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_RefNannyFinishContext();
}

/* "pyreadstat/_readstat_writer.pyx":497
 * 
 * 
 * cdef ssize_t write_bytes(const void *data, size_t _len, void *ctx) noexcept:             # <<<<<<<<<<<<<<
 *     """
 *     for the writer an explicit function to write must be defined
 */

static Py_ssize_t __pyx_f_10pyreadstat_16_readstat_writer_write_bytes(void const *__pyx_v_data, size_t __pyx_v__len, void *__pyx_v_ctx) {
  int __pyx_v_fd;
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_bytes", 0);

  /* "pyreadstat/_readstat_writer.pyx":502
 *     """
 *     cdef int fd
 *     fd = (<int *>ctx)[0]             # <<<<<<<<<<<<<<
 *     if os.name=='nt':
 *         return _write(fd, data, _len)
 */
  __pyx_v_fd = (((int *)__pyx_v_ctx)[0]);

  /* "pyreadstat/_readstat_writer.pyx":503
 *     cdef int fd
 *     fd = (<int *>ctx)[0]
 *     if os.name=='nt':             # <<<<<<<<<<<<<<
 *         return _write(fd, data, _len)
 *     else:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_nt, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pyreadstat/_readstat_writer.pyx":504
 *     fd = (<int *>ctx)[0]
 *     if os.name=='nt':
 *         return _write(fd, data, _len)             # <<<<<<<<<<<<<<
 *     else:
 *         return write(fd, data, _len)
 */
    __pyx_r = _write(__pyx_v_fd, __pyx_v_data, __pyx_v__len);
    goto __pyx_L0;

    /* "pyreadstat/_readstat_writer.pyx":503
 *     cdef int fd
 *     fd = (<int *>ctx)[0]
 *     if os.name=='nt':             # <<<<<<<<<<<<<<
 *         return _write(fd, data, _len)
 *     else:
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":506
 *         return _write(fd, data, _len)
 *     else:
 *         return write(fd, data, _len)             # <<<<<<<<<<<<<<
 * 
 * cdef void _check_exit_status(readstat_error_t retcode) except *:
 */
  /*else*/ {
    __pyx_r = write(__pyx_v_fd, __pyx_v_data, __pyx_v__len);
    goto __pyx_L0;
  }

  /* "pyreadstat/_readstat_writer.pyx":497
 * 
 * 
 * cdef ssize_t write_bytes(const void *data, size_t _len, void *ctx) noexcept:             # <<<<<<<<<<<<<<
 *     """
 *     for the writer an explicit function to write must be defined
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("pyreadstat._readstat_writer.write_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":508
 *         return write(fd, data, _len)
 * 
 * cdef void _check_exit_status(readstat_error_t retcode) except *:             # <<<<<<<<<<<<<<
 *     """
 *     transforms a readstat exit status to a python error if status is not READSTAT OK
 */

static void __pyx_f_10pyreadstat_16_readstat_writer__check_exit_status(readstat_error_t __pyx_v_retcode) {
  char *__pyx_v_err_readstat;
  PyObject *__pyx_v_err_message = 0;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_check_exit_status", 0);

  /* "pyreadstat/_readstat_writer.pyx":515
 *     cdef char * err_readstat
 *     cdef str err_message
 *     if retcode != READSTAT_OK:             # <<<<<<<<<<<<<<
 *         err_readstat = readstat_error_message(retcode)
 *         err_message = <str> err_readstat
 */
  __pyx_t_1 = (__pyx_v_retcode != READSTAT_OK);
  if (unlikely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":516
 *     cdef str err_message
 *     if retcode != READSTAT_OK:
 *         err_readstat = readstat_error_message(retcode)             # <<<<<<<<<<<<<<
 *         err_message = <str> err_readstat
 *         raise ReadstatError(err_message)
 */
    __pyx_v_err_readstat = readstat_error_message(__pyx_v_retcode);

    /* "pyreadstat/_readstat_writer.pyx":517
 *     if retcode != READSTAT_OK:
 *         err_readstat = readstat_error_message(retcode)
 *         err_message = <str> err_readstat             # <<<<<<<<<<<<<<
 *         raise ReadstatError(err_message)
 * 
 */
    __pyx_t_2 = __Pyx_PyStr_FromString(__pyx_v_err_readstat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __pyx_t_2;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_err_message = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyreadstat/_readstat_writer.pyx":518
 *         err_readstat = readstat_error_message(retcode)
 *         err_message = <str> err_readstat
 *         raise ReadstatError(err_message)             # <<<<<<<<<<<<<<
 * 
 * cdef int open_file(bytes filename_path):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ReadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_5 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_err_message};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 518, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":515
 *     cdef char * err_readstat
 *     cdef str err_message
 *     if retcode != READSTAT_OK:             # <<<<<<<<<<<<<<
 *         err_readstat = readstat_error_message(retcode)
 *         err_message = <str> err_readstat
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":508
 *         return write(fd, data, _len)
 * 
 * cdef void _check_exit_status(readstat_error_t retcode) except *:             # <<<<<<<<<<<<<<
 *     """
 *     transforms a readstat exit status to a python error if status is not READSTAT OK
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer._check_exit_status", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_err_message);
  __Pyx_RefNannyFinishContext();
}

/* "pyreadstat/_readstat_writer.pyx":520
 *         raise ReadstatError(err_message)
 * 
 * cdef int open_file(bytes filename_path):             # <<<<<<<<<<<<<<
 * 
 *     cdef int fd
 */

static int __pyx_f_10pyreadstat_16_readstat_writer_open_file(PyObject *__pyx_v_filename_path) {
  int __pyx_v_fd;
  int __pyx_v_flags;
  Py_ssize_t __pyx_v_length;
  char *__pyx_v_path;
  PyObject *__pyx_v_filename_str = NULL;
  wchar_t *__pyx_v_u16_path;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  wchar_t *__pyx_t_6;
  char *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("open_file", 0);

  /* "pyreadstat/_readstat_writer.pyx":529
 *     cdef char *path
 * 
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         filename_str = os.fsdecode(filename_path)
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 529, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 529, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_nt, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 529, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pyreadstat/_readstat_writer.pyx":530
 * 
 *     if os.name == "nt":
 *         filename_str = os.fsdecode(filename_path)             # <<<<<<<<<<<<<<
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
 *         flags = _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_fsdecode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 530, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_5 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_filename_path};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_v_filename_str = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pyreadstat/_readstat_writer.pyx":531
 *     if os.name == "nt":
 *         filename_str = os.fsdecode(filename_path)
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)             # <<<<<<<<<<<<<<
 *         flags = _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC
 *         fd = _wsopen(u16_path, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)
 */
    __pyx_t_6 = PyUnicode_AsWideCharString(__pyx_v_filename_str, (&__pyx_v_length)); if (unlikely(__pyx_t_6 == ((wchar_t *)NULL))) __PYX_ERR(0, 531, __pyx_L1_error)
    __pyx_v_u16_path = __pyx_t_6;

    /* "pyreadstat/_readstat_writer.pyx":532
 *         filename_str = os.fsdecode(filename_path)
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
 *         flags = _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC             # <<<<<<<<<<<<<<
 *         fd = _wsopen(u16_path, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)
 *     else:
 */
    __pyx_v_flags = (((_O_WRONLY | _O_CREAT) | _O_BINARY) | _O_TRUNC);

    /* "pyreadstat/_readstat_writer.pyx":533
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
 *         flags = _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC
 *         fd = _wsopen(u16_path, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)             # <<<<<<<<<<<<<<
 *     else:
 *         #filename_bytes = filename_path.encode("utf-8")
 */
    __pyx_v_fd = _wsopen(__pyx_v_u16_path, __pyx_v_flags, _SH_DENYRW, (_S_IREAD | _S_IWRITE));

    /* "pyreadstat/_readstat_writer.pyx":529
 *     cdef char *path
 * 
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         filename_str = os.fsdecode(filename_path)
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
 */
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":536
 *     else:
 *         #filename_bytes = filename_path.encode("utf-8")
 *         path = <char *> filename_path             # <<<<<<<<<<<<<<
 *         flags = O_WRONLY | O_CREAT | O_TRUNC
 *         fd = open(path, flags, 0644)
 */
  /*else*/ {
    if (unlikely(__pyx_v_filename_path == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
      __PYX_ERR(0, 536, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename_path); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 536, __pyx_L1_error)
    __pyx_v_path = ((char *)__pyx_t_7);

    /* "pyreadstat/_readstat_writer.pyx":537
 *         #filename_bytes = filename_path.encode("utf-8")
 *         path = <char *> filename_path
 *         flags = O_WRONLY | O_CREAT | O_TRUNC             # <<<<<<<<<<<<<<
 *         fd = open(path, flags, 0644)
 * 
 */
    __pyx_v_flags = ((O_WRONLY | O_CREAT) | O_TRUNC);

    /* "pyreadstat/_readstat_writer.pyx":538
 *         path = <char *> filename_path
 *         flags = O_WRONLY | O_CREAT | O_TRUNC
 *         fd = open(path, flags, 0644)             # <<<<<<<<<<<<<<
 * 
 *     return fd
 */
    __pyx_v_fd = open(__pyx_v_path, __pyx_v_flags, 0644);
  }
  __pyx_L3:;

  /* "pyreadstat/_readstat_writer.pyx":540
 *         fd = open(path, flags, 0644)
 * 
 *     return fd             # <<<<<<<<<<<<<<
 * 
 * cdef int close_file(int fd):
 */
  __pyx_r = __pyx_v_fd;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":520
 *         raise ReadstatError(err_message)
 * 
 * cdef int open_file(bytes filename_path):             # <<<<<<<<<<<<<<
 * 
 *     cdef int fd
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.open_file", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_filename_str);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":542
 *     return fd
 * 
 * cdef int close_file(int fd):             # <<<<<<<<<<<<<<
 *     if os.name == "nt":
 *         return _close(fd)
 */

static int __pyx_f_10pyreadstat_16_readstat_writer_close_file(int __pyx_v_fd) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("close_file", 0);

  /* "pyreadstat/_readstat_writer.pyx":543
 * 
 * cdef int close_file(int fd):
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         return _close(fd)
 *     else:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_nt, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pyreadstat/_readstat_writer.pyx":544
 * cdef int close_file(int fd):
 *     if os.name == "nt":
 *         return _close(fd)             # <<<<<<<<<<<<<<
 *     else:
 *         return close(fd)
 */
    __pyx_r = _close(__pyx_v_fd);
    goto __pyx_L0;

    /* "pyreadstat/_readstat_writer.pyx":543
 * 
 * cdef int close_file(int fd):
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         return _close(fd)
 *     else:
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":546
 *         return _close(fd)
 *     else:
 *         return close(fd)             # <<<<<<<<<<<<<<
 * 
 * cdef int run_write(df, object filename_path, dst_file_format file_format, str file_label, object column_labels,
 */
  /*else*/ {
    __pyx_r = close(__pyx_v_fd);
    goto __pyx_L0;
  }

  /* "pyreadstat/_readstat_writer.pyx":542
 *     return fd
 * 
 * cdef int close_file(int fd):             # <<<<<<<<<<<<<<
 *     if os.name == "nt":
 *         return _close(fd)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.close_file", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":548
 *         return close(fd)
 * 
 * cdef int run_write(df, object filename_path, dst_file_format file_format, str file_label, object column_labels,             # <<<<<<<<<<<<<<
 *                    int file_format_version, str note, str table_name, dict variable_value_labels,
 *                    dict missing_ranges, dict missing_user_values, dict variable_alignment,
 */

static int __pyx_f_10pyreadstat_16_readstat_writer_run_write(PyObject *__pyx_v_df, PyObject *__pyx_v_filename_path, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, PyObject *__pyx_v_file_label, PyObject *__pyx_v_column_labels, int __pyx_v_file_format_version, PyObject *__pyx_v_note, PyObject *__pyx_v_table_name, PyObject *__pyx_v_variable_value_labels, PyObject *__pyx_v_missing_ranges, PyObject *__pyx_v_missing_user_values, PyObject *__pyx_v_variable_alignment, PyObject *__pyx_v_variable_display_width, PyObject *__pyx_v_variable_measure, PyObject *__pyx_v_variable_format, int __pyx_v_row_compression) {
  PyObject *__pyx_v_k = NULL;
  PyObject *__pyx_v_v = NULL;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_valid_user_missing = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_missing_values = NULL;
  PyObject *__pyx_v_val = NULL;
  readstat_writer_t *__pyx_v_writer;
  PyObject *__pyx_v_file_label_bytes = 0;
  char *__pyx_v_file_labl;
  PyObject *__pyx_v_col_names = 0;
  PyObject *__pyx_v_variable_name = NULL;
  PyObject *__pyx_v_col_types = 0;
  int __pyx_v_row_count;
  int __pyx_v_col_count;
  PyObject *__pyx_v_col_names_to_types = 0;
  readstat_variable_t *__pyx_v_variable;
  __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_v_curtype;
  int __pyx_v_max_length;
  char *__pyx_v_curformat;
  PyObject *__pyx_v_tempformat = 0;
  int __pyx_v_col_indx;
  PyObject *__pyx_v_cur_col_label = 0;
  int __pyx_v_col_label_count;
  readstat_variable_t *__pyx_v_tempvar;
  PyObject *__pyx_v_curvalstr = 0;
  double __pyx_v_dtimelikeval;
  PyObject *__pyx_v_value_labels = 0;
  int __pyx_v_lblset_cnt;
  readstat_label_set_t *__pyx_v_label_set;
  PyObject *__pyx_v_col_label_temp = 0;
  int __pyx_v_hasdatetime64;
  PyObject *__pyx_v_pywriter_types = 0;
  PyObject *__pyx_v_df2 = 0;
  float __pyx_v_mulfac;
  CYTHON_UNUSED PyObject *__pyx_v_filename_bytes = NULL;
  int __pyx_v_fd;
  PyObject *__pyx_v_table_name_bytes = NULL;
  char *__pyx_v_tab_name;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_labelset_name = NULL;
  PyObject *__pyx_v_curuser_missing = NULL;
  PyObject *__pyx_v_cur_ranges = NULL;
  PyObject *__pyx_v_cur_alignment = NULL;
  PyObject *__pyx_v_cur_display_width = NULL;
  PyObject *__pyx_v_cur_measure = NULL;
  double __pyx_v_offset_secs;
  PyObject *__pyx_v_rowcnt = NULL;
  PyObject *__pyx_v_row = NULL;
  PyObject *__pyx_v_curval = NULL;
  PyObject *__pyx_v_is_missing = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_7genexpr__pyx_v_k = NULL;
  PyObject *__pyx_7genexpr__pyx_v_v = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  long __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  char *__pyx_t_21;
  char const *__pyx_t_22;
  int __pyx_t_23;
  int __pyx_t_24;
  int __pyx_t_25;
  int __pyx_t_26;
  __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_t_27;
  char const *__pyx_t_28;
  readstat_type_t __pyx_t_29;
  char const *__pyx_t_30;
  char const *__pyx_t_31;
  readstat_label_set_t *__pyx_t_32;
  double __pyx_t_33;
  int32_t __pyx_t_34;
  char const *__pyx_t_35;
  char const *__pyx_t_36;
  PyObject *__pyx_t_37 = NULL;
  PyObject *__pyx_t_38 = NULL;
  PyObject *__pyx_t_39 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("run_write", 0);
  __Pyx_INCREF(__pyx_v_filename_path);
  __Pyx_INCREF(__pyx_v_column_labels);

  /* "pyreadstat/_readstat_writer.pyx":558
 *     """
 * 
 *     if not isinstance(df, pd.DataFrame):             # <<<<<<<<<<<<<<
 *         raise PyreadstatError("first argument must be a pandas data frame")
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_DataFrame); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = PyObject_IsInstance(__pyx_v_df, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (unlikely(__pyx_t_4)) {

    /* "pyreadstat/_readstat_writer.pyx":559
 * 
 *     if not isinstance(df, pd.DataFrame):
 *         raise PyreadstatError("first argument must be a pandas data frame")             # <<<<<<<<<<<<<<
 * 
 *     if variable_value_labels:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_6 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_kp_s_first_argument_must_be_a_pandas};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 559, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":558
 *     """
 * 
 *     if not isinstance(df, pd.DataFrame):             # <<<<<<<<<<<<<<
 *         raise PyreadstatError("first argument must be a pandas data frame")
 * 
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":561
 *         raise PyreadstatError("first argument must be a pandas data frame")
 * 
 *     if variable_value_labels:             # <<<<<<<<<<<<<<
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_variable_value_labels); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 561, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "pyreadstat/_readstat_writer.pyx":562
 * 
 *     if variable_value_labels:
 *         for k,v in variable_value_labels.items():             # <<<<<<<<<<<<<<
 *             if type(v) != dict:
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))
 */
    if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items");
      __PYX_ERR(0, 562, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_variable_value_labels); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 562, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 562, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 562, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 562, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_8(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 562, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 562, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_9);
        #else
        __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 562, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 562, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 562, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
        index = 0; __pyx_t_5 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_5)) goto __pyx_L7_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_5);
        index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 562, __pyx_L1_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L8_unpacking_done;
        __pyx_L7_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 562, __pyx_L1_error)
        __pyx_L8_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_5);
      __pyx_t_5 = 0;
      __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":563
 *     if variable_value_labels:
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))
 *                 raise PyreadstatError(msg)
 */
      __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_v)), ((PyObject *)(&PyDict_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 563, __pyx_L1_error)
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 563, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":564
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 * 
 */
        __pyx_t_2 = __Pyx_PyObject_Str(((PyObject *)Py_TYPE(__pyx_v_v))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 564, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_v_k);
        __Pyx_GIVEREF(__pyx_v_k);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_k);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_variable_value_labels_value_for, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_v_msg = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":565
 *             if type(v) != dict:
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     if missing_user_values:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 565, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_5 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
            __pyx_t_6 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 565, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 565, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":563
 *     if variable_value_labels:
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":562
 * 
 *     if variable_value_labels:
 *         for k,v in variable_value_labels.items():             # <<<<<<<<<<<<<<
 *             if type(v) != dict:
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":561
 *         raise PyreadstatError("first argument must be a pandas data frame")
 * 
 *     if variable_value_labels:             # <<<<<<<<<<<<<<
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":567
 *                 raise PyreadstatError(msg)
 * 
 *     if missing_user_values:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 567, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "pyreadstat/_readstat_writer.pyx":568
 * 
 *     if missing_user_values:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             valid_user_missing = valid_user_missing_stata
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:
 */
    switch (__pyx_v_file_format) {
      case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA:

      /* "pyreadstat/_readstat_writer.pyx":569
 *     if missing_user_values:
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata             # <<<<<<<<<<<<<<
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:
 *             valid_user_missing = valid_user_missing_sas
 */
      __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata);
      __pyx_v_valid_user_missing = __pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata;

      /* "pyreadstat/_readstat_writer.pyx":568
 * 
 *     if missing_user_values:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             valid_user_missing = valid_user_missing_stata
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:
 */
      break;
      case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BDAT:

      /* "pyreadstat/_readstat_writer.pyx":570
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:             # <<<<<<<<<<<<<<
 *             valid_user_missing = valid_user_missing_sas
 *         for key, missing_values in missing_user_values.items():
 */
      case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BCAT:

      /* "pyreadstat/_readstat_writer.pyx":571
 *             valid_user_missing = valid_user_missing_stata
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:
 *             valid_user_missing = valid_user_missing_sas             # <<<<<<<<<<<<<<
 *         for key, missing_values in missing_user_values.items():
 *             if not isinstance(missing_values, list):
 */
      __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas);
      __pyx_v_valid_user_missing = __pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas;

      /* "pyreadstat/_readstat_writer.pyx":570
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:             # <<<<<<<<<<<<<<
 *             valid_user_missing = valid_user_missing_sas
 *         for key, missing_values in missing_user_values.items():
 */
      break;
      default: break;
    }

    /* "pyreadstat/_readstat_writer.pyx":572
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:
 *             valid_user_missing = valid_user_missing_sas
 *         for key, missing_values in missing_user_values.items():             # <<<<<<<<<<<<<<
 *             if not isinstance(missing_values, list):
 *                 msg = "missing_user_values: values in dictionary must be list"
 */
    if (unlikely(__pyx_v_missing_user_values == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items");
      __PYX_ERR(0, 572, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_Items(__pyx_v_missing_user_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 572, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 572, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 572, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_8(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 572, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 572, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_5);
        #else
        __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 572, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 572, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 572, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
        index = 0; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L14_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        index = 1; __pyx_t_5 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_5)) goto __pyx_L14_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_5);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 572, __pyx_L1_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L15_unpacking_done;
        __pyx_L14_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 572, __pyx_L1_error)
        __pyx_L15_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_9);
      __pyx_t_9 = 0;
      __Pyx_XDECREF_SET(__pyx_v_missing_values, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyreadstat/_readstat_writer.pyx":573
 *             valid_user_missing = valid_user_missing_sas
 *         for key, missing_values in missing_user_values.items():
 *             if not isinstance(missing_values, list):             # <<<<<<<<<<<<<<
 *                 msg = "missing_user_values: values in dictionary must be list"
 *                 raise PyreadstatError(msg)
 */
      __pyx_t_4 = PyList_Check(__pyx_v_missing_values); 
      __pyx_t_3 = (!__pyx_t_4);
      if (unlikely(__pyx_t_3)) {

        /* "pyreadstat/_readstat_writer.pyx":574
 *         for key, missing_values in missing_user_values.items():
 *             if not isinstance(missing_values, list):
 *                 msg = "missing_user_values: values in dictionary must be list"             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 *             for val in missing_values:
 */
        __Pyx_INCREF(__pyx_kp_s_missing_user_values_values_in_di);
        __pyx_v_msg = __pyx_kp_s_missing_user_values_values_in_di;

        /* "pyreadstat/_readstat_writer.pyx":575
 *             if not isinstance(missing_values, list):
 *                 msg = "missing_user_values: values in dictionary must be list"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *             for val in missing_values:
 *                 if val not in valid_user_missing:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 575, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_9 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_6 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_msg};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 575, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 575, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":573
 *             valid_user_missing = valid_user_missing_sas
 *         for key, missing_values in missing_user_values.items():
 *             if not isinstance(missing_values, list):             # <<<<<<<<<<<<<<
 *                 msg = "missing_user_values: values in dictionary must be list"
 *                 raise PyreadstatError(msg)
 */
      }

      /* "pyreadstat/_readstat_writer.pyx":576
 *                 msg = "missing_user_values: values in dictionary must be list"
 *                 raise PyreadstatError(msg)
 *             for val in missing_values:             # <<<<<<<<<<<<<<
 *                 if val not in valid_user_missing:
 *                     msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val)
 */
      if (likely(PyList_CheckExact(__pyx_v_missing_values)) || PyTuple_CheckExact(__pyx_v_missing_values)) {
        __pyx_t_1 = __pyx_v_missing_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
        __pyx_t_13 = NULL;
      } else {
        __pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_missing_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_13 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 576, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_13)) {
          if (likely(PyList_CheckExact(__pyx_t_1))) {
            if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 576, __pyx_L1_error)
            #else
            __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 576, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            #endif
          } else {
            if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 576, __pyx_L1_error)
            #else
            __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 576, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            #endif
          }
        } else {
          __pyx_t_5 = __pyx_t_13(__pyx_t_1);
          if (unlikely(!__pyx_t_5)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 576, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_5);
        }
        __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_5);
        __pyx_t_5 = 0;

        /* "pyreadstat/_readstat_writer.pyx":577
 *                 raise PyreadstatError(msg)
 *             for val in missing_values:
 *                 if val not in valid_user_missing:             # <<<<<<<<<<<<<<
 *                     msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val)
 *                     raise PyreadstatError(msg)
 */
        if (unlikely(!__pyx_v_valid_user_missing)) { __Pyx_RaiseUnboundLocalError("valid_user_missing"); __PYX_ERR(0, 577, __pyx_L1_error) }
        __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_val, __pyx_v_valid_user_missing, Py_NE)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 577, __pyx_L1_error)
        if (unlikely(__pyx_t_3)) {

          /* "pyreadstat/_readstat_writer.pyx":578
 *             for val in missing_values:
 *                 if val not in valid_user_missing:
 *                     msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val)             # <<<<<<<<<<<<<<
 *                     raise PyreadstatError(msg)
 * 
 */
          __pyx_t_5 = __Pyx_PyObject_Str(__pyx_v_val); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 578, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_9 = __Pyx_PyString_FormatSafe(__pyx_kp_s_missing_user_values_supports_val, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 578, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_v_msg = __pyx_t_9;
          __pyx_t_9 = 0;

          /* "pyreadstat/_readstat_writer.pyx":579
 *                 if val not in valid_user_missing:
 *                     msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val)
 *                     raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     cdef readstat_error_t retcode
 */
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_10 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_6 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_v_msg};
            __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 579, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_Raise(__pyx_t_9, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __PYX_ERR(0, 579, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":577
 *                 raise PyreadstatError(msg)
 *             for val in missing_values:
 *                 if val not in valid_user_missing:             # <<<<<<<<<<<<<<
 *                     msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val)
 *                     raise PyreadstatError(msg)
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":576
 *                 msg = "missing_user_values: values in dictionary must be list"
 *                 raise PyreadstatError(msg)
 *             for val in missing_values:             # <<<<<<<<<<<<<<
 *                 if val not in valid_user_missing:
 *                     msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val)
 */
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyreadstat/_readstat_writer.pyx":572
 *         elif file_format == FILE_FORMAT_SAS7BDAT or file_format == FILE_FORMAT_SAS7BCAT:
 *             valid_user_missing = valid_user_missing_sas
 *         for key, missing_values in missing_user_values.items():             # <<<<<<<<<<<<<<
 *             if not isinstance(missing_values, list):
 *                 msg = "missing_user_values: values in dictionary must be list"
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pyreadstat/_readstat_writer.pyx":567
 *                 raise PyreadstatError(msg)
 * 
 *     if missing_user_values:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":590
 *     cdef char *file_labl
 * 
 *     cdef list col_names = df.columns.values.tolist()             # <<<<<<<<<<<<<<
 *     if len(col_names) != len(set(col_names)):
 *         msg = "Non unique column names detected in the dataframe!"
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_n_s_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_values); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_tolist); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_6 = 1;
    }
  }
  {
    PyObject *__pyx_callargs[1] = {__pyx_t_9, };
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_2))) __PYX_ERR(0, 590, __pyx_L1_error)
  __pyx_v_col_names = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":591
 * 
 *     cdef list col_names = df.columns.values.tolist()
 *     if len(col_names) != len(set(col_names)):             # <<<<<<<<<<<<<<
 *         msg = "Non unique column names detected in the dataframe!"
 *         raise PyreadstatError(msg)
 */
  if (unlikely(__pyx_v_col_names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 591, __pyx_L1_error)
  }
  __pyx_t_7 = PyList_GET_SIZE(__pyx_v_col_names); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 591, __pyx_L1_error)
  __pyx_t_2 = PySet_New(__pyx_v_col_names); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_12 = PySet_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = (__pyx_t_7 != __pyx_t_12);
  if (unlikely(__pyx_t_3)) {

    /* "pyreadstat/_readstat_writer.pyx":592
 *     cdef list col_names = df.columns.values.tolist()
 *     if len(col_names) != len(set(col_names)):
 *         msg = "Non unique column names detected in the dataframe!"             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(msg)
 * 
 */
    __Pyx_INCREF(__pyx_kp_s_Non_unique_column_names_detected);
    __pyx_v_msg = __pyx_kp_s_Non_unique_column_names_detected;

    /* "pyreadstat/_readstat_writer.pyx":593
 *     if len(col_names) != len(set(col_names)):
 *         msg = "Non unique column names detected in the dataframe!"
 *         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     for variable_name in col_names:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_6 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_msg};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 593, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 593, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":591
 * 
 *     cdef list col_names = df.columns.values.tolist()
 *     if len(col_names) != len(set(col_names)):             # <<<<<<<<<<<<<<
 *         msg = "Non unique column names detected in the dataframe!"
 *         raise PyreadstatError(msg)
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":595
 *         raise PyreadstatError(msg)
 * 
 *     for variable_name in col_names:             # <<<<<<<<<<<<<<
 *         if type(variable_name) != str:
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 */
  if (unlikely(__pyx_v_col_names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 595, __pyx_L1_error)
  }
  __pyx_t_2 = __pyx_v_col_names; __Pyx_INCREF(__pyx_t_2); __pyx_t_12 = 0;
  for (;;) {
    if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_2)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 595, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_variable_name, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":596
 * 
 *     for variable_name in col_names:
 *         if type(variable_name) != str:             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 *         if not variable_name[0].isalpha():
 */
    __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_variable_name)), ((PyObject *)(&PyString_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 596, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__pyx_t_3)) {

      /* "pyreadstat/_readstat_writer.pyx":597
 *     for variable_name in col_names:
 *         if type(variable_name) != str:
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))             # <<<<<<<<<<<<<<
 *         if not variable_name[0].isalpha():
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 597, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_5 = __Pyx_PyObject_Str(((PyObject *)Py_TYPE(__pyx_v_variable_name))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 597, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 597, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_variable_name);
      __Pyx_GIVEREF(__pyx_v_variable_name);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_variable_name);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_variable_name_s_is_of_type_s_and, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 597, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_6 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_5};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 597, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 597, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":596
 * 
 *     for variable_name in col_names:
 *         if type(variable_name) != str:             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 *         if not variable_name[0].isalpha():
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":598
 *         if type(variable_name) != str:
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 *         if not variable_name[0].isalpha():             # <<<<<<<<<<<<<<
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))
 *         if " " in variable_name:
 */
    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_variable_name, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_isalpha); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_6 = 1;
      }
    }
    {
      PyObject *__pyx_callargs[1] = {__pyx_t_9, };
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = (!__pyx_t_3);
    if (unlikely(__pyx_t_4)) {

      /* "pyreadstat/_readstat_writer.pyx":599
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 *         if not variable_name[0].isalpha():
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))             # <<<<<<<<<<<<<<
 *         if " " in variable_name:
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_variable_name, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_variable_name, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_14 = __Pyx_PyObject_Ord(__pyx_t_10); if (unlikely(__pyx_t_14 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyInt_From_long(__pyx_t_14); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_INCREF(__pyx_v_variable_name);
      __Pyx_GIVEREF(__pyx_v_variable_name);
      PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_variable_name);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_10);
      __pyx_t_9 = 0;
      __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_variable_name_s_starts_with_an_i, __pyx_t_15); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_15)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_15);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_6 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_10};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 599, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":598
 *         if type(variable_name) != str:
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 *         if not variable_name[0].isalpha():             # <<<<<<<<<<<<<<
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))
 *         if " " in variable_name:
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":600
 *         if not variable_name[0].isalpha():
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))
 *         if " " in variable_name:             # <<<<<<<<<<<<<<
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)
 * 
 */
    __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s__2, __pyx_v_variable_name, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 600, __pyx_L1_error)
    if (unlikely(__pyx_t_4)) {

      /* "pyreadstat/_readstat_writer.pyx":601
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))
 *         if " " in variable_name:
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)             # <<<<<<<<<<<<<<
 * 
 *     if file_format == FILE_FORMAT_POR:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 601, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyString_FormatSafe(__pyx_kp_s_variable_name_s_contains_a_space, __pyx_v_variable_name); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 601, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_15 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_15)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_15);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_6 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_10};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 601, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":600
 *         if not variable_name[0].isalpha():
 *             raise PyreadstatError("variable name '%s' starts with an illegal (non-alphabetic) character: '%s' (ordinal %s)" % (variable_name, variable_name[0], ord(variable_name[0])))
 *         if " " in variable_name:             # <<<<<<<<<<<<<<
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)
 * 
 */
    }

    /* "pyreadstat/_readstat_writer.pyx":595
 *         raise PyreadstatError(msg)
 * 
 *     for variable_name in col_names:             # <<<<<<<<<<<<<<
 *         if type(variable_name) != str:
 *                 raise PyreadstatError("variable name '%s' is of type %s and it must be str (not starting with numbers!)" % (variable_name, str(type(variable_name))))
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":603
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)
 * 
 *     if file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         col_names = [x.upper() for x in col_names]
 * 
 */
  __pyx_t_4 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR);
  if (__pyx_t_4) {

    /* "pyreadstat/_readstat_writer.pyx":604
 * 
 *     if file_format == FILE_FORMAT_POR:
 *         col_names = [x.upper() for x in col_names]             # <<<<<<<<<<<<<<
 * 
 *     cdef list col_types = get_pandas_column_types(df, missing_user_values, variable_value_labels)
 */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(__pyx_v_col_names == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 604, __pyx_L1_error)
    }
    __pyx_t_1 = __pyx_v_col_names; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
    for (;;) {
      if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 604, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_upper); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 604, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_15 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_15)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_15);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_6 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[1] = {__pyx_t_15, };
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 604, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_col_names, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "pyreadstat/_readstat_writer.pyx":603
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)
 * 
 *     if file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         col_names = [x.upper() for x in col_names]
 * 
 */
  }

  /* "pyreadstat/_readstat_writer.pyx":606
 *         col_names = [x.upper() for x in col_names]
 * 
 *     cdef list col_types = get_pandas_column_types(df, missing_user_values, variable_value_labels)             # <<<<<<<<<<<<<<
 *     cdef int row_count = len(df)
 *     cdef int col_count = len(col_names)
 */
  __pyx_t_2 = __pyx_f_10pyreadstat_16_readstat_writer_get_pandas_column_types(__pyx_v_df, __pyx_v_missing_user_values, __pyx_v_variable_value_labels); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 606, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_col_types = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":607
 * 
 *     cdef list col_types = get_pandas_column_types(df, missing_user_values, variable_value_labels)
 *     cdef int row_count = len(df)             # <<<<<<<<<<<<<<
 *     cdef int col_count = len(col_names)
 *     cdef dict col_names_to_types = {k:v[0] for k,v in zip(col_names, col_types)}
 */
  __pyx_t_12 = PyObject_Length(__pyx_v_df); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 607, __pyx_L1_error)
  __pyx_v_row_count = __pyx_t_12;

  /* "pyreadstat/_readstat_writer.pyx":608
 *     cdef list col_types = get_pandas_column_types(df, missing_user_values, variable_value_labels)
 *     cdef int row_count = len(df)
 *     cdef int col_count = len(col_names)             # <<<<<<<<<<<<<<
 *     cdef dict col_names_to_types = {k:v[0] for k,v in zip(col_names, col_types)}
 * 
 */
  if (unlikely(__pyx_v_col_names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 608, __pyx_L1_error)
  }
  __pyx_t_12 = PyList_GET_SIZE(__pyx_v_col_names); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 608, __pyx_L1_error)
  __pyx_v_col_count = __pyx_t_12;

  /* "pyreadstat/_readstat_writer.pyx":609
 *     cdef int row_count = len(df)
 *     cdef int col_count = len(col_names)
 *     cdef dict col_names_to_types = {k:v[0] for k,v in zip(col_names, col_types)}             # <<<<<<<<<<<<<<
 * 
 *     cdef readstat_variable_t *variable
 */
  { /* enter inner scope */
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 609, __pyx_L35_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L35_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_col_names);
    __Pyx_GIVEREF(__pyx_v_col_names);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_col_names);
    __Pyx_INCREF(__pyx_v_col_types);
    __Pyx_GIVEREF(__pyx_v_col_types);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_col_types);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L35_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
      __pyx_t_1 = __pyx_t_5; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L35_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 609, __pyx_L35_error)
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 609, __pyx_L35_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L35_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 609, __pyx_L35_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L35_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        }
      } else {
        __pyx_t_5 = __pyx_t_8(__pyx_t_1);
        if (unlikely(!__pyx_t_5)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 609, __pyx_L35_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
        PyObject* sequence = __pyx_t_5;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 609, __pyx_L35_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_15);
        #else
        __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 609, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 609, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_15);
        #endif
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 609, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_9);
        index = 0; __pyx_t_10 = __pyx_t_11(__pyx_t_9); if (unlikely(!__pyx_t_10)) goto __pyx_L38_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        index = 1; __pyx_t_15 = __pyx_t_11(__pyx_t_9); if (unlikely(!__pyx_t_15)) goto __pyx_L38_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_15);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_9), 2) < 0) __PYX_ERR(0, 609, __pyx_L35_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L39_unpacking_done;
        __pyx_L38_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 609, __pyx_L35_error)
        __pyx_L39_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_k, __pyx_t_10);
      __pyx_t_10 = 0;
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_v, __pyx_t_15);
      __pyx_t_15 = 0;
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_7genexpr__pyx_v_v, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L35_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(PyDict_SetItem(__pyx_t_2, (PyObject*)__pyx_7genexpr__pyx_v_k, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 609, __pyx_L35_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_k); __pyx_7genexpr__pyx_v_k = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v); __pyx_7genexpr__pyx_v_v = 0;
    goto __pyx_L41_exit_scope;
    __pyx_L35_error:;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_k); __pyx_7genexpr__pyx_v_k = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v); __pyx_7genexpr__pyx_v_v = 0;
    goto __pyx_L1_error;
    __pyx_L41_exit_scope:;
  } /* exit inner scope */
  __pyx_v_col_names_to_types = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":618
 *     cdef int col_indx
 *     cdef bytes cur_col_label
 *     cdef int col_label_count = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef readstat_variable_t *tempvar
 */
  __pyx_v_col_label_count = 0;

  /* "pyreadstat/_readstat_writer.pyx":627
 *     cdef object values
 *     cdef dict value_labels
 *     cdef int lblset_cnt = 0             # <<<<<<<<<<<<<<
 *     cdef readstat_label_set_t *label_set
 *     cdef list col_label_temp
 */
  __pyx_v_lblset_cnt = 0;

  /* "pyreadstat/_readstat_writer.pyx":635
 *     cdef float mulfac, conv2secs
 * 
 *     if hasattr(os, 'fsencode'):             # <<<<<<<<<<<<<<
 *         try:
 *             filename_path = os.fsencode(filename_path)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_HasAttr(__pyx_t_2, __pyx_n_s_fsencode); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "pyreadstat/_readstat_writer.pyx":636
 * 
 *     if hasattr(os, 'fsencode'):
 *         try:             # <<<<<<<<<<<<<<
 *             filename_path = os.fsencode(filename_path)
 *         except UnicodeError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
      __Pyx_XGOTREF(__pyx_t_16);
      __Pyx_XGOTREF(__pyx_t_17);
      __Pyx_XGOTREF(__pyx_t_18);
      /*try:*/ {

        /* "pyreadstat/_readstat_writer.pyx":637
 *     if hasattr(os, 'fsencode'):
 *         try:
 *             filename_path = os.fsencode(filename_path)             # <<<<<<<<<<<<<<
 *         except UnicodeError:
 *             warnings.warn("file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly." % sys.getfilesystemencoding())
 */
        __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 637, __pyx_L43_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_fsencode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 637, __pyx_L43_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_6 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_filename_path};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 637, __pyx_L43_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_DECREF_SET(__pyx_v_filename_path, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":636
 * 
 *     if hasattr(os, 'fsencode'):
 *         try:             # <<<<<<<<<<<<<<
 *             filename_path = os.fsencode(filename_path)
 *         except UnicodeError:
 */
      }
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
      goto __pyx_L48_try_end;
      __pyx_L43_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":638
 *         try:
 *             filename_path = os.fsencode(filename_path)
 *         except UnicodeError:             # <<<<<<<<<<<<<<
 *             warnings.warn("file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly." % sys.getfilesystemencoding())
 *             filename_bytes = os.fsdecode(filename_path).encode("utf-8", "surrogateescape")
 */
      __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeError);
      if (__pyx_t_6) {
        __Pyx_AddTraceback("pyreadstat._readstat_writer.run_write", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(0, 638, __pyx_L45_except_error)
        __Pyx_XGOTREF(__pyx_t_2);
        __Pyx_XGOTREF(__pyx_t_5);
        __Pyx_XGOTREF(__pyx_t_1);

        /* "pyreadstat/_readstat_writer.pyx":639
 *             filename_path = os.fsencode(filename_path)
 *         except UnicodeError:
 *             warnings.warn("file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly." % sys.getfilesystemencoding())             # <<<<<<<<<<<<<<
 *             filename_bytes = os.fsdecode(filename_path).encode("utf-8", "surrogateescape")
 *     else:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_warnings); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 639, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_warn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 639, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_sys); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 639, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 639, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __pyx_t_19 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) {
          __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_20);
          if (likely(__pyx_t_19)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
            __Pyx_INCREF(__pyx_t_19);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_20, function);
            __pyx_t_6 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[1] = {__pyx_t_19, };
          __pyx_t_10 = __Pyx_PyObject_FastCall(__pyx_t_20, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 639, __pyx_L45_except_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        }
        __pyx_t_20 = __Pyx_PyString_FormatSafe(__pyx_kp_s_file_path_could_not_be_encoded_w, __pyx_t_10); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 639, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
            __pyx_t_6 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_20};
          __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
          if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 639, __pyx_L45_except_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "pyreadstat/_readstat_writer.pyx":640
 *         except UnicodeError:
 *             warnings.warn("file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly." % sys.getfilesystemencoding())
 *             filename_bytes = os.fsdecode(filename_path).encode("utf-8", "surrogateescape")             # <<<<<<<<<<<<<<
 *     else:
 *         if type(filename_path) == str:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_os); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 640, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_fsdecode); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 640, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_20);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_20, function);
            __pyx_t_6 = 1;
          }
        }
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_filename_path};
          __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_20, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 640, __pyx_L45_except_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        }
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_encode); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 640, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 640, __pyx_L45_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __pyx_v_filename_bytes = __pyx_t_15;
        __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L44_exception_handled;
      }
      goto __pyx_L45_except_error;

      /* "pyreadstat/_readstat_writer.pyx":636
 * 
 *     if hasattr(os, 'fsencode'):
 *         try:             # <<<<<<<<<<<<<<
 *             filename_path = os.fsencode(filename_path)
 *         except UnicodeError:
 */
      __pyx_L45_except_error:;
      __Pyx_XGIVEREF(__pyx_t_16);
      __Pyx_XGIVEREF(__pyx_t_17);
      __Pyx_XGIVEREF(__pyx_t_18);
      __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
      goto __pyx_L1_error;
      __pyx_L44_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_16);
      __Pyx_XGIVEREF(__pyx_t_17);
      __Pyx_XGIVEREF(__pyx_t_18);
      __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
      __pyx_L48_try_end:;
    }

    /* "pyreadstat/_readstat_writer.pyx":635
 *     cdef float mulfac, conv2secs
 * 
 *     if hasattr(os, 'fsencode'):             # <<<<<<<<<<<<<<
 *         try:
 *             filename_path = os.fsencode(filename_path)
 */
    goto __pyx_L42;
  }

  /* "pyreadstat/_readstat_writer.pyx":642
 *             filename_bytes = os.fsdecode(filename_path).encode("utf-8", "surrogateescape")
 *     else:
 *         if type(filename_path) == str:             # <<<<<<<<<<<<<<
 *             filename_bytes = filename_path.encode('utf-8')
 *         elif type(filename_path) == bytes:
 */
  /*else*/ {
    __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_filename_path)), ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 642, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {

      /* "pyreadstat/_readstat_writer.pyx":643
 *     else:
 *         if type(filename_path) == str:
 *             filename_bytes = filename_path.encode('utf-8')             # <<<<<<<<<<<<<<
 *         elif type(filename_path) == bytes:
 *             filename_bytes = filename_path
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 643, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_6 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_utf_8};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 643, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_v_filename_bytes = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pyreadstat/_readstat_writer.pyx":642
 *             filename_bytes = os.fsdecode(filename_path).encode("utf-8", "surrogateescape")
 *     else:
 *         if type(filename_path) == str:             # <<<<<<<<<<<<<<
 *             filename_bytes = filename_path.encode('utf-8')
 *         elif type(filename_path) == bytes:
 */
      goto __pyx_L51;
    }

    /* "pyreadstat/_readstat_writer.pyx":644
 *         if type(filename_path) == str:
 *             filename_bytes = filename_path.encode('utf-8')
 *         elif type(filename_path) == bytes:             # <<<<<<<<<<<<<<
 *             filename_bytes = filename_path
 *         else:
 */
    __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_filename_path)), ((PyObject *)(&PyBytes_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 644, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 644, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(__pyx_t_4)) {

      /* "pyreadstat/_readstat_writer.pyx":645
 *             filename_bytes = filename_path.encode('utf-8')
 *         elif type(filename_path) == bytes:
 *             filename_bytes = filename_path             # <<<<<<<<<<<<<<
 *         else:
 *             raise PyreadstatError("path must be either str or bytes")
 */
      __Pyx_INCREF(__pyx_v_filename_path);
      __pyx_v_filename_bytes = __pyx_v_filename_path;

      /* "pyreadstat/_readstat_writer.pyx":644
 *         if type(filename_path) == str:
 *             filename_bytes = filename_path.encode('utf-8')
 *         elif type(filename_path) == bytes:             # <<<<<<<<<<<<<<
 *             filename_bytes = filename_path
 *         else:
 */
      goto __pyx_L51;
    }

    /* "pyreadstat/_readstat_writer.pyx":647
 *             filename_bytes = filename_path
 *         else:
 *             raise PyreadstatError("path must be either str or bytes")             # <<<<<<<<<<<<<<
 * 
 *     filename_path = os.path.expanduser(filename_path)
 */
    /*else*/ {
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 647, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_6 = 1;
        }
      }
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_path_must_be_either_str_or_bytes};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 647, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 647, __pyx_L1_error)
    }
    __pyx_L51:;
  }
  __pyx_L42:;

  /* "pyreadstat/_readstat_writer.pyx":649
 *             raise PyreadstatError("path must be either str or bytes")
 * 
 *     filename_path = os.path.expanduser(filename_path)             # <<<<<<<<<<<<<<
 *     cdef int fd = open_file(filename_path)
 *     writer = readstat_writer_init()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_expanduser); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_6 = 1;
    }
  }
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_filename_path};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 649, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF_SET(__pyx_v_filename_path, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":650
 * 
 *     filename_path = os.path.expanduser(filename_path)
 *     cdef int fd = open_file(filename_path)             # <<<<<<<<<<<<<<
 *     writer = readstat_writer_init()
 * 
 */
  if (!(likely(PyBytes_CheckExact(__pyx_v_filename_path))||((__pyx_v_filename_path) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_v_filename_path))) __PYX_ERR(0, 650, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_10pyreadstat_16_readstat_writer_open_file(((PyObject*)__pyx_v_filename_path)); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 650, __pyx_L1_error)
  __pyx_v_fd = __pyx_t_6;

  /* "pyreadstat/_readstat_writer.pyx":651
 *     filename_path = os.path.expanduser(filename_path)
 *     cdef int fd = open_file(filename_path)
 *     writer = readstat_writer_init()             # <<<<<<<<<<<<<<
 * 
 *     try:
 */
  __pyx_v_writer = readstat_writer_init();

  /* "pyreadstat/_readstat_writer.pyx":653
 *     writer = readstat_writer_init()
 * 
 *     try:             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
 */
  /*try:*/ {
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16);
      __Pyx_XGOTREF(__pyx_t_18);
      __Pyx_XGOTREF(__pyx_t_17);
      __Pyx_XGOTREF(__pyx_t_16);
      /*try:*/ {

        /* "pyreadstat/_readstat_writer.pyx":655
 *     try:
 * 
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))             # <<<<<<<<<<<<<<
 * 
 *         if file_label:
 */
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_data_writer(__pyx_v_writer, __pyx_f_10pyreadstat_16_readstat_writer_write_bytes)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 655, __pyx_L55_error)

        /* "pyreadstat/_readstat_writer.pyx":657
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
 * 
 *         if file_label:             # <<<<<<<<<<<<<<
 *             file_label_bytes = file_label.encode("utf-8")
 *             file_labl = <char *> file_label_bytes
 */
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_file_label); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 657, __pyx_L55_error)
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":658
 * 
 *         if file_label:
 *             file_label_bytes = file_label.encode("utf-8")             # <<<<<<<<<<<<<<
 *             file_labl = <char *> file_label_bytes
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))
 */
          __pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_file_label, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_1))) __PYX_ERR(0, 658, __pyx_L55_error)
          __pyx_v_file_label_bytes = ((PyObject*)__pyx_t_1);
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":659
 *         if file_label:
 *             file_label_bytes = file_label.encode("utf-8")
 *             file_labl = <char *> file_label_bytes             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))
 * 
 */
          if (unlikely(__pyx_v_file_label_bytes == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
            __PYX_ERR(0, 659, __pyx_L55_error)
          }
          __pyx_t_21 = __Pyx_PyBytes_AsWritableString(__pyx_v_file_label_bytes); if (unlikely((!__pyx_t_21) && PyErr_Occurred())) __PYX_ERR(0, 659, __pyx_L55_error)
          __pyx_v_file_labl = ((char *)__pyx_t_21);

          /* "pyreadstat/_readstat_writer.pyx":660
 *             file_label_bytes = file_label.encode("utf-8")
 *             file_labl = <char *> file_label_bytes
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))             # <<<<<<<<<<<<<<
 * 
 *         if note:
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_writer_set_file_label(__pyx_v_writer, __pyx_v_file_labl)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 660, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":657
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
 * 
 *         if file_label:             # <<<<<<<<<<<<<<
 *             file_label_bytes = file_label.encode("utf-8")
 *             file_labl = <char *> file_label_bytes
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":662
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))
 * 
 *         if note:             # <<<<<<<<<<<<<<
 *             readstat_add_note(writer, note.encode("utf-8"))
 * 
 */
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_note); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 662, __pyx_L55_error)
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":663
 * 
 *         if note:
 *             readstat_add_note(writer, note.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *         if file_format_version > -1:
 */
          __pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_note, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) __PYX_ERR(0, 663, __pyx_L55_error)
          readstat_add_note(__pyx_v_writer, __pyx_t_22);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":662
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))
 * 
 *         if note:             # <<<<<<<<<<<<<<
 *             readstat_add_note(writer, note.encode("utf-8"))
 * 
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":665
 *             readstat_add_note(writer, note.encode("utf-8"))
 * 
 *         if file_format_version > -1:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))
 * 
 */
        __pyx_t_4 = (__pyx_v_file_format_version > -1L);
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":666
 * 
 *         if file_format_version > -1:
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))             # <<<<<<<<<<<<<<
 * 
 *         if row_compression:
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_writer_set_file_format_version(__pyx_v_writer, __pyx_v_file_format_version)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 666, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":665
 *             readstat_add_note(writer, note.encode("utf-8"))
 * 
 *         if file_format_version > -1:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))
 * 
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":668
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))
 * 
 *         if row_compression:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_compression(writer, READSTAT_COMPRESS_ROWS))
 * 
 */
        if (__pyx_v_row_compression) {

          /* "pyreadstat/_readstat_writer.pyx":669
 * 
 *         if row_compression:
 *             check_exit_status(readstat_writer_set_compression(writer, READSTAT_COMPRESS_ROWS))             # <<<<<<<<<<<<<<
 * 
 *         # table name is used only for xpt files
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_writer_set_compression(__pyx_v_writer, READSTAT_COMPRESS_ROWS)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 669, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":668
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))
 * 
 *         if row_compression:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_compression(writer, READSTAT_COMPRESS_ROWS))
 * 
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":672
 * 
 *         # table name is used only for xpt files
 *         if table_name:             # <<<<<<<<<<<<<<
 *             table_name_bytes = table_name.encode("utf-8")
 *             tab_name = <char *> table_name_bytes
 */
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_table_name); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 672, __pyx_L55_error)
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":673
 *         # table name is used only for xpt files
 *         if table_name:
 *             table_name_bytes = table_name.encode("utf-8")             # <<<<<<<<<<<<<<
 *             tab_name = <char *> table_name_bytes
 *             check_exit_status(readstat_writer_set_table_name(writer, tab_name))
 */
          __pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_table_name, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 673, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_v_table_name_bytes = __pyx_t_1;
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":674
 *         if table_name:
 *             table_name_bytes = table_name.encode("utf-8")
 *             tab_name = <char *> table_name_bytes             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_table_name(writer, tab_name))
 * 
 */
          __pyx_t_21 = __Pyx_PyObject_AsWritableString(__pyx_v_table_name_bytes); if (unlikely((!__pyx_t_21) && PyErr_Occurred())) __PYX_ERR(0, 674, __pyx_L55_error)
          __pyx_v_tab_name = ((char *)__pyx_t_21);

          /* "pyreadstat/_readstat_writer.pyx":675
 *             table_name_bytes = table_name.encode("utf-8")
 *             tab_name = <char *> table_name_bytes
 *             check_exit_status(readstat_writer_set_table_name(writer, tab_name))             # <<<<<<<<<<<<<<
 * 
 *         # add variables
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_writer_set_table_name(__pyx_v_writer, __pyx_v_tab_name)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 675, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":672
 * 
 *         # table name is used only for xpt files
 *         if table_name:             # <<<<<<<<<<<<<<
 *             table_name_bytes = table_name.encode("utf-8")
 *             tab_name = <char *> table_name_bytes
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":678
 * 
 *         # add variables
 *         if column_labels:             # <<<<<<<<<<<<<<
 *             if type(column_labels) != list and type(column_labels) != dict:
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 */
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_column_labels); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 678, __pyx_L55_error)
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":679
 *         # add variables
 *         if column_labels:
 *             if type(column_labels) != list and type(column_labels) != dict:             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 *             if type(column_labels) == dict:
 */
          __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_column_labels)), ((PyObject *)(&PyList_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L55_error)
          __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 679, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_3) {
          } else {
            __pyx_t_4 = __pyx_t_3;
            goto __pyx_L68_bool_binop_done;
          }
          __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_column_labels)), ((PyObject *)(&PyDict_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L55_error)
          __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 679, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_4 = __pyx_t_3;
          __pyx_L68_bool_binop_done:;
          if (unlikely(__pyx_t_4)) {

            /* "pyreadstat/_readstat_writer.pyx":680
 *         if column_labels:
 *             if type(column_labels) != list and type(column_labels) != dict:
 *                 raise PyreadstatError("column_labels must be either list or dict!")             # <<<<<<<<<<<<<<
 *             if type(column_labels) == dict:
 *                 col_label_temp = list()
 */
            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 680, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_2 = NULL;
            __pyx_t_6 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_2)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_2);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
                __pyx_t_6 = 1;
              }
            }
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_column_labels_must_be_either_lis};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 680, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            }
            __Pyx_Raise(__pyx_t_1, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __PYX_ERR(0, 680, __pyx_L55_error)

            /* "pyreadstat/_readstat_writer.pyx":679
 *         # add variables
 *         if column_labels:
 *             if type(column_labels) != list and type(column_labels) != dict:             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 *             if type(column_labels) == dict:
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":681
 *             if type(column_labels) != list and type(column_labels) != dict:
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 *             if type(column_labels) == dict:             # <<<<<<<<<<<<<<
 *                 col_label_temp = list()
 *                 for col_indx in range(col_count):
 */
          __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_column_labels)), ((PyObject *)(&PyDict_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L55_error)
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 681, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_4) {

            /* "pyreadstat/_readstat_writer.pyx":682
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 *             if type(column_labels) == dict:
 *                 col_label_temp = list()             # <<<<<<<<<<<<<<
 *                 for col_indx in range(col_count):
 *                     variable_name = col_names[col_indx]
 */
            __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_v_col_label_temp = ((PyObject*)__pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":683
 *             if type(column_labels) == dict:
 *                 col_label_temp = list()
 *                 for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *                     variable_name = col_names[col_indx]
 *                     if variable_name in column_labels.keys():
 */
            __pyx_t_6 = __pyx_v_col_count;
            __pyx_t_23 = __pyx_t_6;
            for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) {
              __pyx_v_col_indx = __pyx_t_24;

              /* "pyreadstat/_readstat_writer.pyx":684
 *                 col_label_temp = list()
 *                 for col_indx in range(col_count):
 *                     variable_name = col_names[col_indx]             # <<<<<<<<<<<<<<
 *                     if variable_name in column_labels.keys():
 *                         col_label_temp.append(column_labels[variable_name])
 */
              if (unlikely(__pyx_v_col_names == Py_None)) {
                PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                __PYX_ERR(0, 684, __pyx_L55_error)
              }
              __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_names, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_XDECREF_SET(__pyx_v_variable_name, __pyx_t_1);
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":685
 *                 for col_indx in range(col_count):
 *                     variable_name = col_names[col_indx]
 *                     if variable_name in column_labels.keys():             # <<<<<<<<<<<<<<
 *                         col_label_temp.append(column_labels[variable_name])
 *                     else:
 */
              __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_column_labels, __pyx_n_s_keys); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 685, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_2 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
                __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
                if (likely(__pyx_t_2)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                  __Pyx_INCREF(__pyx_t_2);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_5, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[1] = {__pyx_t_2, };
                __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_25, 0+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              }
              __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_variable_name, __pyx_t_1, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 685, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              if (__pyx_t_4) {

                /* "pyreadstat/_readstat_writer.pyx":686
 *                     variable_name = col_names[col_indx]
 *                     if variable_name in column_labels.keys():
 *                         col_label_temp.append(column_labels[variable_name])             # <<<<<<<<<<<<<<
 *                     else:
 *                         col_label_temp.append(None)
 */
                __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_column_labels, __pyx_v_variable_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 686, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_1);
                __pyx_t_26 = __Pyx_PyList_Append(__pyx_v_col_label_temp, __pyx_t_1); if (unlikely(__pyx_t_26 == ((int)-1))) __PYX_ERR(0, 686, __pyx_L55_error)
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":685
 *                 for col_indx in range(col_count):
 *                     variable_name = col_names[col_indx]
 *                     if variable_name in column_labels.keys():             # <<<<<<<<<<<<<<
 *                         col_label_temp.append(column_labels[variable_name])
 *                     else:
 */
                goto __pyx_L73;
              }

              /* "pyreadstat/_readstat_writer.pyx":688
 *                         col_label_temp.append(column_labels[variable_name])
 *                     else:
 *                         col_label_temp.append(None)             # <<<<<<<<<<<<<<
 *                 column_labels = col_label_temp
 * 
 */
              /*else*/ {
                __pyx_t_26 = __Pyx_PyList_Append(__pyx_v_col_label_temp, Py_None); if (unlikely(__pyx_t_26 == ((int)-1))) __PYX_ERR(0, 688, __pyx_L55_error)
              }
              __pyx_L73:;
            }

            /* "pyreadstat/_readstat_writer.pyx":689
 *                     else:
 *                         col_label_temp.append(None)
 *                 column_labels = col_label_temp             # <<<<<<<<<<<<<<
 * 
 *             col_label_count = len(column_labels)
 */
            __Pyx_INCREF(__pyx_v_col_label_temp);
            __Pyx_DECREF_SET(__pyx_v_column_labels, __pyx_v_col_label_temp);

            /* "pyreadstat/_readstat_writer.pyx":681
 *             if type(column_labels) != list and type(column_labels) != dict:
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 *             if type(column_labels) == dict:             # <<<<<<<<<<<<<<
 *                 col_label_temp = list()
 *                 for col_indx in range(col_count):
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":691
 *                 column_labels = col_label_temp
 * 
 *             col_label_count = len(column_labels)             # <<<<<<<<<<<<<<
 *             if col_label_count != col_count:
 *                 raise PyreadstatError("length of column labels must be the same as number of columns")
 */
          __pyx_t_12 = PyObject_Length(__pyx_v_column_labels); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 691, __pyx_L55_error)
          __pyx_v_col_label_count = __pyx_t_12;

          /* "pyreadstat/_readstat_writer.pyx":692
 * 
 *             col_label_count = len(column_labels)
 *             if col_label_count != col_count:             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError("length of column labels must be the same as number of columns")
 * 
 */
          __pyx_t_4 = (__pyx_v_col_label_count != __pyx_v_col_count);
          if (unlikely(__pyx_t_4)) {

            /* "pyreadstat/_readstat_writer.pyx":693
 *             col_label_count = len(column_labels)
 *             if col_label_count != col_count:
 *                 raise PyreadstatError("length of column labels must be the same as number of columns")             # <<<<<<<<<<<<<<
 * 
 *         for col_indx in range(col_count):
 */
            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 693, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_2 = NULL;
            __pyx_t_6 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_2)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_2);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
                __pyx_t_6 = 1;
              }
            }
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_length_of_column_labels_must_be};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 693, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            }
            __Pyx_Raise(__pyx_t_1, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __PYX_ERR(0, 693, __pyx_L55_error)

            /* "pyreadstat/_readstat_writer.pyx":692
 * 
 *             col_label_count = len(column_labels)
 *             if col_label_count != col_count:             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError("length of column labels must be the same as number of columns")
 * 
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":678
 * 
 *         # add variables
 *         if column_labels:             # <<<<<<<<<<<<<<
 *             if type(column_labels) != list and type(column_labels) != dict:
 *                 raise PyreadstatError("column_labels must be either list or dict!")
 */
        }

        /* "pyreadstat/_readstat_writer.pyx":695
 *                 raise PyreadstatError("length of column labels must be the same as number of columns")
 * 
 *         for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *             curtype, max_length, _ = col_types[col_indx]
 *             variable_name = col_names[col_indx]
 */
        __pyx_t_6 = __pyx_v_col_count;
        __pyx_t_23 = __pyx_t_6;
        for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) {
          __pyx_v_col_indx = __pyx_t_24;

          /* "pyreadstat/_readstat_writer.pyx":696
 * 
 *         for col_indx in range(col_count):
 *             curtype, max_length, _ = col_types[col_indx]             # <<<<<<<<<<<<<<
 *             variable_name = col_names[col_indx]
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length)
 */
          if (unlikely(__pyx_v_col_types == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 696, __pyx_L55_error)
          }
          __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_types, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 696, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
            PyObject* sequence = __pyx_t_1;
            Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
            if (unlikely(size != 3)) {
              if (size > 3) __Pyx_RaiseTooManyValuesError(3);
              else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
              __PYX_ERR(0, 696, __pyx_L55_error)
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
              __pyx_t_15 = PyTuple_GET_ITEM(sequence, 2); 
            } else {
              __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
              __pyx_t_15 = PyList_GET_ITEM(sequence, 2); 
            }
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_15);
            #else
            __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 696, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 696, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_15 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 696, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            #endif
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_20 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 696, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_20);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_20);
            index = 0; __pyx_t_5 = __pyx_t_11(__pyx_t_20); if (unlikely(!__pyx_t_5)) goto __pyx_L77_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_5);
            index = 1; __pyx_t_2 = __pyx_t_11(__pyx_t_20); if (unlikely(!__pyx_t_2)) goto __pyx_L77_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_2);
            index = 2; __pyx_t_15 = __pyx_t_11(__pyx_t_20); if (unlikely(!__pyx_t_15)) goto __pyx_L77_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_15);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_20), 3) < 0) __PYX_ERR(0, 696, __pyx_L55_error)
            __pyx_t_11 = NULL;
            __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
            goto __pyx_L78_unpacking_done;
            __pyx_L77_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
            __pyx_t_11 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 696, __pyx_L55_error)
            __pyx_L78_unpacking_done:;
          }
          __pyx_t_27 = ((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)__Pyx_PyInt_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_5)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 696, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_25 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_25 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 696, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_v_curtype = __pyx_t_27;
          __pyx_v_max_length = __pyx_t_25;
          __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_15);
          __pyx_t_15 = 0;

          /* "pyreadstat/_readstat_writer.pyx":697
 *         for col_indx in range(col_count):
 *             curtype, max_length, _ = col_types[col_indx]
 *             variable_name = col_names[col_indx]             # <<<<<<<<<<<<<<
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length)
 *             if variable_format:
 */
          if (unlikely(__pyx_v_col_names == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 697, __pyx_L55_error)
          }
          __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_names, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 697, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_XDECREF_SET(__pyx_v_variable_name, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":698
 *             curtype, max_length, _ = col_types[col_indx]
 *             variable_name = col_names[col_indx]
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length)             # <<<<<<<<<<<<<<
 *             if variable_format:
 *                 tempformat = variable_format.get(variable_name)
 */
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_variable_name, __pyx_n_s_encode); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 698, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_2 = NULL;
          __pyx_t_25 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_15);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_15, function);
              __pyx_t_25 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_utf_8};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 698, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          }
          __pyx_t_28 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_28) && PyErr_Occurred())) __PYX_ERR(0, 698, __pyx_L55_error)
          if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 698, __pyx_L55_error)
          }
          __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 698, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 698, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __pyx_t_29 = ((readstat_type_t)__Pyx_PyInt_As_readstat_type_t(__pyx_t_2)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 698, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_v_variable = readstat_add_variable(__pyx_v_writer, __pyx_t_28, __pyx_t_29, __pyx_v_max_length);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":699
 *             variable_name = col_names[col_indx]
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length)
 *             if variable_format:             # <<<<<<<<<<<<<<
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:
 */
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_variable_format); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 699, __pyx_L55_error)
          if (__pyx_t_4) {

            /* "pyreadstat/_readstat_writer.pyx":700
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length)
 *             if variable_format:
 *                 tempformat = variable_format.get(variable_name)             # <<<<<<<<<<<<<<
 *                 if tempformat:
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))
 */
            if (unlikely(__pyx_v_variable_format == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 700, __pyx_L55_error)
            }
            __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_format, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_1);
            if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_1))) __PYX_ERR(0, 700, __pyx_L55_error)
            __Pyx_XDECREF_SET(__pyx_v_tempformat, ((PyObject*)__pyx_t_1));
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":701
 *             if variable_format:
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:             # <<<<<<<<<<<<<<
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):
 */
            __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_tempformat); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 701, __pyx_L55_error)
            if (__pyx_t_4) {

              /* "pyreadstat/_readstat_writer.pyx":702
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))             # <<<<<<<<<<<<<<
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)
 */
              __pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_tempformat, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 702, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_30 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_30) && PyErr_Occurred())) __PYX_ERR(0, 702, __pyx_L55_error)
              readstat_variable_set_format(__pyx_v_variable, __pyx_t_30);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":701
 *             if variable_format:
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:             # <<<<<<<<<<<<<<
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":699
 *             variable_name = col_names[col_indx]
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length)
 *             if variable_format:             # <<<<<<<<<<<<<<
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":703
 *                 if tempformat:
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):             # <<<<<<<<<<<<<<
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)
 *                 readstat_variable_set_format(variable, curformat)
 */
          __pyx_t_1 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 703, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
            __PYX_ERR(0, 703, __pyx_L55_error)
          }
          __pyx_t_3 = (__Pyx_PySet_ContainsTF(__pyx_t_1, __pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 703, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_3) {
          } else {
            __pyx_t_4 = __pyx_t_3;
            goto __pyx_L82_bool_binop_done;
          }
          __pyx_t_3 = (__pyx_v_variable_format == ((PyObject*)Py_None));
          if (!__pyx_t_3) {
          } else {
            __pyx_t_4 = __pyx_t_3;
            goto __pyx_L82_bool_binop_done;
          }
          if (unlikely(__pyx_v_variable_format == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "keys");
            __PYX_ERR(0, 703, __pyx_L55_error)
          }
          __pyx_t_1 = __Pyx_PyDict_Keys(__pyx_v_variable_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 703, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_variable_name, __pyx_t_1, Py_NE)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 703, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_4 = __pyx_t_3;
          __pyx_L82_bool_binop_done:;
          if (__pyx_t_4) {

            /* "pyreadstat/_readstat_writer.pyx":704
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)             # <<<<<<<<<<<<<<
 *                 readstat_variable_set_format(variable, curformat)
 *             if col_label_count:
 */
            __pyx_t_21 = __pyx_f_10pyreadstat_16_readstat_writer_get_datetimelike_format_for_readstat(__pyx_v_file_format, __pyx_v_curtype); if (unlikely(__pyx_t_21 == ((char *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 704, __pyx_L55_error)
            __pyx_v_curformat = __pyx_t_21;

            /* "pyreadstat/_readstat_writer.pyx":705
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)
 *                 readstat_variable_set_format(variable, curformat)             # <<<<<<<<<<<<<<
 *             if col_label_count:
 *                 if column_labels[col_indx] is not None:
 */
            readstat_variable_set_format(__pyx_v_variable, __pyx_v_curformat);

            /* "pyreadstat/_readstat_writer.pyx":703
 *                 if tempformat:
 *                    readstat_variable_set_format(variable, tempformat.encode("utf-8"))
 *             if curtype in pyrwriter_datetimelike_types and (variable_format is None or variable_name not in variable_format.keys()):             # <<<<<<<<<<<<<<
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)
 *                 readstat_variable_set_format(variable, curformat)
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":706
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)
 *                 readstat_variable_set_format(variable, curformat)
 *             if col_label_count:             # <<<<<<<<<<<<<<
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:
 */
          __pyx_t_4 = (__pyx_v_col_label_count != 0);
          if (__pyx_t_4) {

            /* "pyreadstat/_readstat_writer.pyx":707
 *                 readstat_variable_set_format(variable, curformat)
 *             if col_label_count:
 *                 if column_labels[col_indx] is not None:             # <<<<<<<<<<<<<<
 *                     if type(column_labels[col_indx]) != str:
 *                         raise PyreadstatError("Column labels must be strings")
 */
            __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_column_labels, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_4 = (__pyx_t_1 != Py_None);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (__pyx_t_4) {

              /* "pyreadstat/_readstat_writer.pyx":708
 *             if col_label_count:
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:             # <<<<<<<<<<<<<<
 *                         raise PyreadstatError("Column labels must be strings")
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")
 */
              __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_column_labels, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_t_1)), ((PyObject *)(&PyString_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 708, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 708, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              if (unlikely(__pyx_t_4)) {

                /* "pyreadstat/_readstat_writer.pyx":709
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:
 *                         raise PyreadstatError("Column labels must be strings")             # <<<<<<<<<<<<<<
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")
 *                     readstat_variable_set_label(variable, cur_col_label)
 */
                __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 709, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_1);
                __pyx_t_15 = NULL;
                __pyx_t_25 = 0;
                if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
                  __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1);
                  if (likely(__pyx_t_15)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                    __Pyx_INCREF(__pyx_t_15);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_1, function);
                    __pyx_t_25 = 1;
                  }
                }
                {
                  PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_kp_s_Column_labels_must_be_strings};
                  __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                  __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
                  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __pyx_L55_error)
                  __Pyx_GOTREF(__pyx_t_2);
                  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                }
                __Pyx_Raise(__pyx_t_2, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
                __PYX_ERR(0, 709, __pyx_L55_error)

                /* "pyreadstat/_readstat_writer.pyx":708
 *             if col_label_count:
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:             # <<<<<<<<<<<<<<
 *                         raise PyreadstatError("Column labels must be strings")
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")
 */
              }

              /* "pyreadstat/_readstat_writer.pyx":710
 *                     if type(column_labels[col_indx]) != str:
 *                         raise PyreadstatError("Column labels must be strings")
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")             # <<<<<<<<<<<<<<
 *                     readstat_variable_set_label(variable, cur_col_label)
 *             if variable_value_labels:
 */
              __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_column_labels, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 710, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_encode); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 710, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
                __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
                if (likely(__pyx_t_1)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
                  __Pyx_INCREF(__pyx_t_1);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_15, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_kp_s_utf_8};
                __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
                if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 710, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              }
              if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_2))) __PYX_ERR(0, 710, __pyx_L55_error)
              __Pyx_XDECREF_SET(__pyx_v_cur_col_label, ((PyObject*)__pyx_t_2));
              __pyx_t_2 = 0;

              /* "pyreadstat/_readstat_writer.pyx":711
 *                         raise PyreadstatError("Column labels must be strings")
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")
 *                     readstat_variable_set_label(variable, cur_col_label)             # <<<<<<<<<<<<<<
 *             if variable_value_labels:
 *                 value_labels = variable_value_labels.get(variable_name)
 */
              if (unlikely(__pyx_v_cur_col_label == Py_None)) {
                PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
                __PYX_ERR(0, 711, __pyx_L55_error)
              }
              __pyx_t_31 = __Pyx_PyBytes_AsString(__pyx_v_cur_col_label); if (unlikely((!__pyx_t_31) && PyErr_Occurred())) __PYX_ERR(0, 711, __pyx_L55_error)
              readstat_variable_set_label(__pyx_v_variable, __pyx_t_31);

              /* "pyreadstat/_readstat_writer.pyx":707
 *                 readstat_variable_set_format(variable, curformat)
 *             if col_label_count:
 *                 if column_labels[col_indx] is not None:             # <<<<<<<<<<<<<<
 *                     if type(column_labels[col_indx]) != str:
 *                         raise PyreadstatError("Column labels must be strings")
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":706
 *                 curformat = get_datetimelike_format_for_readstat(file_format, curtype)
 *                 readstat_variable_set_format(variable, curformat)
 *             if col_label_count:             # <<<<<<<<<<<<<<
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":712
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")
 *                     readstat_variable_set_label(variable, cur_col_label)
 *             if variable_value_labels:             # <<<<<<<<<<<<<<
 *                 value_labels = variable_value_labels.get(variable_name)
 *                 if value_labels:
 */
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_variable_value_labels); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 712, __pyx_L55_error)
          if (__pyx_t_4) {

            /* "pyreadstat/_readstat_writer.pyx":713
 *                     readstat_variable_set_label(variable, cur_col_label)
 *             if variable_value_labels:
 *                 value_labels = variable_value_labels.get(variable_name)             # <<<<<<<<<<<<<<
 *                 if value_labels:
 *                     labelset_name = variable_name + str(lblset_cnt)
 */
            if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 713, __pyx_L55_error)
            }
            __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 713, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            if (!(likely(PyDict_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_2))) __PYX_ERR(0, 713, __pyx_L55_error)
            __Pyx_XDECREF_SET(__pyx_v_value_labels, ((PyObject*)__pyx_t_2));
            __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":714
 *             if variable_value_labels:
 *                 value_labels = variable_value_labels.get(variable_name)
 *                 if value_labels:             # <<<<<<<<<<<<<<
 *                     labelset_name = variable_name + str(lblset_cnt)
 *                     lblset_cnt += 1
 */
            __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_value_labels); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 714, __pyx_L55_error)
            if (__pyx_t_4) {

              /* "pyreadstat/_readstat_writer.pyx":715
 *                 value_labels = variable_value_labels.get(variable_name)
 *                 if value_labels:
 *                     labelset_name = variable_name + str(lblset_cnt)             # <<<<<<<<<<<<<<
 *                     lblset_cnt += 1
 *                     curuser_missing = None
 */
              __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lblset_cnt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_15 = __Pyx_PyObject_Str(__pyx_t_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 715, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __pyx_t_2 = PyNumber_Add(__pyx_v_variable_name, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __Pyx_XDECREF_SET(__pyx_v_labelset_name, __pyx_t_2);
              __pyx_t_2 = 0;

              /* "pyreadstat/_readstat_writer.pyx":716
 *                 if value_labels:
 *                     labelset_name = variable_name + str(lblset_cnt)
 *                     lblset_cnt += 1             # <<<<<<<<<<<<<<
 *                     curuser_missing = None
 *                     if missing_user_values:
 */
              __pyx_v_lblset_cnt = (__pyx_v_lblset_cnt + 1);

              /* "pyreadstat/_readstat_writer.pyx":717
 *                     labelset_name = variable_name + str(lblset_cnt)
 *                     lblset_cnt += 1
 *                     curuser_missing = None             # <<<<<<<<<<<<<<
 *                     if missing_user_values:
 *                         curuser_missing = missing_user_values.get(variable_name)
 */
              __Pyx_INCREF(Py_None);
              __Pyx_XDECREF_SET(__pyx_v_curuser_missing, Py_None);

              /* "pyreadstat/_readstat_writer.pyx":718
 *                     lblset_cnt += 1
 *                     curuser_missing = None
 *                     if missing_user_values:             # <<<<<<<<<<<<<<
 *                         curuser_missing = missing_user_values.get(variable_name)
 *                     label_set = set_value_label(writer, value_labels, labelset_name,
 */
              __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 718, __pyx_L55_error)
              if (__pyx_t_4) {

                /* "pyreadstat/_readstat_writer.pyx":719
 *                     curuser_missing = None
 *                     if missing_user_values:
 *                         curuser_missing = missing_user_values.get(variable_name)             # <<<<<<<<<<<<<<
 *                     label_set = set_value_label(writer, value_labels, labelset_name,
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)
 */
                if (unlikely(__pyx_v_missing_user_values == Py_None)) {
                  PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
                  __PYX_ERR(0, 719, __pyx_L55_error)
                }
                __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_user_values, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_DECREF_SET(__pyx_v_curuser_missing, __pyx_t_2);
                __pyx_t_2 = 0;

                /* "pyreadstat/_readstat_writer.pyx":718
 *                     lblset_cnt += 1
 *                     curuser_missing = None
 *                     if missing_user_values:             # <<<<<<<<<<<<<<
 *                         curuser_missing = missing_user_values.get(variable_name)
 *                     label_set = set_value_label(writer, value_labels, labelset_name,
 */
              }

              /* "pyreadstat/_readstat_writer.pyx":720
 *                     if missing_user_values:
 *                         curuser_missing = missing_user_values.get(variable_name)
 *                     label_set = set_value_label(writer, value_labels, labelset_name,             # <<<<<<<<<<<<<<
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)
 *                     readstat_variable_set_label_set(variable, label_set)
 */
              if (!(likely(PyString_CheckExact(__pyx_v_labelset_name))||((__pyx_v_labelset_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_labelset_name))) __PYX_ERR(0, 720, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":721
 *                         curuser_missing = missing_user_values.get(variable_name)
 *                     label_set = set_value_label(writer, value_labels, labelset_name,
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)             # <<<<<<<<<<<<<<
 *                     readstat_variable_set_label_set(variable, label_set)
 *             if missing_ranges:
 */
              __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_col_names_to_types, __pyx_v_variable_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 721, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_27 = ((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)__Pyx_PyInt_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_2)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 721, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              if (!(likely(PyString_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 721, __pyx_L55_error)
              if (!(likely(PyList_CheckExact(__pyx_v_curuser_missing))||((__pyx_v_curuser_missing) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_v_curuser_missing))) __PYX_ERR(0, 721, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":720
 *                     if missing_user_values:
 *                         curuser_missing = missing_user_values.get(variable_name)
 *                     label_set = set_value_label(writer, value_labels, labelset_name,             # <<<<<<<<<<<<<<
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)
 *                     readstat_variable_set_label_set(variable, label_set)
 */
              __pyx_t_32 = __pyx_f_10pyreadstat_16_readstat_writer_set_value_label(__pyx_v_writer, __pyx_v_value_labels, ((PyObject*)__pyx_v_labelset_name), __pyx_t_27, __pyx_v_file_format, ((PyObject*)__pyx_v_variable_name), ((PyObject*)__pyx_v_curuser_missing)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 720, __pyx_L55_error)
              __pyx_v_label_set = __pyx_t_32;

              /* "pyreadstat/_readstat_writer.pyx":722
 *                     label_set = set_value_label(writer, value_labels, labelset_name,
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)
 *                     readstat_variable_set_label_set(variable, label_set)             # <<<<<<<<<<<<<<
 *             if missing_ranges:
 *                 cur_ranges = missing_ranges.get(variable_name)
 */
              readstat_variable_set_label_set(__pyx_v_variable, __pyx_v_label_set);

              /* "pyreadstat/_readstat_writer.pyx":714
 *             if variable_value_labels:
 *                 value_labels = variable_value_labels.get(variable_name)
 *                 if value_labels:             # <<<<<<<<<<<<<<
 *                     labelset_name = variable_name + str(lblset_cnt)
 *                     lblset_cnt += 1
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":712
 *                     cur_col_label = column_labels[col_indx].encode("utf-8")
 *                     readstat_variable_set_label(variable, cur_col_label)
 *             if variable_value_labels:             # <<<<<<<<<<<<<<
 *                 value_labels = variable_value_labels.get(variable_name)
 *                 if value_labels:
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":723
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)
 *                     readstat_variable_set_label_set(variable, label_set)
 *             if missing_ranges:             # <<<<<<<<<<<<<<
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:
 */
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_missing_ranges); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 723, __pyx_L55_error)
          if (__pyx_t_4) {

            /* "pyreadstat/_readstat_writer.pyx":724
 *                     readstat_variable_set_label_set(variable, label_set)
 *             if missing_ranges:
 *                 cur_ranges = missing_ranges.get(variable_name)             # <<<<<<<<<<<<<<
 *                 if cur_ranges:
 *                     if not isinstance(cur_ranges, list):
 */
            if (unlikely(__pyx_v_missing_ranges == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 724, __pyx_L55_error)
            }
            __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_ranges, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 724, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_XDECREF_SET(__pyx_v_cur_ranges, __pyx_t_2);
            __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":725
 *             if missing_ranges:
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:             # <<<<<<<<<<<<<<
 *                     if not isinstance(cur_ranges, list):
 *                         msg = "missing_ranges: values in dictionary must be list"
 */
            __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_cur_ranges); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 725, __pyx_L55_error)
            if (__pyx_t_4) {

              /* "pyreadstat/_readstat_writer.pyx":726
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:
 *                     if not isinstance(cur_ranges, list):             # <<<<<<<<<<<<<<
 *                         msg = "missing_ranges: values in dictionary must be list"
 *                         raise PyreadstatError(msg)
 */
              __pyx_t_4 = PyList_Check(__pyx_v_cur_ranges); 
              __pyx_t_3 = (!__pyx_t_4);
              if (unlikely(__pyx_t_3)) {

                /* "pyreadstat/_readstat_writer.pyx":727
 *                 if cur_ranges:
 *                     if not isinstance(cur_ranges, list):
 *                         msg = "missing_ranges: values in dictionary must be list"             # <<<<<<<<<<<<<<
 *                         raise PyreadstatError(msg)
 *                     add_missing_ranges(cur_ranges, variable, curtype, variable_name)
 */
                __Pyx_INCREF(__pyx_kp_s_missing_ranges_values_in_diction);
                __pyx_v_msg = __pyx_kp_s_missing_ranges_values_in_diction;

                /* "pyreadstat/_readstat_writer.pyx":728
 *                     if not isinstance(cur_ranges, list):
 *                         msg = "missing_ranges: values in dictionary must be list"
 *                         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 *                     add_missing_ranges(cur_ranges, variable, curtype, variable_name)
 *             if variable_alignment:
 */
                __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 728, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_15);
                __pyx_t_1 = NULL;
                __pyx_t_25 = 0;
                if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
                  __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
                  if (likely(__pyx_t_1)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
                    __Pyx_INCREF(__pyx_t_1);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_15, function);
                    __pyx_t_25 = 1;
                  }
                }
                {
                  PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_msg};
                  __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
                  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 728, __pyx_L55_error)
                  __Pyx_GOTREF(__pyx_t_2);
                  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
                }
                __Pyx_Raise(__pyx_t_2, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
                __PYX_ERR(0, 728, __pyx_L55_error)

                /* "pyreadstat/_readstat_writer.pyx":726
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:
 *                     if not isinstance(cur_ranges, list):             # <<<<<<<<<<<<<<
 *                         msg = "missing_ranges: values in dictionary must be list"
 *                         raise PyreadstatError(msg)
 */
              }

              /* "pyreadstat/_readstat_writer.pyx":729
 *                         msg = "missing_ranges: values in dictionary must be list"
 *                         raise PyreadstatError(msg)
 *                     add_missing_ranges(cur_ranges, variable, curtype, variable_name)             # <<<<<<<<<<<<<<
 *             if variable_alignment:
 *                 # At the moment this is ineffective for sav and dta (the function runs but in
 */
              if (!(likely(PyList_CheckExact(__pyx_v_cur_ranges))||((__pyx_v_cur_ranges) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_v_cur_ranges))) __PYX_ERR(0, 729, __pyx_L55_error)
              if (!(likely(PyString_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 729, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_writer_add_missing_ranges(((PyObject*)__pyx_v_cur_ranges), __pyx_v_variable, __pyx_v_curtype, ((PyObject*)__pyx_v_variable_name)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 729, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":725
 *             if missing_ranges:
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:             # <<<<<<<<<<<<<<
 *                     if not isinstance(cur_ranges, list):
 *                         msg = "missing_ranges: values in dictionary must be list"
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":723
 *                         col_names_to_types[variable_name], file_format, variable_name, curuser_missing)
 *                     readstat_variable_set_label_set(variable, label_set)
 *             if missing_ranges:             # <<<<<<<<<<<<<<
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":730
 *                         raise PyreadstatError(msg)
 *                     add_missing_ranges(cur_ranges, variable, curtype, variable_name)
 *             if variable_alignment:             # <<<<<<<<<<<<<<
 *                 # At the moment this is ineffective for sav and dta (the function runs but in
 *                 # the resulting file all alignments are still unknown)
 */
          __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_variable_alignment); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 730, __pyx_L55_error)
          if (__pyx_t_3) {

            /* "pyreadstat/_readstat_writer.pyx":733
 *                 # At the moment this is ineffective for sav and dta (the function runs but in
 *                 # the resulting file all alignments are still unknown)
 *                 cur_alignment = variable_alignment.get(variable_name)             # <<<<<<<<<<<<<<
 *                 if cur_alignment:
 *                     set_variable_alignment(variable, cur_alignment, variable_name)
 */
            if (unlikely(__pyx_v_variable_alignment == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 733, __pyx_L55_error)
            }
            __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_alignment, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 733, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_XDECREF_SET(__pyx_v_cur_alignment, __pyx_t_2);
            __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":734
 *                 # the resulting file all alignments are still unknown)
 *                 cur_alignment = variable_alignment.get(variable_name)
 *                 if cur_alignment:             # <<<<<<<<<<<<<<
 *                     set_variable_alignment(variable, cur_alignment, variable_name)
 *             if variable_display_width:
 */
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_cur_alignment); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 734, __pyx_L55_error)
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":735
 *                 cur_alignment = variable_alignment.get(variable_name)
 *                 if cur_alignment:
 *                     set_variable_alignment(variable, cur_alignment, variable_name)             # <<<<<<<<<<<<<<
 *             if variable_display_width:
 *                 cur_display_width = variable_display_width.get(variable_name)
 */
              if (!(likely(PyString_CheckExact(__pyx_v_cur_alignment))||((__pyx_v_cur_alignment) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_cur_alignment))) __PYX_ERR(0, 735, __pyx_L55_error)
              if (!(likely(PyString_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 735, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_writer_set_variable_alignment(__pyx_v_variable, ((PyObject*)__pyx_v_cur_alignment), ((PyObject*)__pyx_v_variable_name)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 735, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":734
 *                 # the resulting file all alignments are still unknown)
 *                 cur_alignment = variable_alignment.get(variable_name)
 *                 if cur_alignment:             # <<<<<<<<<<<<<<
 *                     set_variable_alignment(variable, cur_alignment, variable_name)
 *             if variable_display_width:
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":730
 *                         raise PyreadstatError(msg)
 *                     add_missing_ranges(cur_ranges, variable, curtype, variable_name)
 *             if variable_alignment:             # <<<<<<<<<<<<<<
 *                 # At the moment this is ineffective for sav and dta (the function runs but in
 *                 # the resulting file all alignments are still unknown)
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":736
 *                 if cur_alignment:
 *                     set_variable_alignment(variable, cur_alignment, variable_name)
 *             if variable_display_width:             # <<<<<<<<<<<<<<
 *                 cur_display_width = variable_display_width.get(variable_name)
 *                 if cur_display_width:
 */
          __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_variable_display_width); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 736, __pyx_L55_error)
          if (__pyx_t_3) {

            /* "pyreadstat/_readstat_writer.pyx":737
 *                     set_variable_alignment(variable, cur_alignment, variable_name)
 *             if variable_display_width:
 *                 cur_display_width = variable_display_width.get(variable_name)             # <<<<<<<<<<<<<<
 *                 if cur_display_width:
 *                     set_variable_display_width(variable, cur_display_width, variable_name)
 */
            if (unlikely(__pyx_v_variable_display_width == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 737, __pyx_L55_error)
            }
            __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_display_width, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_XDECREF_SET(__pyx_v_cur_display_width, __pyx_t_2);
            __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":738
 *             if variable_display_width:
 *                 cur_display_width = variable_display_width.get(variable_name)
 *                 if cur_display_width:             # <<<<<<<<<<<<<<
 *                     set_variable_display_width(variable, cur_display_width, variable_name)
 *             if variable_measure:
 */
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_cur_display_width); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 738, __pyx_L55_error)
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":739
 *                 cur_display_width = variable_display_width.get(variable_name)
 *                 if cur_display_width:
 *                     set_variable_display_width(variable, cur_display_width, variable_name)             # <<<<<<<<<<<<<<
 *             if variable_measure:
 *                 cur_measure = variable_measure.get(variable_name)
 */
              __pyx_t_25 = __Pyx_PyInt_As_int(__pyx_v_cur_display_width); if (unlikely((__pyx_t_25 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 739, __pyx_L55_error)
              if (!(likely(PyString_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 739, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_writer_set_variable_display_width(__pyx_v_variable, __pyx_t_25, ((PyObject*)__pyx_v_variable_name)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 739, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":738
 *             if variable_display_width:
 *                 cur_display_width = variable_display_width.get(variable_name)
 *                 if cur_display_width:             # <<<<<<<<<<<<<<
 *                     set_variable_display_width(variable, cur_display_width, variable_name)
 *             if variable_measure:
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":736
 *                 if cur_alignment:
 *                     set_variable_alignment(variable, cur_alignment, variable_name)
 *             if variable_display_width:             # <<<<<<<<<<<<<<
 *                 cur_display_width = variable_display_width.get(variable_name)
 *                 if cur_display_width:
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":740
 *                 if cur_display_width:
 *                     set_variable_display_width(variable, cur_display_width, variable_name)
 *             if variable_measure:             # <<<<<<<<<<<<<<
 *                 cur_measure = variable_measure.get(variable_name)
 *                 if cur_measure:
 */
          __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_variable_measure); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 740, __pyx_L55_error)
          if (__pyx_t_3) {

            /* "pyreadstat/_readstat_writer.pyx":741
 *                     set_variable_display_width(variable, cur_display_width, variable_name)
 *             if variable_measure:
 *                 cur_measure = variable_measure.get(variable_name)             # <<<<<<<<<<<<<<
 *                 if cur_measure:
 *                     set_variable_measure(variable, cur_measure, variable_name)
 */
            if (unlikely(__pyx_v_variable_measure == Py_None)) {
              PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
              __PYX_ERR(0, 741, __pyx_L55_error)
            }
            __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_measure, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 741, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_XDECREF_SET(__pyx_v_cur_measure, __pyx_t_2);
            __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":742
 *             if variable_measure:
 *                 cur_measure = variable_measure.get(variable_name)
 *                 if cur_measure:             # <<<<<<<<<<<<<<
 *                     set_variable_measure(variable, cur_measure, variable_name)
 * 
 */
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_cur_measure); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 742, __pyx_L55_error)
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":743
 *                 cur_measure = variable_measure.get(variable_name)
 *                 if cur_measure:
 *                     set_variable_measure(variable, cur_measure, variable_name)             # <<<<<<<<<<<<<<
 * 
 *         # start writing
 */
              if (!(likely(PyString_CheckExact(__pyx_v_cur_measure))||((__pyx_v_cur_measure) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_cur_measure))) __PYX_ERR(0, 743, __pyx_L55_error)
              if (!(likely(PyString_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 743, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_writer_set_variable_measure(__pyx_v_variable, ((PyObject*)__pyx_v_cur_measure), ((PyObject*)__pyx_v_variable_name)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 743, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":742
 *             if variable_measure:
 *                 cur_measure = variable_measure.get(variable_name)
 *                 if cur_measure:             # <<<<<<<<<<<<<<
 *                     set_variable_measure(variable, cur_measure, variable_name)
 * 
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":740
 *                 if cur_display_width:
 *                     set_variable_display_width(variable, cur_display_width, variable_name)
 *             if variable_measure:             # <<<<<<<<<<<<<<
 *                 cur_measure = variable_measure.get(variable_name)
 *                 if cur_measure:
 */
          }
        }

        /* "pyreadstat/_readstat_writer.pyx":746
 * 
 *         # start writing
 *         if file_format == FILE_FORMAT_SAS7BCAT:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_sas7bcat(writer, &fd))
 *         elif file_format == FILE_FORMAT_DTA:
 */
        switch (__pyx_v_file_format) {
          case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BCAT:

          /* "pyreadstat/_readstat_writer.pyx":747
 *         # start writing
 *         if file_format == FILE_FORMAT_SAS7BCAT:
 *             check_exit_status(readstat_begin_writing_sas7bcat(writer, &fd))             # <<<<<<<<<<<<<<
 *         elif file_format == FILE_FORMAT_DTA:
 *             check_exit_status(readstat_begin_writing_dta(writer, &fd, row_count))
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_writing_sas7bcat(__pyx_v_writer, (&__pyx_v_fd))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 747, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":746
 * 
 *         # start writing
 *         if file_format == FILE_FORMAT_SAS7BCAT:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_sas7bcat(writer, &fd))
 *         elif file_format == FILE_FORMAT_DTA:
 */
          break;
          case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA:

          /* "pyreadstat/_readstat_writer.pyx":749
 *             check_exit_status(readstat_begin_writing_sas7bcat(writer, &fd))
 *         elif file_format == FILE_FORMAT_DTA:
 *             check_exit_status(readstat_begin_writing_dta(writer, &fd, row_count))             # <<<<<<<<<<<<<<
 *         elif file_format == FILE_FORMAT_SAV:
 *             check_exit_status(readstat_begin_writing_sav(writer, &fd, row_count))
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_writing_dta(__pyx_v_writer, (&__pyx_v_fd), __pyx_v_row_count)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 749, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":748
 *         if file_format == FILE_FORMAT_SAS7BCAT:
 *             check_exit_status(readstat_begin_writing_sas7bcat(writer, &fd))
 *         elif file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_dta(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_SAV:
 */
          break;
          case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAV:

          /* "pyreadstat/_readstat_writer.pyx":751
 *             check_exit_status(readstat_begin_writing_dta(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_SAV:
 *             check_exit_status(readstat_begin_writing_sav(writer, &fd, row_count))             # <<<<<<<<<<<<<<
 *         elif file_format == FILE_FORMAT_POR:
 *             check_exit_status(readstat_begin_writing_por(writer, &fd, row_count))
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_writing_sav(__pyx_v_writer, (&__pyx_v_fd), __pyx_v_row_count)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 751, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":750
 *         elif file_format == FILE_FORMAT_DTA:
 *             check_exit_status(readstat_begin_writing_dta(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_SAV:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_sav(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_POR:
 */
          break;
          case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR:

          /* "pyreadstat/_readstat_writer.pyx":753
 *             check_exit_status(readstat_begin_writing_sav(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_POR:
 *             check_exit_status(readstat_begin_writing_por(writer, &fd, row_count))             # <<<<<<<<<<<<<<
 *         elif file_format == FILE_FORMAT_SAS7BDAT:
 *             check_exit_status(readstat_begin_writing_sas7bdat(writer, &fd, row_count))
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_writing_por(__pyx_v_writer, (&__pyx_v_fd), __pyx_v_row_count)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 753, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":752
 *         elif file_format == FILE_FORMAT_SAV:
 *             check_exit_status(readstat_begin_writing_sav(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_por(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_SAS7BDAT:
 */
          break;
          case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BDAT:

          /* "pyreadstat/_readstat_writer.pyx":755
 *             check_exit_status(readstat_begin_writing_por(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_SAS7BDAT:
 *             check_exit_status(readstat_begin_writing_sas7bdat(writer, &fd, row_count))             # <<<<<<<<<<<<<<
 *         elif file_format == FILE_FORMAT_XPORT:
 *             check_exit_status(readstat_begin_writing_xport(writer, &fd, row_count))
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_writing_sas7bdat(__pyx_v_writer, (&__pyx_v_fd), __pyx_v_row_count)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 755, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":754
 *         elif file_format == FILE_FORMAT_POR:
 *             check_exit_status(readstat_begin_writing_por(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_SAS7BDAT:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_sas7bdat(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_XPORT:
 */
          break;
          case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_XPORT:

          /* "pyreadstat/_readstat_writer.pyx":757
 *             check_exit_status(readstat_begin_writing_sas7bdat(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_XPORT:
 *             check_exit_status(readstat_begin_writing_xport(writer, &fd, row_count))             # <<<<<<<<<<<<<<
 *         else:
 *             raise PyreadstatError("unknown file format")
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_writing_xport(__pyx_v_writer, (&__pyx_v_fd), __pyx_v_row_count)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 757, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":756
 *         elif file_format == FILE_FORMAT_SAS7BDAT:
 *             check_exit_status(readstat_begin_writing_sas7bdat(writer, &fd, row_count))
 *         elif file_format == FILE_FORMAT_XPORT:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_writing_xport(writer, &fd, row_count))
 *         else:
 */
          break;
          default:

          /* "pyreadstat/_readstat_writer.pyx":759
 *             check_exit_status(readstat_begin_writing_xport(writer, &fd, row_count))
 *         else:
 *             raise PyreadstatError("unknown file format")             # <<<<<<<<<<<<<<
 * 
 *         # validation
 */
          __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 759, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_1 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_15, function);
              __pyx_t_6 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_kp_s_unknown_file_format};
            __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 759, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          }
          __Pyx_Raise(__pyx_t_2, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __PYX_ERR(0, 759, __pyx_L55_error)
          break;
        }

        /* "pyreadstat/_readstat_writer.pyx":762
 * 
 *         # validation
 *         check_exit_status(readstat_validate_metadata(writer))             # <<<<<<<<<<<<<<
 *         for col_indx in range(col_count):
 *             tempvar = readstat_get_variable(writer, col_indx)
 */
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_validate_metadata(__pyx_v_writer)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 762, __pyx_L55_error)

        /* "pyreadstat/_readstat_writer.pyx":763
 *         # validation
 *         check_exit_status(readstat_validate_metadata(writer))
 *         for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *             tempvar = readstat_get_variable(writer, col_indx)
 *             check_exit_status(readstat_validate_variable(writer, tempvar))
 */
        __pyx_t_6 = __pyx_v_col_count;
        __pyx_t_23 = __pyx_t_6;
        for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) {
          __pyx_v_col_indx = __pyx_t_24;

          /* "pyreadstat/_readstat_writer.pyx":764
 *         check_exit_status(readstat_validate_metadata(writer))
 *         for col_indx in range(col_count):
 *             tempvar = readstat_get_variable(writer, col_indx)             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_validate_variable(writer, tempvar))
 * 
 */
          __pyx_v_tempvar = readstat_get_variable(__pyx_v_writer, __pyx_v_col_indx);

          /* "pyreadstat/_readstat_writer.pyx":765
 *         for col_indx in range(col_count):
 *             tempvar = readstat_get_variable(writer, col_indx)
 *             check_exit_status(readstat_validate_variable(writer, tempvar))             # <<<<<<<<<<<<<<
 * 
 *         # vectorized transform of datetime64ns columns
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_validate_variable(__pyx_v_writer, __pyx_v_tempvar)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 765, __pyx_L55_error)
        }

        /* "pyreadstat/_readstat_writer.pyx":768
 * 
 *         # vectorized transform of datetime64ns columns
 *         pywriter_types = [x[0] for x in col_types]             # <<<<<<<<<<<<<<
 *         hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types
 *         if hasdatetime64:
 */
        __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L55_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (unlikely(__pyx_v_col_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 768, __pyx_L55_error)
        }
        __pyx_t_15 = __pyx_v_col_types; __Pyx_INCREF(__pyx_t_15); __pyx_t_12 = 0;
        for (;;) {
          if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_15)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 768, __pyx_L55_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 768, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
          __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 768, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 768, __pyx_L55_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_v_pywriter_types = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":769
 *         # vectorized transform of datetime64ns columns
 *         pywriter_types = [x[0] for x in col_types]
 *         hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types             # <<<<<<<<<<<<<<
 *         if hasdatetime64:
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 */
        __pyx_t_2 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 769, __pyx_L55_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_pywriter_types, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 769, __pyx_L55_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (!__pyx_t_4) {
        } else {
          __pyx_t_3 = __pyx_t_4;
          goto __pyx_L105_bool_binop_done;
        }
        __pyx_t_2 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 769, __pyx_L55_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_pywriter_types, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 769, __pyx_L55_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_3 = __pyx_t_4;
        __pyx_L105_bool_binop_done:;
        __pyx_v_hasdatetime64 = __pyx_t_3;

        /* "pyreadstat/_readstat_writer.pyx":770
 *         pywriter_types = [x[0] for x in col_types]
 *         hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types
 *         if hasdatetime64:             # <<<<<<<<<<<<<<
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *                 offset_secs = spss_offset_secs
 */
        if (__pyx_v_hasdatetime64) {

          /* "pyreadstat/_readstat_writer.pyx":771
 *         hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types
 *         if hasdatetime64:
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *                 offset_secs = spss_offset_secs
 *             else:
 */
          switch (__pyx_v_file_format) {
            case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAV:
            case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR:

            /* "pyreadstat/_readstat_writer.pyx":772
 *         if hasdatetime64:
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *                 offset_secs = spss_offset_secs             # <<<<<<<<<<<<<<
 *             else:
 *                 offset_secs = sas_offset_secs
 */
            __pyx_v_offset_secs = __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_secs;

            /* "pyreadstat/_readstat_writer.pyx":771
 *         hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types
 *         if hasdatetime64:
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *                 offset_secs = spss_offset_secs
 *             else:
 */
            break;
            default:

            /* "pyreadstat/_readstat_writer.pyx":774
 *                 offset_secs = spss_offset_secs
 *             else:
 *                 offset_secs = sas_offset_secs             # <<<<<<<<<<<<<<
 *             mulfac = 1.0
 *             if file_format == FILE_FORMAT_DTA:
 */
            __pyx_v_offset_secs = __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_secs;
            break;
          }

          /* "pyreadstat/_readstat_writer.pyx":775
 *             else:
 *                 offset_secs = sas_offset_secs
 *             mulfac = 1.0             # <<<<<<<<<<<<<<
 *             if file_format == FILE_FORMAT_DTA:
 *                 # stata stores in milliseconds
 */
          __pyx_v_mulfac = 1.0;

          /* "pyreadstat/_readstat_writer.pyx":776
 *                 offset_secs = sas_offset_secs
 *             mulfac = 1.0
 *             if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *                 # stata stores in milliseconds
 *                 mulfac = 1000.0
 */
          __pyx_t_3 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
          if (__pyx_t_3) {

            /* "pyreadstat/_readstat_writer.pyx":778
 *             if file_format == FILE_FORMAT_DTA:
 *                 # stata stores in milliseconds
 *                 mulfac = 1000.0             # <<<<<<<<<<<<<<
 *             df2 = df.copy()
 *             for col_indx in range(col_count):
 */
            __pyx_v_mulfac = 1000.0;

            /* "pyreadstat/_readstat_writer.pyx":776
 *                 offset_secs = sas_offset_secs
 *             mulfac = 1.0
 *             if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *                 # stata stores in milliseconds
 *                 mulfac = 1000.0
 */
          }

          /* "pyreadstat/_readstat_writer.pyx":779
 *                 # stata stores in milliseconds
 *                 mulfac = 1000.0
 *             df2 = df.copy()             # <<<<<<<<<<<<<<
 *             for col_indx in range(col_count):
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:
 */
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_n_s_copy); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 779, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_1 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_15, function);
              __pyx_t_6 = 1;
            }
          }
          {
            PyObject *__pyx_callargs[1] = {__pyx_t_1, };
            __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 779, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          }
          __pyx_v_df2 = __pyx_t_2;
          __pyx_t_2 = 0;

          /* "pyreadstat/_readstat_writer.pyx":780
 *                 mulfac = 1000.0
 *             df2 = df.copy()
 *             for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac
 */
          __pyx_t_6 = __pyx_v_col_count;
          __pyx_t_23 = __pyx_t_6;
          for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) {
            __pyx_v_col_indx = __pyx_t_24;

            /* "pyreadstat/_readstat_writer.pyx":781
 *             df2 = df.copy()
 *             for col_indx in range(col_count):
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:             # <<<<<<<<<<<<<<
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:
 */
            __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 781, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 781, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_15, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 781, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 781, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":782
 *             for col_indx in range(col_count):
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac             # <<<<<<<<<<<<<<
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(np.float64)/1e6) + offset_secs) * mulfac
 */
              __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_np); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_round); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_iloc); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_20);
              __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_INCREF(__pyx_slice_);
              __Pyx_GIVEREF(__pyx_slice_);
              PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_slice_);
              __Pyx_GIVEREF(__pyx_t_9);
              PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
              __pyx_t_9 = 0;
              __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_20, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_values); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_astype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_10 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
                if (likely(__pyx_t_10)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_10);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_9, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_builtin_object};
                __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 782, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              }
              __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_astype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_5 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
                if (likely(__pyx_t_5)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_5);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_9, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_10};
                __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 782, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_15);
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              }
              __pyx_t_9 = __Pyx_PyFloat_DivideObjC(__pyx_t_15, __pyx_float_1e9, 1e9, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __pyx_t_15 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
                __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_2);
                if (likely(__pyx_t_15)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
                  __Pyx_INCREF(__pyx_t_15);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_2, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_9};
                __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              }
              __pyx_t_2 = PyFloat_FromDouble(__pyx_v_offset_secs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __pyx_t_2 = PyFloat_FromDouble(__pyx_v_mulfac); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_1 = PyNumber_Multiply(__pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_iloc); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __Pyx_INCREF(__pyx_slice_);
              __Pyx_GIVEREF(__pyx_slice_);
              PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_slice_);
              __Pyx_GIVEREF(__pyx_t_9);
              PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_9);
              __pyx_t_9 = 0;
              if (unlikely((PyObject_SetItem(__pyx_t_2, __pyx_t_15, __pyx_t_1) < 0))) __PYX_ERR(0, 782, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":781
 *             df2 = df.copy()
 *             for col_indx in range(col_count):
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:             # <<<<<<<<<<<<<<
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:
 */
              goto __pyx_L111;
            }

            /* "pyreadstat/_readstat_writer.pyx":783
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:             # <<<<<<<<<<<<<<
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(np.float64)/1e6) + offset_secs) * mulfac
 *                     df2.loc[df2[df2.columns[col_indx]]==-9223056417655, df2.columns[col_indx]] = np.nan
 */
            __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 783, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_15, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 783, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 783, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":784
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(np.float64)/1e6) + offset_secs) * mulfac             # <<<<<<<<<<<<<<
 *                     df2.loc[df2[df2.columns[col_indx]]==-9223056417655, df2.columns[col_indx]] = np.nan
 * 
 */
              __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_np); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_round); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_iloc); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_INCREF(__pyx_slice_);
              __Pyx_GIVEREF(__pyx_slice_);
              PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_slice_);
              __Pyx_GIVEREF(__pyx_t_10);
              PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_10);
              __pyx_t_10 = 0;
              __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_astype); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_5 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
                __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_10);
                if (likely(__pyx_t_5)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
                  __Pyx_INCREF(__pyx_t_5);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_10, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_9};
                __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 784, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_15);
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              }
              __pyx_t_10 = __Pyx_PyFloat_DivideObjC(__pyx_t_15, __pyx_float_1e6, 1e6, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __pyx_t_15 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
                __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1);
                if (likely(__pyx_t_15)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                  __Pyx_INCREF(__pyx_t_15);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_1, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_10};
                __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              }
              __pyx_t_1 = PyFloat_FromDouble(__pyx_v_offset_secs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mulfac); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_2 = PyNumber_Multiply(__pyx_t_10, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_iloc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __Pyx_INCREF(__pyx_slice_);
              __Pyx_GIVEREF(__pyx_slice_);
              PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_slice_);
              __Pyx_GIVEREF(__pyx_t_10);
              PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_10);
              __pyx_t_10 = 0;
              if (unlikely((PyObject_SetItem(__pyx_t_1, __pyx_t_15, __pyx_t_2) < 0))) __PYX_ERR(0, 784, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

              /* "pyreadstat/_readstat_writer.pyx":785
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(np.float64)/1e6) + offset_secs) * mulfac
 *                     df2.loc[df2[df2.columns[col_indx]]==-9223056417655, df2.columns[col_indx]] = np.nan             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
              __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_nan); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_loc); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_df2, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_10 = PyObject_RichCompare(__pyx_t_1, __pyx_int_neg_9223056417655, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_GIVEREF(__pyx_t_10);
              PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10);
              __Pyx_GIVEREF(__pyx_t_9);
              PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_9);
              __pyx_t_10 = 0;
              __pyx_t_9 = 0;
              if (unlikely((PyObject_SetItem(__pyx_t_2, __pyx_t_1, __pyx_t_15) < 0))) __PYX_ERR(0, 785, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

              /* "pyreadstat/_readstat_writer.pyx":783
 *                 if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS:
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac
 *                 elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US:             # <<<<<<<<<<<<<<
 *                     df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(np.float64)/1e6) + offset_secs) * mulfac
 *                     df2.loc[df2[df2.columns[col_indx]]==-9223056417655, df2.columns[col_indx]] = np.nan
 */
            }
            __pyx_L111:;
          }

          /* "pyreadstat/_readstat_writer.pyx":770
 *         pywriter_types = [x[0] for x in col_types]
 *         hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types
 *         if hasdatetime64:             # <<<<<<<<<<<<<<
 *             if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *                 offset_secs = spss_offset_secs
 */
          goto __pyx_L107;
        }

        /* "pyreadstat/_readstat_writer.pyx":788
 * 
 *         else:
 *             df2 = df             # <<<<<<<<<<<<<<
 * 
 *         # inserting
 */
        /*else*/ {
          __Pyx_INCREF(__pyx_v_df);
          __pyx_v_df2 = __pyx_v_df;
        }
        __pyx_L107:;

        /* "pyreadstat/_readstat_writer.pyx":791
 * 
 *         # inserting
 *         rowcnt = 0             # <<<<<<<<<<<<<<
 * 
 *         for row in df2.values:
 */
        __Pyx_INCREF(__pyx_int_0);
        __pyx_v_rowcnt = __pyx_int_0;

        /* "pyreadstat/_readstat_writer.pyx":793
 *         rowcnt = 0
 * 
 *         for row in df2.values:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_row(writer))
 * 
 */
        __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_df2, __pyx_n_s_values); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 793, __pyx_L55_error)
        __Pyx_GOTREF(__pyx_t_15);
        if (likely(PyList_CheckExact(__pyx_t_15)) || PyTuple_CheckExact(__pyx_t_15)) {
          __pyx_t_1 = __pyx_t_15; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
          __pyx_t_8 = NULL;
        } else {
          __pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 793, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 793, __pyx_L55_error)
        }
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        for (;;) {
          if (likely(!__pyx_t_8)) {
            if (likely(PyList_CheckExact(__pyx_t_1))) {
              if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_15 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_15); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 793, __pyx_L55_error)
              #else
              __pyx_t_15 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 793, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              #endif
            } else {
              if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_15); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 793, __pyx_L55_error)
              #else
              __pyx_t_15 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 793, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              #endif
            }
          } else {
            __pyx_t_15 = __pyx_t_8(__pyx_t_1);
            if (unlikely(!__pyx_t_15)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 793, __pyx_L55_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_15);
          }
          __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_15);
          __pyx_t_15 = 0;

          /* "pyreadstat/_readstat_writer.pyx":794
 * 
 *         for row in df2.values:
 *             check_exit_status(readstat_begin_row(writer))             # <<<<<<<<<<<<<<
 * 
 *             for col_indx in range(col_count):
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_begin_row(__pyx_v_writer)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 794, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":796
 *             check_exit_status(readstat_begin_row(writer))
 * 
 *             for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 * 
 *                 tempvar = readstat_get_variable(writer, col_indx)
 */
          __pyx_t_6 = __pyx_v_col_count;
          __pyx_t_23 = __pyx_t_6;
          for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) {
            __pyx_v_col_indx = __pyx_t_24;

            /* "pyreadstat/_readstat_writer.pyx":798
 *             for col_indx in range(col_count):
 * 
 *                 tempvar = readstat_get_variable(writer, col_indx)             # <<<<<<<<<<<<<<
 *                 curval = row[col_indx]
 *                 curtype = pywriter_types[col_indx]
 */
            __pyx_v_tempvar = readstat_get_variable(__pyx_v_writer, __pyx_v_col_indx);

            /* "pyreadstat/_readstat_writer.pyx":799
 * 
 *                 tempvar = readstat_get_variable(writer, col_indx)
 *                 curval = row[col_indx]             # <<<<<<<<<<<<<<
 *                 curtype = pywriter_types[col_indx]
 *                 is_missing = col_types[col_indx][2]
 */
            __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_row, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 799, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            __Pyx_XDECREF_SET(__pyx_v_curval, __pyx_t_15);
            __pyx_t_15 = 0;

            /* "pyreadstat/_readstat_writer.pyx":800
 *                 tempvar = readstat_get_variable(writer, col_indx)
 *                 curval = row[col_indx]
 *                 curtype = pywriter_types[col_indx]             # <<<<<<<<<<<<<<
 *                 is_missing = col_types[col_indx][2]
 *                 curuser_missing = None
 */
            __pyx_t_15 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 800, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            __pyx_t_27 = ((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)__Pyx_PyInt_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_15)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 800, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __pyx_v_curtype = __pyx_t_27;

            /* "pyreadstat/_readstat_writer.pyx":801
 *                 curval = row[col_indx]
 *                 curtype = pywriter_types[col_indx]
 *                 is_missing = col_types[col_indx][2]             # <<<<<<<<<<<<<<
 *                 curuser_missing = None
 *                 if missing_user_values:
 */
            if (unlikely(__pyx_v_col_types == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
              __PYX_ERR(0, 801, __pyx_L55_error)
            }
            __pyx_t_15 = __Pyx_GetItemInt_List(__pyx_v_col_types, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 801, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_XDECREF_SET(__pyx_v_is_missing, __pyx_t_2);
            __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":802
 *                 curtype = pywriter_types[col_indx]
 *                 is_missing = col_types[col_indx][2]
 *                 curuser_missing = None             # <<<<<<<<<<<<<<
 *                 if missing_user_values:
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 */
            __Pyx_INCREF(Py_None);
            __Pyx_XDECREF_SET(__pyx_v_curuser_missing, Py_None);

            /* "pyreadstat/_readstat_writer.pyx":803
 *                 is_missing = col_types[col_indx][2]
 *                 curuser_missing = None
 *                 if missing_user_values:             # <<<<<<<<<<<<<<
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 * 
 */
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 803, __pyx_L55_error)
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":804
 *                 curuser_missing = None
 *                 if missing_user_values:
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])             # <<<<<<<<<<<<<<
 * 
 *                 if is_missing:
 */
              if (unlikely(__pyx_v_missing_user_values == Py_None)) {
                PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
                __PYX_ERR(0, 804, __pyx_L55_error)
              }
              if (unlikely(__pyx_v_col_names == Py_None)) {
                PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                __PYX_ERR(0, 804, __pyx_L55_error)
              }
              __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_col_names, __pyx_v_col_indx, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 804, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_15 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_user_values, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 804, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF_SET(__pyx_v_curuser_missing, __pyx_t_15);
              __pyx_t_15 = 0;

              /* "pyreadstat/_readstat_writer.pyx":803
 *                 is_missing = col_types[col_indx][2]
 *                 curuser_missing = None
 *                 if missing_user_values:             # <<<<<<<<<<<<<<
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 * 
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":806
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 * 
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     #if curval is None or (type(curval) in numeric_types and np.isnan(curval)):
 *                     if pd.isna(curval):
 */
            __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_is_missing); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 806, __pyx_L55_error)
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":808
 *                 if is_missing:
 *                     #if curval is None or (type(curval) in numeric_types and np.isnan(curval)):
 *                     if pd.isna(curval):             # <<<<<<<<<<<<<<
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
 *                         continue
 */
              __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 808, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_isna); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 808, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __pyx_t_2 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
                __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
                if (likely(__pyx_t_2)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_2);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_9, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_curval};
                __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 808, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_15);
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              }
              __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 808, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              if (__pyx_t_3) {

                /* "pyreadstat/_readstat_writer.pyx":809
 *                     #if curval is None or (type(curval) in numeric_types and np.isnan(curval)):
 *                     if pd.isna(curval):
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))             # <<<<<<<<<<<<<<
 *                         continue
 * 
 */
                __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_missing_value(__pyx_v_writer, __pyx_v_tempvar)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 809, __pyx_L55_error)

                /* "pyreadstat/_readstat_writer.pyx":810
 *                     if pd.isna(curval):
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                 if curuser_missing and curtype in pywriter_numeric_types:
 */
                goto __pyx_L114_continue;

                /* "pyreadstat/_readstat_writer.pyx":808
 *                 if is_missing:
 *                     #if curval is None or (type(curval) in numeric_types and np.isnan(curval)):
 *                     if pd.isna(curval):             # <<<<<<<<<<<<<<
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
 *                         continue
 */
              }

              /* "pyreadstat/_readstat_writer.pyx":806
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 * 
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     #if curval is None or (type(curval) in numeric_types and np.isnan(curval)):
 *                     if pd.isna(curval):
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":812
 *                         continue
 * 
 *                 if curuser_missing and curtype in pywriter_numeric_types:             # <<<<<<<<<<<<<<
 *                     if curval in curuser_missing:
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))
 */
            __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_curuser_missing); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 812, __pyx_L55_error)
            if (__pyx_t_4) {
            } else {
              __pyx_t_3 = __pyx_t_4;
              goto __pyx_L120_bool_binop_done;
            }
            __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 812, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
              __PYX_ERR(0, 812, __pyx_L55_error)
            }
            __pyx_t_4 = (__Pyx_PySet_ContainsTF(__pyx_t_15, __pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 812, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __pyx_t_3 = __pyx_t_4;
            __pyx_L120_bool_binop_done:;
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":813
 * 
 *                 if curuser_missing and curtype in pywriter_numeric_types:
 *                     if curval in curuser_missing:             # <<<<<<<<<<<<<<
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))
 *                         continue
 */
              __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_curval, __pyx_v_curuser_missing, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 813, __pyx_L55_error)
              if (__pyx_t_3) {

                /* "pyreadstat/_readstat_writer.pyx":814
 *                 if curuser_missing and curtype in pywriter_numeric_types:
 *                     if curval in curuser_missing:
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))             # <<<<<<<<<<<<<<
 *                         continue
 * 
 */
                __pyx_t_14 = __Pyx_PyObject_Ord(__pyx_v_curval); if (unlikely(__pyx_t_14 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 814, __pyx_L55_error)
                __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_tagged_missing_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_14)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 814, __pyx_L55_error)

                /* "pyreadstat/_readstat_writer.pyx":815
 *                     if curval in curuser_missing:
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                 if curtype == PYWRITER_DOUBLE:
 */
                goto __pyx_L114_continue;

                /* "pyreadstat/_readstat_writer.pyx":813
 * 
 *                 if curuser_missing and curtype in pywriter_numeric_types:
 *                     if curval in curuser_missing:             # <<<<<<<<<<<<<<
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))
 *                         continue
 */
              }

              /* "pyreadstat/_readstat_writer.pyx":812
 *                         continue
 * 
 *                 if curuser_missing and curtype in pywriter_numeric_types:             # <<<<<<<<<<<<<<
 *                     if curval in curuser_missing:
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))
 */
            }

            /* "pyreadstat/_readstat_writer.pyx":817
 *                         continue
 * 
 *                 if curtype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:
 */
            __pyx_t_3 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE);
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":818
 * 
 *                 if curtype == PYWRITER_DOUBLE:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_INTEGER:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))
 */
              __pyx_t_33 = __pyx_PyFloat_AsDouble(__pyx_v_curval); if (unlikely((__pyx_t_33 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 818, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_double_value(__pyx_v_writer, __pyx_v_tempvar, ((double)__pyx_t_33))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 818, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":817
 *                         continue
 * 
 *                 if curtype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":819
 *                 if curtype == PYWRITER_DOUBLE:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))
 *                 elif curtype == PYWRITER_LOGICAL:
 */
            __pyx_t_3 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER);
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":820
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_LOGICAL:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))
 */
              __pyx_t_34 = __Pyx_PyInt_As_int32_t(__pyx_v_curval); if (unlikely((__pyx_t_34 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 820, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_int32_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_34)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 820, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":819
 *                 if curtype == PYWRITER_DOUBLE:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))
 *                 elif curtype == PYWRITER_LOGICAL:
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":821
 *                 elif curtype == PYWRITER_INTEGER:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))
 *                 elif curtype == PYWRITER_LOGICAL:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))
 *                 elif curtype == PYWRITER_CHARACTER:
 */
            __pyx_t_3 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL);
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":822
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))
 *                 elif curtype == PYWRITER_LOGICAL:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_CHARACTER:
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))
 */
              __pyx_t_25 = __Pyx_PyInt_As_int(__pyx_v_curval); if (unlikely((__pyx_t_25 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 822, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_int32_value(__pyx_v_writer, __pyx_v_tempvar, ((int)__pyx_t_25))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 822, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":821
 *                 elif curtype == PYWRITER_INTEGER:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, curval))
 *                 elif curtype == PYWRITER_LOGICAL:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))
 *                 elif curtype == PYWRITER_CHARACTER:
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":823
 *                 elif curtype == PYWRITER_LOGICAL:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))
 *                 elif curtype == PYWRITER_CHARACTER:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))
 *                 elif curtype == PYWRITER_OBJECT:
 */
            __pyx_t_3 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER);
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":824
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))
 *                 elif curtype == PYWRITER_CHARACTER:
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_OBJECT:
 *                     curvalstr = str(curval)
 */
              __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_curval, __pyx_n_s_encode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 824, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_2 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
                if (likely(__pyx_t_2)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_2);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_9, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_utf_8};
                __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 824, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_15);
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              }
              __pyx_t_35 = __Pyx_PyObject_AsString(__pyx_t_15); if (unlikely((!__pyx_t_35) && PyErr_Occurred())) __PYX_ERR(0, 824, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_string_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_35)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 824, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

              /* "pyreadstat/_readstat_writer.pyx":823
 *                 elif curtype == PYWRITER_LOGICAL:
 *                     check_exit_status(readstat_insert_int32_value(writer, tempvar, <int>curval))
 *                 elif curtype == PYWRITER_CHARACTER:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))
 *                 elif curtype == PYWRITER_OBJECT:
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":825
 *                 elif curtype == PYWRITER_CHARACTER:
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))
 *                 elif curtype == PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 */
            __pyx_t_3 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT);
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":826
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))
 *                 elif curtype == PYWRITER_OBJECT:
 *                     curvalstr = str(curval)             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:
 */
              __pyx_t_15 = __Pyx_PyObject_Str(__pyx_v_curval); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 826, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              if (!(likely(PyString_CheckExact(__pyx_t_15)) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_15))) __PYX_ERR(0, 826, __pyx_L55_error)
              __Pyx_XDECREF_SET(__pyx_v_curvalstr, ((PyObject*)__pyx_t_15));
              __pyx_t_15 = 0;

              /* "pyreadstat/_readstat_writer.pyx":827
 *                 elif curtype == PYWRITER_OBJECT:
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 */
              __pyx_t_15 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_encode, __pyx_v_curvalstr, __pyx_kp_s_utf_8); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 827, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_15);
              __pyx_t_35 = __Pyx_PyObject_AsString(__pyx_t_15); if (unlikely((!__pyx_t_35) && PyErr_Occurred())) __PYX_ERR(0, 827, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_string_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_35)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 827, __pyx_L55_error)
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

              /* "pyreadstat/_readstat_writer.pyx":825
 *                 elif curtype == PYWRITER_CHARACTER:
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curval.encode("utf-8")))
 *                 elif curtype == PYWRITER_OBJECT:             # <<<<<<<<<<<<<<
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":828
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype in pyrwriter_datetimelike_types:
 */
            switch (__pyx_v_curtype) {
              case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS:
              case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US:
              __pyx_t_3 = 1;
              break;
              default:
              __pyx_t_3 = 0;
              break;
            }
            if (__pyx_t_3) {

              /* "pyreadstat/_readstat_writer.pyx":829
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))             # <<<<<<<<<<<<<<
 *                 elif curtype in pyrwriter_datetimelike_types:
 *                     dtimelikeval = convert_datetimelike_to_number(file_format, curtype, curval)
 */
              __pyx_t_33 = __pyx_PyFloat_AsDouble(__pyx_v_curval); if (unlikely((__pyx_t_33 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 829, __pyx_L55_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_double_value(__pyx_v_writer, __pyx_v_tempvar, ((double)__pyx_t_33))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 829, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":828
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype in pyrwriter_datetimelike_types:
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":830
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype in pyrwriter_datetimelike_types:             # <<<<<<<<<<<<<<
 *                     dtimelikeval = convert_datetimelike_to_number(file_format, curtype, curval)
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, dtimelikeval))
 */
            __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 830, __pyx_L55_error)
            __Pyx_GOTREF(__pyx_t_15);
            if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
              __PYX_ERR(0, 830, __pyx_L55_error)
            }
            __pyx_t_3 = (__Pyx_PySet_ContainsTF(__pyx_t_15, __pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 830, __pyx_L55_error)
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            if (likely(__pyx_t_3)) {

              /* "pyreadstat/_readstat_writer.pyx":831
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype in pyrwriter_datetimelike_types:
 *                     dtimelikeval = convert_datetimelike_to_number(file_format, curtype, curval)             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, dtimelikeval))
 *                 else:
 */
              __pyx_t_33 = __pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number(__pyx_v_file_format, __pyx_v_curtype, __pyx_v_curval); if (unlikely(__pyx_t_33 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 831, __pyx_L55_error)
              __pyx_v_dtimelikeval = __pyx_t_33;

              /* "pyreadstat/_readstat_writer.pyx":832
 *                 elif curtype in pyrwriter_datetimelike_types:
 *                     dtimelikeval = convert_datetimelike_to_number(file_format, curtype, curval)
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, dtimelikeval))             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise PyreadstatError("Unknown data format to insert")
 */
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_double_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_v_dtimelikeval)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 832, __pyx_L55_error)

              /* "pyreadstat/_readstat_writer.pyx":830
 *                 elif curtype == PYWRITER_DATETIME64_NS or curtype ==  PYWRITER_DATETIME64_US:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype in pyrwriter_datetimelike_types:             # <<<<<<<<<<<<<<
 *                     dtimelikeval = convert_datetimelike_to_number(file_format, curtype, curval)
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, dtimelikeval))
 */
              goto __pyx_L123;
            }

            /* "pyreadstat/_readstat_writer.pyx":834
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, dtimelikeval))
 *                 else:
 *                     raise PyreadstatError("Unknown data format to insert")             # <<<<<<<<<<<<<<
 * 
 *             check_exit_status(readstat_end_row(writer))
 */
            /*else*/ {
              __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 834, __pyx_L55_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_2 = NULL;
              __pyx_t_25 = 0;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
                __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
                if (likely(__pyx_t_2)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_2);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_9, function);
                  __pyx_t_25 = 1;
                }
              }
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_s_Unknown_data_format_to_insert};
                __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_25, 1+__pyx_t_25);
                __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 834, __pyx_L55_error)
                __Pyx_GOTREF(__pyx_t_15);
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              }
              __Pyx_Raise(__pyx_t_15, 0, 0, 0);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
              __PYX_ERR(0, 834, __pyx_L55_error)
            }
            __pyx_L123:;
            __pyx_L114_continue:;
          }

          /* "pyreadstat/_readstat_writer.pyx":836
 *                     raise PyreadstatError("Unknown data format to insert")
 * 
 *             check_exit_status(readstat_end_row(writer))             # <<<<<<<<<<<<<<
 *             rowcnt += 1
 * 
 */
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_end_row(__pyx_v_writer)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 836, __pyx_L55_error)

          /* "pyreadstat/_readstat_writer.pyx":837
 * 
 *             check_exit_status(readstat_end_row(writer))
 *             rowcnt += 1             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_end_writing(writer))
 */
          __pyx_t_15 = __Pyx_PyInt_AddObjC(__pyx_v_rowcnt, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 837, __pyx_L55_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF_SET(__pyx_v_rowcnt, __pyx_t_15);
          __pyx_t_15 = 0;

          /* "pyreadstat/_readstat_writer.pyx":793
 *         rowcnt = 0
 * 
 *         for row in df2.values:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_row(writer))
 * 
 */
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":839
 *             rowcnt += 1
 * 
 *         check_exit_status(readstat_end_writing(writer))             # <<<<<<<<<<<<<<
 * 
 *     except:
 */
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_end_writing(__pyx_v_writer)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 839, __pyx_L55_error)

        /* "pyreadstat/_readstat_writer.pyx":653
 *     writer = readstat_writer_init()
 * 
 *     try:             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
 */
      }
      __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L60_try_end;
      __pyx_L55_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":841
 *         check_exit_status(readstat_end_writing(writer))
 * 
 *     except:             # <<<<<<<<<<<<<<
 *         raise
 *     finally:
 */
      /*except:*/ {
        __Pyx_AddTraceback("pyreadstat._readstat_writer.run_write", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_15, &__pyx_t_9) < 0) __PYX_ERR(0, 841, __pyx_L57_except_error)
        __Pyx_XGOTREF(__pyx_t_1);
        __Pyx_XGOTREF(__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_9);

        /* "pyreadstat/_readstat_writer.pyx":842
 * 
 *     except:
 *         raise             # <<<<<<<<<<<<<<
 *     finally:
 *         readstat_writer_free(writer)
 */
        __Pyx_GIVEREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_ErrRestoreWithState(__pyx_t_1, __pyx_t_15, __pyx_t_9);
        __pyx_t_1 = 0; __pyx_t_15 = 0; __pyx_t_9 = 0; 
        __PYX_ERR(0, 842, __pyx_L57_except_error)
      }

      /* "pyreadstat/_readstat_writer.pyx":653
 *     writer = readstat_writer_init()
 * 
 *     try:             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
 */
      __pyx_L57_except_error:;
      __Pyx_XGIVEREF(__pyx_t_18);
      __Pyx_XGIVEREF(__pyx_t_17);
      __Pyx_XGIVEREF(__pyx_t_16);
      __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
      goto __pyx_L53_error;
      __pyx_L60_try_end:;
    }
  }

  /* "pyreadstat/_readstat_writer.pyx":844
 *         raise
 *     finally:
 *         readstat_writer_free(writer)             # <<<<<<<<<<<<<<
 *         close_file(fd)
 * 
 */
  /*finally:*/ {
    /*normal exit:*/{
      readstat_writer_free(__pyx_v_writer);

      /* "pyreadstat/_readstat_writer.pyx":845
 *     finally:
 *         readstat_writer_free(writer)
 *         close_file(fd)             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
      __pyx_t_6 = __pyx_f_10pyreadstat_16_readstat_writer_close_file(__pyx_v_fd); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 845, __pyx_L1_error)
      goto __pyx_L54;
    }
    __pyx_L53_error:;
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_37 = 0; __pyx_t_38 = 0; __pyx_t_39 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_37, &__pyx_t_38, &__pyx_t_39);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18) < 0)) __Pyx_ErrFetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
      __Pyx_XGOTREF(__pyx_t_16);
      __Pyx_XGOTREF(__pyx_t_17);
      __Pyx_XGOTREF(__pyx_t_18);
      __Pyx_XGOTREF(__pyx_t_37);
      __Pyx_XGOTREF(__pyx_t_38);
      __Pyx_XGOTREF(__pyx_t_39);
      __pyx_t_6 = __pyx_lineno; __pyx_t_23 = __pyx_clineno; __pyx_t_36 = __pyx_filename;
      {

        /* "pyreadstat/_readstat_writer.pyx":844
 *         raise
 *     finally:
 *         readstat_writer_free(writer)             # <<<<<<<<<<<<<<
 *         close_file(fd)
 * 
 */
        readstat_writer_free(__pyx_v_writer);

        /* "pyreadstat/_readstat_writer.pyx":845
 *     finally:
 *         readstat_writer_free(writer)
 *         close_file(fd)             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
        __pyx_t_24 = __pyx_f_10pyreadstat_16_readstat_writer_close_file(__pyx_v_fd); if (unlikely(__pyx_t_24 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 845, __pyx_L128_error)
      }
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_37);
        __Pyx_XGIVEREF(__pyx_t_38);
        __Pyx_XGIVEREF(__pyx_t_39);
        __Pyx_ExceptionReset(__pyx_t_37, __pyx_t_38, __pyx_t_39);
      }
      __Pyx_XGIVEREF(__pyx_t_16);
      __Pyx_XGIVEREF(__pyx_t_17);
      __Pyx_XGIVEREF(__pyx_t_18);
      __Pyx_ErrRestore(__pyx_t_16, __pyx_t_17, __pyx_t_18);
      __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_37 = 0; __pyx_t_38 = 0; __pyx_t_39 = 0;
      __pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_23; __pyx_filename = __pyx_t_36;
      goto __pyx_L1_error;
      __pyx_L128_error:;
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_37);
        __Pyx_XGIVEREF(__pyx_t_38);
        __Pyx_XGIVEREF(__pyx_t_39);
        __Pyx_ExceptionReset(__pyx_t_37, __pyx_t_38, __pyx_t_39);
      }
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
      __pyx_t_37 = 0; __pyx_t_38 = 0; __pyx_t_39 = 0;
      goto __pyx_L1_error;
    }
    __pyx_L54:;
  }

  /* "pyreadstat/_readstat_writer.pyx":847
 *         close_file(fd)
 * 
 *     return 0             # <<<<<<<<<<<<<<
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":548
 *         return close(fd)
 * 
 * cdef int run_write(df, object filename_path, dst_file_format file_format, str file_label, object column_labels,             # <<<<<<<<<<<<<<
 *                    int file_format_version, str note, str table_name, dict variable_value_labels,
 *                    dict missing_ranges, dict missing_user_values, dict variable_alignment,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.run_write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_k);
  __Pyx_XDECREF(__pyx_v_v);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_valid_user_missing);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_missing_values);
  __Pyx_XDECREF(__pyx_v_val);
  __Pyx_XDECREF(__pyx_v_file_label_bytes);
  __Pyx_XDECREF(__pyx_v_col_names);
  __Pyx_XDECREF(__pyx_v_variable_name);
  __Pyx_XDECREF(__pyx_v_col_types);
  __Pyx_XDECREF(__pyx_v_col_names_to_types);
  __Pyx_XDECREF(__pyx_v_tempformat);
  __Pyx_XDECREF(__pyx_v_cur_col_label);
  __Pyx_XDECREF(__pyx_v_curvalstr);
  __Pyx_XDECREF(__pyx_v_value_labels);
  __Pyx_XDECREF(__pyx_v_col_label_temp);
  __Pyx_XDECREF(__pyx_v_pywriter_types);
  __Pyx_XDECREF(__pyx_v_df2);
  __Pyx_XDECREF(__pyx_v_filename_bytes);
  __Pyx_XDECREF(__pyx_v_table_name_bytes);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_labelset_name);
  __Pyx_XDECREF(__pyx_v_curuser_missing);
  __Pyx_XDECREF(__pyx_v_cur_ranges);
  __Pyx_XDECREF(__pyx_v_cur_alignment);
  __Pyx_XDECREF(__pyx_v_cur_display_width);
  __Pyx_XDECREF(__pyx_v_cur_measure);
  __Pyx_XDECREF(__pyx_v_rowcnt);
  __Pyx_XDECREF(__pyx_v_row);
  __Pyx_XDECREF(__pyx_v_curval);
  __Pyx_XDECREF(__pyx_v_is_missing);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_k);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v);
  __Pyx_XDECREF(__pyx_v_filename_path);
  __Pyx_XDECREF(__pyx_v_column_labels);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif
/* #### Code section: pystring_table ### */

static int __Pyx_CreateStringTabAndInitStrings(void) {
  __Pyx_StringTabEntry __pyx_string_tab[] = {
    {&__pyx_n_s_CategoricalDtype, __pyx_k_CategoricalDtype, sizeof(__pyx_k_CategoricalDtype), 0, 0, 1, 1},
    {&__pyx_kp_s_Column_labels_must_be_strings, __pyx_k_Column_labels_must_be_strings, sizeof(__pyx_k_Column_labels_must_be_strings), 0, 0, 1, 0},
    {&__pyx_n_s_DataFrame, __pyx_k_DataFrame, sizeof(__pyx_k_DataFrame), 0, 0, 1, 1},
    {&__pyx_n_s_Float32Dtype, __pyx_k_Float32Dtype, sizeof(__pyx_k_Float32Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_Float64Dtype, __pyx_k_Float64Dtype, sizeof(__pyx_k_Float64Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_Int16Dtype, __pyx_k_Int16Dtype, sizeof(__pyx_k_Int16Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_Int32Dtype, __pyx_k_Int32Dtype, sizeof(__pyx_k_Int32Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_Int64Dtype, __pyx_k_Int64Dtype, sizeof(__pyx_k_Int64Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_Int8Dtype, __pyx_k_Int8Dtype, sizeof(__pyx_k_Int8Dtype), 0, 0, 1, 1},
    {&__pyx_kp_s_M8_ns, __pyx_k_M8_ns, sizeof(__pyx_k_M8_ns), 0, 0, 1, 0},
    {&__pyx_kp_s_Non_unique_column_names_detected, __pyx_k_Non_unique_column_names_detected, sizeof(__pyx_k_Non_unique_column_names_detected), 0, 0, 1, 0},
    {&__pyx_n_s_PyreadstatError, __pyx_k_PyreadstatError, sizeof(__pyx_k_PyreadstatError), 0, 0, 1, 1},
    {&__pyx_n_s_ReadstatError, __pyx_k_ReadstatError, sizeof(__pyx_k_ReadstatError), 0, 0, 1, 1},
    {&__pyx_n_s_Timestamp, __pyx_k_Timestamp, sizeof(__pyx_k_Timestamp), 0, 0, 1, 1},
    {&__pyx_n_s_UInt16Dtype, __pyx_k_UInt16Dtype, sizeof(__pyx_k_UInt16Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_UInt32Dtype, __pyx_k_UInt32Dtype, sizeof(__pyx_k_UInt32Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_UInt64Dtype, __pyx_k_UInt64Dtype, sizeof(__pyx_k_UInt64Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_UInt8Dtype, __pyx_k_UInt8Dtype, sizeof(__pyx_k_UInt8Dtype), 0, 0, 1, 1},
    {&__pyx_n_s_UnicodeError, __pyx_k_UnicodeError, sizeof(__pyx_k_UnicodeError), 0, 0, 1, 1},
    {&__pyx_kp_s_Unknown_data_format_to_insert, __pyx_k_Unknown_data_format_to_insert, sizeof(__pyx_k_Unknown_data_format_to_insert), 0, 0, 1, 0},
    {&__pyx_kp_s_Unknown_pywriter_variable_format, __pyx_k_Unknown_pywriter_variable_format, sizeof(__pyx_k_Unknown_pywriter_variable_format), 0, 0, 1, 0},
    {&__pyx_n_s__17, __pyx_k__17, sizeof(__pyx_k__17), 0, 0, 1, 1},
    {&__pyx_n_s__18, __pyx_k__18, sizeof(__pyx_k__18), 0, 0, 1, 1},
    {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0},
    {&__pyx_n_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 1},
    {&__pyx_kp_u__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 1, 0, 0},
    {&__pyx_kp_s_alignment_for_variable_s_must_be, __pyx_k_alignment_for_variable_s_must_be, sizeof(__pyx_k_alignment_for_variable_s_must_be), 0, 0, 1, 0},
    {&__pyx_n_s_any, __pyx_k_any, sizeof(__pyx_k_any), 0, 0, 1, 1},
    {&__pyx_n_s_asarray, __pyx_k_asarray, sizeof(__pyx_k_asarray), 0, 0, 1, 1},
    {&__pyx_n_s_asm8, __pyx_k_asm8, sizeof(__pyx_k_asm8), 0, 0, 1, 1},
    {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1},
    {&__pyx_n_s_calendar, __pyx_k_calendar, sizeof(__pyx_k_calendar), 0, 0, 1, 1},
    {&__pyx_n_s_center, __pyx_k_center, sizeof(__pyx_k_center), 0, 0, 1, 1},
    {&__pyx_kp_s_character_missing_ranges_value_g, __pyx_k_character_missing_ranges_value_g, sizeof(__pyx_k_character_missing_ranges_value_g), 0, 0, 1, 0},
    {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1},
    {&__pyx_n_s_class_getitem, __pyx_k_class_getitem, sizeof(__pyx_k_class_getitem), 0, 0, 1, 1},
    {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
    {&__pyx_kp_s_column_labels_must_be_either_lis, __pyx_k_column_labels_must_be_either_lis, sizeof(__pyx_k_column_labels_must_be_either_lis), 0, 0, 1, 0},
    {&__pyx_n_s_columns, __pyx_k_columns, sizeof(__pyx_k_columns), 0, 0, 1, 1},
    {&__pyx_n_s_combine, __pyx_k_combine, sizeof(__pyx_k_combine), 0, 0, 1, 1},
    {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
    {&__pyx_n_s_core, __pyx_k_core, sizeof(__pyx_k_core), 0, 0, 1, 1},
    {&__pyx_n_s_date, __pyx_k_date, sizeof(__pyx_k_date), 0, 0, 1, 1},
    {&__pyx_n_s_datetime, __pyx_k_datetime, sizeof(__pyx_k_datetime), 0, 0, 1, 1},
    {&__pyx_n_s_datetime64, __pyx_k_datetime64, sizeof(__pyx_k_datetime64), 0, 0, 1, 1},
    {&__pyx_kp_s_datetime64_ms, __pyx_k_datetime64_ms, sizeof(__pyx_k_datetime64_ms), 0, 0, 1, 0},
    {&__pyx_kp_s_datetime64_ns, __pyx_k_datetime64_ns, sizeof(__pyx_k_datetime64_ns), 0, 0, 1, 0},
    {&__pyx_kp_s_datetime64_us, __pyx_k_datetime64_us, sizeof(__pyx_k_datetime64_us), 0, 0, 1, 0},
    {&__pyx_kp_s_datetime64_us_2, __pyx_k_datetime64_us_2, sizeof(__pyx_k_datetime64_us_2), 0, 0, 1, 0},
    {&__pyx_n_s_days, __pyx_k_days, sizeof(__pyx_k_days), 0, 0, 1, 1},
    {&__pyx_kp_s_dictionaries_in_missing_ranges_m, __pyx_k_dictionaries_in_missing_ranges_m, sizeof(__pyx_k_dictionaries_in_missing_ranges_m), 0, 0, 1, 0},
    {&__pyx_n_s_drop, __pyx_k_drop, sizeof(__pyx_k_drop), 0, 0, 1, 1},
    {&__pyx_n_s_dropna, __pyx_k_dropna, sizeof(__pyx_k_dropna), 0, 0, 1, 1},
    {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
    {&__pyx_n_s_dtypes, __pyx_k_dtypes, sizeof(__pyx_k_dtypes), 0, 0, 1, 1},
    {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
    {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
    {&__pyx_n_s_expanduser, __pyx_k_expanduser, sizeof(__pyx_k_expanduser), 0, 0, 1, 1},
    {&__pyx_kp_s_file_path_could_not_be_encoded_w, __pyx_k_file_path_could_not_be_encoded_w, sizeof(__pyx_k_file_path_could_not_be_encoded_w), 0, 0, 1, 0},
    {&__pyx_kp_s_first_argument_must_be_a_pandas, __pyx_k_first_argument_must_be_a_pandas, sizeof(__pyx_k_first_argument_must_be_a_pandas), 0, 0, 1, 0},
    {&__pyx_n_s_float, __pyx_k_float, sizeof(__pyx_k_float), 0, 0, 1, 1},
    {&__pyx_n_s_float32, __pyx_k_float32, sizeof(__pyx_k_float32), 0, 0, 1, 1},
    {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1},
    {&__pyx_n_s_fsdecode, __pyx_k_fsdecode, sizeof(__pyx_k_fsdecode), 0, 0, 1, 1},
    {&__pyx_n_s_fsencode, __pyx_k_fsencode, sizeof(__pyx_k_fsencode), 0, 0, 1, 1},
    {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
    {&__pyx_n_s_getfilesystemencoding, __pyx_k_getfilesystemencoding, sizeof(__pyx_k_getfilesystemencoding), 0, 0, 1, 1},
    {&__pyx_n_s_hi, __pyx_k_hi, sizeof(__pyx_k_hi), 0, 0, 1, 1},
    {&__pyx_n_s_iloc, __pyx_k_iloc, sizeof(__pyx_k_iloc), 0, 0, 1, 1},
    {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
    {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1},
    {&__pyx_n_s_int16, __pyx_k_int16, sizeof(__pyx_k_int16), 0, 0, 1, 1},
    {&__pyx_n_s_int32, __pyx_k_int32, sizeof(__pyx_k_int32), 0, 0, 1, 1},
    {&__pyx_n_s_int64, __pyx_k_int64, sizeof(__pyx_k_int64), 0, 0, 1, 1},
    {&__pyx_n_s_int8, __pyx_k_int8, sizeof(__pyx_k_int8), 0, 0, 1, 1},
    {&__pyx_n_s_is_datetime64_any_dtype, __pyx_k_is_datetime64_any_dtype, sizeof(__pyx_k_is_datetime64_any_dtype), 0, 0, 1, 1},
    {&__pyx_n_s_is_datetime64_ns_dtype, __pyx_k_is_datetime64_ns_dtype, sizeof(__pyx_k_is_datetime64_ns_dtype), 0, 0, 1, 1},
    {&__pyx_n_s_isalpha, __pyx_k_isalpha, sizeof(__pyx_k_isalpha), 0, 0, 1, 1},
    {&__pyx_n_s_isin, __pyx_k_isin, sizeof(__pyx_k_isin), 0, 0, 1, 1},
    {&__pyx_n_s_isna, __pyx_k_isna, sizeof(__pyx_k_isna), 0, 0, 1, 1},
    {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
    {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
    {&__pyx_n_s_left, __pyx_k_left, sizeof(__pyx_k_left), 0, 0, 1, 1},
    {&__pyx_kp_s_length_of_column_labels_must_be, __pyx_k_length_of_column_labels_must_be, sizeof(__pyx_k_length_of_column_labels_must_be), 0, 0, 1, 0},
    {&__pyx_n_s_libs, __pyx_k_libs, sizeof(__pyx_k_libs), 0, 0, 1, 1},
    {&__pyx_n_s_lo, __pyx_k_lo, sizeof(__pyx_k_lo), 0, 0, 1, 1},
    {&__pyx_n_s_loc, __pyx_k_loc, sizeof(__pyx_k_loc), 0, 0, 1, 1},
    {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
    {&__pyx_kp_s_measure_for_variable_s_must_be_e, __pyx_k_measure_for_variable_s_must_be_e, sizeof(__pyx_k_measure_for_variable_s_must_be_e), 0, 0, 1, 0},
    {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
    {&__pyx_kp_s_missing_ranges_hi_and_lo_values, __pyx_k_missing_ranges_hi_and_lo_values, sizeof(__pyx_k_missing_ranges_hi_and_lo_values), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_hi_and_lo_values_2, __pyx_k_missing_ranges_hi_and_lo_values_2, sizeof(__pyx_k_missing_ranges_hi_and_lo_values_2), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_max_1_discrete_nu, __pyx_k_missing_ranges_max_1_discrete_nu, sizeof(__pyx_k_missing_ranges_max_1_discrete_nu), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_max_1_range_value, __pyx_k_missing_ranges_max_1_range_value, sizeof(__pyx_k_missing_ranges_max_1_range_value), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_max_3_discrete_nu, __pyx_k_missing_ranges_max_3_discrete_nu, sizeof(__pyx_k_missing_ranges_max_3_discrete_nu), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_max_3_string_valu, __pyx_k_missing_ranges_max_3_string_valu, sizeof(__pyx_k_missing_ranges_max_3_string_valu), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_string_values_len, __pyx_k_missing_ranges_string_values_len, sizeof(__pyx_k_missing_ranges_string_values_len), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_values_in_diction, __pyx_k_missing_ranges_values_in_diction, sizeof(__pyx_k_missing_ranges_values_in_diction), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_ranges_values_must_be_bo, __pyx_k_missing_ranges_values_must_be_bo, sizeof(__pyx_k_missing_ranges_values_must_be_bo), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_user_values_not_allowed, __pyx_k_missing_user_values_not_allowed, sizeof(__pyx_k_missing_user_values_not_allowed), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_user_values_supports_val, __pyx_k_missing_user_values_supports_val, sizeof(__pyx_k_missing_user_values_supports_val), 0, 0, 1, 0},
    {&__pyx_kp_s_missing_user_values_values_in_di, __pyx_k_missing_user_values_values_in_di, sizeof(__pyx_k_missing_user_values_values_in_di), 0, 0, 1, 0},
    {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
    {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
    {&__pyx_n_s_nan, __pyx_k_nan, sizeof(__pyx_k_nan), 0, 0, 1, 1},
    {&__pyx_n_s_nominal, __pyx_k_nominal, sizeof(__pyx_k_nominal), 0, 0, 1, 1},
    {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1},
    {&__pyx_n_s_nt, __pyx_k_nt, sizeof(__pyx_k_nt), 0, 0, 1, 1},
    {&__pyx_kp_s_numeric_missing_ranges_value_giv, __pyx_k_numeric_missing_ranges_value_giv, sizeof(__pyx_k_numeric_missing_ranges_value_giv), 0, 0, 1, 0},
    {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
    {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
    {&__pyx_n_s_ordinal, __pyx_k_ordinal, sizeof(__pyx_k_ordinal), 0, 0, 1, 1},
    {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
    {&__pyx_n_s_pandas, __pyx_k_pandas, sizeof(__pyx_k_pandas), 0, 0, 1, 1},
    {&__pyx_n_s_pandas_api_types, __pyx_k_pandas_api_types, sizeof(__pyx_k_pandas_api_types), 0, 0, 1, 1},
    {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1},
    {&__pyx_kp_s_path_must_be_either_str_or_bytes, __pyx_k_path_must_be_either_str_or_bytes, sizeof(__pyx_k_path_must_be_either_str_or_bytes), 0, 0, 1, 0},
    {&__pyx_n_s_pd, __pyx_k_pd, sizeof(__pyx_k_pd), 0, 0, 1, 1},
    {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
    {&__pyx_n_s_readstat_parser, __pyx_k_readstat_parser, sizeof(__pyx_k_readstat_parser), 0, 0, 1, 1},
    {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
    {&__pyx_n_s_reset_index, __pyx_k_reset_index, sizeof(__pyx_k_reset_index), 0, 0, 1, 1},
    {&__pyx_n_s_right, __pyx_k_right, sizeof(__pyx_k_right), 0, 0, 1, 1},
    {&__pyx_n_s_round, __pyx_k_round, sizeof(__pyx_k_round), 0, 0, 1, 1},
    {&__pyx_n_s_scale, __pyx_k_scale, sizeof(__pyx_k_scale), 0, 0, 1, 1},
    {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1},
    {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
    {&__pyx_n_s_string, __pyx_k_string, sizeof(__pyx_k_string), 0, 0, 1, 1},
    {&__pyx_n_s_surrogateescape, __pyx_k_surrogateescape, sizeof(__pyx_k_surrogateescape), 0, 0, 1, 1},
    {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
    {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
    {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
    {&__pyx_n_s_timegm, __pyx_k_timegm, sizeof(__pyx_k_timegm), 0, 0, 1, 1},
    {&__pyx_n_s_timestamps, __pyx_k_timestamps, sizeof(__pyx_k_timestamps), 0, 0, 1, 1},
    {&__pyx_n_s_timetuple, __pyx_k_timetuple, sizeof(__pyx_k_timetuple), 0, 0, 1, 1},
    {&__pyx_n_s_timezone, __pyx_k_timezone, sizeof(__pyx_k_timezone), 0, 0, 1, 1},
    {&__pyx_n_s_timezone_2, __pyx_k_timezone_2, sizeof(__pyx_k_timezone_2), 0, 0, 1, 1},
    {&__pyx_n_s_tolist, __pyx_k_tolist, sizeof(__pyx_k_tolist), 0, 0, 1, 1},
    {&__pyx_n_s_total_seconds, __pyx_k_total_seconds, sizeof(__pyx_k_total_seconds), 0, 0, 1, 1},
    {&__pyx_n_s_tslibs, __pyx_k_tslibs, sizeof(__pyx_k_tslibs), 0, 0, 1, 1},
    {&__pyx_n_s_tzinfo, __pyx_k_tzinfo, sizeof(__pyx_k_tzinfo), 0, 0, 1, 1},
    {&__pyx_n_s_uint16, __pyx_k_uint16, sizeof(__pyx_k_uint16), 0, 0, 1, 1},
    {&__pyx_n_s_uint32, __pyx_k_uint32, sizeof(__pyx_k_uint32), 0, 0, 1, 1},
    {&__pyx_n_s_uint64, __pyx_k_uint64, sizeof(__pyx_k_uint64), 0, 0, 1, 1},
    {&__pyx_n_s_uint8, __pyx_k_uint8, sizeof(__pyx_k_uint8), 0, 0, 1, 1},
    {&__pyx_n_s_union, __pyx_k_union, sizeof(__pyx_k_union), 0, 0, 1, 1},
    {&__pyx_n_s_unknown, __pyx_k_unknown, sizeof(__pyx_k_unknown), 0, 0, 1, 1},
    {&__pyx_kp_s_unknown_file_format, __pyx_k_unknown_file_format, sizeof(__pyx_k_unknown_file_format), 0, 0, 1, 0},
    {&__pyx_n_s_upper, __pyx_k_upper, sizeof(__pyx_k_upper), 0, 0, 1, 1},
    {&__pyx_n_s_utc, __pyx_k_utc, sizeof(__pyx_k_utc), 0, 0, 1, 1},
    {&__pyx_kp_s_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 0, 1, 0},
    {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
    {&__pyx_kp_s_variable_name_s_contains_a_space, __pyx_k_variable_name_s_contains_a_space, sizeof(__pyx_k_variable_name_s_contains_a_space), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_name_s_is_of_type_s_and, __pyx_k_variable_name_s_is_of_type_s_and, sizeof(__pyx_k_variable_name_s_is_of_type_s_and), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_name_s_starts_with_an_i, __pyx_k_variable_name_s_starts_with_an_i, sizeof(__pyx_k_variable_name_s_starts_with_an_i), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_value_labels_type_of_La, __pyx_k_variable_value_labels_type_of_La, sizeof(__pyx_k_variable_value_labels_type_of_La), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_value_labels_type_of_Va, __pyx_k_variable_value_labels_type_of_Va, sizeof(__pyx_k_variable_value_labels_type_of_Va), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_value_labels_type_of_Va_2, __pyx_k_variable_value_labels_type_of_Va_2, sizeof(__pyx_k_variable_value_labels_type_of_Va_2), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_value_labels_type_of_Va_3, __pyx_k_variable_value_labels_type_of_Va_3, sizeof(__pyx_k_variable_value_labels_type_of_Va_3), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_value_labels_type_of_Va_4, __pyx_k_variable_value_labels_type_of_Va_4, sizeof(__pyx_k_variable_value_labels_type_of_Va_4), 0, 0, 1, 0},
    {&__pyx_kp_s_variable_value_labels_value_for, __pyx_k_variable_value_labels_value_for, sizeof(__pyx_k_variable_value_labels_value_for), 0, 0, 1, 0},
    {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1},
    {&__pyx_n_s_warnings, __pyx_k_warnings, sizeof(__pyx_k_warnings), 0, 0, 1, 1},
    {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
    {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
    {0, 0, 0, 0, 0, 0, 0}
  };
  return __Pyx_InitStrings(__pyx_string_tab);
}
/* #### Code section: cached_builtins ### */
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 58, __pyx_L1_error)
  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 58, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 199, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 199, __pyx_L1_error)
  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 231, __pyx_L1_error)
  __pyx_builtin_UnicodeError = __Pyx_GetBuiltinName(__pyx_n_s_UnicodeError); if (!__pyx_builtin_UnicodeError) __PYX_ERR(0, 638, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: cached_constants ### */

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pyreadstat/_readstat_writer.pyx":202
 * 
 *         max_length = 0
 *         curseries = df.iloc[:, indx]             # <<<<<<<<<<<<<<
 *         curuser_missing = None
 *         if missing_user_values:
 */
  __pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 202, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice_);
  __Pyx_GIVEREF(__pyx_slice_);

  /* "pyreadstat/_readstat_writer.pyx":640
 *         except UnicodeError:
 *             warnings.warn("file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly." % sys.getfilesystemencoding())
 *             filename_bytes = os.fsdecode(filename_path).encode("utf-8", "surrogateescape")             # <<<<<<<<<<<<<<
 *     else:
 *         if type(filename_path) == str:
 */
  __pyx_tuple__3 = PyTuple_Pack(2, __pyx_kp_s_utf_8, __pyx_n_s_surrogateescape); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 640, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "pyreadstat/_readstat_writer.pyx":35
 * from _readstat_parser cimport check_exit_status
 * 
 * cdef set int_types = {int, np.dtype('int32'), np.dtype('int16'), np.dtype('int8'), np.dtype('uint8'), np.dtype('uint16'),             # <<<<<<<<<<<<<<
 *              np.int32, np.int16, np.int8, np.uint8, np.uint16}
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_n_s_int32); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);
  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_n_s_int16); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);
  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_n_s_int8); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_n_s_uint8); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_n_s_uint16); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pyreadstat/_readstat_writer.pyx":38
 *              np.int32, np.int16, np.int8, np.uint8, np.uint16}
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),             # <<<<<<<<<<<<<<
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),
 *                pd.Float64Dtype(), pd.Float32Dtype()}
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_n_s_int64); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_n_s_uint64); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_n_s_uint32); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_n_s_float); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "pyreadstat/_readstat_writer.pyx":39
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),             # <<<<<<<<<<<<<<
 *                pd.Float64Dtype(), pd.Float32Dtype()}
 * cdef set numeric_types = int_types.union(float_types).union(int_mixed_types)
 */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_n_s_float32); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "pyreadstat/_readstat_writer.pyx":56
 * cdef double spss_offset_days = 141428
 * cdef double sas_offset_days = 3653
 * cdef object date_0 = datetime.datetime(1970,1,1).date()             # <<<<<<<<<<<<<<
 * 
 * cdef valid_user_missing_sas = [chr(x) for x in range(ord("A"), ord("Z")+1)] + ["_"]
 */
  __pyx_tuple__16 = PyTuple_Pack(3, __pyx_int_1970, __pyx_int_1, __pyx_int_1); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}
/* #### Code section: init_constants ### */

static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) {
  __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_get.method_name = &__pyx_n_s_get;
  __pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_items.method_name = &__pyx_n_s_items;
  __pyx_umethod_PyDict_Type_keys.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_keys.method_name = &__pyx_n_s_keys;
  __pyx_umethod_PySet_Type_union.type = (PyObject*)&PySet_Type;
  __pyx_umethod_PySet_Type_union.method_name = &__pyx_n_s_union;
  __pyx_umethod_PyString_Type_encode.type = (PyObject*)&PyString_Type;
  __pyx_umethod_PyString_Type_encode.method_name = &__pyx_n_s_encode;
  if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_1e6 = PyFloat_FromDouble(1e6); if (unlikely(!__pyx_float_1e6)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_1e9 = PyFloat_FromDouble(1e9); if (unlikely(!__pyx_float_1e9)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_65 = PyInt_FromLong(65); if (unlikely(!__pyx_int_65)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_97 = PyInt_FromLong(97); if (unlikely(!__pyx_int_97)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1970 = PyInt_FromLong(1970); if (unlikely(!__pyx_int_1970)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_9223056417655 = PyInt_FromString((char *)"-9223056417655", 0, 0); if (unlikely(!__pyx_int_neg_9223056417655)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: init_globals ### */

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  return 0;
}
/* #### Code section: init_module ### */

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __pyx_v_10pyreadstat_16_readstat_writer_int_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_float_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_numeric_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_datetime_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_nat_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_date_0 = Py_None; Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas = Py_None; Py_INCREF(Py_None);
  __pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata = Py_None; Py_INCREF(Py_None);
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  if (__Pyx_ExportFunction("convert_datetimelike_to_number", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number, "double (__pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_datetimelike_format_for_readstat", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_get_datetimelike_format_for_readstat, "char *(__pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_pandas_str_series_max_length", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_get_pandas_str_series_max_length, "int (PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("check_series_all_same_types", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_check_series_all_same_types, "int (PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_pandas_column_types", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_get_pandas_column_types, "PyObject *(PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("write_bytes", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_write_bytes, "Py_ssize_t (void const *, size_t, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("open_file", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_open_file, "int (PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("close_file", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_close_file, "int (int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("run_write", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_run_write, "int (PyObject *, PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *, int, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule("pyreadstat._readstat_parser"); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_10pyreadstat_16_readstat_parser_data_container = __Pyx_ImportType_3_0_0(__pyx_t_1, "pyreadstat._readstat_parser", "data_container", sizeof(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container), __PYX_GET_STRUCT_ALIGNMENT_3_0_0(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container),__Pyx_ImportType_CheckSize_Warn_3_0_0); if (!__pyx_ptype_10pyreadstat_16_readstat_parser_data_container) __PYX_ERR(1, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __pyx_t_1 = PyImport_ImportModule("pyreadstat._readstat_parser"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "readstat_to_numpy_types", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_readstat_to_numpy_types, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "sas_date_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_sas_date_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "sas_datetime_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_sas_datetime_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "sas_time_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_sas_time_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "sas_all_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_sas_all_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "sas_origin", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_sas_origin, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "spss_datetime_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_spss_datetime_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "spss_date_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_spss_date_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "spss_time_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_spss_time_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "spss_all_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_spss_all_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "spss_origin", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_spss_origin, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "stata_datetime_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_stata_datetime_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "stata_date_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_stata_date_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "stata_time_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_stata_time_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "stata_all_formats", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_stata_all_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr_3_0_0(__pyx_t_1, "stata_origin", (void **)&__pyx_vp_10pyreadstat_16_readstat_parser_stata_origin, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __pyx_t_1 = PyImport_ImportModule("pyreadstat._readstat_parser"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction_3_0_0(__pyx_t_1, "check_exit_status", (void (**)(void))&__pyx_f_10pyreadstat_16_readstat_parser_check_exit_status, "void (readstat_error_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}


#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec__readstat_writer(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec__readstat_writer},
  {0, NULL}
};
#endif

#ifdef __cplusplus
namespace {
  struct PyModuleDef __pyx_moduledef =
  #else
  static struct PyModuleDef __pyx_moduledef =
  #endif
  {
      PyModuleDef_HEAD_INIT,
      "_readstat_writer",
      0, /* m_doc */
    #if CYTHON_PEP489_MULTI_PHASE_INIT
      0, /* m_size */
    #elif CYTHON_USE_MODULE_STATE
      sizeof(__pyx_mstate), /* m_size */
    #else
      -1, /* m_size */
    #endif
      __pyx_methods /* m_methods */,
    #if CYTHON_PEP489_MULTI_PHASE_INIT
      __pyx_moduledef_slots, /* m_slots */
    #else
      NULL, /* m_reload */
    #endif
    #if CYTHON_USE_MODULE_STATE
      __pyx_m_traverse, /* m_traverse */
      __pyx_m_clear, /* m_clear */
      NULL /* m_free */
    #else
      NULL, /* m_traverse */
      NULL, /* m_clear */
      NULL /* m_free */
    #endif
  };
  #ifdef __cplusplus
} /* anonymous namespace */
#endif
#endif

#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC init_readstat_writer(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC init_readstat_writer(void)
#else
__Pyx_PyMODINIT_FUNC PyInit__readstat_writer(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit__readstat_writer(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
#if CYTHON_COMPILING_IN_LIMITED_API
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none)
#else
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none)
#endif
{
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
#if CYTHON_COMPILING_IN_LIMITED_API
            result = PyModule_AddObject(module, to_name, value);
#else
            result = PyDict_SetItemString(moddict, to_name, value);
#endif
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    CYTHON_UNUSED_VAR(def);
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
#if CYTHON_COMPILING_IN_LIMITED_API
    moddict = module;
#else
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
#endif
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec__readstat_writer(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  int stringtab_initialized = 0;
  #if CYTHON_USE_MODULE_STATE
  int pystate_addmodule_run = 0;
  #endif
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  Py_ssize_t __pyx_t_16;
  PyObject *(*__pyx_t_17)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module '_readstat_writer' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("_readstat_writer", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #elif CYTHON_USE_MODULE_STATE
  __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  {
    int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef);
    __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to _readstat_writer pseudovariable */
    if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
    pystate_addmodule_run = 1;
  }
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #endif
  CYTHON_UNUSED_VAR(__pyx_t_1);
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit__readstat_writer(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  stringtab_initialized = 1;
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_pyreadstat___readstat_writer) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "pyreadstat._readstat_writer")) {
      if (unlikely((PyDict_SetItemString(modules, "pyreadstat._readstat_writer", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  if (unlikely((__Pyx_modinit_function_export_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_type_init_code();
  if (unlikely((__Pyx_modinit_type_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely((__Pyx_modinit_variable_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely((__Pyx_modinit_function_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "pyreadstat/_readstat_writer.pyx":18
 * # limitations under the License.
 * # #############################################################################
 * import os             # <<<<<<<<<<<<<<
 * import warnings
 * import sys
 */
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_os, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_2) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":19
 * # #############################################################################
 * import os
 * import warnings             # <<<<<<<<<<<<<<
 * import sys
 * 
 */
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_warnings, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_2) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":20
 * import os
 * import warnings
 * import sys             # <<<<<<<<<<<<<<
 * 
 * import numpy as np
 */
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_sys, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_2) < 0) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":22
 * import sys
 * 
 * import numpy as np             # <<<<<<<<<<<<<<
 * #cimport numpy as np
 * import pandas as pd
 */
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":24
 * import numpy as np
 * #cimport numpy as np
 * import pandas as pd             # <<<<<<<<<<<<<<
 * from pandas.api.types import is_datetime64_any_dtype, is_datetime64_ns_dtype
 * import datetime
 */
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_pandas, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pd, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":25
 * #cimport numpy as np
 * import pandas as pd
 * from pandas.api.types import is_datetime64_any_dtype, is_datetime64_ns_dtype             # <<<<<<<<<<<<<<
 * import datetime
 * import calendar
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_is_datetime64_any_dtype);
  __Pyx_GIVEREF(__pyx_n_s_is_datetime64_any_dtype);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_is_datetime64_any_dtype);
  __Pyx_INCREF(__pyx_n_s_is_datetime64_ns_dtype);
  __Pyx_GIVEREF(__pyx_n_s_is_datetime64_ns_dtype);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_is_datetime64_ns_dtype);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_pandas_api_types, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_is_datetime64_any_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_datetime64_any_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_is_datetime64_ns_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_datetime64_ns_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":26
 * import pandas as pd
 * from pandas.api.types import is_datetime64_any_dtype, is_datetime64_ns_dtype
 * import datetime             # <<<<<<<<<<<<<<
 * import calendar
 * from datetime import timezone as _timezone
 */
  __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_datetime, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_datetime, __pyx_t_3) < 0) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":27
 * from pandas.api.types import is_datetime64_any_dtype, is_datetime64_ns_dtype
 * import datetime
 * import calendar             # <<<<<<<<<<<<<<
 * from datetime import timezone as _timezone
 * from libc.math cimport round, NAN
 */
  __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_n_s_calendar, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calendar, __pyx_t_3) < 0) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":28
 * import datetime
 * import calendar
 * from datetime import timezone as _timezone             # <<<<<<<<<<<<<<
 * from libc.math cimport round, NAN
 * 
 */
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_s_timezone_2);
  __Pyx_GIVEREF(__pyx_n_s_timezone_2);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_timezone_2);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_datetime, __pyx_t_3, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_timezone_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_timezone, __pyx_t_3) < 0) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":32
 * 
 * from readstat_api cimport *
 * from _readstat_parser import ReadstatError, PyreadstatError             # <<<<<<<<<<<<<<
 * from _readstat_parser cimport check_exit_status
 * 
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_ReadstatError);
  __Pyx_GIVEREF(__pyx_n_s_ReadstatError);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ReadstatError);
  __Pyx_INCREF(__pyx_n_s_PyreadstatError);
  __Pyx_GIVEREF(__pyx_n_s_PyreadstatError);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_PyreadstatError);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_readstat_parser, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_ReadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ReadstatError, __pyx_t_2) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_PyreadstatError, __pyx_t_2) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":35
 * from _readstat_parser cimport check_exit_status
 * 
 * cdef set int_types = {int, np.dtype('int32'), np.dtype('int16'), np.dtype('int8'), np.dtype('uint8'), np.dtype('uint16'),             # <<<<<<<<<<<<<<
 *              np.int32, np.int16, np.int8, np.uint8, np.uint16}
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_dtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_dtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":36
 * 
 * cdef set int_types = {int, np.dtype('int32'), np.dtype('int16'), np.dtype('int8'), np.dtype('uint8'), np.dtype('uint16'),
 *              np.int32, np.int16, np.int8, np.uint8, np.uint16}             # <<<<<<<<<<<<<<
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int32); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_uint8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_uint16); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PySet_Add(__pyx_t_7, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  if (PySet_Add(__pyx_t_7, __pyx_t_3) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_2) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_4) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_5) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_8) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_9) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_10) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_11) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (PySet_Add(__pyx_t_7, __pyx_t_12) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_int_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_int_types, ((PyObject*)__pyx_t_7));
  __Pyx_GIVEREF(__pyx_t_7);
  __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":37
 * cdef set int_types = {int, np.dtype('int32'), np.dtype('int16'), np.dtype('int8'), np.dtype('uint8'), np.dtype('uint16'),
 *              np.int32, np.int16, np.int8, np.uint8, np.uint16}
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}             # <<<<<<<<<<<<<<
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pd); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Int8Dtype); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_pd); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_Int16Dtype); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pd); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_Int32Dtype); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pd); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_UInt8Dtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pd); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_UInt16Dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PySet_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PySet_Add(__pyx_t_8, __pyx_t_7) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PySet_Add(__pyx_t_8, __pyx_t_12) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  if (PySet_Add(__pyx_t_8, __pyx_t_11) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (PySet_Add(__pyx_t_8, __pyx_t_10) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (PySet_Add(__pyx_t_8, __pyx_t_9) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types, ((PyObject*)__pyx_t_8));
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pyreadstat/_readstat_writer.pyx":38
 *              np.int32, np.int16, np.int8, np.uint8, np.uint16}
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),             # <<<<<<<<<<<<<<
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),
 *                pd.Float64Dtype(), pd.Float32Dtype()}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_dtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_dtype); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_dtype); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_dtype); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

  /* "pyreadstat/_readstat_writer.pyx":39
 * cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()}
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),             # <<<<<<<<<<<<<<
 *                pd.Float64Dtype(), pd.Float32Dtype()}
 * cdef set numeric_types = int_types.union(float_types).union(int_mixed_types)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_dtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_uint64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_uint32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pd); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Int64Dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_UInt32Dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_UInt64Dtype); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

  /* "pyreadstat/_readstat_writer.pyx":40
 * cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'),
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),
 *                pd.Float64Dtype(), pd.Float32Dtype()}             # <<<<<<<<<<<<<<
 * cdef set numeric_types = int_types.union(float_types).union(int_mixed_types)
 * cdef set datetime_types = {datetime.datetime}#, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, pd.DatetimeTZDtype, 'datetime64[ns, UTC]'}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_pd); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_Float64Dtype); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_14); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pd); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_Float32Dtype); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_t_14 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = PySet_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  if (PySet_Add(__pyx_t_15, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  if (PySet_Add(__pyx_t_15, __pyx_t_8) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_9) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_10) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_11) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_12) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_6) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_5) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_4) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_7) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_2) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_3) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_13) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  if (PySet_Add(__pyx_t_15, __pyx_t_14) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_float_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_float_types, ((PyObject*)__pyx_t_15));
  __Pyx_GIVEREF(__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyreadstat/_readstat_writer.pyx":41
 *                np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(),
 *                pd.Float64Dtype(), pd.Float32Dtype()}
 * cdef set numeric_types = int_types.union(float_types).union(int_mixed_types)             # <<<<<<<<<<<<<<
 * cdef set datetime_types = {datetime.datetime}#, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, pd.DatetimeTZDtype, 'datetime64[ns, UTC]'}
 * cdef set nat_types = {datetime.datetime, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, datetime.time, datetime.date}
 */
  __pyx_t_15 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PySet_Type_union, __pyx_v_10pyreadstat_16_readstat_writer_int_types, __pyx_v_10pyreadstat_16_readstat_writer_float_types); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_union); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_10pyreadstat_16_readstat_writer_int_mixed_types); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  if (!(likely(PySet_CheckExact(__pyx_t_15))||((__pyx_t_15) == Py_None) || __Pyx_RaiseUnexpectedTypeError("set", __pyx_t_15))) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_numeric_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_numeric_types, ((PyObject*)__pyx_t_15));
  __Pyx_GIVEREF(__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyreadstat/_readstat_writer.pyx":42
 *                pd.Float64Dtype(), pd.Float32Dtype()}
 * cdef set numeric_types = int_types.union(float_types).union(int_mixed_types)
 * cdef set datetime_types = {datetime.datetime}#, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, pd.DatetimeTZDtype, 'datetime64[ns, UTC]'}             # <<<<<<<<<<<<<<
 * cdef set nat_types = {datetime.datetime, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, datetime.time, datetime.date}
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS,  PYWRITER_DATETIME64_US}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_datetime); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_datetime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = PySet_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  if (PySet_Add(__pyx_t_15, __pyx_t_14) < 0) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_datetime_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_datetime_types, ((PyObject*)__pyx_t_15));
  __Pyx_GIVEREF(__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyreadstat/_readstat_writer.pyx":43
 * cdef set numeric_types = int_types.union(float_types).union(int_mixed_types)
 * cdef set datetime_types = {datetime.datetime}#, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, pd.DatetimeTZDtype, 'datetime64[ns, UTC]'}
 * cdef set nat_types = {datetime.datetime, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, datetime.time, datetime.date}             # <<<<<<<<<<<<<<
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS,  PYWRITER_DATETIME64_US}
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_datetime); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_datetime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_np); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_datetime64); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pd); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_libs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_tslibs); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_timestamps); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Timestamp); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_date); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PySet_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PySet_Add(__pyx_t_3, __pyx_t_14) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  if (PySet_Add(__pyx_t_3, __pyx_t_13) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  if (PySet_Add(__pyx_t_3, __pyx_t_15) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  if (PySet_Add(__pyx_t_3, __pyx_t_2) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PySet_Add(__pyx_t_3, __pyx_t_7) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_nat_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_nat_types, ((PyObject*)__pyx_t_3));
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":44
 * cdef set datetime_types = {datetime.datetime}#, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, pd.DatetimeTZDtype, 'datetime64[ns, UTC]'}
 * cdef set nat_types = {datetime.datetime, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, datetime.time, datetime.date}
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS,  PYWRITER_DATETIME64_US}             # <<<<<<<<<<<<<<
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME}
 * cdef dict pandas_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
 */
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_13 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_14 = PySet_New(0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  if (PySet_Add(__pyx_t_14, __pyx_t_3) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PySet_Add(__pyx_t_14, __pyx_t_7) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PySet_Add(__pyx_t_14, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PySet_Add(__pyx_t_14, __pyx_t_15) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  if (PySet_Add(__pyx_t_14, __pyx_t_13) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types, ((PyObject*)__pyx_t_14));
  __Pyx_GIVEREF(__pyx_t_14);
  __pyx_t_14 = 0;

  /* "pyreadstat/_readstat_writer.pyx":45
 * cdef set nat_types = {datetime.datetime, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, datetime.time, datetime.date}
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS,  PYWRITER_DATETIME64_US}
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME}             # <<<<<<<<<<<<<<
 * cdef dict pandas_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 */
  __pyx_t_14 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_13 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_15 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_2 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PySet_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PySet_Add(__pyx_t_4, __pyx_t_14) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  if (PySet_Add(__pyx_t_4, __pyx_t_13) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  if (PySet_Add(__pyx_t_4, __pyx_t_15) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  if (PySet_Add(__pyx_t_4, __pyx_t_2) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PySet_Add(__pyx_t_4, __pyx_t_7) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PySet_Add(__pyx_t_4, __pyx_t_3) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types, ((PyObject*)__pyx_t_4));
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyreadstat/_readstat_writer.pyx":46
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS,  PYWRITER_DATETIME64_US}
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME}
 * cdef dict pandas_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 */
  __pyx_t_4 = __Pyx_PyDict_NewPresized(10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_3, __pyx_t_7) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_INT32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_7, __pyx_t_3) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":47
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME}
 * cdef dict pandas_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
 */
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 47, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_STRING); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 47, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_3, __pyx_t_7) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 47, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_INT32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 47, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_7, __pyx_t_3) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":48
 * cdef dict pandas_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME64_NS: READSTAT_TYPE_DOUBLE, PYWRITER_DATETIME64_US: READSTAT_TYPE_DOUBLE}
 */
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_STRING); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_3, __pyx_t_7) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_7, __pyx_t_3) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":49
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_DATETIME64_NS: READSTAT_TYPE_DOUBLE, PYWRITER_DATETIME64_US: READSTAT_TYPE_DOUBLE}
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_3, __pyx_t_7) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_7, __pyx_t_3) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":50
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME64_NS: READSTAT_TYPE_DOUBLE, PYWRITER_DATETIME64_US: READSTAT_TYPE_DOUBLE}             # <<<<<<<<<<<<<<
 * 
 * cdef double spss_offset_secs = 12219379200
 */
  __pyx_t_3 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_NS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_3, __pyx_t_7) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64_US); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, __pyx_t_7, __pyx_t_3) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_pandas_to_readstat_types, ((PyObject*)__pyx_t_4));
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyreadstat/_readstat_writer.pyx":52
 *                                       PYWRITER_DATETIME64_NS: READSTAT_TYPE_DOUBLE, PYWRITER_DATETIME64_US: READSTAT_TYPE_DOUBLE}
 * 
 * cdef double spss_offset_secs = 12219379200             # <<<<<<<<<<<<<<
 * cdef double sas_offset_secs = 315619200
 * cdef double spss_offset_days = 141428
 */
  __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_secs = 12219379200.0;

  /* "pyreadstat/_readstat_writer.pyx":53
 * 
 * cdef double spss_offset_secs = 12219379200
 * cdef double sas_offset_secs = 315619200             # <<<<<<<<<<<<<<
 * cdef double spss_offset_days = 141428
 * cdef double sas_offset_days = 3653
 */
  __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_secs = 315619200.0;

  /* "pyreadstat/_readstat_writer.pyx":54
 * cdef double spss_offset_secs = 12219379200
 * cdef double sas_offset_secs = 315619200
 * cdef double spss_offset_days = 141428             # <<<<<<<<<<<<<<
 * cdef double sas_offset_days = 3653
 * cdef object date_0 = datetime.datetime(1970,1,1).date()
 */
  __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_days = 141428.0;

  /* "pyreadstat/_readstat_writer.pyx":55
 * cdef double sas_offset_secs = 315619200
 * cdef double spss_offset_days = 141428
 * cdef double sas_offset_days = 3653             # <<<<<<<<<<<<<<
 * cdef object date_0 = datetime.datetime(1970,1,1).date()
 * 
 */
  __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_days = 3653.0;

  /* "pyreadstat/_readstat_writer.pyx":56
 * cdef double spss_offset_days = 141428
 * cdef double sas_offset_days = 3653
 * cdef object date_0 = datetime.datetime(1970,1,1).date()             # <<<<<<<<<<<<<<
 * 
 * cdef valid_user_missing_sas = [chr(x) for x in range(ord("A"), ord("Z")+1)] + ["_"]
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_date); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_date_0);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_date_0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyreadstat/_readstat_writer.pyx":58
 * cdef object date_0 = datetime.datetime(1970,1,1).date()
 * 
 * cdef valid_user_missing_sas = [chr(x) for x in range(ord("A"), ord("Z")+1)] + ["_"]             # <<<<<<<<<<<<<<
 * cdef valid_user_missing_stata = [chr(x) for x in range(ord("a"), ord("z")+1)]
 * 
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyInt_From_long((90 + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_int_65);
  __Pyx_GIVEREF(__pyx_int_65);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_int_65);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_7 = __pyx_t_3; __Pyx_INCREF(__pyx_t_7); __pyx_t_16 = 0;
    __pyx_t_17 = NULL;
  } else {
    __pyx_t_16 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_17 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 58, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_17)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_16 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_16); __Pyx_INCREF(__pyx_t_3); __pyx_t_16++; if (unlikely((0 < 0))) __PYX_ERR(0, 58, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_7, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 58, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_16 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_16); __Pyx_INCREF(__pyx_t_3); __pyx_t_16++; if (unlikely((0 < 0))) __PYX_ERR(0, 58, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_7, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 58, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_17(__pyx_t_7);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 58, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_x, __pyx_t_3) < 0) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s__17);
  __Pyx_GIVEREF(__pyx_n_s__17);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s__17);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":59
 * 
 * cdef valid_user_missing_sas = [chr(x) for x in range(ord("A"), ord("Z")+1)] + ["_"]
 * cdef valid_user_missing_stata = [chr(x) for x in range(ord("a"), ord("z")+1)]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyInt_From_long((0x7A + 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_int_97);
  __Pyx_GIVEREF(__pyx_int_97);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_97);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_4 = __pyx_t_7; __Pyx_INCREF(__pyx_t_4); __pyx_t_16 = 0;
    __pyx_t_17 = NULL;
  } else {
    __pyx_t_16 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_17 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 59, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_17)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_16 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_16); __Pyx_INCREF(__pyx_t_7); __pyx_t_16++; if (unlikely((0 < 0))) __PYX_ERR(0, 59, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 59, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_16 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_16); __Pyx_INCREF(__pyx_t_7); __pyx_t_16++; if (unlikely((0 < 0))) __PYX_ERR(0, 59, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 59, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_17(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 59, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_x, __pyx_t_7) < 0) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":1
 * # cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2             # <<<<<<<<<<<<<<
 * # ###cython: profile=True
 * # #############################################################################
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  if (__pyx_m) {
    if (__pyx_d && stringtab_initialized) {
      __Pyx_AddTraceback("init pyreadstat._readstat_writer", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    #if !CYTHON_USE_MODULE_STATE
    Py_CLEAR(__pyx_m);
    #else
    Py_DECREF(__pyx_m);
    if (pystate_addmodule_run) {
      PyObject *tp, *value, *tb;
      PyErr_Fetch(&tp, &value, &tb);
      PyState_RemoveModule(&__pyx_moduledef);
      PyErr_Restore(tp, value, tb);
    }
    #endif
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pyreadstat._readstat_writer");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}
/* #### Code section: cleanup_globals ### */
/* #### Code section: cleanup_module ### */
/* #### Code section: main_method ### */
/* #### Code section: utility_code_pragmas ### */
#ifdef _MSC_VER
#pragma warning( push )
/* Warning 4127: conditional expression is constant
 * Cython uses constant conditional expressions to allow in inline functions to be optimized at
 * compile-time, so this warning is not useful
 */
#pragma warning( disable : 4127 )
#endif



/* #### Code section: utility_code_def ### */

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    int result;
    PyObject *exc_type;
#if PY_VERSION_HEX >= 0x030C00A6
    PyObject *current_exception = tstate->current_exception;
    if (unlikely(!current_exception)) return 0;
    exc_type = (PyObject*) Py_TYPE(current_exception);
    if (exc_type == err) return 1;
#else
    exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
#endif
    #if CYTHON_AVOID_BORROWED_REFS
    Py_INCREF(exc_type);
    #endif
    if (unlikely(PyTuple_Check(err))) {
        result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    } else {
        result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
    }
    #if CYTHON_AVOID_BORROWED_REFS
    Py_DECREF(exc_type);
    #endif
    return result;
}
#endif

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
#if PY_VERSION_HEX >= 0x030C00A6
    PyObject *tmp_value;
    assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value)));
    if (value) {
        #if CYTHON_COMPILING_IN_CPYTHON
        if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb))
        #endif
            PyException_SetTraceback(value, tb);
    }
    tmp_value = tstate->current_exception;
    tstate->current_exception = value;
    Py_XDECREF(tmp_value);
#else
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#if PY_VERSION_HEX >= 0x030C00A6
    PyObject* exc_value;
    exc_value = tstate->current_exception;
    tstate->current_exception = 0;
    *value = exc_value;
    *type = NULL;
    *tb = NULL;
    if (exc_value) {
        *type = (PyObject*) Py_TYPE(exc_value);
        Py_INCREF(*type);
        #if CYTHON_COMPILING_IN_CPYTHON
        *tb = ((PyBaseExceptionObject*) exc_value)->traceback;
        Py_XINCREF(*tb);
        #else
        *tb = PyException_GetTraceback(exc_value);
        #endif
    }
#else
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#endif
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* PyObjectGetAttrStrNoError */
static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
        return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
    }
#endif
    result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
    if (unlikely(!result)) {
        __Pyx_PyObject_GetAttrStr_ClearAttributeError();
    }
    return result;
}

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name);
    if (unlikely(!result) && !PyErr_Occurred()) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#elif CYTHON_COMPILING_IN_LIMITED_API
    if (unlikely(!__pyx_m)) {
        return NULL;
    }
    result = PyObject_GetAttr(__pyx_m, name);
    if (likely(result)) {
        return result;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectFastCall */
static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) {
    PyObject *argstuple;
    PyObject *result;
    size_t i;
    argstuple = PyTuple_New((Py_ssize_t)nargs);
    if (unlikely(!argstuple)) return NULL;
    for (i = 0; i < nargs; i++) {
        Py_INCREF(args[i]);
        PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]);
    }
    result = __Pyx_PyObject_Call(func, argstuple, kwargs);
    Py_DECREF(argstuple);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) {
    Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs);
#if CYTHON_COMPILING_IN_CPYTHON
    if (nargs == 0 && kwargs == NULL) {
#if defined(__Pyx_CyFunction_USED) && defined(NDEBUG)
        if (__Pyx_IsCyOrPyCFunction(func))
#else
        if (PyCFunction_Check(func))
#endif
        {
            if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
                return __Pyx_PyObject_CallMethO(func, NULL);
            }
        }
    }
    else if (nargs == 1 && kwargs == NULL) {
        if (PyCFunction_Check(func))
        {
            if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
                return __Pyx_PyObject_CallMethO(func, args[0]);
            }
        }
    }
#endif
    #if PY_VERSION_HEX < 0x030800B1
    #if CYTHON_FAST_PYCCALL
    if (PyCFunction_Check(func)) {
        if (kwargs) {
            return _PyCFunction_FastCallDict(func, args, nargs, kwargs);
        } else {
            return _PyCFunction_FastCallKeywords(func, args, nargs, NULL);
        }
    }
    #if PY_VERSION_HEX >= 0x030700A1
    if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) {
        return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL);
    }
    #endif
    #endif
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs);
    }
    #endif
    #endif
    #if CYTHON_VECTORCALL
    vectorcallfunc f = _PyVectorcall_Function(func);
    if (f) {
        return f(func, args, (size_t)nargs, kwargs);
    }
    #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL
    if (__Pyx_CyFunction_CheckExact(func)) {
        __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func);
        if (f) return f(func, args, (size_t)nargs, kwargs);
    }
    #endif
    if (nargs == 0) {
        return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs);
    }
    return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs);
}

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        #if PY_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    __Pyx_PyThreadState_declare
    CYTHON_UNUSED_VAR(cause);
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
      #if PY_VERSION_HEX >= 0x030C00A6
        PyException_SetTraceback(value, tb);
      #elif CYTHON_FAST_THREAD_STATE
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#else
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* RaiseUnexpectedTypeError */
static int
__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj)
{
    __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME,
                 expected, obj_type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
    return 0;
}

/* UnpackUnboundCMethod */
static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *args, PyObject *kwargs) {
    PyObject *selfless_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
    if (unlikely(!selfless_args)) return NULL;
    PyObject *result = PyObject_Call(method, selfless_args, kwargs);
    Py_DECREF(selfless_args);
    return result;
}
static PyMethodDef __Pyx_UnboundCMethod_Def = {
     "CythonUnboundCMethod",
     __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_SelflessCall),
     METH_VARARGS | METH_KEYWORDS,
     NULL
};
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    #else
    if (likely(!PyCFunction_Check(method)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
    } else
#endif
#if defined(CYTHON_COMPILING_IN_PYPY)
#elif PY_VERSION_HEX >= 0x03090000
    if (PyCFunction_CheckExact(method))
#else
    if (PyCFunction_Check(method))
#endif
    {
        PyObject *self;
        int self_found;
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
        self = PyObject_GetAttrString(method, "__self__");
        if (!self) {
            PyErr_Clear();
        }
#else
        self = PyCFunction_GET_SELF(method);
#endif
        self_found = (self && self != Py_None);
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
        Py_XDECREF(self);
#endif
        if (self_found) {
            PyObject *unbound_method = PyCFunction_New(&__Pyx_UnboundCMethod_Def, method);
            if (unlikely(!unbound_method)) return -1;
            Py_DECREF(method);
            target->method = unbound_method;
        }
    }
    return 0;
}

/* CallUnboundCMethod1 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
    if (likely(cfunc->func)) {
        int flag = cfunc->flag;
        if (flag == METH_O) {
            return (*(cfunc->func))(self, arg);
        } else if ((PY_VERSION_HEX >= 0x030600B1) && flag == METH_FASTCALL) {
            #if PY_VERSION_HEX >= 0x030700A0
                return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
            #else
                return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
            #endif
        } else if ((PY_VERSION_HEX >= 0x030700A0) && flag == (METH_FASTCALL | METH_KEYWORDS)) {
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
        }
    }
    return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 0, arg);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 1, arg);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(2, self, arg);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* CallUnboundCMethod0 */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_ASSUME_SAFE_MACROS
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

/* py_dict_keys */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_keys, d);
    else
        return PyDict_Keys(d);
}

/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    PyObject* exc_type = __Pyx_PyErr_CurrentExceptionType();
    if (unlikely(exc_type)) {
        if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
            return -1;
        __Pyx_PyErr_Clear();
        return 0;
    }
    return 0;
}

/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    }
    return __Pyx_IterFinish();
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_MAYBE_UNUSED_VAR(inplace);
    CYTHON_UNUSED_VAR(zerodivision_check);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
        
            x = (long)((unsigned long)a + (unsigned long)b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        if (unlikely(__Pyx_PyLong_IsZero(op1))) {
            return __Pyx_NewRef(op2);
        }
        if (likely(__Pyx_PyLong_IsCompact(op1))) {
            a = __Pyx_PyLong_CompactValue(op1);
        } else {
            const digit* digits = __Pyx_PyLong_Digits(op1);
            const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1);
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
#if CYTHON_COMPILING_IN_LIMITED_API
        double a = __pyx_PyFloat_AsDouble(op1);
#else
        double a = PyFloat_AS_DOUBLE(op1);
#endif
            double result;
            
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (unlikely(!j)) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping;
        PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence;
        if (mm && mm->mp_subscript) {
            PyObject *r, *key = PyInt_FromSsize_t(i);
            if (unlikely(!key)) return NULL;
            r = mm->mp_subscript(o, key);
            Py_DECREF(key);
            return r;
        }
        if (likely(sm && sm->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) {
                Py_ssize_t l = sm->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return sm->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* PyObjectCallOneArg */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *args[2] = {NULL, arg};
    return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject *index) {
    PyObject *runerr = NULL;
    Py_ssize_t key_value;
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        __Pyx_TypeName index_type_name = __Pyx_PyType_GetName(Py_TYPE(index));
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError,
            "cannot fit '" __Pyx_FMT_TYPENAME "' into an index-sized integer", index_type_name);
        __Pyx_DECREF_TypeName(index_type_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem_Slow(PyObject *obj, PyObject *key) {
    __Pyx_TypeName obj_type_name;
    if (likely(PyType_Check(obj))) {
        PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(obj, __pyx_n_s_class_getitem);
        if (meth) {
            PyObject *result = __Pyx_PyObject_CallOneArg(meth, key);
            Py_DECREF(meth);
            return result;
        }
    }
    obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    PyErr_Format(PyExc_TypeError,
        "'" __Pyx_FMT_TYPENAME "' object is not subscriptable", obj_type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject *key) {
    PyTypeObject *tp = Py_TYPE(obj);
    PyMappingMethods *mm = tp->tp_as_mapping;
    PySequenceMethods *sm = tp->tp_as_sequence;
    if (likely(mm && mm->mp_subscript)) {
        return mm->mp_subscript(obj, key);
    }
    if (likely(sm && sm->sq_item)) {
        return __Pyx_PyObject_GetIndex(obj, key);
    }
    return __Pyx_PyObject_GetItem_Slow(obj, key);
}
#endif

/* CallUnboundCMethod2 */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
    if (likely(cfunc->func)) {
        PyObject *args[2] = {arg1, arg2};
        if (cfunc->flag == METH_FASTCALL) {
            #if PY_VERSION_HEX >= 0x030700A0
            return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
            #else
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
            #endif
        }
        #if PY_VERSION_HEX >= 0x030700A0
        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
        #endif
    }
    return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 0, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 1, arg2);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(3);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 1, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 2, arg2);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(3, self, arg1, arg2);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* dict_getitem_default */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000)
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            return NULL;
        value = default_value;
    }
    Py_INCREF(value);
    if ((1));
#else
    if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
        value = PyDict_GetItem(d, key);
        if (unlikely(!value)) {
            value = default_value;
        }
        Py_INCREF(value);
    }
#endif
    else {
        if (default_value == Py_None)
            value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key);
        else
            value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value);
    }
    return value;
}

/* pyfrozenset_new */
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
    if (it) {
        PyObject* result;
#if CYTHON_COMPILING_IN_PYPY
        PyObject* args;
        args = PyTuple_Pack(1, it);
        if (unlikely(!args))
            return NULL;
        result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL);
        Py_DECREF(args);
        return result;
#else
        if (PyFrozenSet_CheckExact(it)) {
            Py_INCREF(it);
            return it;
        }
        result = PyFrozenSet_New(it);
        if (unlikely(!result))
            return NULL;
        if ((PY_VERSION_HEX >= 0x031000A1) || likely(PySet_GET_SIZE(result)))
            return result;
        Py_DECREF(result);
#endif
    }
#if CYTHON_USE_TYPE_SLOTS
    return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#else
    return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#endif
}

/* PySetContains */
static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) {
    int result = -1;
    if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) {
        PyObject *tmpkey;
        PyErr_Clear();
        tmpkey = __Pyx_PyFrozenSet_New(key);
        if (tmpkey != NULL) {
            result = PySet_Contains(set, tmpkey);
            Py_DECREF(tmpkey);
        }
    }
    return result;
}
static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) {
    int result = PySet_Contains(set, key);
    if (unlikely(result < 0)) {
        result = __Pyx_PySet_ContainsUnhashable(set, key);
    }
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* DictGetItem */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            if (unlikely(PyTuple_Check(key))) {
                PyObject* args = PyTuple_Pack(1, key);
                if (likely(args)) {
                    PyErr_SetObject(PyExc_KeyError, args);
                    Py_DECREF(args);
                }
            } else {
                PyErr_SetObject(PyExc_KeyError, key);
            }
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* py_dict_items */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d);
    else
        return PyDict_Items(d);
}

/* UnicodeAsUCS4 */
static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
   Py_ssize_t length;
   #if CYTHON_PEP393_ENABLED
   length = PyUnicode_GET_LENGTH(x);
   if (likely(length == 1)) {
       return PyUnicode_READ_CHAR(x, 0);
   }
   #else
   length = PyUnicode_GET_SIZE(x);
   if (likely(length == 1)) {
       return PyUnicode_AS_UNICODE(x)[0];
   }
   #if Py_UNICODE_SIZE == 2
   else if (PyUnicode_GET_SIZE(x) == 2) {
       Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
       if (high_val >= 0xD800 && high_val <= 0xDBFF) {
           Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
           if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
               return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
           }
       }
   }
   #endif
   #endif
   PyErr_Format(PyExc_ValueError,
                "only single character unicode strings can be converted to Py_UCS4, "
                "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
   return (Py_UCS4)-1;
}

/* object_ord */
static long __Pyx__PyObject_Ord(PyObject* c) {
    Py_ssize_t size;
    if (PyBytes_Check(c)) {
        size = PyBytes_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyBytes_AS_STRING(c)[0];
        }
#if PY_MAJOR_VERSION < 3
    } else if (PyUnicode_Check(c)) {
        return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    } else if (PyByteArray_Check(c)) {
        size = PyByteArray_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyByteArray_AS_STRING(c)[0];
        }
#endif
    } else {
        __Pyx_TypeName c_type_name = __Pyx_PyType_GetName(Py_TYPE(c));
        PyErr_Format(PyExc_TypeError,
            "ord() expected string of length 1, but " __Pyx_FMT_TYPENAME " found",
            c_type_name);
        __Pyx_DECREF_TypeName(c_type_name);
        return (long)(Py_UCS4)-1;
    }
    PyErr_Format(PyExc_TypeError,
        "ord() expected a character, but string of length %zd found", size);
    return (long)(Py_UCS4)-1;
}

/* PyIntCompare */
static CYTHON_INLINE int __Pyx_PyInt_BoolNeObjC(PyObject *op1, PyObject *op2, long intval, long inplace) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_UNUSED_VAR(inplace);
    if (op1 == op2) {
        return 0;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        return (a != b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = __Pyx_PyLong_DigitCount(op1);
        const digit* digits = __Pyx_PyLong_Digits(op1);
        if (intval == 0) {
            return (__Pyx_PyLong_IsZero(op1) != 1);
        } else if (intval < 0) {
            if (__Pyx_PyLong_IsNonNeg(op1))
                return 1;
            intval = -intval;
        } else {
            if (__Pyx_PyLong_IsNeg(op1))
                return 1;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        return (unequal != 0);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
#if CYTHON_COMPILING_IN_LIMITED_API
        double a = __pyx_PyFloat_AsDouble(op1);
#else
        double a = PyFloat_AS_DOUBLE(op1);
#endif
        return ((double)a != (double)b);
    }
    return __Pyx_PyObject_IsTrueAndDecref(
        PyObject_RichCompare(op1, op2, Py_NE));
}

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
    else state = (PyGILState_STATE)0;
#endif
    CYTHON_UNUSED_VAR(clineno);
    CYTHON_UNUSED_VAR(lineno);
    CYTHON_UNUSED_VAR(filename);
    CYTHON_MAYBE_UNUSED_VAR(nogil);
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* RaiseUnboundLocalError */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* GetAttr */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* HasAttr */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (!r) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    PyObject *exc_value = exc_info->exc_value;
    if (exc_value == NULL || exc_value == Py_None) {
        *value = NULL;
        *type = NULL;
        *tb = NULL;
    } else {
        *value = exc_value;
        Py_INCREF(*value);
        *type = (PyObject*) Py_TYPE(exc_value);
        Py_INCREF(*type);
        *tb = PyException_GetTraceback(exc_value);
    }
  #elif CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
  #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
  #endif
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
    _PyErr_StackItem *exc_info = tstate->exc_info;
    PyObject *tmp_value = exc_info->exc_value;
    exc_info->exc_value = value;
    Py_XDECREF(tmp_value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
  #else
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
  #endif
}
#endif

/* GetException */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
#endif
{
    PyObject *local_type = NULL, *local_value, *local_tb = NULL;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
  #if PY_VERSION_HEX >= 0x030C00A6
    local_value = tstate->current_exception;
    tstate->current_exception = 0;
    if (likely(local_value)) {
        local_type = (PyObject*) Py_TYPE(local_value);
        Py_INCREF(local_type);
        local_tb = PyException_GetTraceback(local_value);
    }
  #else
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
  #endif
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6
    if (unlikely(tstate->current_exception))
#elif CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    #if CYTHON_USE_EXC_INFO_STACK
    {
        _PyErr_StackItem *exc_info = tstate->exc_info;
      #if PY_VERSION_HEX >= 0x030B00a4
        tmp_value = exc_info->exc_value;
        exc_info->exc_value = local_value;
        tmp_type = NULL;
        tmp_tb = NULL;
        Py_XDECREF(local_type);
        Py_XDECREF(local_tb);
      #else
        tmp_type = exc_info->exc_type;
        tmp_value = exc_info->exc_value;
        tmp_tb = exc_info->exc_traceback;
        exc_info->exc_type = local_type;
        exc_info->exc_value = local_value;
        exc_info->exc_traceback = local_tb;
      #endif
    }
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* PyFloatBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_DivideObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check) {
    const double b = floatval;
    double a, result;
    CYTHON_UNUSED_VAR(inplace);
    CYTHON_UNUSED_VAR(zerodivision_check);
    if (likely(PyFloat_CheckExact(op1))) {
#if CYTHON_COMPILING_IN_LIMITED_API
        a = __pyx_PyFloat_AsDouble(op1);
#else
        a = PyFloat_AS_DOUBLE(op1);
#endif
        
    } else
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        a = (double) PyInt_AS_LONG(op1);
        
    } else
    #endif
    if (likely(PyLong_CheckExact(op1))) {
        #if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsZero(op1)) {
            a = 0.0;
            
        } else if (__Pyx_PyLong_IsCompact(op1)) {
            a = (double) __Pyx_PyLong_CompactValue(op1);
        } else {
            const digit* digits = __Pyx_PyLong_Digits(op1);
            const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1);
            switch (size) {
                case -2:
                case 2:
                    if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (1 * PyLong_SHIFT < 53))) {
                        a = (double) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        if ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53) || (a < (double) ((PY_LONG_LONG)1 << 53))) {
                            if (size == -2)
                                a = -a;
                            break;
                        }
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                case 3:
                    if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53))) {
                        a = (double) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        if ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53) || (a < (double) ((PY_LONG_LONG)1 << 53))) {
                            if (size == -3)
                                a = -a;
                            break;
                        }
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                case 4:
                    if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53))) {
                        a = (double) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        if ((8 * sizeof(unsigned long) < 53) || (4 * PyLong_SHIFT < 53) || (a < (double) ((PY_LONG_LONG)1 << 53))) {
                            if (size == -4)
                                a = -a;
                            break;
                        }
                    }
                    CYTHON_FALLTHROUGH;
                default:
        #endif
                    a = PyLong_AsDouble(op1);
                    if (unlikely(a == -1.0 && PyErr_Occurred())) return NULL;
        #if CYTHON_USE_PYLONG_INTERNALS
            }
        }
        #endif
    } else {
        return (inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2));
    }
        PyFPE_START_PROTECT("divide", return NULL)
        result = a / b;
        PyFPE_END_PROTECT(result)
        return PyFloat_FromDouble(result);
}
#endif

/* SwapException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
  #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_value = exc_info->exc_value;
    exc_info->exc_value = *value;
    if (tmp_value == NULL || tmp_value == Py_None) {
        Py_XDECREF(tmp_value);
        tmp_value = NULL;
        tmp_type = NULL;
        tmp_tb = NULL;
    } else {
        tmp_type = (PyObject*) Py_TYPE(tmp_value);
        Py_INCREF(tmp_type);
        #if CYTHON_COMPILING_IN_CPYTHON
        tmp_tb = ((PyBaseExceptionObject*) tmp_value)->traceback;
        Py_XINCREF(tmp_tb);
        #else
        tmp_tb = PyException_GetTraceback(tmp_value);
        #endif
    }
  #elif CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = *type;
    exc_info->exc_value = *value;
    exc_info->exc_traceback = *tb;
  #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
  #endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#endif

/* TypeImport */
#ifndef __PYX_HAVE_RT_ImportType_3_0_0
#define __PYX_HAVE_RT_ImportType_3_0_0
static PyTypeObject *__Pyx_ImportType_3_0_0(PyObject *module, const char *module_name, const char *class_name,
    size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_0 check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
    Py_ssize_t itemsize;
#if CYTHON_COMPILING_IN_LIMITED_API
    PyObject *py_basicsize;
    PyObject *py_itemsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#if !CYTHON_COMPILING_IN_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
    itemsize = ((PyTypeObject *)result)->tp_itemsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
    py_itemsize = PyObject_GetAttrString(result, "__itemsize__");
    if (!py_itemsize)
        goto bad;
    itemsize = PyLong_AsSsize_t(py_itemsize);
    Py_DECREF(py_itemsize);
    py_itemsize = 0;
    if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (itemsize) {
        if (size % alignment) {
            alignment = size % alignment;
        }
        if (itemsize < (Py_ssize_t)alignment)
            itemsize = (Py_ssize_t)alignment;
    }
    if ((size_t)(basicsize + itemsize) < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize+itemsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error_3_0_0 &&
            ((size_t)basicsize > size || (size_t)(basicsize + itemsize) < size)) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd-%zd from PyObject",
            module_name, class_name, size, basicsize, basicsize+itemsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn_3_0_0 && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *module = 0;
    PyObject *empty_dict = 0;
    PyObject *empty_list = 0;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (unlikely(!py_import))
        goto bad;
    if (!from_list) {
        empty_list = PyList_New(0);
        if (unlikely(!empty_list))
            goto bad;
        from_list = empty_list;
    }
    #endif
    empty_dict = PyDict_New();
    if (unlikely(!empty_dict))
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                #if CYTHON_COMPILING_IN_LIMITED_API
                module = PyImport_ImportModuleLevelObject(
                    name, empty_dict, empty_dict, from_list, 1);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, __pyx_d, empty_dict, from_list, 1);
                #endif
                if (unlikely(!module)) {
                    if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (unlikely(!py_level))
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            #if CYTHON_COMPILING_IN_LIMITED_API
            module = PyImport_ImportModuleLevelObject(
                name, empty_dict, empty_dict, from_list, level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, __pyx_d, empty_dict, from_list, level);
            #endif
            #endif
        }
    }
bad:
    Py_XDECREF(empty_dict);
    Py_XDECREF(empty_list);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    return module;
}

/* ImportDottedModule */
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) {
    PyObject *partial_name = NULL, *slice = NULL, *sep = NULL;
    if (unlikely(PyErr_Occurred())) {
        PyErr_Clear();
    }
    if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) {
        partial_name = name;
    } else {
        slice = PySequence_GetSlice(parts_tuple, 0, count);
        if (unlikely(!slice))
            goto bad;
        sep = PyUnicode_FromStringAndSize(".", 1);
        if (unlikely(!sep))
            goto bad;
        partial_name = PyUnicode_Join(sep, slice);
    }
    PyErr_Format(
#if PY_MAJOR_VERSION < 3
        PyExc_ImportError,
        "No module named '%s'", PyString_AS_STRING(partial_name));
#else
#if PY_VERSION_HEX >= 0x030600B1
        PyExc_ModuleNotFoundError,
#else
        PyExc_ImportError,
#endif
        "No module named '%U'", partial_name);
#endif
bad:
    Py_XDECREF(sep);
    Py_XDECREF(slice);
    Py_XDECREF(partial_name);
    return NULL;
}
#endif
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) {
    PyObject *imported_module;
#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM  < 0x07030400)
    PyObject *modules = PyImport_GetModuleDict();
    if (unlikely(!modules))
        return NULL;
    imported_module = __Pyx_PyDict_GetItemStr(modules, name);
    Py_XINCREF(imported_module);
#else
    imported_module = PyImport_GetModule(name);
#endif
    return imported_module;
}
#endif
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) {
    Py_ssize_t i, nparts;
    nparts = PyTuple_GET_SIZE(parts_tuple);
    for (i=1; i < nparts && module; i++) {
        PyObject *part, *submodule;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        part = PyTuple_GET_ITEM(parts_tuple, i);
#else
        part = PySequence_ITEM(parts_tuple, i);
#endif
        submodule = __Pyx_PyObject_GetAttrStrNoError(module, part);
#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
        Py_DECREF(part);
#endif
        Py_DECREF(module);
        module = submodule;
    }
    if (unlikely(!module)) {
        return __Pyx__ImportDottedModule_Error(name, parts_tuple, i);
    }
    return module;
}
#endif
static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
#if PY_MAJOR_VERSION < 3
    PyObject *module, *from_list, *star = __pyx_n_s__4;
    CYTHON_UNUSED_VAR(parts_tuple);
    from_list = PyList_New(1);
    if (unlikely(!from_list))
        return NULL;
    Py_INCREF(star);
    PyList_SET_ITEM(from_list, 0, star);
    module = __Pyx_Import(name, from_list, 0);
    Py_DECREF(from_list);
    return module;
#else
    PyObject *imported_module;
    PyObject *module = __Pyx_Import(name, NULL, 0);
    if (!parts_tuple || unlikely(!module))
        return module;
    imported_module = __Pyx__ImportDottedModule_Lookup(name);
    if (likely(imported_module)) {
        Py_DECREF(module);
        return imported_module;
    }
    PyErr_Clear();
    return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple);
#endif
}
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1
    PyObject *module = __Pyx__ImportDottedModule_Lookup(name);
    if (likely(module)) {
        PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec);
        if (likely(spec)) {
            PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing);
            if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) {
                Py_DECREF(spec);
                spec = NULL;
            }
            Py_XDECREF(unsafe);
        }
        if (likely(!spec)) {
            PyErr_Clear();
            return module;
        }
        Py_DECREF(spec);
        Py_DECREF(module);
    } else if (PyErr_Occurred()) {
        PyErr_Clear();
    }
#endif
    return __Pyx__ImportDottedModule(name, parts_tuple);
}

/* ImportDottedModuleRelFirst */
static PyObject *__Pyx_ImportDottedModuleRelFirst(PyObject *name, PyObject *parts_tuple) {
    PyObject *module;
    PyObject *from_list = NULL;
#if PY_MAJOR_VERSION < 3
    PyObject *star = __pyx_n_s__4;
    from_list = PyList_New(1);
    if (unlikely(!from_list))
        return NULL;
    Py_INCREF(star);
    PyList_SET_ITEM(from_list, 0, star);
#endif
    module = __Pyx_Import(name, from_list, -1);
    Py_XDECREF(from_list);
    if (module) {
        #if PY_MAJOR_VERSION >= 3
        if (parts_tuple) {
            module = __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple);
        }
        #endif
        return module;
    }
    if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
        return NULL;
    PyErr_Clear();
    return __Pyx_ImportDottedModule(name, parts_tuple);
}

/* ImportFrom */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        const char* module_name_str = 0;
        PyObject* module_name = 0;
        PyObject* module_dot = 0;
        PyObject* full_name = 0;
        PyErr_Clear();
        module_name_str = PyModule_GetName(module);
        if (unlikely(!module_name_str)) { goto modbad; }
        module_name = PyUnicode_FromString(module_name_str);
        if (unlikely(!module_name)) { goto modbad; }
        module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__5);
        if (unlikely(!module_dot)) { goto modbad; }
        full_name = PyUnicode_Concat(module_dot, name);
        if (unlikely(!full_name)) { goto modbad; }
        #if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM  < 0x07030400)
        {
            PyObject *modules = PyImport_GetModuleDict();
            if (unlikely(!modules))
                goto modbad;
            value = PyObject_GetItem(modules, full_name);
        }
        #else
        value = PyImport_GetModule(full_name);
        #endif
      modbad:
        Py_XDECREF(full_name);
        Py_XDECREF(module_dot);
        Py_XDECREF(module_name);
    }
    if (unlikely(!value)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* PyObjectCallNoArg */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
    PyObject *arg = NULL;
    return __Pyx_PyObject_FastCall(func, (&arg)+1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    CYTHON_MAYBE_UNUSED_VAR(tstate);
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
#if !CYTHON_COMPILING_IN_LIMITED_API
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}
#endif

/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    if (c_line) {
        (void) __pyx_cfilenm;
        (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line);
    }
    _PyTraceback_Add(funcname, filename, py_line);
}
#else
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);  // XDECREF since it's only set on Py3 if cline
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject *ptype, *pvalue, *ptraceback;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) {
            /* If the code object creation fails, then we should clear the
               fetched exception references and propagate the new exception */
            Py_XDECREF(ptype);
            Py_XDECREF(pvalue);
            Py_XDECREF(ptraceback);
            goto bad;
        }
        __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
#endif

/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type neg_one = (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1, const_zero = (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_readstat_type_t(readstat_type_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const readstat_type_t neg_one = (readstat_type_t) -1, const_zero = (readstat_type_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(readstat_type_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(readstat_type_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(readstat_type_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(readstat_type_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(readstat_type_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(readstat_type_t),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE readstat_type_t __Pyx_PyInt_As_readstat_type_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const readstat_type_t neg_one = (readstat_type_t) -1, const_zero = (readstat_type_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(readstat_type_t) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(readstat_type_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (readstat_type_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            if (unlikely(__Pyx_PyLong_IsNeg(x))) {
                goto raise_neg_overflow;
            } else if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(readstat_type_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_DigitCount(x)) {
                    case 2:
                        if ((8 * sizeof(readstat_type_t) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) >= 2 * PyLong_SHIFT)) {
                                return (readstat_type_t) (((((readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0]));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(readstat_type_t) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) >= 3 * PyLong_SHIFT)) {
                                return (readstat_type_t) (((((((readstat_type_t)digits[2]) << PyLong_SHIFT) | (readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0]));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(readstat_type_t) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) >= 4 * PyLong_SHIFT)) {
                                return (readstat_type_t) (((((((((readstat_type_t)digits[3]) << PyLong_SHIFT) | (readstat_type_t)digits[2]) << PyLong_SHIFT) | (readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0]));
                            }
                        }
                        break;
                }
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (readstat_type_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if ((sizeof(readstat_type_t) <= sizeof(unsigned long))) {
                __PYX_VERIFY_RETURN_INT_EXC(readstat_type_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(readstat_type_t) <= sizeof(unsigned PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(readstat_type_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(readstat_type_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_SignedDigitCount(x)) {
                    case -2:
                        if ((8 * sizeof(readstat_type_t) - 1 > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) - 1 > 2 * PyLong_SHIFT)) {
                                return (readstat_type_t) (((readstat_type_t)-1)*(((((readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0])));
                            }
                        }
                        break;
                    case 2:
                        if ((8 * sizeof(readstat_type_t) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) - 1 > 2 * PyLong_SHIFT)) {
                                return (readstat_type_t) ((((((readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0])));
                            }
                        }
                        break;
                    case -3:
                        if ((8 * sizeof(readstat_type_t) - 1 > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) - 1 > 3 * PyLong_SHIFT)) {
                                return (readstat_type_t) (((readstat_type_t)-1)*(((((((readstat_type_t)digits[2]) << PyLong_SHIFT) | (readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0])));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(readstat_type_t) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) - 1 > 3 * PyLong_SHIFT)) {
                                return (readstat_type_t) ((((((((readstat_type_t)digits[2]) << PyLong_SHIFT) | (readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0])));
                            }
                        }
                        break;
                    case -4:
                        if ((8 * sizeof(readstat_type_t) - 1 > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) - 1 > 4 * PyLong_SHIFT)) {
                                return (readstat_type_t) (((readstat_type_t)-1)*(((((((((readstat_type_t)digits[3]) << PyLong_SHIFT) | (readstat_type_t)digits[2]) << PyLong_SHIFT) | (readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0])));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(readstat_type_t) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(readstat_type_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(readstat_type_t) - 1 > 4 * PyLong_SHIFT)) {
                                return (readstat_type_t) ((((((((((readstat_type_t)digits[3]) << PyLong_SHIFT) | (readstat_type_t)digits[2]) << PyLong_SHIFT) | (readstat_type_t)digits[1]) << PyLong_SHIFT) | (readstat_type_t)digits[0])));
                            }
                        }
                        break;
                }
            }
#endif
            if ((sizeof(readstat_type_t) <= sizeof(long))) {
                __PYX_VERIFY_RETURN_INT_EXC(readstat_type_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(readstat_type_t) <= sizeof(PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(readstat_type_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        PyErr_SetString(PyExc_RuntimeError,
                        "_PyLong_AsByteArray() not available, cannot convert large enums");
        return (readstat_type_t) -1;
    } else {
        readstat_type_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (readstat_type_t) -1;
        val = __Pyx_PyInt_As_readstat_type_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to readstat_type_t");
    return (readstat_type_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to readstat_type_t");
    return (readstat_type_t) -1;
}

/* CIntFromPy */
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(int32_t) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int32_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            if (unlikely(__Pyx_PyLong_IsNeg(x))) {
                goto raise_neg_overflow;
            } else if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(int32_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_DigitCount(x)) {
                    case 2:
                        if ((8 * sizeof(int32_t) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) >= 2 * PyLong_SHIFT)) {
                                return (int32_t) (((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(int32_t) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) >= 3 * PyLong_SHIFT)) {
                                return (int32_t) (((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(int32_t) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) >= 4 * PyLong_SHIFT)) {
                                return (int32_t) (((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                            }
                        }
                        break;
                }
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int32_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if ((sizeof(int32_t) <= sizeof(unsigned long))) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(int32_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_SignedDigitCount(x)) {
                    case -2:
                        if ((8 * sizeof(int32_t) - 1 > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT)) {
                                return (int32_t) (((int32_t)-1)*(((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                            }
                        }
                        break;
                    case 2:
                        if ((8 * sizeof(int32_t) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT)) {
                                return (int32_t) ((((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                            }
                        }
                        break;
                    case -3:
                        if ((8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT)) {
                                return (int32_t) (((int32_t)-1)*(((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(int32_t) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT)) {
                                return (int32_t) ((((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                            }
                        }
                        break;
                    case -4:
                        if ((8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT)) {
                                return (int32_t) (((int32_t)-1)*(((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(int32_t) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT)) {
                                return (int32_t) ((((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                            }
                        }
                        break;
                }
            }
#endif
            if ((sizeof(int32_t) <= sizeof(long))) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(int32_t) <= sizeof(PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
            int32_t val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
#if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
#endif
            if (likely(v)) {
                int ret = -1;
#if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                ret = _PyLong_AsByteArray((PyLongObject *)v,
                                           bytes, sizeof(val),
                                           is_little, !is_unsigned);
#else
                PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
                int bits, remaining_bits, is_negative = 0;
                long idigit;
                int chunk_size = (sizeof(long) < 8) ? 30 : 62;
                if (unlikely(!PyLong_CheckExact(v))) {
                    PyObject *tmp = v;
                    v = PyNumber_Long(v);
                    assert(PyLong_CheckExact(v));
                    Py_DECREF(tmp);
                    if (unlikely(!v)) return (int32_t) -1;
                }
#if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
                if (Py_SIZE(x) == 0)
                    return (int32_t) 0;
                is_negative = Py_SIZE(x) < 0;
#else
                {
                    int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                    if (unlikely(result < 0))
                        return (int32_t) -1;
                    is_negative = result == 1;
                }
#endif
                if (is_unsigned && unlikely(is_negative)) {
                    goto raise_neg_overflow;
                } else if (is_negative) {
                    stepval = PyNumber_Invert(v);
                    if (unlikely(!stepval))
                        return (int32_t) -1;
                } else {
                    stepval = __Pyx_NewRef(v);
                }
                val = (int32_t) 0;
                mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
                shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
                for (bits = 0; bits < (int) sizeof(int32_t) * 8 - chunk_size; bits += chunk_size) {
                    PyObject *tmp, *digit;
                    digit = PyNumber_And(stepval, mask);
                    if (unlikely(!digit)) goto done;
                    idigit = PyLong_AsLong(digit);
                    Py_DECREF(digit);
                    if (unlikely(idigit < 0)) goto done;
                    tmp = PyNumber_Rshift(stepval, shift);
                    if (unlikely(!tmp)) goto done;
                    Py_DECREF(stepval); stepval = tmp;
                    val |= ((int32_t) idigit) << bits;
                    #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
                    if (Py_SIZE(stepval) == 0)
                        goto unpacking_done;
                    #endif
                }
                idigit = PyLong_AsLong(stepval);
                if (unlikely(idigit < 0)) goto done;
                remaining_bits = ((int) sizeof(int32_t) * 8) - bits - (is_unsigned ? 0 : 1);
                if (unlikely(idigit >= (1L << remaining_bits)))
                    goto raise_overflow;
                val |= ((int32_t) idigit) << bits;
            #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
            unpacking_done:
            #endif
                if (!is_unsigned) {
                    if (unlikely(val & (((int32_t) 1) << (sizeof(int32_t) * 8 - 1))))
                        goto raise_overflow;
                    if (is_negative)
                        val = ~val;
                }
                ret = 0;
            done:
                Py_XDECREF(shift);
                Py_XDECREF(mask);
                Py_XDECREF(stepval);
#endif
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
            return (int32_t) -1;
        }
    } else {
        int32_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyInt_As_int32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int32_t");
    return (int32_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int32_t");
    return (int32_t) -1;
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(int) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            if (unlikely(__Pyx_PyLong_IsNeg(x))) {
                goto raise_neg_overflow;
            } else if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_DigitCount(x)) {
                    case 2:
                        if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
                                return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
                                return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
                                return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                            }
                        }
                        break;
                }
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if ((sizeof(int) <= sizeof(unsigned long))) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_SignedDigitCount(x)) {
                    case -2:
                        if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
                                return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                            }
                        }
                        break;
                    case 2:
                        if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
                                return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                            }
                        }
                        break;
                    case -3:
                        if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
                                return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
                                return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                            }
                        }
                        break;
                    case -4:
                        if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
                                return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
                                return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                            }
                        }
                        break;
                }
            }
#endif
            if ((sizeof(int) <= sizeof(long))) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
#if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
#endif
            if (likely(v)) {
                int ret = -1;
#if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                ret = _PyLong_AsByteArray((PyLongObject *)v,
                                           bytes, sizeof(val),
                                           is_little, !is_unsigned);
#else
                PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
                int bits, remaining_bits, is_negative = 0;
                long idigit;
                int chunk_size = (sizeof(long) < 8) ? 30 : 62;
                if (unlikely(!PyLong_CheckExact(v))) {
                    PyObject *tmp = v;
                    v = PyNumber_Long(v);
                    assert(PyLong_CheckExact(v));
                    Py_DECREF(tmp);
                    if (unlikely(!v)) return (int) -1;
                }
#if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
                if (Py_SIZE(x) == 0)
                    return (int) 0;
                is_negative = Py_SIZE(x) < 0;
#else
                {
                    int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                    if (unlikely(result < 0))
                        return (int) -1;
                    is_negative = result == 1;
                }
#endif
                if (is_unsigned && unlikely(is_negative)) {
                    goto raise_neg_overflow;
                } else if (is_negative) {
                    stepval = PyNumber_Invert(v);
                    if (unlikely(!stepval))
                        return (int) -1;
                } else {
                    stepval = __Pyx_NewRef(v);
                }
                val = (int) 0;
                mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
                shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
                for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
                    PyObject *tmp, *digit;
                    digit = PyNumber_And(stepval, mask);
                    if (unlikely(!digit)) goto done;
                    idigit = PyLong_AsLong(digit);
                    Py_DECREF(digit);
                    if (unlikely(idigit < 0)) goto done;
                    tmp = PyNumber_Rshift(stepval, shift);
                    if (unlikely(!tmp)) goto done;
                    Py_DECREF(stepval); stepval = tmp;
                    val |= ((int) idigit) << bits;
                    #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
                    if (Py_SIZE(stepval) == 0)
                        goto unpacking_done;
                    #endif
                }
                idigit = PyLong_AsLong(stepval);
                if (unlikely(idigit < 0)) goto done;
                remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
                if (unlikely(idigit >= (1L << remaining_bits)))
                    goto raise_overflow;
                val |= ((int) idigit) << bits;
            #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
            unpacking_done:
            #endif
                if (!is_unsigned) {
                    if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
                        goto raise_overflow;
                    if (is_negative)
                        val = ~val;
                }
                ret = 0;
            done:
                Py_XDECREF(shift);
                Py_XDECREF(mask);
                Py_XDECREF(stepval);
#endif
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
static CYTHON_INLINE __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __Pyx_PyInt_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type neg_one = (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1, const_zero = (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            if (unlikely(__Pyx_PyLong_IsNeg(x))) {
                goto raise_neg_overflow;
            } else if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_DigitCount(x)) {
                    case 2:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) >= 2 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) (((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0]));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) >= 3 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) (((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0]));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) >= 4 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) (((((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[3]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0]));
                            }
                        }
                        break;
                }
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if ((sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(unsigned long))) {
                __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(unsigned PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_SignedDigitCount(x)) {
                    case -2:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 2 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) (((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)-1)*(((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0])));
                            }
                        }
                        break;
                    case 2:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 2 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) ((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0])));
                            }
                        }
                        break;
                    case -3:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 3 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) (((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)-1)*(((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0])));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 3 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) ((((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0])));
                            }
                        }
                        break;
                    case -4:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 4 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) (((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)-1)*(((((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[3]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0])));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) - 1 > 4 * PyLong_SHIFT)) {
                                return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) ((((((((((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[3]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)digits[0])));
                            }
                        }
                        break;
                }
            }
#endif
            if ((sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(long))) {
                __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        PyErr_SetString(PyExc_RuntimeError,
                        "_PyLong_AsByteArray() not available, cannot convert large enums");
        return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
    } else {
        __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
        val = __Pyx_PyInt_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type");
    return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type");
    return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
}

/* FormatTypeName */
#if CYTHON_COMPILING_IN_LIMITED_API
static __Pyx_TypeName
__Pyx_PyType_GetName(PyTypeObject* tp)
{
    PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp,
                                               __pyx_n_s_name_2);
    if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) {
        PyErr_Clear();
        Py_XSETREF(name, __Pyx_NewRef(__pyx_n_s__18));
    }
    return name;
}
#endif

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(long) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            if (unlikely(__Pyx_PyLong_IsNeg(x))) {
                goto raise_neg_overflow;
            } else if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_DigitCount(x)) {
                    case 2:
                        if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
                                return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
                                return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
                                return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                            }
                        }
                        break;
                }
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if ((sizeof(long) <= sizeof(unsigned long))) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            if (__Pyx_PyLong_IsCompact(x)) {
                __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
            } else {
                const digit* digits = __Pyx_PyLong_Digits(x);
                assert(__Pyx_PyLong_DigitCount(x) > 1);
                switch (__Pyx_PyLong_SignedDigitCount(x)) {
                    case -2:
                        if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
                                return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                            }
                        }
                        break;
                    case 2:
                        if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
                                return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                            }
                        }
                        break;
                    case -3:
                        if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
                                return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                            }
                        }
                        break;
                    case 3:
                        if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
                                return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                            }
                        }
                        break;
                    case -4:
                        if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
                                return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                            }
                        }
                        break;
                    case 4:
                        if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
                            if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                                __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                            } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
                                return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                            }
                        }
                        break;
                }
            }
#endif
            if ((sizeof(long) <= sizeof(long))) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
#if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
#endif
            if (likely(v)) {
                int ret = -1;
#if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                ret = _PyLong_AsByteArray((PyLongObject *)v,
                                           bytes, sizeof(val),
                                           is_little, !is_unsigned);
#else
                PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
                int bits, remaining_bits, is_negative = 0;
                long idigit;
                int chunk_size = (sizeof(long) < 8) ? 30 : 62;
                if (unlikely(!PyLong_CheckExact(v))) {
                    PyObject *tmp = v;
                    v = PyNumber_Long(v);
                    assert(PyLong_CheckExact(v));
                    Py_DECREF(tmp);
                    if (unlikely(!v)) return (long) -1;
                }
#if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
                if (Py_SIZE(x) == 0)
                    return (long) 0;
                is_negative = Py_SIZE(x) < 0;
#else
                {
                    int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                    if (unlikely(result < 0))
                        return (long) -1;
                    is_negative = result == 1;
                }
#endif
                if (is_unsigned && unlikely(is_negative)) {
                    goto raise_neg_overflow;
                } else if (is_negative) {
                    stepval = PyNumber_Invert(v);
                    if (unlikely(!stepval))
                        return (long) -1;
                } else {
                    stepval = __Pyx_NewRef(v);
                }
                val = (long) 0;
                mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
                shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
                for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
                    PyObject *tmp, *digit;
                    digit = PyNumber_And(stepval, mask);
                    if (unlikely(!digit)) goto done;
                    idigit = PyLong_AsLong(digit);
                    Py_DECREF(digit);
                    if (unlikely(idigit < 0)) goto done;
                    tmp = PyNumber_Rshift(stepval, shift);
                    if (unlikely(!tmp)) goto done;
                    Py_DECREF(stepval); stepval = tmp;
                    val |= ((long) idigit) << bits;
                    #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
                    if (Py_SIZE(stepval) == 0)
                        goto unpacking_done;
                    #endif
                }
                idigit = PyLong_AsLong(stepval);
                if (unlikely(idigit < 0)) goto done;
                remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
                if (unlikely(idigit >= (1L << remaining_bits)))
                    goto raise_overflow;
                val |= ((long) idigit) << bits;
            #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
            unpacking_done:
            #endif
                if (!is_unsigned) {
                    if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
                        goto raise_overflow;
                    if (is_negative)
                        val = ~val;
                }
                ret = 0;
            done:
                Py_XDECREF(shift);
                Py_XDECREF(mask);
                Py_XDECREF(stepval);
#endif
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*);
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (cls == a || cls == b) return 1;
    mro = cls->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            PyObject *base = PyTuple_GET_ITEM(mro, i);
            if (base == (PyObject *)a || base == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    if (exc_type1) {
        return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2);
    } else {
        return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* CheckBinaryVersion */
static int __Pyx_check_binary_version(void) {
    char ctversion[5];
    int same=1, i, found_dot;
    const char* rt_from_call = Py_GetVersion();
    PyOS_snprintf(ctversion, 5, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    found_dot = 0;
    for (i = 0; i < 4; i++) {
        if (!ctversion[i]) {
            same = (rt_from_call[i] < '0' || rt_from_call[i] > '9');
            break;
        }
        if (rt_from_call[i] != ctversion[i]) {
            same = 0;
            break;
        }
    }
    if (!same) {
        char rtversion[5] = {'\0'};
        char message[200];
        for (i=0; i<4; ++i) {
            if (rt_from_call[i] == '.') {
                if (found_dot) break;
                found_dot = 1;
            } else if (rt_from_call[i] < '0' || rt_from_call[i] > '9') {
                break;
            }
            rtversion[i] = rt_from_call[i];
        }
        PyOS_snprintf(message, sizeof(message),
                      "compile time version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* FunctionExport */
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
    if (!d) {
        PyErr_Clear();
        d = PyDict_New();
        if (!d)
            goto bad;
        Py_INCREF(d);
        if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
            goto bad;
    }
    tmp.fp = f;
    cobj = PyCapsule_New(tmp.p, sig, 0);
    if (!cobj)
        goto bad;
    if (PyDict_SetItemString(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

/* VoidPtrImport */
#ifndef __PYX_HAVE_RT_ImportVoidPtr_3_0_0
#define __PYX_HAVE_RT_ImportVoidPtr_3_0_0
static int __Pyx_ImportVoidPtr_3_0_0(PyObject *module, const char *name, void **p, const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, name);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C variable %.200s",
                PyModule_GetName(module), name);
        goto bad;
    }
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), name, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    *p = PyCapsule_GetPointer(cobj, sig);
    if (!(*p))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* FunctionImport */
#ifndef __PYX_HAVE_RT_ImportFunction_3_0_0
#define __PYX_HAVE_RT_ImportFunction_3_0_0
static int __Pyx_ImportFunction_3_0_0(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.p = PyCapsule_GetPointer(cobj, sig);
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* InitStrings */
#if PY_MAJOR_VERSION >= 3
static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) {
    if (t.is_unicode | t.is_str) {
        if (t.intern) {
            *str = PyUnicode_InternFromString(t.s);
        } else if (t.encoding) {
            *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL);
        } else {
            *str = PyUnicode_FromStringAndSize(t.s, t.n - 1);
        }
    } else {
        *str = PyBytes_FromStringAndSize(t.s, t.n - 1);
    }
    if (!*str)
        return -1;
    if (PyObject_Hash(*str) == -1)
        return -1;
    return 0;
}
#endif
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION >= 3
        __Pyx_InitString(*t, t->p);
        #else
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        #endif
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
    __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result));
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type " __Pyx_FMT_TYPENAME ").  "
                "The ability to return an instance of a strict subclass of int is deprecated, "
                "and may be removed in a future version of Python.",
                result_type_name)) {
            __Pyx_DECREF_TypeName(result_type_name);
            Py_DECREF(result);
            return NULL;
        }
        __Pyx_DECREF_TypeName(result_type_name);
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")",
                 type_name, type_name, result_type_name);
    __Pyx_DECREF_TypeName(result_type_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(__Pyx_PyLong_IsCompact(b))) {
        return __Pyx_PyLong_CompactValue(b);
    } else {
      const digit* digits = __Pyx_PyLong_Digits(b);
      const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b);
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


/* #### Code section: utility_code_pragmas_end ### */
#ifdef _MSC_VER
#pragma warning( pop )
#endif



/* #### Code section: end ### */
#endif /* Py_PYTHON_H */
