/* Generated by Cython 3.1.2 */

/* 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/sas",
            "src/spss",
            "src/stata",
            "."
        ],
        "libraries": [
            "m",
            "z",
            "iconv"
        ],
        "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_mr_name.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 */
/* InitLimitedAPI */
#if defined(Py_LIMITED_API) && !defined(CYTHON_LIMITED_API)
  #define CYTHON_LIMITED_API 1
#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 < 0x03080000
    #error Cython requires Python 3.8+.
#else
#define __PYX_ABI_VERSION "3_1_2"
#define CYTHON_HEX_VERSION 0x030102F0
#define CYTHON_FUTURE_DIVISION 0
/* CModulePreamble */
#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
#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX
#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_CPYTHON_FREETHREADING 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
  #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_AVOID_THREAD_UNSAFE_BORROWED_REFS
  #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_ASSUME_SAFE_SIZE
  #define CYTHON_ASSUME_SAFE_SIZE 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 1
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 0
  #undef CYTHON_USE_SYS_MONITORING
  #define CYTHON_USE_SYS_MONITORING 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_AM_SEND
  #define CYTHON_USE_AM_SEND 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 1
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
  #undef CYTHON_USE_FREELISTS
  #define CYTHON_USE_FREELISTS 0
#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_CPYTHON_FREETHREADING 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 1
  #ifndef CYTHON_USE_TYPE_SPECS
    #define CYTHON_USE_TYPE_SPECS 0
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #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_AVOID_THREAD_UNSAFE_BORROWED_REFS
  #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #ifndef CYTHON_ASSUME_SAFE_SIZE
    #define CYTHON_ASSUME_SAFE_SIZE 1
  #endif
  #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
  #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_SYS_MONITORING
  #define CYTHON_USE_SYS_MONITORING 0
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PYPY_VERSION_NUM >= 0x07030C00)
  #endif
  #undef CYTHON_USE_AM_SEND
  #define CYTHON_USE_AM_SEND 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 (PYPY_VERSION_NUM >= 0x07031100)
  #endif
  #undef CYTHON_USE_FREELISTS
  #define CYTHON_USE_FREELISTS 0
#elif defined(CYTHON_LIMITED_API)
  #ifdef Py_LIMITED_API
    #undef __PYX_LIMITED_VERSION_HEX
    #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API
  #endif
  #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_CPYTHON_FREETHREADING 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_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
  #ifndef CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
    #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 0
  #endif
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_ASSUME_SAFE_SIZE
  #define CYTHON_ASSUME_SAFE_SIZE 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 (__PYX_LIMITED_VERSION_HEX >= 0x030C0000)
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #ifndef 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
  #undef CYTHON_USE_SYS_MONITORING
  #define CYTHON_USE_SYS_MONITORING 0
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 0
  #endif
  #ifndef CYTHON_USE_AM_SEND
    #define CYTHON_USE_AM_SEND (__PYX_LIMITED_VERSION_HEX >= 0x030A0000)
  #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
  #undef CYTHON_USE_FREELISTS
  #define CYTHON_USE_FREELISTS 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
  #ifdef Py_GIL_DISABLED
    #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 1
  #else
    #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 0
  #endif
  #if PY_VERSION_HEX < 0x030A0000
    #undef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #elif !defined(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
  #ifndef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    #undef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLIST_INTERNALS)
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING || 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
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    #undef CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
    #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 1
  #elif !defined(CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS)
    #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_ASSUME_SAFE_SIZE
    #define CYTHON_ASSUME_SAFE_SIZE 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    #undef CYTHON_FAST_GIL
    #define CYTHON_FAST_GIL 0
  #elif !defined(CYTHON_FAST_GIL)
    #define CYTHON_FAST_GIL (PY_VERSION_HEX < 0x030C00A6)
  #endif
  #ifndef CYTHON_METH_FASTCALL
    #define CYTHON_METH_FASTCALL 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #ifndef 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
  #ifndef CYTHON_USE_SYS_MONITORING
    #define CYTHON_USE_SYS_MONITORING (PY_VERSION_HEX >= 0x030d00B1)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #ifndef CYTHON_USE_AM_SEND
    #define CYTHON_USE_AM_SEND 1
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    #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 && !CYTHON_USE_MODULE_STATE)
  #endif
  #ifndef 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
  #ifndef CYTHON_USE_FREELISTS
    #define CYTHON_USE_FREELISTS (!CYTHON_COMPILING_IN_CPYTHON_FREETHREADING)
  #endif
#endif
#ifndef CYTHON_FAST_PYCCALL
#define CYTHON_FAST_PYCCALL  CYTHON_FAST_PYCALL
#endif
#ifndef CYTHON_VECTORCALL
#if CYTHON_COMPILING_IN_LIMITED_API
#define CYTHON_VECTORCALL  (__PYX_LIMITED_VERSION_HEX >= 0x030C0000)
#else
#define CYTHON_VECTORCALL  (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1)
#endif
#endif
#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1)
#if CYTHON_USE_PYLONG_INTERNALS
  #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 && !CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_USE_CPP_STD_MOVE
  #if defined(__cplusplus) && (\
    __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600))
    #define CYTHON_USE_CPP_STD_MOVE 1
  #else
    #define CYTHON_USE_CPP_STD_MOVE 0
  #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
#ifndef Py_UNREACHABLE
  #define Py_UNREACHABLE()  assert(0); abort()
#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))

/* CInitCode */
#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

/* PythonCompatibility */
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#define __Pyx_BUILTIN_MODULE_NAME "builtins"
#define __Pyx_DefaultClassType PyType_Type
#if CYTHON_COMPILING_IN_LIMITED_API
    #ifndef CO_OPTIMIZED
    static int CO_OPTIMIZED;
    #endif
    #ifndef CO_NEWLOCALS
    static int CO_NEWLOCALS;
    #endif
    #ifndef CO_VARARGS
    static int CO_VARARGS;
    #endif
    #ifndef CO_VARKEYWORDS
    static int CO_VARKEYWORDS;
    #endif
    #ifndef CO_ASYNC_GENERATOR
    static int CO_ASYNC_GENERATOR;
    #endif
    #ifndef CO_GENERATOR
    static int CO_GENERATOR;
    #endif
    #ifndef CO_COROUTINE
    static int CO_COROUTINE;
    #endif
#else
    #ifndef CO_COROUTINE
      #define CO_COROUTINE 0x80
    #endif
    #ifndef CO_ASYNC_GENERATOR
      #define CO_ASYNC_GENERATOR 0x200
    #endif
#endif
static int __Pyx_init_co_variables(void);
#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 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
#ifndef 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
  #if PY_VERSION_HEX >= 0x030d00A4
  #  define __Pyx_PyCFunctionFast PyCFunctionFast
  #  define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords
  #else
  #  define __Pyx_PyCFunctionFast _PyCFunctionFast
  #  define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  #endif
#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_PyCFunction_CheckExact(func)  PyCFunction_CheckExact(func)
#else
#define __Pyx_PyCFunction_CheckExact(func)  PyCFunction_Check(func)
#endif
#define __Pyx_CyOrPyCFunction_Check(func)  PyCFunction_Check(func)
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func)  (((PyCFunctionObject*)(func))->m_ml->ml_meth)
#elif !CYTHON_COMPILING_IN_LIMITED_API
#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func)  PyCFunction_GET_FUNCTION(func)
#endif
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CyOrPyCFunction_GET_FLAGS(func)  (((PyCFunctionObject*)(func))->m_ml->ml_flags)
static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) {
    return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self;
}
#endif
static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void (*cfunc)(void)) {
#if CYTHON_COMPILING_IN_LIMITED_API
    return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc;
#else
    return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc;
#endif
}
#define __Pyx_IsSameCFunction(func, cfunc)   __Pyx__IsSameCFunction(func, cfunc)
#if __PYX_LIMITED_VERSION_HEX < 0x03090000
  #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_PyFrame_SetLineNumber(frame, lineno)
#elif CYTHON_COMPILING_IN_GRAAL
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) _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 >= 0x030d00A1
  #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#endif
#if CYTHON_USE_MODULE_STATE
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;
}
#define __Pyx_PyModule_GetState(o) (__pyx_mstatetype *)__Pyx__PyModule_GetState(o)
#else
#define __Pyx_PyModule_GetState(op) ((void)op,__pyx_mstate_global)
#endif
#define __Pyx_PyObject_GetSlot(obj, name, func_ctype)  __Pyx_PyType_GetSlot(Py_TYPE((PyObject *) obj), name, func_ctype)
#define __Pyx_PyObject_TryGetSlot(obj, name, func_ctype) __Pyx_PyType_TryGetSlot(Py_TYPE(obj), name, func_ctype)
#define __Pyx_PyObject_GetSubSlot(obj, sub, name, func_ctype) __Pyx_PyType_GetSubSlot(Py_TYPE(obj), sub, name, func_ctype)
#define __Pyx_PyObject_TryGetSubSlot(obj, sub, name, func_ctype) __Pyx_PyType_TryGetSubSlot(Py_TYPE(obj), sub, name, func_ctype)
#if CYTHON_USE_TYPE_SLOTS
  #define __Pyx_PyType_GetSlot(type, name, func_ctype)  ((type)->name)
  #define __Pyx_PyType_TryGetSlot(type, name, func_ctype) __Pyx_PyType_GetSlot(type, name, func_ctype)
  #define __Pyx_PyType_GetSubSlot(type, sub, name, func_ctype) (((type)->sub) ? ((type)->sub->name) : NULL)
  #define __Pyx_PyType_TryGetSubSlot(type, sub, name, func_ctype) __Pyx_PyType_GetSubSlot(type, sub, name, func_ctype)
#else
  #define __Pyx_PyType_GetSlot(type, name, func_ctype)  ((func_ctype) PyType_GetSlot((type), Py_##name))
  #define __Pyx_PyType_TryGetSlot(type, name, func_ctype)\
    ((__PYX_LIMITED_VERSION_HEX >= 0x030A0000 ||\
     (PyType_GetFlags(type) & Py_TPFLAGS_HEAPTYPE) || __Pyx_get_runtime_version() >= 0x030A0000) ?\
     __Pyx_PyType_GetSlot(type, name, func_ctype) : NULL)
  #define __Pyx_PyType_GetSubSlot(obj, sub, name, func_ctype) __Pyx_PyType_GetSlot(obj, name, func_ctype)
  #define __Pyx_PyType_TryGetSubSlot(obj, sub, name, func_ctype) __Pyx_PyType_TryGetSlot(obj, name, func_ctype)
#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
#define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#if CYTHON_COMPILING_IN_CPYTHON && 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 !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)
#else
  #define __Pyx_PyType_GetFlags(tp)   (PyType_GetFlags((PyTypeObject *)tp))
  #define __Pyx_PyType_HasFeature(type, feature)  PyType_HasFeature(type, feature)
#endif
#define __Pyx_PyObject_GetIterNextFunc(iterator)  __Pyx_PyObject_GetSlot(iterator, tp_iternext, iternextfunc)
#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000
#define __Pyx_PyHeapTypeObject_GC_Del(obj)  {\
    PyTypeObject *type = Py_TYPE((PyObject*)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 __Pyx_PyUnicode_READY(op)       (0)
  #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))
#else
  #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_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
#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)
    #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_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#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_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
  #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
    #define __Pyx_PyList_GetItemRef(o, i) PyList_GetItemRef(o, i)
  #elif CYTHON_COMPILING_IN_LIMITED_API || !CYTHON_ASSUME_SAFE_MACROS
    #define __Pyx_PyList_GetItemRef(o, i) (likely((i) >= 0) ? PySequence_GetItem(o, i) : (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
  #else
    #define __Pyx_PyList_GetItemRef(o, i) PySequence_ITEM(o, i)
  #endif
#elif CYTHON_COMPILING_IN_LIMITED_API || !CYTHON_ASSUME_SAFE_MACROS
  #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
    #define __Pyx_PyList_GetItemRef(o, i) PyList_GetItemRef(o, i)
  #else
    #define __Pyx_PyList_GetItemRef(o, i) __Pyx_XNewRef(PyList_GetItem(o, i))
  #endif
#else
  #define __Pyx_PyList_GetItemRef(o, i) __Pyx_NewRef(PyList_GET_ITEM(o, i))
#endif
#if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
#define __Pyx_PyDict_GetItemRef(dict, key, result) PyDict_GetItemRef(dict, key, result)
#elif CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
static CYTHON_INLINE int __Pyx_PyDict_GetItemRef(PyObject *dict, PyObject *key, PyObject **result) {
  *result = PyObject_GetItem(dict, key);
  if (*result == NULL) {
    if (PyErr_ExceptionMatches(PyExc_KeyError)) {
      PyErr_Clear();
      return 0;
    }
    return -1;
  }
  return 1;
}
#else
static CYTHON_INLINE int __Pyx_PyDict_GetItemRef(PyObject *dict, PyObject *key, PyObject **result) {
  *result = PyDict_GetItemWithError(dict, key);
  if (*result == NULL) {
    return PyErr_Occurred() ? -1 : 0;
  }
  Py_INCREF(*result);
  return 1;
}
#endif
#if defined(CYTHON_DEBUG_VISIT_CONST) && CYTHON_DEBUG_VISIT_CONST
  #define __Pyx_VISIT_CONST(obj)  Py_VISIT(obj)
#else
  #define __Pyx_VISIT_CONST(obj)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i)
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
  #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0))
  #define __Pyx_PyTuple_GET_ITEM(o, i) PyTuple_GET_ITEM(o, i)
  #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0))
  #define __Pyx_PyList_GET_ITEM(o, i) PyList_GET_ITEM(o, i)
#else
  #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i)
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
  #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v)
  #define __Pyx_PyTuple_GET_ITEM(o, i) PyTuple_GetItem(o, i)
  #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v)
  #define __Pyx_PyList_GET_ITEM(o, i) PyList_GetItem(o, i)
#endif
#if CYTHON_ASSUME_SAFE_SIZE
  #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o)
  #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o)
  #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o)
  #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o)
  #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o)
  #define __Pyx_PyUnicode_GET_LENGTH(o) PyUnicode_GET_LENGTH(o)
#else
  #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o)
  #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o)
  #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o)
  #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o)
  #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o)
  #define __Pyx_PyUnicode_GET_LENGTH(o) PyUnicode_GetLength(o)
#endif
#if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
  #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name)
#else
  static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) {
      PyObject *module = PyImport_AddModule(name);
      Py_XINCREF(module);
      return module;
  }
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_InternFromString)
  #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
#endif
#define __Pyx_PyLong_FromHash_t PyLong_FromSsize_t
#define __Pyx_PyLong_AsHash_t   __Pyx_PyIndex_AsSsize_t
#if __PYX_LIMITED_VERSION_HEX >= 0x030A0000
    #define __Pyx_PySendResult PySendResult
#else
    typedef enum {
        PYGEN_RETURN = 0,
        PYGEN_ERROR = -1,
        PYGEN_NEXT = 1,
    } __Pyx_PySendResult;
#endif
#if CYTHON_COMPILING_IN_LIMITED_API || PY_VERSION_HEX < 0x030A00A3
  typedef __Pyx_PySendResult (*__Pyx_pyiter_sendfunc)(PyObject *iter, PyObject *value, PyObject **result);
#else
  #define __Pyx_pyiter_sendfunc sendfunc
#endif
#if !CYTHON_USE_AM_SEND
#define __PYX_HAS_PY_AM_SEND 0
#elif __PYX_LIMITED_VERSION_HEX >= 0x030A0000
#define __PYX_HAS_PY_AM_SEND 1
#else
#define __PYX_HAS_PY_AM_SEND 2  // our own backported implementation
#endif
#if __PYX_HAS_PY_AM_SEND < 2
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#else
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
        __Pyx_pyiter_sendfunc am_send;
    } __Pyx_PyAsyncMethodsStruct;
    #define __Pyx_SlotTpAsAsync(s) ((PyAsyncMethods*)(s))
#endif
#if CYTHON_USE_AM_SEND && PY_VERSION_HEX < 0x030A00F0
    #define __Pyx_TPFLAGS_HAVE_AM_SEND (1UL << 21)
#else
    #define __Pyx_TPFLAGS_HAVE_AM_SEND (0)
#endif
#if PY_VERSION_HEX >= 0x03090000
#define __Pyx_PyInterpreterState_Get() PyInterpreterState_Get()
#else
#define __Pyx_PyInterpreterState_Get() PyThreadState_Get()->interp
#endif
#if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030A0000
#ifdef __cplusplus
extern "C"
#endif
PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize);
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
static int __Pyx_init_co_variable(PyObject *inspect, const char* name, int *write_to) {
    int value;
    PyObject *py_value = PyObject_GetAttrString(inspect, name);
    if (!py_value) return 0;
    value = (int) PyLong_AsLong(py_value);
    Py_DECREF(py_value);
    *write_to = value;
    return value != -1 || !PyErr_Occurred();
}
static int __Pyx_init_co_variables(void) {
    PyObject *inspect;
    int result;
    inspect = PyImport_ImportModule("inspect");
    result =
#if !defined(CO_OPTIMIZED)
        __Pyx_init_co_variable(inspect, "CO_OPTIMIZED", &CO_OPTIMIZED) &&
#endif
#if !defined(CO_NEWLOCALS)
        __Pyx_init_co_variable(inspect, "CO_NEWLOCALS", &CO_NEWLOCALS) &&
#endif
#if !defined(CO_VARARGS)
        __Pyx_init_co_variable(inspect, "CO_VARARGS", &CO_VARARGS) &&
#endif
#if !defined(CO_VARKEYWORDS)
        __Pyx_init_co_variable(inspect, "CO_VARKEYWORDS", &CO_VARKEYWORDS) &&
#endif
#if !defined(CO_ASYNC_GENERATOR)
        __Pyx_init_co_variable(inspect, "CO_ASYNC_GENERATOR", &CO_ASYNC_GENERATOR) &&
#endif
#if !defined(CO_GENERATOR)
        __Pyx_init_co_variable(inspect, "CO_GENERATOR", &CO_GENERATOR) &&
#endif
#if !defined(CO_COROUTINE)
        __Pyx_init_co_variable(inspect, "CO_COROUTINE", &CO_COROUTINE) &&
#endif
        1;
    Py_DECREF(inspect);
    return result ? 0 : -1;
}
#else
static int __Pyx_init_co_variables(void) {
    return 0;  // It's a limited API-only feature
}
#endif

/* MathInitCode */
#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
  #ifndef _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

#ifndef CYTHON_CLINE_IN_TRACEBACK_RUNTIME
#define CYTHON_CLINE_IN_TRACEBACK_RUNTIME 0
#endif
#ifndef CYTHON_CLINE_IN_TRACEBACK
#define CYTHON_CLINE_IN_TRACEBACK CYTHON_CLINE_IN_TRACEBACK_RUNTIME
#endif
#if CYTHON_CLINE_IN_TRACEBACK
#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; }
#else
#define __PYX_MARK_ERR_POS(f_index, lineno)  { __pyx_filename = __pyx_f[f_index]; (void) __pyx_filename; __pyx_lineno = lineno; (void) __pyx_lineno; (void) __pyx_clineno; }
#endif
#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"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

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

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 1
#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 Py_ssize_t __Pyx_ssize_strlen(const char *s);
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*);
#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 CYTHON_ASSUME_SAFE_MACROS
    #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_PyByteArray_AsString(s) PyByteArray_AS_STRING(s)
#else
    #define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AsString(s))
    #define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AsString(s))
    #define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AsString(s))
    #define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AsString(s))
    #define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AsString(s))
    #define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AsString(s))
    #define __Pyx_PyByteArray_AsString(s) PyByteArray_AsString(s)
#endif
#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_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#define __Pyx_PyUnicode_FromOrdinal(o)       PyUnicode_FromOrdinal((int)o)
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
static CYTHON_INLINE PyObject *__Pyx_NewRef(PyObject *obj) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030a0000 || defined(Py_NewRef)
    return Py_NewRef(obj);
#else
    Py_INCREF(obj);
    return obj;
#endif
}
static CYTHON_INLINE PyObject *__Pyx_XNewRef(PyObject *obj) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030a0000 || defined(Py_XNewRef)
    return Py_XNewRef(obj);
#else
    Py_XINCREF(obj);
    return obj;
#endif
}
static CYTHON_INLINE PyObject *__Pyx_Owned_Py_None(int b);
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_Long(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_PyLong_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))
#define __Pyx_PyFloat_AS_DOUBLE(x) PyFloat_AS_DOUBLE(x)
#else
#define __Pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#define __Pyx_PyFloat_AS_DOUBLE(x) PyFloat_AsDouble(x)
#endif
#define __Pyx_PyFloat_AsFloat(x) ((float) __Pyx_PyFloat_AsDouble(x))
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#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
  #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 __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
  #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#elif __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeASCII(c_str, size, NULL)
#else
  #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#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__ */
/* PretendToInitialize */
#ifdef __cplusplus
#if __cplusplus > 201103L
#include <type_traits>
#endif
template <typename T>
static void __Pyx_pretend_to_initialize(T* ptr) {
#if __cplusplus > 201103L
    if ((std::is_trivially_default_constructible<T>::value))
#endif
        *ptr = T();
    (void)ptr;
}
#else
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
#endif


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

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

static const char* const __pyx_f[] = {
  "pyreadstat/_readstat_writer.pyx",
  "pyreadstat/_readstat_parser.pxd",
};
/* #### Code section: utility_code_proto_before_types ### */
/* Atomics.proto */
#include <pythread.h>
#ifndef CYTHON_ATOMICS
    #define CYTHON_ATOMICS 1
#endif
#define __PYX_CYTHON_ATOMICS_ENABLED() CYTHON_ATOMICS
#define __PYX_GET_CYTHON_COMPILING_IN_CPYTHON_FREETHREADING() CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
#define __pyx_atomic_int_type int
#define __pyx_nonatomic_int_type int
#if CYTHON_ATOMICS && (defined(__STDC_VERSION__) &&\
                        (__STDC_VERSION__ >= 201112L) &&\
                        !defined(__STDC_NO_ATOMICS__))
    #include <stdatomic.h>
#elif CYTHON_ATOMICS && (defined(__cplusplus) && (\
                    (__cplusplus >= 201103L) ||\
                    (defined(_MSC_VER) && _MSC_VER >= 1700)))
    #include <atomic>
#endif
#if CYTHON_ATOMICS && (defined(__STDC_VERSION__) &&\
                        (__STDC_VERSION__ >= 201112L) &&\
                        !defined(__STDC_NO_ATOMICS__) &&\
                       ATOMIC_INT_LOCK_FREE == 2)
    #undef __pyx_atomic_int_type
    #define __pyx_atomic_int_type atomic_int
    #define __pyx_atomic_ptr_type atomic_uintptr_t
    #define __pyx_nonatomic_ptr_type uintptr_t
    #define __pyx_atomic_incr_relaxed(value) atomic_fetch_add_explicit(value, 1, memory_order_relaxed)
    #define __pyx_atomic_incr_acq_rel(value) atomic_fetch_add_explicit(value, 1, memory_order_acq_rel)
    #define __pyx_atomic_decr_acq_rel(value) atomic_fetch_sub_explicit(value, 1, memory_order_acq_rel)
    #define __pyx_atomic_sub(value, arg) atomic_fetch_sub(value, arg)
    #define __pyx_atomic_int_cmp_exchange(value, expected, desired) atomic_compare_exchange_strong(value, expected, desired)
    #define __pyx_atomic_load(value) atomic_load(value)
    #define __pyx_atomic_store(value, new_value) atomic_store(value, new_value)
    #define __pyx_atomic_pointer_load_relaxed(value) atomic_load_explicit(value, memory_order_relaxed)
    #define __pyx_atomic_pointer_load_acquire(value) atomic_load_explicit(value, memory_order_acquire)
    #define __pyx_atomic_pointer_exchange(value, new_value) atomic_exchange(value, (__pyx_nonatomic_ptr_type)new_value)
    #if defined(__PYX_DEBUG_ATOMICS) && defined(_MSC_VER)
        #pragma message ("Using standard C atomics")
    #elif defined(__PYX_DEBUG_ATOMICS)
        #warning "Using standard C atomics"
    #endif
#elif CYTHON_ATOMICS && (defined(__cplusplus) && (\
                    (__cplusplus >= 201103L) ||\
\
                    (defined(_MSC_VER) && _MSC_VER >= 1700)) &&\
                    ATOMIC_INT_LOCK_FREE == 2)
    #undef __pyx_atomic_int_type
    #define __pyx_atomic_int_type std::atomic_int
    #define __pyx_atomic_ptr_type std::atomic_uintptr_t
    #define __pyx_nonatomic_ptr_type uintptr_t
    #define __pyx_atomic_incr_relaxed(value) std::atomic_fetch_add_explicit(value, 1, std::memory_order_relaxed)
    #define __pyx_atomic_incr_acq_rel(value) std::atomic_fetch_add_explicit(value, 1, std::memory_order_acq_rel)
    #define __pyx_atomic_decr_acq_rel(value) std::atomic_fetch_sub_explicit(value, 1, std::memory_order_acq_rel)
    #define __pyx_atomic_sub(value, arg) std::atomic_fetch_sub(value, arg)
    #define __pyx_atomic_int_cmp_exchange(value, expected, desired) std::atomic_compare_exchange_strong(value, expected, desired)
    #define __pyx_atomic_load(value) std::atomic_load(value)
    #define __pyx_atomic_store(value, new_value) std::atomic_store(value, new_value)
    #define __pyx_atomic_pointer_load_relaxed(value) std::atomic_load_explicit(value, std::memory_order_relaxed)
    #define __pyx_atomic_pointer_load_acquire(value) std::atomic_load_explicit(value, std::memory_order_acquire)
    #define __pyx_atomic_pointer_exchange(value, new_value) std::atomic_exchange(value, (__pyx_nonatomic_ptr_type)new_value)
    #if defined(__PYX_DEBUG_ATOMICS) && defined(_MSC_VER)
        #pragma message ("Using standard C++ atomics")
    #elif defined(__PYX_DEBUG_ATOMICS)
        #warning "Using standard C++ atomics"
    #endif
#elif CYTHON_ATOMICS && (__GNUC__ >= 5 || (__GNUC__ == 4 &&\
                    (__GNUC_MINOR__ > 1 ||\
                    (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ >= 2))))
    #define __pyx_atomic_ptr_type void*
    #define __pyx_atomic_incr_relaxed(value) __sync_fetch_and_add(value, 1)
    #define __pyx_atomic_incr_acq_rel(value) __sync_fetch_and_add(value, 1)
    #define __pyx_atomic_decr_acq_rel(value) __sync_fetch_and_sub(value, 1)
    #define __pyx_atomic_sub(value, arg) __sync_fetch_and_sub(value, arg)
    static CYTHON_INLINE int __pyx_atomic_int_cmp_exchange(__pyx_atomic_int_type* value, __pyx_nonatomic_int_type* expected, __pyx_nonatomic_int_type desired) {
        __pyx_nonatomic_int_type old = __sync_val_compare_and_swap(value, *expected, desired);
        int result = old == *expected;
        *expected = old;
        return result;
    }
    #define __pyx_atomic_load(value) __sync_fetch_and_add(value, 0)
    #define __pyx_atomic_store(value, new_value) __sync_lock_test_and_set(value, new_value)
    #define __pyx_atomic_pointer_load_relaxed(value) __sync_fetch_and_add(value, 0)
    #define __pyx_atomic_pointer_load_acquire(value) __sync_fetch_and_add(value, 0)
    #define __pyx_atomic_pointer_exchange(value, new_value) __sync_lock_test_and_set(value, (__pyx_atomic_ptr_type)new_value)
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Using GNU atomics"
    #endif
#elif CYTHON_ATOMICS && defined(_MSC_VER)
    #include <intrin.h>
    #undef __pyx_atomic_int_type
    #define __pyx_atomic_int_type long
    #define __pyx_atomic_ptr_type void*
    #undef __pyx_nonatomic_int_type
    #define __pyx_nonatomic_int_type long
    #pragma intrinsic (_InterlockedExchangeAdd, _InterlockedExchange, _InterlockedCompareExchange, _InterlockedCompareExchangePointer, _InterlockedExchangePointer)
    #define __pyx_atomic_incr_relaxed(value) _InterlockedExchangeAdd(value, 1)
    #define __pyx_atomic_incr_acq_rel(value) _InterlockedExchangeAdd(value, 1)
    #define __pyx_atomic_decr_acq_rel(value) _InterlockedExchangeAdd(value, -1)
    #define __pyx_atomic_sub(value, arg) _InterlockedExchangeAdd(value, -arg)
    static CYTHON_INLINE int __pyx_atomic_int_cmp_exchange(__pyx_atomic_int_type* value, __pyx_nonatomic_int_type* expected, __pyx_nonatomic_int_type desired) {
        __pyx_nonatomic_int_type old = _InterlockedCompareExchange(value, desired, *expected);
        int result = old == *expected;
        *expected = old;
        return result;
    }
    #define __pyx_atomic_load(value) _InterlockedExchangeAdd(value, 0)
    #define __pyx_atomic_store(value, new_value) _InterlockedExchange(value, new_value)
    #define __pyx_atomic_pointer_load_relaxed(value) *(void * volatile *)value
    #define __pyx_atomic_pointer_load_acquire(value) _InterlockedCompareExchangePointer(value, 0, 0)
    #define __pyx_atomic_pointer_exchange(value, new_value) _InterlockedExchangePointer(value, (__pyx_atomic_ptr_type)new_value)
    #ifdef __PYX_DEBUG_ATOMICS
        #pragma message ("Using MSVC atomics")
    #endif
#else
    #undef CYTHON_ATOMICS
    #define CYTHON_ATOMICS 0
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Not using atomics"
    #endif
#endif
#if CYTHON_ATOMICS
    #define __pyx_add_acquisition_count(memview)\
             __pyx_atomic_incr_relaxed(__pyx_get_slice_count_pointer(memview))
    #define __pyx_sub_acquisition_count(memview)\
            __pyx_atomic_decr_acq_rel(__pyx_get_slice_count_pointer(memview))
#else
    #define __pyx_add_acquisition_count(memview)\
            __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
    #define __pyx_sub_acquisition_count(memview)\
            __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
#endif

/* CriticalSections.proto */
#if !CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
#define __Pyx_PyCriticalSection void*
#define __Pyx_PyCriticalSection2 void*
#define __Pyx_PyCriticalSection_Begin1(cs, arg) (void)cs
#define __Pyx_PyCriticalSection_Begin2(cs, arg1, arg2) (void)cs
#define __Pyx_PyCriticalSection_End1(cs)
#define __Pyx_PyCriticalSection_End2(cs)
#else
#define __Pyx_PyCriticalSection PyCriticalSection
#define __Pyx_PyCriticalSection2 PyCriticalSection2
#define __Pyx_PyCriticalSection_Begin1 PyCriticalSection_Begin
#define __Pyx_PyCriticalSection_Begin2 PyCriticalSection2_Begin
#define __Pyx_PyCriticalSection_End1 PyCriticalSection_End
#define __Pyx_PyCriticalSection_End2 PyCriticalSection2_End
#endif
#if PY_VERSION_HEX < 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API
#define __Pyx_BEGIN_CRITICAL_SECTION(o) {
#define __Pyx_END_CRITICAL_SECTION() }
#else
#define __Pyx_BEGIN_CRITICAL_SECTION Py_BEGIN_CRITICAL_SECTION
#define __Pyx_END_CRITICAL_SECTION Py_END_CRITICAL_SECTION
#endif

/* #### 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_DATE64,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64,
  __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF
};
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;
  double unix_to_origin_secs;
  __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;
  PyObject *mr_sets;
  PyObject *output_format;
};

/* #### 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;
  #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);\
          }
  #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);

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck, has_gil)\
    (__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, has_gil)\
    (__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, has_gil)\
    (__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);

/* 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);
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
        L->ob_item[len] = x;
        #else
        PyList_SET_ITEM(list, len, x);
        #endif
        __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

/* 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_mstate_global->__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

/* 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 *const *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"
  #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

/* 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

/* 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 * const*args, size_t nargs, PyObject *kwargs);

/* PyObjectFastCallMethod.proto */
#if CYTHON_VECTORCALL && PY_VERSION_HEX >= 0x03090000
#define __Pyx_PyObject_FastCallMethod(name, args, nargsf) PyObject_VectorcallMethod(name, args, nargsf, NULL)
#else
static PyObject *__Pyx_PyObject_FastCallMethod(PyObject *name, PyObject *const *args, size_t nargsf);
#endif

/* DictGetItem.proto */
#if !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

/* 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

/* PyObjectVectorCallKwBuilder.proto */
CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n);
#if CYTHON_VECTORCALL
#if PY_VERSION_HEX >= 0x03090000
#define __Pyx_Object_Vectorcall_CallFromBuilder PyObject_Vectorcall
#else
#define __Pyx_Object_Vectorcall_CallFromBuilder _PyObject_Vectorcall
#endif
#define __Pyx_MakeVectorcallBuilderKwds(n) PyTuple_New(n)
static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n);
static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n);
#else
#define __Pyx_Object_Vectorcall_CallFromBuilder __Pyx_PyObject_FastCallDict
#define __Pyx_MakeVectorcallBuilderKwds(n) __Pyx_PyDict_NewPresized(n)
#define __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n) PyDict_SetItem(builder, key, value)
#define __Pyx_VectorcallBuilder_AddArgStr(key, value, builder, args, n) PyDict_SetItemString(builder, key, value)
#endif

/* PyObjectVectorCallMethodKwBuilder.proto */
#if CYTHON_VECTORCALL && PY_VERSION_HEX >= 0x03090000
#define __Pyx_Object_VectorcallMethod_CallFromBuilder PyObject_VectorcallMethod
#else
static PyObject *__Pyx_Object_VectorcallMethod_CallFromBuilder(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames);
#endif

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

/* PyObject_Unicode.proto */
#define __Pyx_PyObject_Unicode(obj)\
    (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj))

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

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

/* CallCFunction.proto */
#define __Pyx_CallCFunction(cfunc, self, args)\
    ((PyCFunction)(void(*)(void))(cfunc)->func)(self, args)
#define __Pyx_CallCFunctionWithKeywords(cfunc, self, args, kwargs)\
    ((PyCFunctionWithKeywords)(void(*)(void))(cfunc)->func)(self, args, kwargs)
#define __Pyx_CallCFunctionFast(cfunc, self, args, nargs)\
    ((__Pyx_PyCFunctionFast)(void(*)(void))(PyCFunction)(cfunc)->func)(self, args, nargs)
#define __Pyx_CallCFunctionFastWithKeywords(cfunc, self, args, nargs, kwnames)\
    ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))(PyCFunction)(cfunc)->func)(self, args, nargs, kwnames)

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

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
    __pyx_atomic_int_type initialized;
#endif
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
static CYTHON_INLINE int __Pyx_CachedCFunction_GetAndSetInitializing(__Pyx_CachedCFunction *cfunc) {
#if !CYTHON_ATOMICS
    return 1;
#else
    __pyx_nonatomic_int_type expected = 0;
    if (__pyx_atomic_int_cmp_exchange(&cfunc->initialized, &expected, 1)) {
        return 0;
    }
    return expected;
#endif
}
static CYTHON_INLINE void __Pyx_CachedCFunction_SetFinishedInitializing(__Pyx_CachedCFunction *cfunc) {
#if CYTHON_ATOMICS
    __pyx_atomic_store(&cfunc->initialized, 2);
#endif
}
#else
#define __Pyx_CachedCFunction_GetAndSetInitializing(cfunc) 2
#define __Pyx_CachedCFunction_SetFinishedInitializing(cfunc)
#endif

/* CallUnboundCMethod0.proto */
CYTHON_UNUSED
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

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

/* PyObjectCall2Args.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

/* CallUnboundCMethod1.proto */
CYTHON_UNUSED
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

/* CallUnboundCMethod2.proto */
CYTHON_UNUSED
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2);
#if CYTHON_COMPILING_IN_CPYTHON
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

/* 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));
}

/* 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);
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
        L->ob_item[len] = x;
        #else
        PyList_SET_ITEM(list, len, x);
        #endif
        __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

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

/* 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);

/* 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);

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

/* 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);

/* PyUnicode_Unicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj);

/* JoinPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char);

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

/* object_ord.proto */
#define __Pyx_PyObject_Ord(c)\
    (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
static long __Pyx__PyObject_Ord(PyObject* c);

/* PyLongCompare.proto */
static CYTHON_INLINE int __Pyx_PyLong_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);

/* PyObjectFormatAndDecref.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f);
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f);

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

/* BuildPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, const char* chars, int clength,
                                                int prepend_sign, char padding_char);

/* COrdinalToPyUnicode.proto */
static CYTHON_INLINE int __Pyx_CheckUnicodeValue(int value);
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromOrdinal_Padded(int value, Py_ssize_t width, char padding_char);

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

/* IncludeStdlibH.proto */
#include <stdlib.h>

/* CIntToPyUnicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char);

/* PyObjectFormatSimple.proto */
#if CYTHON_COMPILING_IN_PYPY
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        PyObject_Format(s, f))
#elif CYTHON_USE_TYPE_SLOTS
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_repr(s) :\
        likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_repr(s) :\
        PyObject_Format(s, f))
#else
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        PyObject_Format(s, f))
#endif

/* HasAttr.proto */
#if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
#define __Pyx_HasAttr(o, n)  PyObject_HasAttrWithError(o, n)
#else
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);
#endif

/* 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

/* 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

/* PyDictContains.proto */
static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
    int result = PyDict_Contains(dict, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* PyLongBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static CYTHON_INLINE PyObject* __Pyx_PyLong_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyLong_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(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_1_2
#define __PYX_HAVE_RT_ImportType_proto_3_1_2
#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_1_2(s) alignof(s)
#else
#define __PYX_GET_STRUCT_ALIGNMENT_3_1_2(s) sizeof(void*)
#endif
enum __Pyx_ImportType_CheckSize_3_1_2 {
   __Pyx_ImportType_CheckSize_Error_3_1_2 = 0,
   __Pyx_ImportType_CheckSize_Warn_3_1_2 = 1,
   __Pyx_ImportType_CheckSize_Ignore_3_1_2 = 2
};
static PyTypeObject *__Pyx_ImportType_3_1_2(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_1_2 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);
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple);

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

/* ListPack.proto */
static PyObject *__Pyx_PyList_Pack(Py_ssize_t n, ...);

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

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

/* CodeObjectCache.proto */
#if CYTHON_COMPILING_IN_LIMITED_API
typedef PyObject __Pyx_CachedCodeObjectType;
#else
typedef PyCodeObject __Pyx_CachedCodeObjectType;
#endif
typedef struct {
    __Pyx_CachedCodeObjectType* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    __pyx_atomic_int_type accessor_count;
  #endif
};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static __Pyx_CachedCodeObjectType *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, __Pyx_CachedCodeObjectType* code_object);

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyLong_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_PyLong_From_readstat_type_t(readstat_type_t value);

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

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

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

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

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

/* CIntFromPy.proto */
static CYTHON_INLINE __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __Pyx_PyLong_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"
#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj)
#if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
#define __Pyx_PyType_GetFullyQualifiedName PyType_GetFullyQualifiedName
#else
static __Pyx_TypeName __Pyx_PyType_GetFullyQualifiedName(PyTypeObject* tp);
#endif
#else  // !LIMITED_API
typedef const char *__Pyx_TypeName;
#define __Pyx_FMT_TYPENAME "%.200s"
#define __Pyx_PyType_GetFullyQualifiedName(tp) ((tp)->tp_name)
#define __Pyx_DECREF_TypeName(obj)
#endif

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyLong_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)
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2) {
    return 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)
#ifdef PyExceptionInstance_Check
  #define __Pyx_PyBaseException_Check(obj) PyExceptionInstance_Check(obj)
#else
  #define __Pyx_PyBaseException_Check(obj) __Pyx_TypeCheck(obj, PyExc_BaseException)
#endif

/* GetRuntimeVersion.proto */
static unsigned long __Pyx_get_runtime_version(void);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer);

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

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

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

/* MultiPhaseInitModuleState.proto */
#if CYTHON_PEP489_MULTI_PHASE_INIT && CYTHON_USE_MODULE_STATE
static PyObject *__Pyx_State_FindModule(void*);
static int __Pyx_State_AddModule(PyObject* module, void*);
static int __Pyx_State_RemoveModule(void*);
#elif CYTHON_USE_MODULE_STATE
#define __Pyx_State_FindModule PyState_FindModule
#define __Pyx_State_AddModule PyState_AddModule
#define __Pyx_State_RemoveModule PyState_RemoveModule
#endif

/* #### Code section: module_declarations ### */
/* CythonABIVersion.proto */
#if CYTHON_COMPILING_IN_LIMITED_API
    #if CYTHON_METH_FASTCALL
        #define __PYX_FASTCALL_ABI_SUFFIX  "_fastcall"
    #else
        #define __PYX_FASTCALL_ABI_SUFFIX
    #endif
    #define __PYX_LIMITED_ABI_SUFFIX "limited" __PYX_FASTCALL_ABI_SUFFIX __PYX_AM_SEND_ABI_SUFFIX
#else
    #define __PYX_LIMITED_ABI_SUFFIX
#endif
#if __PYX_HAS_PY_AM_SEND == 1
    #define __PYX_AM_SEND_ABI_SUFFIX
#elif __PYX_HAS_PY_AM_SEND == 2
    #define __PYX_AM_SEND_ABI_SUFFIX "amsendbackport"
#else
    #define __PYX_AM_SEND_ABI_SUFFIX "noamsend"
#endif
#ifndef __PYX_MONITORING_ABI_SUFFIX
    #define __PYX_MONITORING_ABI_SUFFIX
#endif
#if CYTHON_USE_TP_FINALIZE
    #define __PYX_TP_FINALIZE_ABI_SUFFIX
#else
    #define __PYX_TP_FINALIZE_ABI_SUFFIX "nofinalize"
#endif
#if CYTHON_USE_FREELISTS || !defined(__Pyx_AsyncGen_USED)
    #define __PYX_FREELISTS_ABI_SUFFIX
#else
    #define __PYX_FREELISTS_ABI_SUFFIX "nofreelists"
#endif
#define CYTHON_ABI  __PYX_ABI_VERSION __PYX_LIMITED_ABI_SUFFIX __PYX_MONITORING_ABI_SUFFIX __PYX_TP_FINALIZE_ABI_SUFFIX __PYX_FREELISTS_ABI_SUFFIX __PYX_AM_SEND_ABI_SUFFIX
#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."


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

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

/* 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_float_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_narwhals_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 int __pyx_v_10pyreadstat_16_readstat_writer_dta_old_max_width;
static int __pyx_v_10pyreadstat_16_readstat_writer_dta_111_max_width;
static int __pyx_v_10pyreadstat_16_readstat_writer_dta_117_max_width;
static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_datetime_to_number(PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *, int); /*proto*/
static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_date_to_number(PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, int); /*proto*/
static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_time_to_number(PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, int); /*proto*/
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_narwhals_str_series_max_length(PyObject *, PyObject *, int); /*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_narwhals_column_types(PyObject *, PyObject *, PyObject *, int); /*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 PyObject *__pyx_f_10pyreadstat_16_readstat_writer_filepath_to_bytes(PyObject *); /*proto*/
static void __pyx_f_10pyreadstat_16_readstat_writer_initial_checks(int, int, PyObject *, PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *); /*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_UnicodeError;
static PyObject *__pyx_builtin_zip;
/* #### Code section: string_decls ### */
static const char __pyx_k_[] = ")";
static const char __pyx_k_x[] = "x";
static const char __pyx_k__2[] = " ";
static const char __pyx_k__3[] = ".";
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_ms[] = "ms";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_ns[] = "ns";
static const char __pyx_k_nt[] = "nt";
static const char __pyx_k_nw[] = "nw";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_us[] = "us";
static const char __pyx_k_v2[] = "v2";
static const char __pyx_k_cat[] = "cat";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_min[] = "min";
static const char __pyx_k_nth[] = "nth";
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_Date[] = "Date";
static const char __pyx_k_Enum[] = "Enum";
static const char __pyx_k_Int8[] = "Int8";
static const char __pyx_k_None[] = "None";
static const char __pyx_k_Time[] = "Time";
static const char __pyx_k_cast[] = "cast";
static const char __pyx_k_date[] = "date";
static const char __pyx_k_days[] = "days";
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_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_then[] = "then";
static const char __pyx_k_time[] = "time";
static const char __pyx_k_warn[] = "warn";
static const char __pyx_k_when[] = "when";
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_UInt8[] = "UInt8";
static const char __pyx_k_clone[] = "clone";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_is_in[] = "is_in";
static const char __pyx_k_isdir[] = "isdir";
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_upper[] = "upper";
static const char __pyx_k_utf_8[] = "utf-8";
static const char __pyx_k_Int128[] = "Int128";
static const char __pyx_k_Object[] = "Object";
static const char __pyx_k_String[] = "String";
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_center[] = "center";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_filter[] = "filter";
static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_name_2[] = "__name__";
static const char __pyx_k_stable[] = "stable";
static const char __pyx_k_tzinfo[] = "tzinfo";
static const char __pyx_k_Boolean[] = "Boolean";
static const char __pyx_k_Decimal[] = "Decimal";
static const char __pyx_k_Float32[] = "Float32";
static const char __pyx_k_Float64[] = "Float64";
static const char __pyx_k_UInt128[] = "UInt128";
static const char __pyx_k_columns[] = "columns";
static const char __pyx_k_combine[] = "combine";
static const char __pyx_k_dirname[] = "dirname";
static const char __pyx_k_instead[] = " instead";
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_Datetime[] = "Datetime";
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_narwhals[] = "narwhals";
static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_timezone[] = "timezone";
static const char __pyx_k_warnings[] = "warnings";
static const char __pyx_k_is_pandas[] = "is_pandas";
static const char __pyx_k_is_polars[] = "is_polars";
static const char __pyx_k_iter_rows[] = "iter_rows";
static const char __pyx_k_ordinal_2[] = "' (ordinal ";
static const char __pyx_k_time_unit[] = "time_unit";
static const char __pyx_k_timestamp[] = "timestamp";
static const char __pyx_k_datetime64[] = "datetime64";
static const char __pyx_k_drop_nulls[] = "drop_nulls";
static const char __pyx_k_eager_only[] = "eager_only";
static const char __pyx_k_expanduser[] = "expanduser";
static const char __pyx_k_is_of_type[] = "' is of type ";
static const char __pyx_k_null_count[] = "null_count";
static const char __pyx_k_Categorical[] = "Categorical";
static const char __pyx_k_from_native[] = "from_native";
static const char __pyx_k_in_variable[] = " in variable ";
static const char __pyx_k_must_be_int[] = " must be int";
static const char __pyx_k_UnicodeError[] = "UnicodeError";
static const char __pyx_k_initializing[] = "_initializing";
static const char __pyx_k_iter_columns[] = "iter_columns";
static const char __pyx_k_with_columns[] = "with_columns";
static const char __pyx_k_ReadstatError[] = "ReadstatError";
static const char __pyx_k_class_getitem[] = "__class_getitem__";
static const char __pyx_k_total_seconds[] = "total_seconds";
static const char __pyx_k_variable_name[] = "variable name '";
static const char __pyx_k_does_not_exist[] = " does not exist!";
static const char __pyx_k_get_categories[] = "get_categories";
static const char __pyx_k_implementation[] = "implementation";
static const char __pyx_k_must_be_string[] = " must be string";
static const char __pyx_k_PyreadstatError[] = "PyreadstatError";
static const char __pyx_k_must_be_numeric[] = " must be numeric";
static const char __pyx_k_readstat_parser[] = "_readstat_parser";
static const char __pyx_k_surrogateescape[] = "surrogateescape";
static const char __pyx_k_must_be_dict_got[] = " must be dict, got ";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_narwhals_stable_v2[] = "narwhals.stable.v2";
static const char __pyx_k_unknown_file_format[] = "unknown file format";
static const char __pyx_k_get_native_namespace[] = "get_native_namespace";
static const char __pyx_k_measure_for_variable[] = "measure for variable ";
static const char __pyx_k_getfilesystemencoding[] = "getfilesystemencoding";
static const char __pyx_k_alignment_for_variable[] = "alignment for variable ";
static const char __pyx_k_the_destination_folder[] = "the destination folder ";
static const char __pyx_k_must_be_boolean_or_be_1_or_0[] = " must be boolean or be 1 or 0";
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_must_be_either_nominal_ordinal[] = " must be either nominal, ordinal, scale or unknown got ";
static const char __pyx_k_and_it_must_be_str_not_starting[] = " and it must be str (not starting with numbers!)";
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_must_be_either_right_center_lef[] = " must be either right, center, left or unknown got ";
static const char __pyx_k_must_match_the_type_of_the_colu[] = " must match the type of the column in dataframe and be of type date, datetime or time";
static const char __pyx_k_starts_with_an_illegal_non_alph[] = "' starts with an illegal (non-alphabetic) character: '";
static const char __pyx_k_variable_value_labels_value_for[] = "variable_value_labels: value for key ";
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_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_dataframe_must_be_pandas_or_pola[] = "dataframe must be pandas or polars dataframe";
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_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_note_should_be_either_str_or_lis[] = "note should be either str or list, got ";
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_names_must_be_non_empty[] = "variable names must be non-empty strings, not starting with numbers";
static const char __pyx_k_variable_value_labels_type_of_La[] = "variable_value_labels: type of Label ";
static const char __pyx_k_variable_value_labels_type_of_Va[] = "variable_value_labels: type of Value ";
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";
/* #### Code section: decls ### */
/* #### Code section: late_includes ### */
/* #### Code section: module_state ### */
/* SmallCodeConfig */
#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

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
  PyTypeObject *__pyx_ptype_10pyreadstat_16_readstat_parser_data_container;
  __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get;
  __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items;
  __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_keys;
  PyObject *__pyx_tuple[3];
  PyObject *__pyx_string_tab[171];
  PyObject *__pyx_float_1e3;
  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_9223372036854775808;
/* #### Code section: module_state_contents ### */
/* CodeObjectCache.module_state_decls */
struct __Pyx_CodeObjectCache __pyx_code_cache;

/* #### Code section: module_state_end ### */
} __pyx_mstatetype;

#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_global (__Pyx_PyModule_GetState(__Pyx_State_FindModule(&__pyx_moduledef)))

#define __pyx_m (__Pyx_State_FindModule(&__pyx_moduledef))
#else
static __pyx_mstatetype __pyx_mstate_global_static =
#ifdef __cplusplus
    {};
#else
    {0};
#endif
static __pyx_mstatetype * const __pyx_mstate_global = &__pyx_mstate_global_static;
#endif
/* #### Code section: constant_name_defines ### */
#define __pyx_kp_u_ __pyx_string_tab[0]
#define __pyx_n_u_Boolean __pyx_string_tab[1]
#define __pyx_n_u_Categorical __pyx_string_tab[2]
#define __pyx_kp_u_Column_labels_must_be_strings __pyx_string_tab[3]
#define __pyx_n_u_Date __pyx_string_tab[4]
#define __pyx_n_u_Datetime __pyx_string_tab[5]
#define __pyx_n_u_Decimal __pyx_string_tab[6]
#define __pyx_n_u_Enum __pyx_string_tab[7]
#define __pyx_n_u_Float32 __pyx_string_tab[8]
#define __pyx_n_u_Float64 __pyx_string_tab[9]
#define __pyx_n_u_Int128 __pyx_string_tab[10]
#define __pyx_n_u_Int16 __pyx_string_tab[11]
#define __pyx_n_u_Int32 __pyx_string_tab[12]
#define __pyx_n_u_Int64 __pyx_string_tab[13]
#define __pyx_n_u_Int8 __pyx_string_tab[14]
#define __pyx_kp_u_Non_unique_column_names_detected __pyx_string_tab[15]
#define __pyx_kp_u_None __pyx_string_tab[16]
#define __pyx_n_u_Object __pyx_string_tab[17]
#define __pyx_n_u_PyreadstatError __pyx_string_tab[18]
#define __pyx_n_u_ReadstatError __pyx_string_tab[19]
#define __pyx_n_u_String __pyx_string_tab[20]
#define __pyx_n_u_Time __pyx_string_tab[21]
#define __pyx_n_u_UInt128 __pyx_string_tab[22]
#define __pyx_n_u_UInt16 __pyx_string_tab[23]
#define __pyx_n_u_UInt32 __pyx_string_tab[24]
#define __pyx_n_u_UInt64 __pyx_string_tab[25]
#define __pyx_n_u_UInt8 __pyx_string_tab[26]
#define __pyx_n_u_UnicodeError __pyx_string_tab[27]
#define __pyx_kp_u_Unknown_data_format_to_insert __pyx_string_tab[28]
#define __pyx_kp_u_Unknown_pywriter_variable_format __pyx_string_tab[29]
#define __pyx_kp_u__2 __pyx_string_tab[30]
#define __pyx_kp_u__3 __pyx_string_tab[31]
#define __pyx_n_u__4 __pyx_string_tab[32]
#define __pyx_kp_u__5 __pyx_string_tab[33]
#define __pyx_kp_u_alignment_for_variable __pyx_string_tab[34]
#define __pyx_kp_u_and_it_must_be_str_not_starting __pyx_string_tab[35]
#define __pyx_n_u_cast __pyx_string_tab[36]
#define __pyx_n_u_cat __pyx_string_tab[37]
#define __pyx_n_u_center __pyx_string_tab[38]
#define __pyx_kp_u_character_missing_ranges_value_g __pyx_string_tab[39]
#define __pyx_n_u_class_getitem __pyx_string_tab[40]
#define __pyx_n_u_cline_in_traceback __pyx_string_tab[41]
#define __pyx_n_u_clone __pyx_string_tab[42]
#define __pyx_kp_u_column_labels_must_be_either_lis __pyx_string_tab[43]
#define __pyx_n_u_columns __pyx_string_tab[44]
#define __pyx_n_u_combine __pyx_string_tab[45]
#define __pyx_kp_u_dataframe_must_be_pandas_or_pola __pyx_string_tab[46]
#define __pyx_n_u_date __pyx_string_tab[47]
#define __pyx_n_u_datetime __pyx_string_tab[48]
#define __pyx_n_u_datetime64 __pyx_string_tab[49]
#define __pyx_n_u_days __pyx_string_tab[50]
#define __pyx_kp_u_dictionaries_in_missing_ranges_m __pyx_string_tab[51]
#define __pyx_n_u_dirname __pyx_string_tab[52]
#define __pyx_kp_u_does_not_exist __pyx_string_tab[53]
#define __pyx_n_u_drop_nulls __pyx_string_tab[54]
#define __pyx_n_u_dtype __pyx_string_tab[55]
#define __pyx_n_u_eager_only __pyx_string_tab[56]
#define __pyx_n_u_encode __pyx_string_tab[57]
#define __pyx_n_u_expanduser __pyx_string_tab[58]
#define __pyx_kp_u_file_path_could_not_be_encoded_w __pyx_string_tab[59]
#define __pyx_n_u_filter __pyx_string_tab[60]
#define __pyx_n_u_from_native __pyx_string_tab[61]
#define __pyx_n_u_fsdecode __pyx_string_tab[62]
#define __pyx_n_u_fsencode __pyx_string_tab[63]
#define __pyx_n_u_get __pyx_string_tab[64]
#define __pyx_n_u_get_categories __pyx_string_tab[65]
#define __pyx_n_u_get_native_namespace __pyx_string_tab[66]
#define __pyx_n_u_getfilesystemencoding __pyx_string_tab[67]
#define __pyx_n_u_hi __pyx_string_tab[68]
#define __pyx_n_u_implementation __pyx_string_tab[69]
#define __pyx_kp_u_in_variable __pyx_string_tab[70]
#define __pyx_n_u_initializing __pyx_string_tab[71]
#define __pyx_kp_u_instead __pyx_string_tab[72]
#define __pyx_n_u_is_in __pyx_string_tab[73]
#define __pyx_kp_u_is_of_type __pyx_string_tab[74]
#define __pyx_n_u_is_pandas __pyx_string_tab[75]
#define __pyx_n_u_is_polars __pyx_string_tab[76]
#define __pyx_n_u_isalpha __pyx_string_tab[77]
#define __pyx_n_u_isdir __pyx_string_tab[78]
#define __pyx_n_u_isna __pyx_string_tab[79]
#define __pyx_n_u_items __pyx_string_tab[80]
#define __pyx_n_u_iter_columns __pyx_string_tab[81]
#define __pyx_n_u_iter_rows __pyx_string_tab[82]
#define __pyx_n_u_keys __pyx_string_tab[83]
#define __pyx_n_u_left __pyx_string_tab[84]
#define __pyx_kp_u_length_of_column_labels_must_be __pyx_string_tab[85]
#define __pyx_n_u_lo __pyx_string_tab[86]
#define __pyx_n_u_main __pyx_string_tab[87]
#define __pyx_kp_u_measure_for_variable __pyx_string_tab[88]
#define __pyx_n_u_min __pyx_string_tab[89]
#define __pyx_kp_u_missing_ranges_hi_and_lo_values __pyx_string_tab[90]
#define __pyx_kp_u_missing_ranges_hi_and_lo_values_2 __pyx_string_tab[91]
#define __pyx_kp_u_missing_ranges_max_1_discrete_nu __pyx_string_tab[92]
#define __pyx_kp_u_missing_ranges_max_1_range_value __pyx_string_tab[93]
#define __pyx_kp_u_missing_ranges_max_3_discrete_nu __pyx_string_tab[94]
#define __pyx_kp_u_missing_ranges_max_3_string_valu __pyx_string_tab[95]
#define __pyx_kp_u_missing_ranges_string_values_len __pyx_string_tab[96]
#define __pyx_kp_u_missing_ranges_values_in_diction __pyx_string_tab[97]
#define __pyx_kp_u_missing_ranges_values_must_be_bo __pyx_string_tab[98]
#define __pyx_kp_u_missing_user_values_not_allowed __pyx_string_tab[99]
#define __pyx_kp_u_missing_user_values_supports_val __pyx_string_tab[100]
#define __pyx_kp_u_missing_user_values_values_in_di __pyx_string_tab[101]
#define __pyx_n_u_module __pyx_string_tab[102]
#define __pyx_n_u_ms __pyx_string_tab[103]
#define __pyx_kp_u_must_be_boolean_or_be_1_or_0 __pyx_string_tab[104]
#define __pyx_kp_u_must_be_dict_got __pyx_string_tab[105]
#define __pyx_kp_u_must_be_either_nominal_ordinal __pyx_string_tab[106]
#define __pyx_kp_u_must_be_either_right_center_lef __pyx_string_tab[107]
#define __pyx_kp_u_must_be_int __pyx_string_tab[108]
#define __pyx_kp_u_must_be_numeric __pyx_string_tab[109]
#define __pyx_kp_u_must_be_string __pyx_string_tab[110]
#define __pyx_kp_u_must_match_the_type_of_the_colu __pyx_string_tab[111]
#define __pyx_n_u_name __pyx_string_tab[112]
#define __pyx_n_u_name_2 __pyx_string_tab[113]
#define __pyx_n_u_narwhals __pyx_string_tab[114]
#define __pyx_n_u_narwhals_stable_v2 __pyx_string_tab[115]
#define __pyx_n_u_nominal __pyx_string_tab[116]
#define __pyx_kp_u_note_should_be_either_str_or_lis __pyx_string_tab[117]
#define __pyx_n_u_np __pyx_string_tab[118]
#define __pyx_n_u_ns __pyx_string_tab[119]
#define __pyx_n_u_nt __pyx_string_tab[120]
#define __pyx_n_u_nth __pyx_string_tab[121]
#define __pyx_n_u_null_count __pyx_string_tab[122]
#define __pyx_kp_u_numeric_missing_ranges_value_giv __pyx_string_tab[123]
#define __pyx_n_u_numpy __pyx_string_tab[124]
#define __pyx_n_u_nw __pyx_string_tab[125]
#define __pyx_n_u_ordinal __pyx_string_tab[126]
#define __pyx_kp_u_ordinal_2 __pyx_string_tab[127]
#define __pyx_n_u_os __pyx_string_tab[128]
#define __pyx_n_u_path __pyx_string_tab[129]
#define __pyx_kp_u_path_must_be_either_str_or_bytes __pyx_string_tab[130]
#define __pyx_n_u_qualname __pyx_string_tab[131]
#define __pyx_n_u_range __pyx_string_tab[132]
#define __pyx_n_u_readstat_parser __pyx_string_tab[133]
#define __pyx_n_u_replace __pyx_string_tab[134]
#define __pyx_n_u_right __pyx_string_tab[135]
#define __pyx_n_u_round __pyx_string_tab[136]
#define __pyx_n_u_scale __pyx_string_tab[137]
#define __pyx_n_u_spec __pyx_string_tab[138]
#define __pyx_n_u_stable __pyx_string_tab[139]
#define __pyx_kp_u_starts_with_an_illegal_non_alph __pyx_string_tab[140]
#define __pyx_n_u_surrogateescape __pyx_string_tab[141]
#define __pyx_n_u_sys __pyx_string_tab[142]
#define __pyx_n_u_test __pyx_string_tab[143]
#define __pyx_kp_u_the_destination_folder __pyx_string_tab[144]
#define __pyx_n_u_then __pyx_string_tab[145]
#define __pyx_n_u_time __pyx_string_tab[146]
#define __pyx_n_u_time_unit __pyx_string_tab[147]
#define __pyx_n_u_timestamp __pyx_string_tab[148]
#define __pyx_n_u_timezone __pyx_string_tab[149]
#define __pyx_n_u_total_seconds __pyx_string_tab[150]
#define __pyx_n_u_tzinfo __pyx_string_tab[151]
#define __pyx_n_u_unknown __pyx_string_tab[152]
#define __pyx_kp_u_unknown_file_format __pyx_string_tab[153]
#define __pyx_n_u_upper __pyx_string_tab[154]
#define __pyx_n_u_us __pyx_string_tab[155]
#define __pyx_n_u_utc __pyx_string_tab[156]
#define __pyx_kp_u_utf_8 __pyx_string_tab[157]
#define __pyx_n_u_v2 __pyx_string_tab[158]
#define __pyx_kp_u_variable_name __pyx_string_tab[159]
#define __pyx_kp_u_variable_name_s_contains_a_space __pyx_string_tab[160]
#define __pyx_kp_u_variable_names_must_be_non_empty __pyx_string_tab[161]
#define __pyx_kp_u_variable_value_labels_type_of_La __pyx_string_tab[162]
#define __pyx_kp_u_variable_value_labels_type_of_Va __pyx_string_tab[163]
#define __pyx_kp_u_variable_value_labels_value_for __pyx_string_tab[164]
#define __pyx_n_u_warn __pyx_string_tab[165]
#define __pyx_n_u_warnings __pyx_string_tab[166]
#define __pyx_n_u_when __pyx_string_tab[167]
#define __pyx_n_u_with_columns __pyx_string_tab[168]
#define __pyx_n_u_x __pyx_string_tab[169]
#define __pyx_n_u_zip __pyx_string_tab[170]
/* #### Code section: module_state_clear ### */
#if CYTHON_USE_MODULE_STATE
static CYTHON_SMALL_CODE int __pyx_m_clear(PyObject *m) {
  __pyx_mstatetype *clear_module_state = __Pyx_PyModule_GetState(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
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __Pyx_State_RemoveModule(NULL);
  #endif
  Py_CLEAR(clear_module_state->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container);
  for (int i=0; i<3; ++i) { Py_CLEAR(clear_module_state->__pyx_tuple[i]); }
  for (int i=0; i<171; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); }
  Py_CLEAR(clear_module_state->__pyx_float_1e3);
  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_9223372036854775808);
  return 0;
}
#endif
/* #### Code section: module_state_traverse ### */
#if CYTHON_USE_MODULE_STATE
static CYTHON_SMALL_CODE int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) {
  __pyx_mstatetype *traverse_module_state = __Pyx_PyModule_GetState(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);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_empty_tuple);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_empty_bytes);
  __Pyx_VISIT_CONST(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);
  for (int i=0; i<3; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_tuple[i]); }
  for (int i=0; i<171; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); }
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_float_1e3);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_float_1e6);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_float_1e9);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_0);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_1);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_65);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_97);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_1970);
  __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_neg_9223372036854775808);
  return 0;
}
#endif
/* #### Code section: module_code ### */

/* "pyreadstat/_readstat_writer.pyx":62
 * cdef int dta_117_max_width = 2045
 * 
 * cdef object vectorized_convert_datetime_to_number(object df, dst_file_format file_format, list pywriter_types, list pywriter_timeunits, int col_count):             # <<<<<<<<<<<<<<
 *     """
 *     transforms datetime64 columns in the dataframe to floats
*/

static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_datetime_to_number(PyObject *__pyx_v_df, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, PyObject *__pyx_v_pywriter_types, PyObject *__pyx_v_pywriter_timeunits, int __pyx_v_col_count) {
  PyObject *__pyx_v_convfacs = 0;
  double __pyx_v_offset_secs;
  double __pyx_v_mulfac;
  int __pyx_v_col_indx;
  PyObject *__pyx_v_col_indxs = 0;
  double __pyx_v_convfac;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  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;
  size_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  double __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("vectorized_convert_datetime_to_number", 0);
  __Pyx_INCREF(__pyx_v_df);

  /* "pyreadstat/_readstat_writer.pyx":68
 *     cdef dict convfacs
 *     cdef double offset_secs
 *     cdef double mulfac = 1.0             # <<<<<<<<<<<<<<
 *     cdef int col_indx
 *     cdef list col_indxs
*/
  __pyx_v_mulfac = 1.0;

  /* "pyreadstat/_readstat_writer.pyx":73
 *     cdef double convfac
 * 
 *     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":74
 * 
 *     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":73
 *     cdef double convfac
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         offset_secs = spss_offset_secs
 *     else:
*/
    break;
    default:

    /* "pyreadstat/_readstat_writer.pyx":76
 *         offset_secs = spss_offset_secs
 *     else:
 *         offset_secs = sas_offset_secs             # <<<<<<<<<<<<<<
 *     if file_format == FILE_FORMAT_DTA:
 *         # stata stores in milliseconds
*/
    __pyx_v_offset_secs = __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_secs;
    break;
  }

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

    /* "pyreadstat/_readstat_writer.pyx":79
 *     if file_format == FILE_FORMAT_DTA:
 *         # stata stores in milliseconds
 *         mulfac = 1000.0             # <<<<<<<<<<<<<<
 *     convfacs = {'ns': 1e9, 'us': 1e6, 'ms': 1e3}
 * 
*/
    __pyx_v_mulfac = 1000.0;

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

  /* "pyreadstat/_readstat_writer.pyx":80
 *         # stata stores in milliseconds
 *         mulfac = 1000.0
 *     convfacs = {'ns': 1e9, 'us': 1e6, 'ms': 1e3}             # <<<<<<<<<<<<<<
 * 
 *     col_indxs = list()
*/
  __pyx_t_2 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_ns, __pyx_mstate_global->__pyx_float_1e9) < 0) __PYX_ERR(0, 80, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_us, __pyx_mstate_global->__pyx_float_1e6) < 0) __PYX_ERR(0, 80, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_ms, __pyx_mstate_global->__pyx_float_1e3) < 0) __PYX_ERR(0, 80, __pyx_L1_error)
  __pyx_v_convfacs = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":82
 *     convfacs = {'ns': 1e9, 'us': 1e6, 'ms': 1e3}
 * 
 *     col_indxs = list()             # <<<<<<<<<<<<<<
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATETIME64:
*/
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_col_indxs = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":83
 * 
 *     col_indxs = list()
 *     for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *         if pywriter_types[col_indx] == PYWRITER_DATETIME64:
 *             col_indxs.append(col_indx)
*/
  __pyx_t_3 = __pyx_v_col_count;
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
    __pyx_v_col_indx = __pyx_t_5;

    /* "pyreadstat/_readstat_writer.pyx":84
 *     col_indxs = list()
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATETIME64:             # <<<<<<<<<<<<<<
 *             col_indxs.append(col_indx)
 * 
*/
    if (unlikely(__pyx_v_pywriter_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 84, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 84, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_1) {

      /* "pyreadstat/_readstat_writer.pyx":85
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATETIME64:
 *             col_indxs.append(col_indx)             # <<<<<<<<<<<<<<
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
*/
      __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 85, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_col_indxs, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 85, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pyreadstat/_readstat_writer.pyx":84
 *     col_indxs = list()
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATETIME64:             # <<<<<<<<<<<<<<
 *             col_indxs.append(col_indx)
 * 
*/
    }
  }

  /* "pyreadstat/_readstat_writer.pyx":87
 *             col_indxs.append(col_indx)
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))             # <<<<<<<<<<<<<<
 *     for col_indx in col_indxs:
 *         convfac = convfacs[pywriter_timeunits[col_indx]]
*/
  __pyx_t_6 = __pyx_v_df;
  __Pyx_INCREF(__pyx_t_6);
  __pyx_t_11 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_14 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13);
    assert(__pyx_t_11);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_13);
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_13, __pyx__function);
    __pyx_t_14 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_v_col_indxs};
    __pyx_t_10 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
  }
  __pyx_t_9 = __pyx_t_10;
  __Pyx_INCREF(__pyx_t_9);
  __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_Int64); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_14 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_11};
    __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_cast, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  }
  __pyx_t_14 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_2};
    __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
  }
  __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":88
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:             # <<<<<<<<<<<<<<
 *         convfac = convfacs[pywriter_timeunits[col_indx]]
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
*/
  __pyx_t_7 = __pyx_v_col_indxs; __Pyx_INCREF(__pyx_t_7);
  __pyx_t_15 = 0;
  for (;;) {
    {
      Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_7);
      #if !CYTHON_ASSUME_SAFE_SIZE
      if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 88, __pyx_L1_error)
      #endif
      if (__pyx_t_15 >= __pyx_temp) break;
    }
    __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_7, __pyx_t_15);
    ++__pyx_t_15;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_col_indx = __pyx_t_3;

    /* "pyreadstat/_readstat_writer.pyx":89
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:
 *         convfac = convfacs[pywriter_timeunits[col_indx]]             # <<<<<<<<<<<<<<
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((((nw.nth(col_indx).cast(nw.Float64))/convfac) + offset_secs).round() * mulfac)
*/
    if (unlikely(__pyx_v_pywriter_timeunits == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 89, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_pywriter_timeunits, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_convfacs, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_16 = __Pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_convfac = __pyx_t_16;

    /* "pyreadstat/_readstat_writer.pyx":90
 *     for col_indx in col_indxs:
 *         convfac = convfacs[pywriter_timeunits[col_indx]]
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))             # <<<<<<<<<<<<<<
 *         df = df.with_columns((((nw.nth(col_indx).cast(nw.Float64))/convfac) + offset_secs).round() * mulfac)
 *     return df
*/
    __pyx_t_2 = __pyx_v_df;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_13 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_when); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_18 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_19 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_20))) {
      __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_20);
      assert(__pyx_t_18);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_20);
      __Pyx_INCREF(__pyx_t_18);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_20, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_18, __pyx_t_19};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_20, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
    }
    __pyx_t_20 = PyObject_RichCompare(__pyx_t_12, __pyx_mstate_global->__pyx_int_neg_9223372036854775808, Py_NE); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_17))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_17);
      assert(__pyx_t_13);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_17);
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_17, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_20};
      __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    }
    __pyx_t_11 = __pyx_t_9;
    __Pyx_INCREF(__pyx_t_11);
    __pyx_t_20 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 90, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_12);
      assert(__pyx_t_20);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_12, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_20, __pyx_t_13};
      __pyx_t_17 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
    }
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_17};
      __pyx_t_10 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_then, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
    }
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_10};
      __pyx_t_6 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
    }
    __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pyreadstat/_readstat_writer.pyx":91
 *         convfac = convfacs[pywriter_timeunits[col_indx]]
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((((nw.nth(col_indx).cast(nw.Float64))/convfac) + offset_secs).round() * mulfac)             # <<<<<<<<<<<<<<
 *     return df
 * 
*/
    __pyx_t_10 = __pyx_v_df;
    __Pyx_INCREF(__pyx_t_10);
    __pyx_t_13 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_20, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_19))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_19);
      assert(__pyx_t_13);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_19);
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_19, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_20};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_19, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 91, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
    }
    __pyx_t_11 = __pyx_t_12;
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_Float64); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_20};
      __pyx_t_17 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_cast, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 91, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
    }
    __pyx_t_12 = PyFloat_FromDouble(__pyx_v_convfac); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_20 = __Pyx_PyNumber_Divide(__pyx_t_17, __pyx_t_12); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = PyFloat_FromDouble(__pyx_v_offset_secs); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_17 = PyNumber_Add(__pyx_t_20, __pyx_t_12); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_9 = __pyx_t_17;
    __Pyx_INCREF(__pyx_t_9);
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL};
      __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_round, __pyx_callargs+__pyx_t_14, (1-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    }
    __pyx_t_17 = PyFloat_FromDouble(__pyx_v_mulfac); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __pyx_t_9 = PyNumber_Multiply(__pyx_t_2, __pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_9};
      __pyx_t_6 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 91, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
    }
    __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pyreadstat/_readstat_writer.pyx":88
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:             # <<<<<<<<<<<<<<
 *         convfac = convfacs[pywriter_timeunits[col_indx]]
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
*/
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":92
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((((nw.nth(col_indx).cast(nw.Float64))/convfac) + offset_secs).round() * mulfac)
 *     return df             # <<<<<<<<<<<<<<
 * 
 * 
*/
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_df);
  __pyx_r = __pyx_v_df;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":62
 * cdef int dta_117_max_width = 2045
 * 
 * cdef object vectorized_convert_datetime_to_number(object df, dst_file_format file_format, list pywriter_types, list pywriter_timeunits, int col_count):             # <<<<<<<<<<<<<<
 *     """
 *     transforms datetime64 columns in the dataframe to floats
*/

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __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_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.vectorized_convert_datetime_to_number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_convfacs);
  __Pyx_XDECREF(__pyx_v_col_indxs);
  __Pyx_XDECREF(__pyx_v_df);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":95
 * 
 * 
 * cdef object vectorized_convert_date_to_number(object df, dst_file_format file_format, list pywriter_types,  int col_count):             # <<<<<<<<<<<<<<
 *     """
 *     transforms date64 columns in the dataframe to floats
*/

static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_date_to_number(PyObject *__pyx_v_df, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, PyObject *__pyx_v_pywriter_types, int __pyx_v_col_count) {
  double __pyx_v_offset_days;
  double __pyx_v_mulfac;
  int __pyx_v_col_indx;
  PyObject *__pyx_v_col_indxs = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  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;
  size_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("vectorized_convert_date_to_number", 0);
  __Pyx_INCREF(__pyx_v_df);

  /* "pyreadstat/_readstat_writer.pyx":100
 *     """
 *     cdef double offset_days
 *     cdef double mulfac = 1.0             # <<<<<<<<<<<<<<
 *     cdef int col_indx
 *     cdef list col_indxs
*/
  __pyx_v_mulfac = 1.0;

  /* "pyreadstat/_readstat_writer.pyx":104
 *     cdef list col_indxs
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         offset_days = spss_offset_days
 *         # spss stores in seconds
*/
  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":105
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:
 *         offset_days = spss_offset_days             # <<<<<<<<<<<<<<
 *         # spss stores in seconds
 *         mulfac = 86400
*/
    __pyx_v_offset_days = __pyx_v_10pyreadstat_16_readstat_writer_spss_offset_days;

    /* "pyreadstat/_readstat_writer.pyx":107
 *         offset_days = spss_offset_days
 *         # spss stores in seconds
 *         mulfac = 86400             # <<<<<<<<<<<<<<
 *     else:
 *         offset_days = sas_offset_days
*/
    __pyx_v_mulfac = 86400.0;

    /* "pyreadstat/_readstat_writer.pyx":104
 *     cdef list col_indxs
 * 
 *     if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         offset_days = spss_offset_days
 *         # spss stores in seconds
*/
    break;
    default:

    /* "pyreadstat/_readstat_writer.pyx":109
 *         mulfac = 86400
 *     else:
 *         offset_days = sas_offset_days             # <<<<<<<<<<<<<<
 *     col_indxs = list()
 *     for col_indx in range(col_count):
*/
    __pyx_v_offset_days = __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_days;
    break;
  }

  /* "pyreadstat/_readstat_writer.pyx":110
 *     else:
 *         offset_days = sas_offset_days
 *     col_indxs = list()             # <<<<<<<<<<<<<<
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATE64:
*/
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_col_indxs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":111
 *         offset_days = sas_offset_days
 *     col_indxs = list()
 *     for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *         if pywriter_types[col_indx] == PYWRITER_DATE64:
 *             col_indxs.append(col_indx)
*/
  __pyx_t_2 = __pyx_v_col_count;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_col_indx = __pyx_t_4;

    /* "pyreadstat/_readstat_writer.pyx":112
 *     col_indxs = list()
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATE64:             # <<<<<<<<<<<<<<
 *             col_indxs.append(col_indx)
 * 
*/
    if (unlikely(__pyx_v_pywriter_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 112, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 112, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 112, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_7) {

      /* "pyreadstat/_readstat_writer.pyx":113
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATE64:
 *             col_indxs.append(col_indx)             # <<<<<<<<<<<<<<
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
*/
      __pyx_t_6 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 113, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_col_indxs, __pyx_t_6); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 113, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pyreadstat/_readstat_writer.pyx":112
 *     col_indxs = list()
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_DATE64:             # <<<<<<<<<<<<<<
 *             col_indxs.append(col_indx)
 * 
*/
    }
  }

  /* "pyreadstat/_readstat_writer.pyx":115
 *             col_indxs.append(col_indx)
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))             # <<<<<<<<<<<<<<
 *     for col_indx in col_indxs:
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
*/
  __pyx_t_5 = __pyx_v_df;
  __Pyx_INCREF(__pyx_t_5);
  __pyx_t_11 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_14 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13);
    assert(__pyx_t_11);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_13);
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_13, __pyx__function);
    __pyx_t_14 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_v_col_indxs};
    __pyx_t_10 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 115, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
  }
  __pyx_t_9 = __pyx_t_10;
  __Pyx_INCREF(__pyx_t_9);
  __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_Int64); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_14 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_11};
    __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_cast, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __pyx_t_14 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_1};
    __pyx_t_6 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 115, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
  }
  __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_6);
  __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":116
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:             # <<<<<<<<<<<<<<
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64) + offset_days).round() * mulfac)
*/
  __pyx_t_6 = __pyx_v_col_indxs; __Pyx_INCREF(__pyx_t_6);
  __pyx_t_15 = 0;
  for (;;) {
    {
      Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_6);
      #if !CYTHON_ASSUME_SAFE_SIZE
      if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 116, __pyx_L1_error)
      #endif
      if (__pyx_t_15 >= __pyx_temp) break;
    }
    __pyx_t_1 = __Pyx_PyList_GetItemRef(__pyx_t_6, __pyx_t_15);
    ++__pyx_t_15;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyLong_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 116, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_col_indx = __pyx_t_2;

    /* "pyreadstat/_readstat_writer.pyx":117
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))             # <<<<<<<<<<<<<<
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64) + offset_days).round() * mulfac)
 *     return df
*/
    __pyx_t_5 = __pyx_v_df;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_t_13 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_when); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_17 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_19))) {
      __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_19);
      assert(__pyx_t_17);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_19);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_19, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_18};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_19, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
    }
    __pyx_t_19 = PyObject_RichCompare(__pyx_t_12, __pyx_mstate_global->__pyx_int_neg_9223372036854775808, Py_NE); __Pyx_XGOTREF(__pyx_t_19); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_16))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_16);
      assert(__pyx_t_13);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_16, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_19};
      __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    }
    __pyx_t_11 = __pyx_t_9;
    __Pyx_INCREF(__pyx_t_11);
    __pyx_t_19 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12);
      assert(__pyx_t_19);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_12, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_19, __pyx_t_13};
      __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
    }
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_16};
      __pyx_t_10 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_then, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
    }
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_10};
      __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":118
 *     for col_indx in col_indxs:
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64) + offset_days).round() * mulfac)             # <<<<<<<<<<<<<<
 *     return df
 * 
*/
    __pyx_t_10 = __pyx_v_df;
    __Pyx_INCREF(__pyx_t_10);
    __pyx_t_13 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_19 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_18))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_18);
      assert(__pyx_t_13);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_18);
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_18, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_19};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_18, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 118, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
    }
    __pyx_t_11 = __pyx_t_12;
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_Float64); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_19};
      __pyx_t_16 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_cast, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 118, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
    }
    __pyx_t_12 = PyFloat_FromDouble(__pyx_v_offset_days); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_19 = PyNumber_Add(__pyx_t_16, __pyx_t_12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_9 = __pyx_t_19;
    __Pyx_INCREF(__pyx_t_9);
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL};
      __pyx_t_5 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_round, __pyx_callargs+__pyx_t_14, (1-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 118, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    }
    __pyx_t_19 = PyFloat_FromDouble(__pyx_v_mulfac); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_9 = PyNumber_Multiply(__pyx_t_5, __pyx_t_19); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_9};
      __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":116
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:             # <<<<<<<<<<<<<<
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64) + offset_days).round() * mulfac)
*/
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":119
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64) + offset_days).round() * mulfac)
 *     return df             # <<<<<<<<<<<<<<
 * 
 * cdef object vectorized_convert_time_to_number(object df, dst_file_format file_format, list pywriter_types,  int col_count):
*/
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_df);
  __pyx_r = __pyx_v_df;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":95
 * 
 * 
 * cdef object vectorized_convert_date_to_number(object df, dst_file_format file_format, list pywriter_types,  int col_count):             # <<<<<<<<<<<<<<
 *     """
 *     transforms date64 columns in the dataframe to floats
*/

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __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_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.vectorized_convert_date_to_number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_col_indxs);
  __Pyx_XDECREF(__pyx_v_df);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":121
 *     return df
 * 
 * cdef object vectorized_convert_time_to_number(object df, dst_file_format file_format, list pywriter_types,  int col_count):             # <<<<<<<<<<<<<<
 *     """
 *     transforms time64 columns in the dataframe to floats
*/

static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_time_to_number(PyObject *__pyx_v_df, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, PyObject *__pyx_v_pywriter_types, int __pyx_v_col_count) {
  double __pyx_v_mulfac;
  int __pyx_v_col_indx;
  PyObject *__pyx_v_col_indxs = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  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;
  size_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("vectorized_convert_time_to_number", 0);
  __Pyx_INCREF(__pyx_v_df);

  /* "pyreadstat/_readstat_writer.pyx":125
 *     transforms time64 columns in the dataframe to floats
 *     """
 *     cdef double mulfac = 1.0             # <<<<<<<<<<<<<<
 *     cdef int col_indx
 *     cdef list col_indxs
*/
  __pyx_v_mulfac = 1.0;

  /* "pyreadstat/_readstat_writer.pyx":129
 *     cdef list col_indxs
 * 
 *     if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *         # stata stores in milliseconds
 *         mulfac = 1000.0
*/
  __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
 *     if file_format == FILE_FORMAT_DTA:
 *         # stata stores in milliseconds
 *         mulfac = 1000.0             # <<<<<<<<<<<<<<
 * 
 *     col_indxs = list()
*/
    __pyx_v_mulfac = 1000.0;

    /* "pyreadstat/_readstat_writer.pyx":129
 *     cdef list col_indxs
 * 
 *     if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *         # stata stores in milliseconds
 *         mulfac = 1000.0
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":133
 *         mulfac = 1000.0
 * 
 *     col_indxs = list()             # <<<<<<<<<<<<<<
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_TIME64:
*/
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_col_indxs = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":134
 * 
 *     col_indxs = list()
 *     for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *         if pywriter_types[col_indx] == PYWRITER_TIME64:
 *             col_indxs.append(col_indx)
*/
  __pyx_t_3 = __pyx_v_col_count;
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
    __pyx_v_col_indx = __pyx_t_5;

    /* "pyreadstat/_readstat_writer.pyx":135
 *     col_indxs = list()
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_TIME64:             # <<<<<<<<<<<<<<
 *             col_indxs.append(col_indx)
 * 
*/
    if (unlikely(__pyx_v_pywriter_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 135, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 135, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 135, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 135, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_1) {

      /* "pyreadstat/_readstat_writer.pyx":136
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_TIME64:
 *             col_indxs.append(col_indx)             # <<<<<<<<<<<<<<
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
*/
      __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_col_indxs, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 136, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pyreadstat/_readstat_writer.pyx":135
 *     col_indxs = list()
 *     for col_indx in range(col_count):
 *         if pywriter_types[col_indx] == PYWRITER_TIME64:             # <<<<<<<<<<<<<<
 *             col_indxs.append(col_indx)
 * 
*/
    }
  }

  /* "pyreadstat/_readstat_writer.pyx":138
 *             col_indxs.append(col_indx)
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))             # <<<<<<<<<<<<<<
 *     for col_indx in col_indxs:
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
*/
  __pyx_t_6 = __pyx_v_df;
  __Pyx_INCREF(__pyx_t_6);
  __pyx_t_11 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_14 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13);
    assert(__pyx_t_11);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_13);
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_13, __pyx__function);
    __pyx_t_14 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_v_col_indxs};
    __pyx_t_10 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
  }
  __pyx_t_9 = __pyx_t_10;
  __Pyx_INCREF(__pyx_t_9);
  __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_Int64); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_14 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_11};
    __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_cast, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  }
  __pyx_t_14 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_2};
    __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
  }
  __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":139
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:             # <<<<<<<<<<<<<<
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64)/1e9).round() * mulfac)
*/
  __pyx_t_7 = __pyx_v_col_indxs; __Pyx_INCREF(__pyx_t_7);
  __pyx_t_15 = 0;
  for (;;) {
    {
      Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_7);
      #if !CYTHON_ASSUME_SAFE_SIZE
      if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 139, __pyx_L1_error)
      #endif
      if (__pyx_t_15 >= __pyx_temp) break;
    }
    __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_7, __pyx_t_15);
    ++__pyx_t_15;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 139, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_col_indx = __pyx_t_3;

    /* "pyreadstat/_readstat_writer.pyx":140
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))             # <<<<<<<<<<<<<<
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64)/1e9).round() * mulfac)
 *     return df
*/
    __pyx_t_6 = __pyx_v_df;
    __Pyx_INCREF(__pyx_t_6);
    __pyx_t_13 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_when); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_17 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_19))) {
      __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_19);
      assert(__pyx_t_17);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_19);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_19, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_18};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_19, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
    }
    __pyx_t_19 = PyObject_RichCompare(__pyx_t_12, __pyx_mstate_global->__pyx_int_neg_9223372036854775808, Py_NE); __Pyx_XGOTREF(__pyx_t_19); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_16))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_16);
      assert(__pyx_t_13);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_16, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_19};
      __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    }
    __pyx_t_11 = __pyx_t_9;
    __Pyx_INCREF(__pyx_t_11);
    __pyx_t_19 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12);
      assert(__pyx_t_19);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_12, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_19, __pyx_t_13};
      __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
    }
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_16};
      __pyx_t_10 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_then, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
    }
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_10};
      __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pyreadstat/_readstat_writer.pyx":141
 *     for col_indx in col_indxs:
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64)/1e9).round() * mulfac)             # <<<<<<<<<<<<<<
 *     return df
 * 
*/
    __pyx_t_10 = __pyx_v_df;
    __Pyx_INCREF(__pyx_t_10);
    __pyx_t_13 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_mstate_global->__pyx_n_u_nth); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_19 = __Pyx_PyLong_From_int(__pyx_v_col_indx); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_14 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_18))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_18);
      assert(__pyx_t_13);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_18);
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_18, __pyx__function);
      __pyx_t_14 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_19};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_18, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (__pyx_t_14*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
    }
    __pyx_t_11 = __pyx_t_12;
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_mstate_global->__pyx_n_u_Float64); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_19};
      __pyx_t_16 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_cast, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
    }
    __pyx_t_12 = __Pyx_PyFloat_DivideObjC(__pyx_t_16, __pyx_mstate_global->__pyx_float_1e9, 1e9, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_9 = __pyx_t_12;
    __Pyx_INCREF(__pyx_t_9);
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL};
      __pyx_t_6 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_round, __pyx_callargs+__pyx_t_14, (1-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
    }
    __pyx_t_12 = PyFloat_FromDouble(__pyx_v_mulfac); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_9 = PyNumber_Multiply(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_14 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_9};
      __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_14, (2-__pyx_t_14) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pyreadstat/_readstat_writer.pyx":139
 * 
 *     df = df.with_columns(nw.nth(col_indxs).cast(nw.Int64))
 *     for col_indx in col_indxs:             # <<<<<<<<<<<<<<
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64)/1e9).round() * mulfac)
*/
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":142
 *         df = df.with_columns(nw.when(nw.nth(col_indx)!=-9223372036854775808).then(nw.nth(col_indx)))
 *         df = df.with_columns((nw.nth(col_indx).cast(nw.Float64)/1e9).round() * mulfac)
 *     return df             # <<<<<<<<<<<<<<
 * 
 * cdef double convert_datetimelike_to_number(dst_file_format file_format, pywriter_variable_type curtype, object curval) except *:
*/
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_df);
  __pyx_r = __pyx_v_df;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":121
 *     return df
 * 
 * cdef object vectorized_convert_time_to_number(object df, dst_file_format file_format, list pywriter_types,  int col_count):             # <<<<<<<<<<<<<<
 *     """
 *     transforms time64 columns in the dataframe to floats
*/

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __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_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.vectorized_convert_time_to_number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_col_indxs);
  __Pyx_XDECREF(__pyx_v_df);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":144
 *     return df
 * 
 * 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;
  size_t __pyx_t_8;
  double __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_datetimelike_to_number", 0);

  /* "pyreadstat/_readstat_writer.pyx":151
 *     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":152
 * 
 *     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":153
 *     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":151
 *     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":155
 *         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":156
 *     else:
 *         offset_days = sas_offset_days
 *         offset_secs = sas_offset_secs             # <<<<<<<<<<<<<<
 * 
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:
*/
    __pyx_v_offset_secs = __pyx_v_10pyreadstat_16_readstat_writer_sas_offset_secs;
    break;
  }

  /* "pyreadstat/_readstat_writer.pyx":158
 *         offset_secs = sas_offset_secs
 * 
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:             # <<<<<<<<<<<<<<
 *         # get timestamp in seconds
 *         if type(curval) == datetime.datetime:
*/
  switch (__pyx_v_curtype) {
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME:
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64:

    /* "pyreadstat/_readstat_writer.pyx":160
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:
 *         # get timestamp in seconds
 *         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_1, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":161
 *         # get timestamp in seconds
 *         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_t_5 = __pyx_v_curval;
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_timezone); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_utc); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_8 = 0;
      {
        PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, NULL};
        __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_tzinfo, __pyx_t_7, __pyx_t_6, __pyx_callargs+1, 0) < 0) __PYX_ERR(0, 161, __pyx_L1_error)
        __pyx_t_4 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_replace, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
      }
      __pyx_t_2 = __pyx_t_4;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_8 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_timestamp, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __pyx_t_9 = __Pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_tstamp = __pyx_t_9;

      /* "pyreadstat/_readstat_writer.pyx":160
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:
 *         # get timestamp in seconds
 *         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())
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":164
 *             #tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple())
 * 
 *         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":165
 * 
 *         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":167
 *         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":165
 * 
 *         tstamp += offset_secs
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             # stata stores in milliseconds
 *             tstamp *= 1000
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":158
 *         offset_secs = sas_offset_secs
 * 
 *     if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:             # <<<<<<<<<<<<<<
 *         # get timestamp in seconds
 *         if type(curval) == datetime.datetime:
*/
    break;
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE:

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

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

      /* "pyreadstat/_readstat_writer.pyx":172
 *         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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_days, __pyx_mstate_global->__pyx_n_u_days); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_tstamp = __pyx_t_9;

      /* "pyreadstat/_readstat_writer.pyx":173
 *             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":174
 *             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":176
 *             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":174
 *             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":170
 * 
 *     elif curtype == PYWRITER_DATE:
 *         if type(curval) == datetime.date:             # <<<<<<<<<<<<<<
 *             days = curval - date_0
 *             tstamp = days.days
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":169
 *             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":179
 * 
 *     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_1, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 179, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_curval)), __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 179, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {

      /* "pyreadstat/_readstat_writer.pyx":180
 *     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_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = __pyx_t_6;
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_date); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_min); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_8 = 0;
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_t_2, __pyx_v_curval};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_combine, __pyx_callargs+__pyx_t_8, (3-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_min); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_tdelta = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":181
 *         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_6 = __pyx_v_tdelta;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_8 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
        __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_total_seconds, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 181, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      }
      __pyx_t_9 = __Pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 181, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_tstamp = __pyx_t_9;

      /* "pyreadstat/_readstat_writer.pyx":183
 *             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":185
 *             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":183
 *             tstamp = tdelta.total_seconds()
 *             #tstamp += offset * 86400
 *             if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *                 # stata stores in milliseconds
 *                 tstamp *= 1000
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":179
 * 
 *     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":178
 *                 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":187
 *                 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":144
 *     return df
 * 
 * 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_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_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":189
 *     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;
  size_t __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":194
 *     """
 * 
 *     if curtype == PYWRITER_DATE or curtype == PYWRITER_DATE64:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%td"
*/
  switch (__pyx_v_curtype) {
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE:
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64:

    /* "pyreadstat/_readstat_writer.pyx":195
 * 
 *     if curtype == PYWRITER_DATE or curtype == PYWRITER_DATE64:
 *         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":196
 *     if curtype == PYWRITER_DATE or curtype == PYWRITER_DATE64:
 *         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":195
 * 
 *     if curtype == PYWRITER_DATE or curtype == PYWRITER_DATE64:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%td"
 *         #elif file_format == FILE_FORMAT_SAV:
*/
    }

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

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

    /* "pyreadstat/_readstat_writer.pyx":201
 *         else:
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tc"
*/
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64:

    /* "pyreadstat/_readstat_writer.pyx":202
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:
 *         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":203
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:
 *         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":202
 *             return "DATE"
 *     elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%tc"
 *         #elif file_format == FILE_FORMAT_SAV:
*/
    }

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

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

    /* "pyreadstat/_readstat_writer.pyx":208
 *         else:
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME or curtype == PYWRITER_TIME64:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tcHH:MM:SS"
*/
    case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64:

    /* "pyreadstat/_readstat_writer.pyx":209
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME or curtype == PYWRITER_TIME64:
 *         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":210
 *     elif curtype == PYWRITER_TIME or curtype == PYWRITER_TIME64:
 *         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":209
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME or curtype == PYWRITER_TIME64:
 *         if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *             return "%tcHH:MM:SS"
 *         else:
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":212
 *             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":208
 *         else:
 *             return "DATETIME"
 *     elif curtype == PYWRITER_TIME or curtype == PYWRITER_TIME64:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             return "%tcHH:MM:SS"
*/
    break;
    default:

    /* "pyreadstat/_readstat_writer.pyx":214
 *             return "TIME"
 *     else:
 *         raise PyreadstatError("Unknown pywriter variable format")             # <<<<<<<<<<<<<<
 * 
 * cdef int get_narwhals_str_series_max_length(object series, dict value_labels, bint isobject):
*/
    __pyx_t_3 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      assert(__pyx_t_3);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
      __pyx_t_5 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_Unknown_pywriter_variable_format};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 214, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 214, __pyx_L1_error)
    break;
  }

  /* "pyreadstat/_readstat_writer.pyx":189
 *     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 = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":216
 *         raise PyreadstatError("Unknown pywriter variable format")
 * 
 * cdef int get_narwhals_str_series_max_length(object series, dict value_labels, bint isobject):             # <<<<<<<<<<<<<<
 *     """ For a 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_narwhals_str_series_max_length(PyObject *__pyx_v_series, PyObject *__pyx_v_value_labels, int __pyx_v_isobject) {
  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;
  PyObject *__pyx_t_5 = NULL;
  size_t __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_narwhals_str_series_max_length", 0);

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

  /* "pyreadstat/_readstat_writer.pyx":224
 *     cdef int curlen
 *     cdef list labels
 *     for val in series:             # <<<<<<<<<<<<<<
 *         if isobject:
 *             val = str(val)
*/
  if (likely(PyList_CheckExact(__pyx_v_series)) || PyTuple_CheckExact(__pyx_v_series)) {
    __pyx_t_1 = __pyx_v_series; __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_series); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 224, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 224, __pyx_L1_error)
          #endif
          if (__pyx_t_2 >= __pyx_temp) break;
        }
        __pyx_t_4 = __Pyx_PyList_GetItemRef(__pyx_t_1, __pyx_t_2);
        ++__pyx_t_2;
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 224, __pyx_L1_error)
          #endif
          if (__pyx_t_2 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2));
        #else
        __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_2);
        #endif
        ++__pyx_t_2;
      }
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 224, __pyx_L1_error)
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 224, __pyx_L1_error)
          PyErr_Clear();
        }
        break;
      }
    }
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":225
 *     cdef list labels
 *     for val in series:
 *         if isobject:             # <<<<<<<<<<<<<<
 *             val = str(val)
 *         temp = val.encode("utf-8")
*/
    if (__pyx_v_isobject) {

      /* "pyreadstat/_readstat_writer.pyx":226
 *     for val in series:
 *         if isobject:
 *             val = str(val)             # <<<<<<<<<<<<<<
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)
*/
      __pyx_t_4 = __Pyx_PyObject_Unicode(__pyx_v_val); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF_SET(__pyx_v_val, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pyreadstat/_readstat_writer.pyx":225
 *     cdef list labels
 *     for val in series:
 *         if isobject:             # <<<<<<<<<<<<<<
 *             val = str(val)
 *         temp = val.encode("utf-8")
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":227
 *         if isobject:
 *             val = str(val)
 *         temp = val.encode("utf-8")             # <<<<<<<<<<<<<<
 *         curlen = len(temp)
 *         if curlen > max_length:
*/
    __pyx_t_5 = __pyx_v_val;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_t_6 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_mstate_global->__pyx_kp_u_utf_8};
      __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 227, __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, 227, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_temp, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":228
 *             val = str(val)
 *         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, 228, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_PyBytes_GET_SIZE(__pyx_v_temp); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 228, __pyx_L1_error)
    __pyx_v_curlen = __pyx_t_7;

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

      /* "pyreadstat/_readstat_writer.pyx":230
 *         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":229
 *         temp = val.encode("utf-8")
 *         curlen = len(temp)
 *         if curlen > max_length:             # <<<<<<<<<<<<<<
 *             max_length = curlen
 *     if value_labels:
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":224
 *     cdef int curlen
 *     cdef list labels
 *     for val in series:             # <<<<<<<<<<<<<<
 *         if isobject:
 *             val = str(val)
*/
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

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

    /* "pyreadstat/_readstat_writer.pyx":232
 *             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, 232, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_Keys(__pyx_v_value_labels); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __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, 232, __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":233
 *     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 (;;) {
      {
        Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_4);
        #if !CYTHON_ASSUME_SAFE_SIZE
        if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 233, __pyx_L1_error)
        #endif
        if (__pyx_t_2 >= __pyx_temp) break;
      }
      __pyx_t_1 = __Pyx_PyList_GetItemRef(__pyx_t_4, __pyx_t_2);
      ++__pyx_t_2;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 233, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_lab, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pyreadstat/_readstat_writer.pyx":234
 *         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_Unicode(__pyx_v_lab); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 234, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 234, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_curlen = __pyx_t_7;

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

        /* "pyreadstat/_readstat_writer.pyx":236
 *             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":235
 *         for lab in labels:
 *             curlen = len(str(lab))
 *             if curlen > max_length:             # <<<<<<<<<<<<<<
 *                 max_length = curlen
 * 
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":233
 *     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":231
 *         if curlen > max_length:
 *             max_length = curlen
 *     if value_labels:             # <<<<<<<<<<<<<<
 *         labels = list(value_labels.keys())
 *         for lab in labels:
*/
  }

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

  /* "pyreadstat/_readstat_writer.pyx":216
 *         raise PyreadstatError("Unknown pywriter variable format")
 * 
 * cdef int get_narwhals_str_series_max_length(object series, dict value_labels, bint isobject):             # <<<<<<<<<<<<<<
 *     """ For a 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_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.get_narwhals_str_series_max_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __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":241
 * 
 * 
 * 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_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":245
 *     1 if all elements in a series are of type type_to_check, 0 otherwise
 *     """
 *     for val in series:             # <<<<<<<<<<<<<<
 *         if type(val) != type_to_check:
 *             return 0
*/
  if (likely(PyList_CheckExact(__pyx_v_series)) || PyTuple_CheckExact(__pyx_v_series)) {
    __pyx_t_1 = __pyx_v_series; __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_series); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 245, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 245, __pyx_L1_error)
          #endif
          if (__pyx_t_2 >= __pyx_temp) break;
        }
        __pyx_t_4 = __Pyx_PyList_GetItemRef(__pyx_t_1, __pyx_t_2);
        ++__pyx_t_2;
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 245, __pyx_L1_error)
          #endif
          if (__pyx_t_2 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2));
        #else
        __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_2);
        #endif
        ++__pyx_t_2;
      }
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 245, __pyx_L1_error)
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 245, __pyx_L1_error)
          PyErr_Clear();
        }
        break;
      }
    }
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":246
 *     """
 *     for val in series:
 *         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, 246, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 246, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_5) {

      /* "pyreadstat/_readstat_writer.pyx":247
 *     for val in series:
 *         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":246
 *     """
 *     for val in series:
 *         if type(val) != type_to_check:             # <<<<<<<<<<<<<<
 *             return 0
 *     return 1
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":245
 *     1 if all elements in a series are of type type_to_check, 0 otherwise
 *     """
 *     for val in series:             # <<<<<<<<<<<<<<
 *         if type(val) != type_to_check:
 *             return 0
*/
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":248
 *         if type(val) != type_to_check:
 *             return 0
 *     return 1             # <<<<<<<<<<<<<<
 * 
 * cdef list get_narwhals_column_types(object df, dict missing_user_values, dict variable_value_labels, int dta_str_max_len):
*/
  __pyx_r = 1;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":241
 * 
 * 
 * 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_val);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":250
 *     return 1
 * 
 * cdef list get_narwhals_column_types(object df, dict missing_user_values, dict variable_value_labels, int dta_str_max_len):             # <<<<<<<<<<<<<<
 *     """
 *     From a narwhals data frame, get a list with tuples column types as first element, max_length as second, is_missing
*/

static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_get_narwhals_column_types(PyObject *__pyx_v_df, PyObject *__pyx_v_missing_user_values, PyObject *__pyx_v_variable_value_labels, int __pyx_v_dta_str_max_len) {
  int __pyx_v_max_length;
  int __pyx_v_isobject;
  int __pyx_v_has_missing;
  PyObject *__pyx_v_result = 0;
  int __pyx_v_equal;
  PyObject *__pyx_v_curseries = NULL;
  PyObject *__pyx_v_col_name = NULL;
  PyObject *__pyx_v_col_type = NULL;
  PyObject *__pyx_v_curuser_missing = NULL;
  PyTypeObject *__pyx_v_curtype = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  size_t __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_narwhals_column_types", 0);
  __Pyx_INCREF(__pyx_v_variable_value_labels);

  /* "pyreadstat/_readstat_writer.pyx":261
 *     cdef int max_length, isobject
 *     cdef bint has_missing
 *     cdef list result = list()             # <<<<<<<<<<<<<<
 *     cdef int equal, is_missing
 * 
*/
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

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

    /* "pyreadstat/_readstat_writer.pyx":265
 * 
 *     if variable_value_labels is None:
 *         variable_value_labels = dict()             # <<<<<<<<<<<<<<
 * 
 *     for curseries in df.iter_columns():
*/
    __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __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":264
 *     cdef int equal, is_missing
 * 
 *     if variable_value_labels is None:             # <<<<<<<<<<<<<<
 *         variable_value_labels = dict()
 * 
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":267
 *         variable_value_labels = dict()
 * 
 *     for curseries in df.iter_columns():             # <<<<<<<<<<<<<<
 *         col_name = curseries.name
 *         col_type = curseries.dtype
*/
  __pyx_t_3 = __pyx_v_df;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_iter_columns, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 267, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_3);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 267, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        __pyx_t_1 = __Pyx_PyList_GetItemRef(__pyx_t_3, __pyx_t_5);
        ++__pyx_t_5;
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_3);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 267, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5));
        #else
        __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_5);
        #endif
        ++__pyx_t_5;
      }
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 267, __pyx_L1_error)
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_3);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 267, __pyx_L1_error)
          PyErr_Clear();
        }
        break;
      }
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_curseries, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":268
 * 
 *     for curseries in df.iter_columns():
 *         col_name = curseries.name             # <<<<<<<<<<<<<<
 *         col_type = curseries.dtype
 * 
*/
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_col_name, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":269
 *     for curseries in df.iter_columns():
 *         col_name = curseries.name
 *         col_type = curseries.dtype             # <<<<<<<<<<<<<<
 * 
 *         # if categorical, let's use the type of the categories
*/
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_mstate_global->__pyx_n_u_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_col_type, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":272
 * 
 *         # if categorical, let's use the type of the categories
 *         if col_type == nw.Categorical:             # <<<<<<<<<<<<<<
 *             col_type = curseries.cat.get_categories().dtype
 * 
*/
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_Categorical); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":273
 *         # if categorical, let's use the type of the categories
 *         if col_type == nw.Categorical:
 *             col_type = curseries.cat.get_categories().dtype             # <<<<<<<<<<<<<<
 * 
 *         # we need to remove nulls for series inspection
*/
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curseries, __pyx_mstate_global->__pyx_n_u_cat); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 273, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __pyx_t_8;
      __Pyx_INCREF(__pyx_t_7);
      __pyx_t_4 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_get_categories, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 273, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF_SET(__pyx_v_col_type, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":272
 * 
 *         # if categorical, let's use the type of the categories
 *         if col_type == nw.Categorical:             # <<<<<<<<<<<<<<
 *             col_type = curseries.cat.get_categories().dtype
 * 
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":276
 * 
 *         # we need to remove nulls for series inspection
 *         has_missing = <bint>curseries.null_count()>0             # <<<<<<<<<<<<<<
 *         if has_missing:
 *             curseries = curseries.drop_nulls()
*/
    __pyx_t_1 = __pyx_v_curseries;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_4 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL};
      __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_null_count, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 276, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
    }
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 276, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_v_has_missing = (__pyx_t_2 > 0);

    /* "pyreadstat/_readstat_writer.pyx":277
 *         # we need to remove nulls for series inspection
 *         has_missing = <bint>curseries.null_count()>0
 *         if has_missing:             # <<<<<<<<<<<<<<
 *             curseries = curseries.drop_nulls()
 * 
*/
    if (__pyx_v_has_missing) {

      /* "pyreadstat/_readstat_writer.pyx":278
 *         has_missing = <bint>curseries.null_count()>0
 *         if has_missing:
 *             curseries = curseries.drop_nulls()             # <<<<<<<<<<<<<<
 * 
 *         # missing_user_values are strings that represent a missing value in a numeric column
*/
      __pyx_t_1 = __pyx_v_curseries;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL};
        __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_drop_nulls, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      }
      __Pyx_DECREF_SET(__pyx_v_curseries, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":277
 *         # we need to remove nulls for series inspection
 *         has_missing = <bint>curseries.null_count()>0
 *         if has_missing:             # <<<<<<<<<<<<<<
 *             curseries = curseries.drop_nulls()
 * 
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":285
 *         # missing values and missing_user_values.
 *         # we need to take out those before inspecting the object series futher
 *         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":286
 *         # we need to take out those before inspecting the object series futher
 *         curuser_missing = None
 *         if missing_user_values:             # <<<<<<<<<<<<<<
 *             curuser_missing = missing_user_values.get(col_name)
 *         if curuser_missing:
*/
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 286, __pyx_L1_error)
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":287
 *         curuser_missing = None
 *         if missing_user_values:
 *             curuser_missing = missing_user_values.get(col_name)             # <<<<<<<<<<<<<<
 *         if curuser_missing:
 *             if not df.implementation.is_pandas() and col_type == nw.Object:
*/
      if (unlikely(__pyx_v_missing_user_values == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 287, __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, 287, __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":286
 *         # we need to take out those before inspecting the object series futher
 *         curuser_missing = None
 *         if missing_user_values:             # <<<<<<<<<<<<<<
 *             curuser_missing = missing_user_values.get(col_name)
 *         if curuser_missing:
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":288
 *         if missing_user_values:
 *             curuser_missing = missing_user_values.get(col_name)
 *         if curuser_missing:             # <<<<<<<<<<<<<<
 *             if not df.implementation.is_pandas() and col_type == nw.Object:
 *                 curseries = [x for x in curseries if x not in curuser_missing]
*/
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_curuser_missing); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 288, __pyx_L1_error)
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":289
 *             curuser_missing = missing_user_values.get(col_name)
 *         if curuser_missing:
 *             if not df.implementation.is_pandas() and col_type == nw.Object:             # <<<<<<<<<<<<<<
 *                 curseries = [x for x in curseries if x not in curuser_missing]
 *             else:
*/
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_mstate_global->__pyx_n_u_implementation); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __pyx_t_7;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL};
        __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_pandas, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 289, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      }
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_10 = (!__pyx_t_9);
      if (__pyx_t_10) {
      } else {
        __pyx_t_2 = __pyx_t_10;
        goto __pyx_L11_bool_binop_done;
      }
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_Object); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_2 = __pyx_t_10;
      __pyx_L11_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":290
 *         if curuser_missing:
 *             if not df.implementation.is_pandas() and col_type == nw.Object:
 *                 curseries = [x for x in curseries if x not in curuser_missing]             # <<<<<<<<<<<<<<
 *             else:
 *                 curseries = curseries.filter(~curseries.is_in(curuser_missing))
*/
        __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (likely(PyList_CheckExact(__pyx_v_curseries)) || PyTuple_CheckExact(__pyx_v_curseries)) {
          __pyx_t_7 = __pyx_v_curseries; __Pyx_INCREF(__pyx_t_7);
          __pyx_t_11 = 0;
          __pyx_t_12 = NULL;
        } else {
          __pyx_t_11 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_curseries); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_12 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 290, __pyx_L1_error)
        }
        for (;;) {
          if (likely(!__pyx_t_12)) {
            if (likely(PyList_CheckExact(__pyx_t_7))) {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_7);
                #if !CYTHON_ASSUME_SAFE_SIZE
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 290, __pyx_L1_error)
                #endif
                if (__pyx_t_11 >= __pyx_temp) break;
              }
              __pyx_t_1 = __Pyx_PyList_GetItemRef(__pyx_t_7, __pyx_t_11);
              ++__pyx_t_11;
            } else {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_7);
                #if !CYTHON_ASSUME_SAFE_SIZE
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 290, __pyx_L1_error)
                #endif
                if (__pyx_t_11 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_11));
              #else
              __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_7, __pyx_t_11);
              #endif
              ++__pyx_t_11;
            }
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error)
          } else {
            __pyx_t_1 = __pyx_t_12(__pyx_t_7);
            if (unlikely(!__pyx_t_1)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 290, __pyx_L1_error)
                PyErr_Clear();
              }
              break;
            }
          }
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_x, __pyx_v_curuser_missing, Py_NE)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 290, __pyx_L1_error)
          if (__pyx_t_2) {
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_v_x))) __PYX_ERR(0, 290, __pyx_L1_error)
          }
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF_SET(__pyx_v_curseries, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "pyreadstat/_readstat_writer.pyx":289
 *             curuser_missing = missing_user_values.get(col_name)
 *         if curuser_missing:
 *             if not df.implementation.is_pandas() and col_type == nw.Object:             # <<<<<<<<<<<<<<
 *                 curseries = [x for x in curseries if x not in curuser_missing]
 *             else:
*/
        goto __pyx_L10;
      }

      /* "pyreadstat/_readstat_writer.pyx":292
 *                 curseries = [x for x in curseries if x not in curuser_missing]
 *             else:
 *                 curseries = curseries.filter(~curseries.is_in(curuser_missing))             # <<<<<<<<<<<<<<
 *             if not len(curseries):
 *                 result.append((PYWRITER_DOUBLE, 0, 1, None))
*/
      /*else*/ {
        __pyx_t_7 = __pyx_v_curseries;
        __Pyx_INCREF(__pyx_t_7);
        __pyx_t_13 = __pyx_v_curseries;
        __Pyx_INCREF(__pyx_t_13);
        __pyx_t_4 = 0;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_v_curuser_missing};
          __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_in, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
        }
        __pyx_t_13 = PyNumber_Invert(__pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_4 = 0;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_13};
          __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_filter, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_DECREF_SET(__pyx_v_curseries, __pyx_t_8);
        __pyx_t_8 = 0;
      }
      __pyx_L10:;

      /* "pyreadstat/_readstat_writer.pyx":293
 *             else:
 *                 curseries = curseries.filter(~curseries.is_in(curuser_missing))
 *             if not len(curseries):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DOUBLE, 0, 1, None))
 *                 continue
*/
      __pyx_t_11 = PyObject_Length(__pyx_v_curseries); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 293, __pyx_L1_error)
      __pyx_t_2 = (!(__pyx_t_11 != 0));
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":294
 *                 curseries = curseries.filter(~curseries.is_in(curuser_missing))
 *             if not len(curseries):
 *                 result.append((PYWRITER_DOUBLE, 0, 1, None))             # <<<<<<<<<<<<<<
 *                 continue
 * 
*/
        __pyx_t_8 = __Pyx_PyLong_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, 294, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 294, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_8);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_8) != (0)) __PYX_ERR(0, 294, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 294, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_1);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_1);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_mstate_global->__pyx_int_1) != (0)) __PYX_ERR(0, 294, __pyx_L1_error);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 3, Py_None) != (0)) __PYX_ERR(0, 294, __pyx_L1_error);
        __pyx_t_8 = 0;
        __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 294, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

        /* "pyreadstat/_readstat_writer.pyx":295
 *             if not len(curseries):
 *                 result.append((PYWRITER_DOUBLE, 0, 1, None))
 *                 continue             # <<<<<<<<<<<<<<
 * 
 *         max_length = 0
*/
        goto __pyx_L4_continue;

        /* "pyreadstat/_readstat_writer.pyx":293
 *             else:
 *                 curseries = curseries.filter(~curseries.is_in(curuser_missing))
 *             if not len(curseries):             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DOUBLE, 0, 1, None))
 *                 continue
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":288
 *         if missing_user_values:
 *             curuser_missing = missing_user_values.get(col_name)
 *         if curuser_missing:             # <<<<<<<<<<<<<<
 *             if not df.implementation.is_pandas() and col_type == nw.Object:
 *                 curseries = [x for x in curseries if x not in curuser_missing]
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":297
 *                 continue
 * 
 *         max_length = 0             # <<<<<<<<<<<<<<
 *         curtype = None
 *         equal = True
*/
    __pyx_v_max_length = 0;

    /* "pyreadstat/_readstat_writer.pyx":298
 * 
 *         max_length = 0
 *         curtype = None             # <<<<<<<<<<<<<<
 *         equal = True
 *         # let's deal first with object type, Enum could also be anything
*/
    __Pyx_INCREF(Py_None);
    __Pyx_XDECREF_SET(__pyx_v_curtype, ((PyTypeObject*)Py_None));

    /* "pyreadstat/_readstat_writer.pyx":299
 *         max_length = 0
 *         curtype = None
 *         equal = True             # <<<<<<<<<<<<<<
 *         # let's deal first with object type, Enum could also be anything
 *         if col_type == nw.Object or col_type==nw.Enum:
*/
    __pyx_v_equal = 1;

    /* "pyreadstat/_readstat_writer.pyx":301
 *         equal = True
 *         # let's deal first with object type, Enum could also be anything
 *         if col_type == nw.Object or col_type==nw.Enum:             # <<<<<<<<<<<<<<
 *             curtype = type(curseries[0])
 *             equal = check_series_all_same_types(curseries, curtype)
*/
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_Object); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (!__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L19_bool_binop_done;
    }
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_Enum); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_2 = __pyx_t_10;
    __pyx_L19_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":302
 *         # let's deal first with object type, Enum could also be anything
 *         if col_type == nw.Object or col_type==nw.Enum:
 *             curtype = type(curseries[0])             # <<<<<<<<<<<<<<
 *             equal = check_series_all_same_types(curseries, curtype)
 *             # if all elements are equal, they could be a few we expect to be an object class
*/
      __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_curseries, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_13)));
      __Pyx_DECREF_SET(__pyx_v_curtype, ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_t_13))));
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

      /* "pyreadstat/_readstat_writer.pyx":303
 *         if col_type == nw.Object or col_type==nw.Enum:
 *             curtype = type(curseries[0])
 *             equal = check_series_all_same_types(curseries, curtype)             # <<<<<<<<<<<<<<
 *             # if all elements are equal, they could be a few we expect to be an object class
 *             # or it could be that they are some other common types (numeric) after removing the missing_user_values
*/
      __pyx_t_15 = __pyx_f_10pyreadstat_16_readstat_writer_check_series_all_same_types(__pyx_v_curseries, ((PyObject *)__pyx_v_curtype)); if (unlikely(__pyx_t_15 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 303, __pyx_L1_error)
      __pyx_v_equal = __pyx_t_15;

      /* "pyreadstat/_readstat_writer.pyx":309
 *             # if not all the elements of the series are from the same type, then we deal with it at the end
 *             # as other types we don't know what to do with
 *             if equal:             # <<<<<<<<<<<<<<
 *                 # types expected to be object
 *                 if curtype == datetime.date:
*/
      __pyx_t_2 = (__pyx_v_equal != 0);
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":311
 *             if equal:
 *                 # types expected to be object
 *                 if curtype == datetime.date:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_DATE, 0, has_missing, None))
 *                     continue
*/
        __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 311, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_date); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 311, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 311, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 311, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (__pyx_t_2) {

          /* "pyreadstat/_readstat_writer.pyx":312
 *                 # types expected to be object
 *                 if curtype == datetime.date:
 *                     result.append((PYWRITER_DATE, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *                     continue
 *                 elif curtype == datetime.datetime:
*/
          __pyx_t_13 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 312, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 312, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 312, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_13);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13) != (0)) __PYX_ERR(0, 312, __pyx_L1_error);
          __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
          __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 312, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_8);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 312, __pyx_L1_error);
          __Pyx_INCREF(Py_None);
          __Pyx_GIVEREF(Py_None);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 3, Py_None) != (0)) __PYX_ERR(0, 312, __pyx_L1_error);
          __pyx_t_13 = 0;
          __pyx_t_8 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 312, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "pyreadstat/_readstat_writer.pyx":313
 *                 if curtype == datetime.date:
 *                     result.append((PYWRITER_DATE, 0, has_missing, None))
 *                     continue             # <<<<<<<<<<<<<<
 *                 elif curtype == datetime.datetime:
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))
*/
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":311
 *             if equal:
 *                 # types expected to be object
 *                 if curtype == datetime.date:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_DATE, 0, has_missing, None))
 *                     continue
*/
        }

        /* "pyreadstat/_readstat_writer.pyx":314
 *                     result.append((PYWRITER_DATE, 0, has_missing, None))
 *                     continue
 *                 elif curtype == datetime.datetime:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                     continue
*/
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 314, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 314, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__pyx_t_2) {

          /* "pyreadstat/_readstat_writer.pyx":315
 *                     continue
 *                 elif curtype == datetime.datetime:
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *                     continue
 *                 elif curtype == datetime.time:
*/
          __pyx_t_7 = __Pyx_PyLong_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, 315, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 315, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 315, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_7);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_7) != (0)) __PYX_ERR(0, 315, __pyx_L1_error);
          __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
          __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 315, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_8);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 315, __pyx_L1_error);
          __Pyx_INCREF(Py_None);
          __Pyx_GIVEREF(Py_None);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 3, Py_None) != (0)) __PYX_ERR(0, 315, __pyx_L1_error);
          __pyx_t_7 = 0;
          __pyx_t_8 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 315, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

          /* "pyreadstat/_readstat_writer.pyx":316
 *                 elif curtype == datetime.datetime:
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                     continue             # <<<<<<<<<<<<<<
 *                 elif curtype == datetime.time:
 *                     result.append((PYWRITER_TIME, 0, has_missing, None))
*/
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":314
 *                     result.append((PYWRITER_DATE, 0, has_missing, None))
 *                     continue
 *                 elif curtype == datetime.datetime:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                     continue
*/
        }

        /* "pyreadstat/_readstat_writer.pyx":317
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                     continue
 *                 elif curtype == datetime.time:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_TIME, 0, has_missing, None))
 *                     continue
*/
        __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (__pyx_t_2) {

          /* "pyreadstat/_readstat_writer.pyx":318
 *                     continue
 *                 elif curtype == datetime.time:
 *                     result.append((PYWRITER_TIME, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *                     continue
 * 
*/
          __pyx_t_13 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 318, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 318, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_13);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13) != (0)) __PYX_ERR(0, 318, __pyx_L1_error);
          __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
          __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 318, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_8);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 318, __pyx_L1_error);
          __Pyx_INCREF(Py_None);
          __Pyx_GIVEREF(Py_None);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 3, Py_None) != (0)) __PYX_ERR(0, 318, __pyx_L1_error);
          __pyx_t_13 = 0;
          __pyx_t_8 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 318, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "pyreadstat/_readstat_writer.pyx":319
 *                 elif curtype == datetime.time:
 *                     result.append((PYWRITER_TIME, 0, has_missing, None))
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *         # numeric types: they could contain missing_user_values
*/
          goto __pyx_L4_continue;

          /* "pyreadstat/_readstat_writer.pyx":317
 *                     result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                     continue
 *                 elif curtype == datetime.time:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_TIME, 0, has_missing, None))
 *                     continue
*/
        }

        /* "pyreadstat/_readstat_writer.pyx":309
 *             # if not all the elements of the series are from the same type, then we deal with it at the end
 *             # as other types we don't know what to do with
 *             if equal:             # <<<<<<<<<<<<<<
 *                 # types expected to be object
 *                 if curtype == datetime.date:
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":301
 *         equal = True
 *         # let's deal first with object type, Enum could also be anything
 *         if col_type == nw.Object or col_type==nw.Enum:             # <<<<<<<<<<<<<<
 *             curtype = type(curseries[0])
 *             equal = check_series_all_same_types(curseries, curtype)
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":322
 * 
 *         # numeric types: they could contain missing_user_values
 *         if equal and (col_type in float_types or curtype == float):             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_DOUBLE, 0, has_missing, None))
 *             continue
*/
    __pyx_t_10 = (__pyx_v_equal != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L24_bool_binop_done;
    }
    if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_float_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 322, __pyx_L1_error)
    }
    __pyx_t_10 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_float_types, Py_EQ)); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 322, __pyx_L1_error)
    if (!__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L24_bool_binop_done;
    }
    __pyx_t_7 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), ((PyObject *)(&PyFloat_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 322, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 322, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __pyx_t_10;
    __pyx_L24_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":323
 *         # numeric types: they could contain missing_user_values
 *         if equal and (col_type in float_types or curtype == float):
 *             result.append((PYWRITER_DOUBLE, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *             continue
 *         elif equal and (col_type in int_types or curtype == int):
*/
      __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_7) != (0)) __PYX_ERR(0, 323, __pyx_L1_error);
      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 323, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_8);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 323, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 3, Py_None) != (0)) __PYX_ERR(0, 323, __pyx_L1_error);
      __pyx_t_7 = 0;
      __pyx_t_8 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 323, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

      /* "pyreadstat/_readstat_writer.pyx":324
 *         if equal and (col_type in float_types or curtype == float):
 *             result.append((PYWRITER_DOUBLE, 0, has_missing, None))
 *             continue             # <<<<<<<<<<<<<<
 *         elif equal and (col_type in int_types or curtype == int):
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))
*/
      goto __pyx_L4_continue;

      /* "pyreadstat/_readstat_writer.pyx":322
 * 
 *         # numeric types: they could contain missing_user_values
 *         if equal and (col_type in float_types or curtype == float):             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_DOUBLE, 0, has_missing, None))
 *             continue
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":325
 *             result.append((PYWRITER_DOUBLE, 0, has_missing, None))
 *             continue
 *         elif equal and (col_type in int_types or curtype == int):             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))
 *             continue
*/
    __pyx_t_10 = (__pyx_v_equal != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L27_bool_binop_done;
    }
    if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_int_types == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 325, __pyx_L1_error)
    }
    __pyx_t_10 = (__Pyx_PySet_ContainsTF(__pyx_v_col_type, __pyx_v_10pyreadstat_16_readstat_writer_int_types, Py_EQ)); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 325, __pyx_L1_error)
    if (!__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L27_bool_binop_done;
    }
    __pyx_t_13 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), ((PyObject *)(&PyLong_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 325, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 325, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_2 = __pyx_t_10;
    __pyx_L27_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":326
 *             continue
 *         elif equal and (col_type in int_types or curtype == int):
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))             # <<<<<<<<<<<<<<
 *             continue
 *         elif equal and (col_type == nw.Boolean or curtype == bool):
*/
      __pyx_t_13 = __Pyx_PyLong_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, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_13);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13) != (0)) __PYX_ERR(0, 326, __pyx_L1_error);
      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 326, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_8);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 326, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 3, Py_None) != (0)) __PYX_ERR(0, 326, __pyx_L1_error);
      __pyx_t_13 = 0;
      __pyx_t_8 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pyreadstat/_readstat_writer.pyx":327
 *         elif equal and (col_type in int_types or curtype == int):
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))
 *             continue             # <<<<<<<<<<<<<<
 *         elif equal and (col_type == nw.Boolean or curtype == bool):
 *             result.append((PYWRITER_LOGICAL, 0,has_missing, None))
*/
      goto __pyx_L4_continue;

      /* "pyreadstat/_readstat_writer.pyx":325
 *             result.append((PYWRITER_DOUBLE, 0, has_missing, None))
 *             continue
 *         elif equal and (col_type in int_types or curtype == int):             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))
 *             continue
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":328
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))
 *             continue
 *         elif equal and (col_type == nw.Boolean or curtype == bool):             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_LOGICAL, 0,has_missing, None))
 *             continue
*/
    __pyx_t_10 = (__pyx_v_equal != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L30_bool_binop_done;
    }
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_Boolean); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 328, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 328, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L30_bool_binop_done;
    }
    __pyx_t_7 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), ((PyObject*)&PyBool_Type), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 328, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 328, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __pyx_t_10;
    __pyx_L30_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":329
 *             continue
 *         elif equal and (col_type == nw.Boolean or curtype == bool):
 *             result.append((PYWRITER_LOGICAL, 0,has_missing, None))             # <<<<<<<<<<<<<<
 *             continue
 *         # these types here should not contain missing_user_values,
*/
      __pyx_t_7 = __Pyx_PyLong_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, 329, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 329, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 329, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_7) != (0)) __PYX_ERR(0, 329, __pyx_L1_error);
      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 329, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_8);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 329, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 3, Py_None) != (0)) __PYX_ERR(0, 329, __pyx_L1_error);
      __pyx_t_7 = 0;
      __pyx_t_8 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 329, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

      /* "pyreadstat/_readstat_writer.pyx":330
 *         elif equal and (col_type == nw.Boolean or curtype == bool):
 *             result.append((PYWRITER_LOGICAL, 0,has_missing, None))
 *             continue             # <<<<<<<<<<<<<<
 *         # these types here should not contain missing_user_values,
 *         # for string we still check, as later we will raise an error
*/
      goto __pyx_L4_continue;

      /* "pyreadstat/_readstat_writer.pyx":328
 *             result.append((PYWRITER_INTEGER, 0,has_missing, None))
 *             continue
 *         elif equal and (col_type == nw.Boolean or curtype == bool):             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_LOGICAL, 0,has_missing, None))
 *             continue
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":333
 *         # these types here should not contain missing_user_values,
 *         # for string we still check, as later we will raise an error
 *         elif col_type == nw.String or curtype == str:             # <<<<<<<<<<<<<<
 *             isobject = 0
 *             if not equal:
*/
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_String); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (!__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L33_bool_binop_done;
    }
    __pyx_t_13 = PyObject_RichCompare(((PyObject *)__pyx_v_curtype), ((PyObject *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 333, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_2 = __pyx_t_10;
    __pyx_L33_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":334
 *         # for string we still check, as later we will raise an error
 *         elif col_type == nw.String or curtype == str:
 *             isobject = 0             # <<<<<<<<<<<<<<
 *             if not equal:
 *                 isobject = 1
*/
      __pyx_v_isobject = 0;

      /* "pyreadstat/_readstat_writer.pyx":335
 *         elif col_type == nw.String or curtype == str:
 *             isobject = 0
 *             if not equal:             # <<<<<<<<<<<<<<
 *                 isobject = 1
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)
*/
      __pyx_t_2 = (!(__pyx_v_equal != 0));
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":336
 *             isobject = 0
 *             if not equal:
 *                 isobject = 1             # <<<<<<<<<<<<<<
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)
 *             if dta_str_max_len and max_length >= dta_str_max_len:
*/
        __pyx_v_isobject = 1;

        /* "pyreadstat/_readstat_writer.pyx":335
 *         elif col_type == nw.String or curtype == str:
 *             isobject = 0
 *             if not equal:             # <<<<<<<<<<<<<<
 *                 isobject = 1
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":337
 *             if not equal:
 *                 isobject = 1
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)             # <<<<<<<<<<<<<<
 *             if dta_str_max_len and max_length >= dta_str_max_len:
 *                 result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
*/
      if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 337, __pyx_L1_error)
      }
      __pyx_t_13 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      if (!(likely(PyDict_CheckExact(__pyx_t_13))||((__pyx_t_13) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_13))) __PYX_ERR(0, 337, __pyx_L1_error)
      __pyx_t_15 = __pyx_f_10pyreadstat_16_readstat_writer_get_narwhals_str_series_max_length(__pyx_v_curseries, ((PyObject*)__pyx_t_13), __pyx_v_isobject); if (unlikely(__pyx_t_15 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 337, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_v_max_length = __pyx_t_15;

      /* "pyreadstat/_readstat_writer.pyx":338
 *                 isobject = 1
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)
 *             if dta_str_max_len and max_length >= dta_str_max_len:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
 *                 continue
*/
      __pyx_t_10 = (__pyx_v_dta_str_max_len != 0);
      if (__pyx_t_10) {
      } else {
        __pyx_t_2 = __pyx_t_10;
        goto __pyx_L37_bool_binop_done;
      }
      __pyx_t_10 = (__pyx_v_max_length >= __pyx_v_dta_str_max_len);
      __pyx_t_2 = __pyx_t_10;
      __pyx_L37_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":339
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)
 *             if dta_str_max_len and max_length >= dta_str_max_len:
 *                 result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))             # <<<<<<<<<<<<<<
 *                 continue
 *             else:
*/
        __pyx_t_13 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_8 = __Pyx_PyLong_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_13);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_13) != (0)) __PYX_ERR(0, 339, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_8);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8) != (0)) __PYX_ERR(0, 339, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_7);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 339, __pyx_L1_error);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None) != (0)) __PYX_ERR(0, 339, __pyx_L1_error);
        __pyx_t_13 = 0;
        __pyx_t_8 = 0;
        __pyx_t_7 = 0;
        __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":340
 *             if dta_str_max_len and max_length >= dta_str_max_len:
 *                 result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
 *                 continue             # <<<<<<<<<<<<<<
 *             else:
 *                 if isobject:
*/
        goto __pyx_L4_continue;

        /* "pyreadstat/_readstat_writer.pyx":338
 *                 isobject = 1
 *             max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), isobject)
 *             if dta_str_max_len and max_length >= dta_str_max_len:             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
 *                 continue
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":342
 *                 continue
 *             else:
 *                 if isobject:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_OBJECT, max_length, has_missing, None))
 *                 else:
*/
      /*else*/ {
        __pyx_t_2 = (__pyx_v_isobject != 0);
        if (__pyx_t_2) {

          /* "pyreadstat/_readstat_writer.pyx":343
 *             else:
 *                 if isobject:
 *                     result.append((PYWRITER_OBJECT, max_length, has_missing, None))             # <<<<<<<<<<<<<<
 *                 else:
 *                     result.append((PYWRITER_CHARACTER, max_length, has_missing, None))
*/
          __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 343, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 343, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 343, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_1);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 343, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_7);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_7) != (0)) __PYX_ERR(0, 343, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_8);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 343, __pyx_L1_error);
          __Pyx_INCREF(Py_None);
          __Pyx_GIVEREF(Py_None);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 3, Py_None) != (0)) __PYX_ERR(0, 343, __pyx_L1_error);
          __pyx_t_1 = 0;
          __pyx_t_7 = 0;
          __pyx_t_8 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 343, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

          /* "pyreadstat/_readstat_writer.pyx":342
 *                 continue
 *             else:
 *                 if isobject:             # <<<<<<<<<<<<<<
 *                     result.append((PYWRITER_OBJECT, max_length, has_missing, None))
 *                 else:
*/
          goto __pyx_L39;
        }

        /* "pyreadstat/_readstat_writer.pyx":345
 *                     result.append((PYWRITER_OBJECT, max_length, has_missing, None))
 *                 else:
 *                     result.append((PYWRITER_CHARACTER, max_length, has_missing, None))             # <<<<<<<<<<<<<<
 *                 continue
 *         elif col_type == nw.Datetime:
*/
        /*else*/ {
          __pyx_t_13 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 345, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_8 = __Pyx_PyLong_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 345, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 345, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_13);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_13) != (0)) __PYX_ERR(0, 345, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_8);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8) != (0)) __PYX_ERR(0, 345, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_7);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 345, __pyx_L1_error);
          __Pyx_INCREF(Py_None);
          __Pyx_GIVEREF(Py_None);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None) != (0)) __PYX_ERR(0, 345, __pyx_L1_error);
          __pyx_t_13 = 0;
          __pyx_t_8 = 0;
          __pyx_t_7 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 345, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __pyx_L39:;

        /* "pyreadstat/_readstat_writer.pyx":346
 *                 else:
 *                     result.append((PYWRITER_CHARACTER, max_length, has_missing, None))
 *                 continue             # <<<<<<<<<<<<<<
 *         elif col_type == nw.Datetime:
 *             if col_type.time_unit == 'us':
*/
        goto __pyx_L4_continue;
      }

      /* "pyreadstat/_readstat_writer.pyx":333
 *         # these types here should not contain missing_user_values,
 *         # for string we still check, as later we will raise an error
 *         elif col_type == nw.String or curtype == str:             # <<<<<<<<<<<<<<
 *             isobject = 0
 *             if not equal:
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":347
 *                     result.append((PYWRITER_CHARACTER, max_length, has_missing, None))
 *                 continue
 *         elif col_type == nw.Datetime:             # <<<<<<<<<<<<<<
 *             if col_type.time_unit == 'us':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
*/
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_Datetime); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":348
 *                 continue
 *         elif col_type == nw.Datetime:
 *             if col_type.time_unit == 'us':             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
 *                 continue
*/
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_col_type, __pyx_mstate_global->__pyx_n_u_time_unit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 348, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_us, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 348, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":349
 *         elif col_type == nw.Datetime:
 *             if col_type.time_unit == 'us':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))             # <<<<<<<<<<<<<<
 *                 continue
 *             elif col_type.time_unit == 'ns':
*/
        __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 349, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 349, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_1);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 349, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 349, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_7);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 349, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_us);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_n_u_us);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_mstate_global->__pyx_n_u_us) != (0)) __PYX_ERR(0, 349, __pyx_L1_error);
        __pyx_t_1 = 0;
        __pyx_t_7 = 0;
        __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 349, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pyreadstat/_readstat_writer.pyx":350
 *             if col_type.time_unit == 'us':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
 *                 continue             # <<<<<<<<<<<<<<
 *             elif col_type.time_unit == 'ns':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))
*/
        goto __pyx_L4_continue;

        /* "pyreadstat/_readstat_writer.pyx":348
 *                 continue
 *         elif col_type == nw.Datetime:
 *             if col_type.time_unit == 'us':             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
 *                 continue
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":351
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
 *                 continue
 *             elif col_type.time_unit == 'ns':             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))
 *                 continue
*/
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_col_type, __pyx_mstate_global->__pyx_n_u_time_unit); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 351, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_ns, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 351, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":352
 *                 continue
 *             elif col_type.time_unit == 'ns':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))             # <<<<<<<<<<<<<<
 *                 continue
 *             elif col_type.time_unit == 'ms':
*/
        __pyx_t_8 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_8);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8) != (0)) __PYX_ERR(0, 352, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 352, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_7);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 352, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_ns);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_n_u_ns);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_mstate_global->__pyx_n_u_ns) != (0)) __PYX_ERR(0, 352, __pyx_L1_error);
        __pyx_t_8 = 0;
        __pyx_t_7 = 0;
        __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 352, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":353
 *             elif col_type.time_unit == 'ns':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))
 *                 continue             # <<<<<<<<<<<<<<
 *             elif col_type.time_unit == 'ms':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ms'))
*/
        goto __pyx_L4_continue;

        /* "pyreadstat/_readstat_writer.pyx":351
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
 *                 continue
 *             elif col_type.time_unit == 'ns':             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))
 *                 continue
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":354
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))
 *                 continue
 *             elif col_type.time_unit == 'ms':             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ms'))
 *                 continue
*/
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_col_type, __pyx_mstate_global->__pyx_n_u_time_unit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 354, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_ms, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 354, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_2) {

        /* "pyreadstat/_readstat_writer.pyx":355
 *                 continue
 *             elif col_type.time_unit == 'ms':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ms'))             # <<<<<<<<<<<<<<
 *                 continue
 *             else:
*/
        __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_1);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 355, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 355, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_7);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 355, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_ms);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_n_u_ms);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_mstate_global->__pyx_n_u_ms) != (0)) __PYX_ERR(0, 355, __pyx_L1_error);
        __pyx_t_1 = 0;
        __pyx_t_7 = 0;
        __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pyreadstat/_readstat_writer.pyx":356
 *             elif col_type.time_unit == 'ms':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ms'))
 *                 continue             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, has_missing, None))
*/
        goto __pyx_L4_continue;

        /* "pyreadstat/_readstat_writer.pyx":354
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ns'))
 *                 continue
 *             elif col_type.time_unit == 'ms':             # <<<<<<<<<<<<<<
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'ms'))
 *                 continue
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":358
 *                 continue
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *                 continue
 *         elif col_type == nw.Date:
*/
      /*else*/ {
        __pyx_t_8 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_8);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8) != (0)) __PYX_ERR(0, 358, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 358, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_7);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 358, __pyx_L1_error);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None) != (0)) __PYX_ERR(0, 358, __pyx_L1_error);
        __pyx_t_8 = 0;
        __pyx_t_7 = 0;
        __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":359
 *             else:
 *                 result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                 continue             # <<<<<<<<<<<<<<
 *         elif col_type == nw.Date:
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))
*/
        goto __pyx_L4_continue;
      }

      /* "pyreadstat/_readstat_writer.pyx":347
 *                     result.append((PYWRITER_CHARACTER, max_length, has_missing, None))
 *                 continue
 *         elif col_type == nw.Datetime:             # <<<<<<<<<<<<<<
 *             if col_type.time_unit == 'us':
 *                 result.append((PYWRITER_DATETIME64, 0,has_missing, 'us'))
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":360
 *                 result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                 continue
 *         elif col_type == nw.Date:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))
 *             continue
*/
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_Date); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 360, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":361
 *                 continue
 *         elif col_type == nw.Date:
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *             continue
 *         elif col_type == nw.Time:
*/
      __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_1);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 361, __pyx_L1_error);
      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 361, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 361, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 3, Py_None) != (0)) __PYX_ERR(0, 361, __pyx_L1_error);
      __pyx_t_1 = 0;
      __pyx_t_7 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 361, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":362
 *         elif col_type == nw.Date:
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))
 *             continue             # <<<<<<<<<<<<<<
 *         elif col_type == nw.Time:
 *             result.append((PYWRITER_TIME64, 0, has_missing, None))
*/
      goto __pyx_L4_continue;

      /* "pyreadstat/_readstat_writer.pyx":360
 *                 result.append((PYWRITER_DATETIME, 0, has_missing, None))
 *                 continue
 *         elif col_type == nw.Date:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))
 *             continue
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":363
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))
 *             continue
 *         elif col_type == nw.Time:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_TIME64, 0, has_missing, None))
 *             continue
*/
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_Time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_RichCompare(__pyx_v_col_type, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":364
 *             continue
 *         elif col_type == nw.Time:
 *             result.append((PYWRITER_TIME64, 0, has_missing, None))             # <<<<<<<<<<<<<<
 *             continue
 * 
*/
      __pyx_t_8 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_8);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8) != (0)) __PYX_ERR(0, 364, __pyx_L1_error);
      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 364, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 364, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None) != (0)) __PYX_ERR(0, 364, __pyx_L1_error);
      __pyx_t_8 = 0;
      __pyx_t_7 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 364, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyreadstat/_readstat_writer.pyx":365
 *         elif col_type == nw.Time:
 *             result.append((PYWRITER_TIME64, 0, has_missing, None))
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         # if the object was not captured by any of the previous cases, we transform it to string
*/
      goto __pyx_L4_continue;

      /* "pyreadstat/_readstat_writer.pyx":363
 *             result.append((PYWRITER_DATE64, 0, has_missing, None))
 *             continue
 *         elif col_type == nw.Time:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_TIME64, 0, has_missing, None))
 *             continue
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":368
 * 
 *         # if the object was not captured by any of the previous cases, we transform it to string
 *         max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), 1)             # <<<<<<<<<<<<<<
 *         if dta_str_max_len and max_length >= dta_str_max_len:
 *             result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
*/
    if (unlikely(__pyx_v_variable_value_labels == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
      __PYX_ERR(0, 368, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_col_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_1))) __PYX_ERR(0, 368, __pyx_L1_error)
    __pyx_t_15 = __pyx_f_10pyreadstat_16_readstat_writer_get_narwhals_str_series_max_length(__pyx_v_curseries, ((PyObject*)__pyx_t_1), 1); if (unlikely(__pyx_t_15 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 368, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_max_length = __pyx_t_15;

    /* "pyreadstat/_readstat_writer.pyx":369
 *         # if the object was not captured by any of the previous cases, we transform it to string
 *         max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), 1)
 *         if dta_str_max_len and max_length >= dta_str_max_len:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
 *         else:
*/
    __pyx_t_10 = (__pyx_v_dta_str_max_len != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_2 = __pyx_t_10;
      goto __pyx_L42_bool_binop_done;
    }
    __pyx_t_10 = (__pyx_v_max_length >= __pyx_v_dta_str_max_len);
    __pyx_t_2 = __pyx_t_10;
    __pyx_L42_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":370
 *         max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), 1)
 *         if dta_str_max_len and max_length >= dta_str_max_len:
 *             result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))             # <<<<<<<<<<<<<<
 *         else:
 *             result.append((PYWRITER_OBJECT, max_length, has_missing, None))
*/
      __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_1);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 370, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_7) != (0)) __PYX_ERR(0, 370, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_8);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_8) != (0)) __PYX_ERR(0, 370, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_13, 3, Py_None) != (0)) __PYX_ERR(0, 370, __pyx_L1_error);
      __pyx_t_1 = 0;
      __pyx_t_7 = 0;
      __pyx_t_8 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_13); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

      /* "pyreadstat/_readstat_writer.pyx":369
 *         # if the object was not captured by any of the previous cases, we transform it to string
 *         max_length = get_narwhals_str_series_max_length(curseries, variable_value_labels.get(col_name), 1)
 *         if dta_str_max_len and max_length >= dta_str_max_len:             # <<<<<<<<<<<<<<
 *             result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
 *         else:
*/
      goto __pyx_L41;
    }

    /* "pyreadstat/_readstat_writer.pyx":372
 *             result.append((PYWRITER_DTA_STR_REF, max_length, has_missing, None))
 *         else:
 *             result.append((PYWRITER_OBJECT, max_length, has_missing, None))             # <<<<<<<<<<<<<<
 *         continue
 * 
*/
    /*else*/ {
      __pyx_t_13 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_8 = __Pyx_PyLong_From_int(__pyx_v_max_length); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_has_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_13);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_13) != (0)) __PYX_ERR(0, 372, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_8);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8) != (0)) __PYX_ERR(0, 372, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7) != (0)) __PYX_ERR(0, 372, __pyx_L1_error);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None) != (0)) __PYX_ERR(0, 372, __pyx_L1_error);
      __pyx_t_13 = 0;
      __pyx_t_8 = 0;
      __pyx_t_7 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __pyx_L41:;

    /* "pyreadstat/_readstat_writer.pyx":373
 *         else:
 *             result.append((PYWRITER_OBJECT, max_length, has_missing, None))
 *         continue             # <<<<<<<<<<<<<<
 * 
 *     return result
*/
    goto __pyx_L4_continue;

    /* "pyreadstat/_readstat_writer.pyx":267
 *         variable_value_labels = dict()
 * 
 *     for curseries in df.iter_columns():             # <<<<<<<<<<<<<<
 *         col_name = curseries.name
 *         col_type = curseries.dtype
*/
    __pyx_L4_continue:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":375
 *         continue
 * 
 *     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":250
 *     return 1
 * 
 * cdef list get_narwhals_column_types(object df, dict missing_user_values, dict variable_value_labels, int dta_str_max_len):             # <<<<<<<<<<<<<<
 *     """
 *     From a narwhals data frame, get a list with tuples column types as first element, max_length as second, is_missing
*/

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.get_narwhals_column_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_curseries);
  __Pyx_XDECREF(__pyx_v_col_name);
  __Pyx_XDECREF(__pyx_v_col_type);
  __Pyx_XDECREF(__pyx_v_curuser_missing);
  __Pyx_XDECREF((PyObject *)__pyx_v_curtype);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_variable_value_labels);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":377
 *     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;
  PyObject *__pyx_t_12[5];
  size_t __pyx_t_13;
  int __pyx_t_14;
  long __pyx_t_15;
  char const *__pyx_t_16;
  double __pyx_t_17;
  char const *__pyx_t_18;
  int32_t __pyx_t_19;
  char const *__pyx_t_20;
  char const *__pyx_t_21;
  char const *__pyx_t_22;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_value_label", 0);

  /* "pyreadstat/_readstat_writer.pyx":388
 *     cdef double double_val
 * 
 *     curtype = narwhals_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_narwhals_to_readstat_types == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 388, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curpytype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_10pyreadstat_16_readstat_writer_narwhals_to_readstat_types, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((readstat_type_t)__Pyx_PyLong_As_readstat_type_t(__pyx_t_2)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 388, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_curtype = __pyx_t_3;

  /* "pyreadstat/_readstat_writer.pyx":389
 * 
 *     curtype = narwhals_to_readstat_types[curpytype]
 *     label_set = readstat_add_label_set(writer, curtype, labelset_name.encode("utf-8"))             # <<<<<<<<<<<<<<
 * 
 *     for value, label in value_labels.items():
*/
  if (unlikely(__pyx_v_labelset_name == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
    __PYX_ERR(0, 389, __pyx_L1_error)
  }
  __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_labelset_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_t_2); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 389, __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":391
 *     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, 391, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_value_labels); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __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, 391, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 391, __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))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 391, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_1, __pyx_t_5);
        ++__pyx_t_5;
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 391, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5));
        #else
        __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5);
        #endif
        ++__pyx_t_5;
      }
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __pyx_L1_error)
    } else {
      __pyx_t_2 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 391, __pyx_L1_error)
          PyErr_Clear();
        }
        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, 391, __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_INCREF(__pyx_t_7);
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1);
        __Pyx_INCREF(__pyx_t_8);
      } else {
        __pyx_t_7 = __Pyx_PyList_GetItemRef(sequence, 0);
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 391, __pyx_L1_error)
        __Pyx_XGOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyList_GetItemRef(sequence, 1);
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 391, __pyx_L1_error)
        __Pyx_XGOTREF(__pyx_t_8);
      }
      #else
      __pyx_t_7 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 391, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 391, __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, 391, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 391, __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, 391, __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":393
 *     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 *)(&PyUnicode_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 393, __pyx_L1_error)
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 393, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(__pyx_t_11)) {

      /* "pyreadstat/_readstat_writer.pyx":394
 * 
 *         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_Unicode(__pyx_v_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = __Pyx_PyUnicode_Unicode(__pyx_v_variable_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_variable_value_labels_type_of_La;
      __pyx_t_12[1] = __pyx_t_2;
      __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_in_variable;
      __pyx_t_12[3] = __pyx_t_8;
      __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u_must_be_string;
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 13 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8) + 15, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8));
      if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_v_msg = ((PyObject*)__pyx_t_7);
      __pyx_t_7 = 0;

      /* "pyreadstat/_readstat_writer.pyx":395
 *         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_t_8 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_13 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2);
        assert(__pyx_t_8);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
        __pyx_t_13 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
        __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 395, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
      }
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 395, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":393
 *     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":397
 *             raise PyreadstatError(msg)
 * 
 *         if user_missing_tags and value in user_missing_tags:             # <<<<<<<<<<<<<<
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name
*/
    __pyx_t_14 = (__pyx_v_user_missing_tags != Py_None)&&(__Pyx_PyList_GET_SIZE(__pyx_v_user_missing_tags) != 0);
    if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_14 < 0))) __PYX_ERR(0, 397, __pyx_L1_error)
    if (__pyx_t_14) {
    } else {
      __pyx_t_11 = __pyx_t_14;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_14 = (__Pyx_PySequence_ContainsTF(__pyx_v_value, __pyx_v_user_missing_tags, Py_EQ)); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 397, __pyx_L1_error)
    __pyx_t_11 = __pyx_t_14;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_11) {

      /* "pyreadstat/_readstat_writer.pyx":398
 * 
 *         if user_missing_tags and value in user_missing_tags:
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                 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:
        case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF:

        /* "pyreadstat/_readstat_writer.pyx":399
 *         if user_missing_tags and value in user_missing_tags:
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:
 *                 msg = "missing_user_values not allowed for character variable %s" % variable_name             # <<<<<<<<<<<<<<
 *                 raise PyreadstatError(msg)
 * 
*/
        __pyx_t_7 = PyUnicode_Format(__pyx_mstate_global->__pyx_kp_u_missing_user_values_not_allowed, __pyx_v_variable_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 399, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_v_msg = ((PyObject*)__pyx_t_7);
        __pyx_t_7 = 0;

        /* "pyreadstat/_readstat_writer.pyx":400
 *             if curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:
 *                 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_t_2 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 400, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_13 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_2);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_13 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_msg};
          __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
        }
        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __PYX_ERR(0, 400, __pyx_L1_error)

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

      /* "pyreadstat/_readstat_writer.pyx":402
 *                 raise PyreadstatError(msg)
 * 
 *             readstat_label_tagged_value(label_set, ord(value), label.encode("utf-8"))             # <<<<<<<<<<<<<<
 *             continue
 * 
*/
      __pyx_t_15 = __Pyx_PyObject_Ord(__pyx_v_value); if (unlikely(__pyx_t_15 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 402, __pyx_L1_error)
      __pyx_t_8 = __pyx_v_label;
      __Pyx_INCREF(__pyx_t_8);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
      }
      __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_t_7); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 402, __pyx_L1_error)
      readstat_label_tagged_value(__pyx_v_label_set, __pyx_t_15, __pyx_t_16);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

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

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

    /* "pyreadstat/_readstat_writer.pyx":406
 * 
 * 
 *         if curpytype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *             if type(value) != float and type(value) != int:
 *                 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":407
 * 
 *         if curpytype == PYWRITER_DOUBLE:
 *             if type(value) != float and type(value) != int:             # <<<<<<<<<<<<<<
 *                 msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
*/
      __pyx_t_7 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_value)), ((PyObject *)(&PyFloat_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 407, __pyx_L1_error)
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 407, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_14) {
      } else {
        __pyx_t_11 = __pyx_t_14;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_7 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_value)), ((PyObject *)(&PyLong_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 407, __pyx_L1_error)
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 407, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_11 = __pyx_t_14;
      __pyx_L12_bool_binop_done:;
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":408
 *         if curpytype == PYWRITER_DOUBLE:
 *             if type(value) != float and type(value) != int:
 *                 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_7 = __Pyx_PyObject_Unicode(__pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 408, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyUnicode_Unicode(__pyx_v_variable_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 408, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_variable_value_labels_type_of_Va;
        __pyx_t_12[1] = __pyx_t_7;
        __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_in_variable;
        __pyx_t_12[3] = __pyx_t_8;
        __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u_must_be_numeric;
        __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7) + 13 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8) + 16, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8));
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 408, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_v_msg = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":409
 *             if type(value) != float and type(value) != int:
 *                 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_8 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 409, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_13 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
          assert(__pyx_t_8);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_7, __pyx__function);
          __pyx_t_13 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 409, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 409, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":407
 * 
 *         if curpytype == PYWRITER_DOUBLE:
 *             if type(value) != float and type(value) != int:             # <<<<<<<<<<<<<<
 *                 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":410
 *                 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_17 = __Pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 410, __pyx_L1_error)
      __pyx_t_7 = __pyx_v_label;
      __Pyx_INCREF(__pyx_t_7);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 410, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      }
      __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 410, __pyx_L1_error)
      readstat_label_double_value(__pyx_v_label_set, __pyx_t_17, __pyx_t_18);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":406
 * 
 * 
 *         if curpytype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *             if type(value) != float and type(value) != int:
 *                 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":413
 * 
 *         elif curpytype == PYWRITER_INTEGER:
 *             if type(value) != int:             # <<<<<<<<<<<<<<
 *                 #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)
*/
      __pyx_t_2 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_value)), ((PyObject *)(&PyLong_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 413, __pyx_L1_error)
      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 413, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":415
 *             if type(value) != int:
 *                 #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_Unicode(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 415, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyUnicode_Unicode(__pyx_v_variable_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 415, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_variable_value_labels_type_of_Va;
        __pyx_t_12[1] = __pyx_t_2;
        __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_in_variable;
        __pyx_t_12[3] = __pyx_t_7;
        __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u_must_be_int;
        __pyx_t_8 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 13 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7) + 12, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7));
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 415, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_v_msg = ((PyObject*)__pyx_t_8);
        __pyx_t_8 = 0;

        /* "pyreadstat/_readstat_writer.pyx":416
 *                 #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_7 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 416, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_13 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
          assert(__pyx_t_7);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
          __pyx_t_13 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 416, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __PYX_ERR(0, 416, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":413
 * 
 *         elif curpytype == PYWRITER_INTEGER:
 *             if type(value) != int:             # <<<<<<<<<<<<<<
 *                 #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)
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":417
 *                 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_19 = __Pyx_PyLong_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_19 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 417, __pyx_L1_error)
      __pyx_t_2 = __pyx_v_label;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 417, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      }
      __pyx_t_20 = __Pyx_PyObject_AsString(__pyx_t_8); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) __PYX_ERR(0, 417, __pyx_L1_error)
      readstat_label_int32_value(__pyx_v_label_set, __pyx_t_19, __pyx_t_20);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":412
 *             readstat_label_double_value(label_set, value, label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_INTEGER:             # <<<<<<<<<<<<<<
 *             if type(value) != int:
 *                 #if type(value) not in int_types:
*/
      break;
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL:

      /* "pyreadstat/_readstat_writer.pyx":420
 * 
 *         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_8 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_value)), ((PyObject*)&PyBool_Type), Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 420, __pyx_L1_error)
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 420, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_14) {
      } else {
        __pyx_t_11 = __pyx_t_14;
        goto __pyx_L16_bool_binop_done;
      }
      __pyx_t_14 = (__Pyx_PyLong_BoolNeObjC(__pyx_v_value, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 420, __pyx_L1_error)
      if (__pyx_t_14) {
      } else {
        __pyx_t_11 = __pyx_t_14;
        goto __pyx_L16_bool_binop_done;
      }
      __pyx_t_14 = (__Pyx_PyLong_BoolNeObjC(__pyx_v_value, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 420, __pyx_L1_error)
      __pyx_t_11 = __pyx_t_14;
      __pyx_L16_bool_binop_done:;
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":421
 *         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_8 = __Pyx_PyObject_Unicode(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 421, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_2 = __Pyx_PyUnicode_Unicode(__pyx_v_variable_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 421, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_variable_value_labels_type_of_Va;
        __pyx_t_12[1] = __pyx_t_8;
        __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_in_variable;
        __pyx_t_12[3] = __pyx_t_2;
        __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u_must_be_boolean_or_be_1_or_0;
        __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8) + 13 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 29, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2));
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 421, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_msg = ((PyObject*)__pyx_t_7);
        __pyx_t_7 = 0;

        /* "pyreadstat/_readstat_writer.pyx":422
 *             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 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 422, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_13 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_2);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_13 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_msg};
          __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 422, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
        }
        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __PYX_ERR(0, 422, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":420
 * 
 *         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":423
 *                 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 or curpytype==PYWRITER_DTA_STR_REF:
*/
      __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 423, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __Pyx_PyLong_As_int32_t(__pyx_t_7); if (unlikely((__pyx_t_19 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 423, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_8 = __pyx_v_label;
      __Pyx_INCREF(__pyx_t_8);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 423, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
      }
      __pyx_t_20 = __Pyx_PyObject_AsString(__pyx_t_7); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) __PYX_ERR(0, 423, __pyx_L1_error)
      readstat_label_int32_value(__pyx_v_label_set, __pyx_t_19, __pyx_t_20);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pyreadstat/_readstat_writer.pyx":419
 *             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":425
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *             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:
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF:

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

      /* "pyreadstat/_readstat_writer.pyx":427
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:
 *             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, PYWRITER_DATE64, PYWRITER_TIME64):
*/
      __pyx_t_8 = __pyx_v_value;
      __Pyx_INCREF(__pyx_t_8);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 427, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
      }
      __pyx_t_21 = __Pyx_PyObject_AsString(__pyx_t_7); if (unlikely((!__pyx_t_21) && PyErr_Occurred())) __PYX_ERR(0, 427, __pyx_L1_error)
      __pyx_t_2 = __pyx_v_label;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 427, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      }
      __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_t_8); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) __PYX_ERR(0, 427, __pyx_L1_error)
      readstat_label_string_value(__pyx_v_label_set, __pyx_t_21, __pyx_t_22);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":425
 *             readstat_label_int32_value(label_set, int(value), label.encode("utf-8"))
 * 
 *         elif curpytype == PYWRITER_CHARACTER or curpytype == PYWRITER_OBJECT or curpytype==PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *             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":429
 *             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, PYWRITER_DATE64, PYWRITER_TIME64):             # <<<<<<<<<<<<<<
 *             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 dataframe 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:
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64:
      case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64:

      /* "pyreadstat/_readstat_writer.pyx":430
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64):
 *             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 dataframe 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, 430, __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, 430, __pyx_L1_error)
      if (unlikely(__pyx_t_11)) {

        /* "pyreadstat/_readstat_writer.pyx":431
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64):
 *             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 dataframe 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_Unicode(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __Pyx_PyUnicode_Unicode(__pyx_v_variable_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_variable_value_labels_type_of_Va;
        __pyx_t_12[1] = __pyx_t_8;
        __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_in_variable;
        __pyx_t_12[3] = __pyx_t_7;
        __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u_must_match_the_type_of_the_colu;
        __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8) + 13 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7) + 85, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7));
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_v_msg = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":432
 *             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 dataframe 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_7 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 432, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_13 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_7);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_13 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_msg};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 432, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 432, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":430
 * 
 *         elif curpytype in (PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64):
 *             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 dataframe and be of type date, datetime or time" % (str(value), variable_name)
 *                 raise PyreadstatError(msg)
*/
      }

      /* "pyreadstat/_readstat_writer.pyx":433
 *                 msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in dataframe 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_17 = __pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number(__pyx_v_file_format, __pyx_v_curpytype, __pyx_v_value); if (unlikely(__pyx_t_17 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 433, __pyx_L1_error)
      __pyx_v_double_val = __pyx_t_17;

      /* "pyreadstat/_readstat_writer.pyx":434
 *                 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_8 = __pyx_v_label;
      __Pyx_INCREF(__pyx_t_8);
      __pyx_t_13 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_13, (2-__pyx_t_13) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 434, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      }
      __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 434, __pyx_L1_error)
      readstat_label_double_value(__pyx_v_label_set, __pyx_v_double_val, __pyx_t_18);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyreadstat/_readstat_writer.pyx":429
 *             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, PYWRITER_DATE64, PYWRITER_TIME64):             # <<<<<<<<<<<<<<
 *             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 dataframe and be of type date, datetime or time" % (str(value), variable_name)
*/
      break;
      default: break;
    }

    /* "pyreadstat/_readstat_writer.pyx":391
 *     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":436
 *             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":377
 *     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":438
 *     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;
  size_t __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  double __pyx_t_10;
  double __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  char const *__pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_missing_ranges", 0);

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

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

  /* "pyreadstat/_readstat_writer.pyx":446
 *     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":448
 *     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, 448, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_cur_ranges; __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = 0;
  for (;;) {
    {
      Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
      #if !CYTHON_ASSUME_SAFE_SIZE
      if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 448, __pyx_L1_error)
      #endif
      if (__pyx_t_2 >= __pyx_temp) break;
    }
    __pyx_t_3 = __Pyx_PyList_GetItemRef(__pyx_t_1, __pyx_t_2);
    ++__pyx_t_2;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_cur_range, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyreadstat/_readstat_writer.pyx":449
 * 
 *     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":450
 *     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_v_cur_range;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_6 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_mstate_global->__pyx_n_u_hi};
        __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_get, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_hi, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyreadstat/_readstat_writer.pyx":451
 *         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_v_cur_range;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_6 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_mstate_global->__pyx_n_u_lo};
        __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_get, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 451, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_lo, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyreadstat/_readstat_writer.pyx":452
 *             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_7 = (__pyx_v_hi == Py_None);
      if (!__pyx_t_7) {
      } else {
        __pyx_t_4 = __pyx_t_7;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_7 = (__pyx_v_lo == Py_None);
      __pyx_t_4 = __pyx_t_7;
      __pyx_L7_bool_binop_done:;
      if (unlikely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":453
 *             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 (int, float)  and type(lo) in (int, float):
*/
        __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_dictionaries_in_missing_ranges_m);
        __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_dictionaries_in_missing_ranges_m;

        /* "pyreadstat/_readstat_writer.pyx":454
 *             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 (int, float)  and type(lo) in (int, float):
 *                 if vartype not in pywriter_numeric_types:
*/
        __pyx_t_5 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_5);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 454, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":452
 *             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":455
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)
 *             if type(hi) in (int, float)  and type(lo) in (int, float):             # <<<<<<<<<<<<<<
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
*/
      __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_hi)));
      __pyx_t_3 = ((PyObject *)Py_TYPE(__pyx_v_hi));
      __pyx_t_8 = PyObject_RichCompare(((PyObject *)__pyx_t_3), ((PyObject *)(&PyLong_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 455, __pyx_L1_error)
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 455, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (!__pyx_t_9) {
      } else {
        __pyx_t_7 = __pyx_t_9;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_8 = PyObject_RichCompare(((PyObject *)__pyx_t_3), ((PyObject *)(&PyFloat_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 455, __pyx_L1_error)
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 455, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_7 = __pyx_t_9;
      __pyx_L12_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = __pyx_t_7;
      if (__pyx_t_9) {
      } else {
        __pyx_t_4 = __pyx_t_9;
        goto __pyx_L10_bool_binop_done;
      }
      __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_lo)));
      __pyx_t_3 = ((PyObject *)Py_TYPE(__pyx_v_lo));
      __pyx_t_8 = PyObject_RichCompare(((PyObject *)__pyx_t_3), ((PyObject *)(&PyLong_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 455, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 455, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (!__pyx_t_7) {
      } else {
        __pyx_t_9 = __pyx_t_7;
        goto __pyx_L14_bool_binop_done;
      }
      __pyx_t_8 = PyObject_RichCompare(((PyObject *)__pyx_t_3), ((PyObject *)(&PyFloat_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 455, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 455, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_9 = __pyx_t_7;
      __pyx_L14_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __pyx_t_9;
      __pyx_t_4 = __pyx_t_7;
      __pyx_L10_bool_binop_done:;
      if (__pyx_t_4) {

        /* "pyreadstat/_readstat_writer.pyx":456
 *                 raise PyreadstatError(msg)
 *             if type(hi) in (int, float)  and type(lo) in (int, float):
 *                 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_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_vartype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 456, __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, 456, __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, 456, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":457
 *             if type(hi) in (int, float)  and type(lo) in (int, float):
 *                 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 = PyUnicode_Format(__pyx_mstate_global->__pyx_kp_u_numeric_missing_ranges_value_giv, __pyx_v_variablename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 457, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_msg = ((PyObject*)__pyx_t_3);
          __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":458
 *                 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_t_8 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 458, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
            assert(__pyx_t_8);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 458, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":456
 *                 raise PyreadstatError(msg)
 *             if type(hi) in (int, float)  and type(lo) in (int, float):
 *                 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":459
 *                     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, 459, __pyx_L1_error)
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 459, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_4) {

          /* "pyreadstat/_readstat_writer.pyx":460
 *                     raise PyreadstatError(msg)
 *                 if hi == lo:
 *                     check_exit_status(readstat_variable_add_missing_double_value(variable, hi))             # <<<<<<<<<<<<<<
 *                     discrete_values += 1
 *                 else:
*/
          __pyx_t_10 = __Pyx_PyFloat_AsDouble(__pyx_v_hi); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 460, __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, 460, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":461
 *                 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":459
 *                     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_L17;
        }

        /* "pyreadstat/_readstat_writer.pyx":463
 *                     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_10 = __Pyx_PyFloat_AsDouble(__pyx_v_lo); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 463, __pyx_L1_error)
          __pyx_t_11 = __Pyx_PyFloat_AsDouble(__pyx_v_hi); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 463, __pyx_L1_error)
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_double_range(__pyx_v_variable, __pyx_t_10, __pyx_t_11)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 463, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":464
 *                 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 and vartype !=PYWRITER_DTA_STR_REF:
*/
          __pyx_v_range_values = (__pyx_v_range_values + 1);
        }
        __pyx_L17:;

        /* "pyreadstat/_readstat_writer.pyx":455
 *                 msg = "dictionaries in missing_ranges must have the keys hi and lo"
 *                 raise PyreadstatError(msg)
 *             if type(hi) in (int, float)  and type(lo) in (int, float):             # <<<<<<<<<<<<<<
 *                 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":465
 *                     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 and vartype !=PYWRITER_DTA_STR_REF:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
*/
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_hi)), ((PyObject *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 465, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
      } else {
        __pyx_t_4 = __pyx_t_7;
        goto __pyx_L18_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_lo)), ((PyObject *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 465, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_4 = __pyx_t_7;
      __pyx_L18_bool_binop_done:;
      if (likely(__pyx_t_4)) {

        /* "pyreadstat/_readstat_writer.pyx":466
 *                     range_values += 1
 *             elif type(hi) == str and type(lo) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT and vartype !=PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                     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:
          case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF:
          __pyx_t_4 = 0;
          break;
          default:
          __pyx_t_4 = 1;
          break;
        }
        if (unlikely(__pyx_t_4)) {

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

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

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

        /* "pyreadstat/_readstat_writer.pyx":469
 *                     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, 469, __pyx_L1_error)
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 469, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (likely(__pyx_t_4)) {

          /* "pyreadstat/_readstat_writer.pyx":470
 *                     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_12 = PyObject_Length(__pyx_v_hi); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 470, __pyx_L1_error)
          __pyx_t_4 = (__pyx_t_12 > 8);
          if (unlikely(__pyx_t_4)) {

            /* "pyreadstat/_readstat_writer.pyx":471
 *                 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_mstate_global->__pyx_kp_u_missing_ranges_string_values_len);
            __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_string_values_len;

            /* "pyreadstat/_readstat_writer.pyx":472
 *                     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_t_8 = NULL;
            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 472, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_6 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
              assert(__pyx_t_8);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
              __pyx_t_6 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
              __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 472, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
            }
            __Pyx_Raise(__pyx_t_3, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __PYX_ERR(0, 472, __pyx_L1_error)

            /* "pyreadstat/_readstat_writer.pyx":470
 *                     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":473
 *                         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_13 = __Pyx_PyObject_AsString(__pyx_v_hi); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 473, __pyx_L1_error)
          __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_string_value(__pyx_v_variable, __pyx_t_13)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 473, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":474
 *                         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":469
 *                     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_L21;
        }

        /* "pyreadstat/_readstat_writer.pyx":477
 *                 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_mstate_global->__pyx_kp_u_missing_ranges_hi_and_lo_values);
          __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_hi_and_lo_values;

          /* "pyreadstat/_readstat_writer.pyx":478
 *                     #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_t_5 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 478, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
            assert(__pyx_t_5);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 478, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 478, __pyx_L1_error)
        }
        __pyx_L21:;

        /* "pyreadstat/_readstat_writer.pyx":465
 *                     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 and vartype !=PYWRITER_DTA_STR_REF:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
*/
        goto __pyx_L9;
      }

      /* "pyreadstat/_readstat_writer.pyx":480
 *                     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_mstate_global->__pyx_kp_u_missing_ranges_hi_and_lo_values_2);
        __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_hi_and_lo_values_2;

        /* "pyreadstat/_readstat_writer.pyx":481
 *             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 (int, float):
*/
        __pyx_t_8 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 481, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_8);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 481, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 481, __pyx_L1_error)
      }
      __pyx_L9:;

      /* "pyreadstat/_readstat_writer.pyx":449
 * 
 *     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":483
 *                 raise PyreadstatError(msg)
 *         else:
 *             if type(cur_range) in (int, float):             # <<<<<<<<<<<<<<
 *                 if vartype not in pywriter_numeric_types:
 *                     msg = "numeric missing_ranges value given for non numeric variable %s" %variablename
*/
    /*else*/ {
      __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_cur_range)));
      __pyx_t_3 = ((PyObject *)Py_TYPE(__pyx_v_cur_range));
      __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_3), ((PyObject *)(&PyLong_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 483, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 483, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!__pyx_t_7) {
      } else {
        __pyx_t_4 = __pyx_t_7;
        goto __pyx_L24_bool_binop_done;
      }
      __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_3), ((PyObject *)(&PyFloat_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 483, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 483, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __pyx_t_7;
      __pyx_L24_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __pyx_t_4;
      if (__pyx_t_7) {

        /* "pyreadstat/_readstat_writer.pyx":484
 *         else:
 *             if type(cur_range) in (int, float):
 *                 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_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_vartype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __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, 484, __pyx_L1_error)
        }
        __pyx_t_7 = (__Pyx_PySet_ContainsTF(__pyx_t_3, __pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types, Py_NE)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 484, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(__pyx_t_7)) {

          /* "pyreadstat/_readstat_writer.pyx":485
 *             if type(cur_range) in (int, float):
 *                 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 = PyUnicode_Format(__pyx_mstate_global->__pyx_kp_u_numeric_missing_ranges_value_giv, __pyx_v_variablename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_msg = ((PyObject*)__pyx_t_3);
          __pyx_t_3 = 0;

          /* "pyreadstat/_readstat_writer.pyx":486
 *                 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_t_5 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 486, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
            assert(__pyx_t_5);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 486, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 486, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":484
 *         else:
 *             if type(cur_range) in (int, float):
 *                 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":487
 *                     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_11 = __Pyx_PyFloat_AsDouble(__pyx_v_cur_range); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 487, __pyx_L1_error)
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_double_value(__pyx_v_variable, __pyx_t_11)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 487, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":488
 *                     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 or vartype==PYWRITER_DTA_STR_REF:
*/
        __pyx_v_discrete_values = (__pyx_v_discrete_values + 1);

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

      /* "pyreadstat/_readstat_writer.pyx":489
 *                 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 or vartype==PYWRITER_DTA_STR_REF:
 *                     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 *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 489, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 489, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(__pyx_t_7)) {

        /* "pyreadstat/_readstat_writer.pyx":490
 *                 discrete_values += 1
 *             elif type(cur_range) == str:
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT or vartype==PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                     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 (!__pyx_t_4) {
        } else {
          __pyx_t_7 = __pyx_t_4;
          goto __pyx_L28_bool_binop_done;
        }
        __pyx_t_4 = (__pyx_v_vartype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF);
        __pyx_t_7 = __pyx_t_4;
        __pyx_L28_bool_binop_done:;
        if (unlikely(__pyx_t_7)) {

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

          /* "pyreadstat/_readstat_writer.pyx":492
 *                 if vartype != PYWRITER_CHARACTER and vartype != PYWRITER_OBJECT or vartype==PYWRITER_DTA_STR_REF:
 *                     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_t_8 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 492, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
            assert(__pyx_t_8);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 492, __pyx_L1_error)

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

        /* "pyreadstat/_readstat_writer.pyx":493
 *                     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_12 = PyObject_Length(__pyx_v_cur_range); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 493, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_12 > 8);
        if (unlikely(__pyx_t_7)) {

          /* "pyreadstat/_readstat_writer.pyx":494
 *                     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_mstate_global->__pyx_kp_u_missing_ranges_string_values_len);
          __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_string_values_len;

          /* "pyreadstat/_readstat_writer.pyx":495
 *                 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_t_5 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
            assert(__pyx_t_5);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
            __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 495, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
          }
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __PYX_ERR(0, 495, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":493
 *                     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":496
 *                         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_13 = __Pyx_PyObject_AsString(__pyx_v_cur_range); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 496, __pyx_L1_error)
        __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_variable_add_missing_string_value(__pyx_v_variable, __pyx_t_13)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 496, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":497
 *                         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":489
 *                 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 or vartype==PYWRITER_DTA_STR_REF:
 *                     msg = "character missing_ranges value given for non character variable %s" %variablename
*/
        goto __pyx_L23;
      }

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

        /* "pyreadstat/_readstat_writer.pyx":500
 *             else:
 *                 msg = "missing_ranges: values must be both either of numeric or string type"
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *         if discrete_strings > 3:
*/
        __pyx_t_8 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 500, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_8);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 500, __pyx_L1_error)
      }
      __pyx_L23:;
    }
    __pyx_L5:;

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

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

      /* "pyreadstat/_readstat_writer.pyx":504
 *         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_t_5 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 504, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
        assert(__pyx_t_5);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 504, __pyx_L1_error)

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

    /* "pyreadstat/_readstat_writer.pyx":505
 *             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_7 = (__pyx_v_range_values != 0);
    if (__pyx_t_7) {

      /* "pyreadstat/_readstat_writer.pyx":506
 *             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_7 = (__pyx_v_range_values > 1);
      if (unlikely(__pyx_t_7)) {

        /* "pyreadstat/_readstat_writer.pyx":507
 *         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_mstate_global->__pyx_kp_u_missing_ranges_max_1_range_value);
        __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_max_1_range_value;

        /* "pyreadstat/_readstat_writer.pyx":508
 *             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_t_8 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 508, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_8);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 508, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":506
 *             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":509
 *                 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_7 = (__pyx_v_discrete_values > 1);
      if (unlikely(__pyx_t_7)) {

        /* "pyreadstat/_readstat_writer.pyx":510
 *                 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_mstate_global->__pyx_kp_u_missing_ranges_max_1_discrete_nu);
        __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_max_1_discrete_nu;

        /* "pyreadstat/_readstat_writer.pyx":511
 *             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_t_5 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 511, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_5);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 511, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 511, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":509
 *                 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":505
 *             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":512
 *                 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_7 = (__pyx_v_discrete_values > 3);
    if (unlikely(__pyx_t_7)) {

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

      /* "pyreadstat/_readstat_writer.pyx":514
 *         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_t_8 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
        assert(__pyx_t_8);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_msg};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 514, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":512
 *                 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":448
 *     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":438
 *     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_8);
  __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":516
 *             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[5];
  PyObject *__pyx_t_5 = NULL;
  size_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_variable_alignment", 0);

  /* "pyreadstat/_readstat_writer.pyx":523
 *     cdef readstat_alignment_t alignment
 * 
 *     if alignment_str == "right":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_alignment_str, __pyx_mstate_global->__pyx_n_u_right, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 523, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":524
 * 
 *     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":523
 *     cdef readstat_alignment_t alignment
 * 
 *     if alignment_str == "right":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":
*/
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":525
 *     if alignment_str == "right":
 *         alignment = READSTAT_ALIGNMENT_RIGHT
 *     elif alignment_str == "left":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_alignment_str, __pyx_mstate_global->__pyx_n_u_left, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 525, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":526
 *         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":525
 *     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":527
 *     elif alignment_str == "left":
 *         alignment = READSTAT_ALIGNMENT_LEFT
 *     elif alignment_str == "center":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_alignment_str, __pyx_mstate_global->__pyx_n_u_center, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 527, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":528
 *         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":527
 *     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":529
 *     elif alignment_str == "center":
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN
 *     else:
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_alignment_str, __pyx_mstate_global->__pyx_n_u_unknown, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 529, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":530
 *         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":529
 *     elif alignment_str == "center":
 *         alignment = READSTAT_ALIGNMENT_CENTER
 *     elif alignment_str == "unknown":             # <<<<<<<<<<<<<<
 *         alignment = READSTAT_ALIGNMENT_UNKNOWN
 *     else:
*/
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":532
 *         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 = __Pyx_PyUnicode_Unicode(__pyx_v_var_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyUnicode_Unicode(__pyx_v_alignment_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4[0] = __pyx_mstate_global->__pyx_kp_u_alignment_for_variable;
    __pyx_t_4[1] = __pyx_t_2;
    __pyx_t_4[2] = __pyx_mstate_global->__pyx_kp_u_must_be_either_right_center_lef;
    __pyx_t_4[3] = __pyx_t_3;
    __pyx_t_4[4] = __pyx_mstate_global->__pyx_kp_u_instead;
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 5, 23 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 51 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 8, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3));
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_msg = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "pyreadstat/_readstat_writer.pyx":533
 *     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_t_3 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      assert(__pyx_t_3);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
      __pyx_t_6 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_msg};
      __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 533, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 533, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "pyreadstat/_readstat_writer.pyx":535
 *         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":516
 *             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_5);
  __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":537
 *     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) {

  /* "pyreadstat/_readstat_writer.pyx":542
 *     """
 * 
 *     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":537
 *     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 */
}

/* "pyreadstat/_readstat_writer.pyx":544
 *     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[5];
  PyObject *__pyx_t_5 = NULL;
  size_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_variable_measure", 0);

  /* "pyreadstat/_readstat_writer.pyx":551
 *     cdef readstat_measure_t measure
 * 
 *     if measure_str == "nominal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_measure_str, __pyx_mstate_global->__pyx_n_u_nominal, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 551, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":552
 * 
 *     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":551
 *     cdef readstat_measure_t measure
 * 
 *     if measure_str == "nominal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":
*/
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":553
 *     if measure_str == "nominal":
 *         measure = READSTAT_MEASURE_NOMINAL
 *     elif measure_str == "ordinal":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_measure_str, __pyx_mstate_global->__pyx_n_u_ordinal, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 553, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":554
 *         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":553
 *     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":555
 *     elif measure_str == "ordinal":
 *         measure = READSTAT_MEASURE_ORDINAL
 *     elif measure_str == "scale":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_measure_str, __pyx_mstate_global->__pyx_n_u_scale, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 555, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":556
 *         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":555
 *     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":557
 *     elif measure_str == "scale":
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_UNKNOWN
 *     else:
*/
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_measure_str, __pyx_mstate_global->__pyx_n_u_unknown, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 557, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":558
 *         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":557
 *     elif measure_str == "scale":
 *         measure = READSTAT_MEASURE_SCALE
 *     elif measure_str == "unknown":             # <<<<<<<<<<<<<<
 *         measure = READSTAT_MEASURE_UNKNOWN
 *     else:
*/
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":560
 *         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 = __Pyx_PyUnicode_Unicode(__pyx_v_var_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyUnicode_Unicode(__pyx_v_measure_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4[0] = __pyx_mstate_global->__pyx_kp_u_measure_for_variable;
    __pyx_t_4[1] = __pyx_t_2;
    __pyx_t_4[2] = __pyx_mstate_global->__pyx_kp_u_must_be_either_nominal_ordinal;
    __pyx_t_4[3] = __pyx_t_3;
    __pyx_t_4[4] = __pyx_mstate_global->__pyx_kp_u_instead;
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 5, 21 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 55 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 8, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3));
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_msg = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "pyreadstat/_readstat_writer.pyx":561
 *     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_t_3 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      assert(__pyx_t_3);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
      __pyx_t_6 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_msg};
      __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 561, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 561, __pyx_L1_error)
  }
  __pyx_L3:;

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

  /* "pyreadstat/_readstat_writer.pyx":544
 *     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_5);
  __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":566
 * 
 * 
 * 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":571
 *     """
 *     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":572
 *     cdef int fd
 *     fd = (<int *>ctx)[0]
 *     if os.name=='nt':             # <<<<<<<<<<<<<<
 *         return _write(fd, data, _len)
 *     else:
*/
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nt, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pyreadstat/_readstat_writer.pyx":573
 *     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":572
 *     cdef int fd
 *     fd = (<int *>ctx)[0]
 *     if os.name=='nt':             # <<<<<<<<<<<<<<
 *         return _write(fd, data, _len)
 *     else:
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":575
 *         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":566
 * 
 * 
 * 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":577
 *         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;
  size_t __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":584
 *     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":585
 *     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":586
 *     if retcode != READSTAT_OK:
 *         err_readstat = readstat_error_message(retcode)
 *         err_message = <str> err_readstat             # <<<<<<<<<<<<<<
 *         raise ReadstatError(err_message)
 * 
*/
    __pyx_t_2 = __Pyx_PyUnicode_FromString(__pyx_v_err_readstat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 586, __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":587
 *         err_readstat = readstat_error_message(retcode)
 *         err_message = <str> err_readstat
 *         raise ReadstatError(err_message)             # <<<<<<<<<<<<<<
 * 
 * cdef int open_file(bytes filename_bytes):
*/
    __pyx_t_2 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_ReadstatError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 587, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
      assert(__pyx_t_2);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
      __pyx_t_5 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_err_message};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 587, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":584
 *     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":577
 *         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":589
 *         raise ReadstatError(err_message)
 * 
 * cdef int open_file(bytes filename_bytes):             # <<<<<<<<<<<<<<
 * 
 *     cdef int fd
*/

static int __pyx_f_10pyreadstat_16_readstat_writer_open_file(PyObject *__pyx_v_filename_bytes) {
  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;
  PyObject *__pyx_t_5 = NULL;
  size_t __pyx_t_6;
  wchar_t *__pyx_t_7;
  char *__pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("open_file", 0);

  /* "pyreadstat/_readstat_writer.pyx":597
 *     cdef char *path
 * 
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         filename_str = os.fsdecode(filename_bytes)
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
*/
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nt, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 597, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pyreadstat/_readstat_writer.pyx":598
 * 
 *     if os.name == "nt":
 *         filename_str = os.fsdecode(filename_bytes)             # <<<<<<<<<<<<<<
 *         u16_path = PyUnicode_AsWideCharString(filename_str, &length)
 *         flags = _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC
*/
    __pyx_t_1 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_fsdecode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      assert(__pyx_t_1);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
      __pyx_t_6 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_filename_bytes};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    }
    __pyx_v_filename_str = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pyreadstat/_readstat_writer.pyx":599
 *     if os.name == "nt":
 *         filename_str = os.fsdecode(filename_bytes)
 *         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_7 = PyUnicode_AsWideCharString(__pyx_v_filename_str, (&__pyx_v_length)); if (unlikely(__pyx_t_7 == ((wchar_t *)0))) __PYX_ERR(0, 599, __pyx_L1_error)
    __pyx_v_u16_path = __pyx_t_7;

    /* "pyreadstat/_readstat_writer.pyx":600
 *         filename_str = os.fsdecode(filename_bytes)
 *         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":601
 *         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:
 *         path = <char *> filename_bytes
*/
    __pyx_v_fd = _wsopen(__pyx_v_u16_path, __pyx_v_flags, _SH_DENYRW, (_S_IREAD | _S_IWRITE));

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

  /* "pyreadstat/_readstat_writer.pyx":603
 *         fd = _wsopen(u16_path, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)
 *     else:
 *         path = <char *> filename_bytes             # <<<<<<<<<<<<<<
 *         flags = O_WRONLY | O_CREAT | O_TRUNC
 *         fd = open(path, flags, 0644)
*/
  /*else*/ {
    if (unlikely(__pyx_v_filename_bytes == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
      __PYX_ERR(0, 603, __pyx_L1_error)
    }
    __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 603, __pyx_L1_error)
    __pyx_v_path = ((char *)__pyx_t_8);

    /* "pyreadstat/_readstat_writer.pyx":604
 *     else:
 *         path = <char *> filename_bytes
 *         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":605
 *         path = <char *> filename_bytes
 *         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":607
 *         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":589
 *         raise ReadstatError(err_message)
 * 
 * cdef int open_file(bytes filename_bytes):             # <<<<<<<<<<<<<<
 * 
 *     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_XDECREF(__pyx_t_5);
  __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":609
 *     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":610
 * 
 * cdef int close_file(int fd):
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         return _close(fd)
 *     else:
*/
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nt, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pyreadstat/_readstat_writer.pyx":611
 * 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":610
 * 
 * cdef int close_file(int fd):
 *     if os.name == "nt":             # <<<<<<<<<<<<<<
 *         return _close(fd)
 *     else:
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":613
 *         return _close(fd)
 *     else:
 *         return close(fd)             # <<<<<<<<<<<<<<
 * 
 * cdef void initial_checks(bint is_pandas, bint is_polars, dict variable_value_labels, dict missing_user_values,
*/
  /*else*/ {
    __pyx_r = close(__pyx_v_fd);
    goto __pyx_L0;
  }

  /* "pyreadstat/_readstat_writer.pyx":609
 *     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":615
 *         return close(fd)
 * 
 * cdef void initial_checks(bint is_pandas, bint is_polars, dict variable_value_labels, dict missing_user_values,             # <<<<<<<<<<<<<<
 *                         dst_file_format file_format, list col_names, bytes filename_bytes) except *:
 *     """
*/

static void __pyx_f_10pyreadstat_16_readstat_writer_initial_checks(int __pyx_v_is_pandas, int __pyx_v_is_polars, PyObject *__pyx_v_variable_value_labels, PyObject *__pyx_v_missing_user_values, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format __pyx_v_file_format, PyObject *__pyx_v_col_names, PyObject *__pyx_v_filename_bytes) {
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_k = NULL;
  PyObject *__pyx_v_v = NULL;
  PyObject *__pyx_v_valid_user_missing = 0;
  CYTHON_UNUSED PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_missing_values = NULL;
  PyObject *__pyx_v_val = NULL;
  PyObject *__pyx_v_variable_name = NULL;
  PyObject *__pyx_v_dirname = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  size_t __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 *);
  PyObject *__pyx_t_12[4];
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16[5];
  PyObject *__pyx_t_17 = NULL;
  long __pyx_t_18;
  PyObject *__pyx_t_19[7];
  PyObject *__pyx_t_20 = NULL;
  int __pyx_t_21;
  PyObject *__pyx_t_22[3];
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("initial_checks", 0);

  /* "pyreadstat/_readstat_writer.pyx":621
 *     """
 * 
 *     if not is_pandas and not is_polars:             # <<<<<<<<<<<<<<
 *         msg = "dataframe must be pandas or polars dataframe"
 *         raise PyreadstatError(msg)
*/
  __pyx_t_2 = (!__pyx_v_is_pandas);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (!__pyx_v_is_polars);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":622
 * 
 *     if not is_pandas and not is_polars:
 *         msg = "dataframe must be pandas or polars dataframe"             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(msg)
 * 
*/
    __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_dataframe_must_be_pandas_or_pola);
    __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_dataframe_must_be_pandas_or_pola;

    /* "pyreadstat/_readstat_writer.pyx":623
 *     if not is_pandas and not is_polars:
 *         msg = "dataframe must be pandas or polars dataframe"
 *         raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     if variable_value_labels:
*/
    __pyx_t_4 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 623, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      assert(__pyx_t_4);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
      __pyx_t_6 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_msg};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 623, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 623, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":621
 *     """
 * 
 *     if not is_pandas and not is_polars:             # <<<<<<<<<<<<<<
 *         msg = "dataframe must be pandas or polars dataframe"
 *         raise PyreadstatError(msg)
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":625
 *         raise PyreadstatError(msg)
 * 
 *     if variable_value_labels:             # <<<<<<<<<<<<<<
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:
*/
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_variable_value_labels); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 625, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":626
 * 
 *     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, 626, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyDict_Items(__pyx_v_variable_value_labels); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 626, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5);
      __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 626, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 626, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_5))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_5);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 626, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          __pyx_t_3 = __Pyx_PyList_GetItemRef(__pyx_t_5, __pyx_t_7);
          ++__pyx_t_7;
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_5);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 626, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7));
          #else
          __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_7);
          #endif
          ++__pyx_t_7;
        }
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 626, __pyx_L1_error)
      } else {
        __pyx_t_3 = __pyx_t_8(__pyx_t_5);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 626, __pyx_L1_error)
            PyErr_Clear();
          }
          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, 626, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0);
          __Pyx_INCREF(__pyx_t_4);
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1);
          __Pyx_INCREF(__pyx_t_9);
        } else {
          __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 0);
          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 626, __pyx_L1_error)
          __Pyx_XGOTREF(__pyx_t_4);
          __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1);
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 626, __pyx_L1_error)
          __Pyx_XGOTREF(__pyx_t_9);
        }
        #else
        __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 626, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 626, __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, 626, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
        index = 0; __pyx_t_4 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_4)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_4);
        index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 626, __pyx_L1_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_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, 626, __pyx_L1_error)
        __pyx_L10_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_4);
      __pyx_t_4 = 0;
      __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":627
 *     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_3 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_v)), ((PyObject *)(&PyDict_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 627, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 627, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(__pyx_t_1)) {

        /* "pyreadstat/_readstat_writer.pyx":628
 *         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_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_v_k), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 628, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = __Pyx_PyObject_Unicode(((PyObject *)Py_TYPE(__pyx_v_v))); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 628, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_variable_value_labels_value_for;
        __pyx_t_12[1] = __pyx_t_3;
        __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_must_be_dict_got;
        __pyx_t_12[3] = __pyx_t_9;
        __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_12, 4, 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 19 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9));
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 628, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_v_msg = ((PyObject*)__pyx_t_4);
        __pyx_t_4 = 0;

        /* "pyreadstat/_readstat_writer.pyx":629
 *             if type(v) != dict:
 *                 msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v)))
 *                 raise PyreadstatError(msg)             # <<<<<<<<<<<<<<
 * 
 *     cdef list valid_user_missing
*/
        __pyx_t_9 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 629, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
          assert(__pyx_t_9);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_msg};
          __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 629, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
        }
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(0, 629, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":627
 *     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":626
 * 
 *     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_5); __pyx_t_5 = 0;

    /* "pyreadstat/_readstat_writer.pyx":625
 *         raise PyreadstatError(msg)
 * 
 *     if variable_value_labels:             # <<<<<<<<<<<<<<
 *         for k,v in variable_value_labels.items():
 *             if type(v) != dict:
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":632
 * 
 *     cdef list valid_user_missing
 *     if missing_user_values:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata
*/
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 632, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pyreadstat/_readstat_writer.pyx":633
 *     cdef list valid_user_missing
 *     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":634
 *     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_t_5 = __pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_stata;
      __Pyx_INCREF(__pyx_t_5);
      if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_5))) __PYX_ERR(0, 634, __pyx_L1_error)
      __pyx_v_valid_user_missing = ((PyObject*)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyreadstat/_readstat_writer.pyx":633
 *     cdef list valid_user_missing
 *     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":635
 *         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
 * 
*/
      case __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAS7BCAT:

      /* "pyreadstat/_readstat_writer.pyx":636
 *             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():
*/
      __pyx_t_5 = __pyx_v_10pyreadstat_16_readstat_writer_valid_user_missing_sas;
      __Pyx_INCREF(__pyx_t_5);
      if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_5))) __PYX_ERR(0, 636, __pyx_L1_error)
      __pyx_v_valid_user_missing = ((PyObject*)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyreadstat/_readstat_writer.pyx":635
 *         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
 * 
*/
      break;
      default: break;
    }

    /* "pyreadstat/_readstat_writer.pyx":638
 *             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, 638, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_PyDict_Items(__pyx_v_missing_user_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 638, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
      __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4);
      __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 638, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 638, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_4);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 638, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          __pyx_t_5 = __Pyx_PyList_GetItemRef(__pyx_t_4, __pyx_t_7);
          ++__pyx_t_7;
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_4);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 638, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_7));
          #else
          __pyx_t_5 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_7);
          #endif
          ++__pyx_t_7;
        }
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 638, __pyx_L1_error)
      } else {
        __pyx_t_5 = __pyx_t_8(__pyx_t_4);
        if (unlikely(!__pyx_t_5)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 638, __pyx_L1_error)
            PyErr_Clear();
          }
          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, 638, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0);
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1);
          __Pyx_INCREF(__pyx_t_9);
        } else {
          __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0);
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 638, __pyx_L1_error)
          __Pyx_XGOTREF(__pyx_t_3);
          __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1);
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 638, __pyx_L1_error)
          __Pyx_XGOTREF(__pyx_t_9);
        }
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 638, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 638, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 638, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
        index = 0; __pyx_t_3 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_3)) goto __pyx_L16_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L16_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 638, __pyx_L1_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L17_unpacking_done;
        __pyx_L16_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, 638, __pyx_L1_error)
        __pyx_L17_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_missing_values, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":639
 * 
 *         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_1 = PyList_Check(__pyx_v_missing_values); 
      __pyx_t_2 = (!__pyx_t_1);
      if (unlikely(__pyx_t_2)) {

        /* "pyreadstat/_readstat_writer.pyx":640
 *         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_mstate_global->__pyx_kp_u_missing_user_values_values_in_di);
        __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_user_values_values_in_di;

        /* "pyreadstat/_readstat_writer.pyx":641
 *             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_t_9 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 641, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
          assert(__pyx_t_9);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_msg};
          __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 641, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
        }
        __Pyx_Raise(__pyx_t_5, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __PYX_ERR(0, 641, __pyx_L1_error)

        /* "pyreadstat/_readstat_writer.pyx":639
 * 
 *         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":642
 *                 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_5 = __pyx_v_missing_values; __Pyx_INCREF(__pyx_t_5);
        __pyx_t_13 = 0;
        __pyx_t_14 = NULL;
      } else {
        __pyx_t_13 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_missing_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 642, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_14 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 642, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_14)) {
          if (likely(PyList_CheckExact(__pyx_t_5))) {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_5);
              #if !CYTHON_ASSUME_SAFE_SIZE
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 642, __pyx_L1_error)
              #endif
              if (__pyx_t_13 >= __pyx_temp) break;
            }
            __pyx_t_3 = __Pyx_PyList_GetItemRef(__pyx_t_5, __pyx_t_13);
            ++__pyx_t_13;
          } else {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_5);
              #if !CYTHON_ASSUME_SAFE_SIZE
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 642, __pyx_L1_error)
              #endif
              if (__pyx_t_13 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_13));
            #else
            __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_13);
            #endif
            ++__pyx_t_13;
          }
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 642, __pyx_L1_error)
        } else {
          __pyx_t_3 = __pyx_t_14(__pyx_t_5);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 642, __pyx_L1_error)
              PyErr_Clear();
            }
            break;
          }
        }
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "pyreadstat/_readstat_writer.pyx":643
 *                 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, 643, __pyx_L1_error) }
        __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_val, __pyx_v_valid_user_missing, Py_NE)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 643, __pyx_L1_error)
        if (unlikely(__pyx_t_2)) {

          /* "pyreadstat/_readstat_writer.pyx":644
 *             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_3 = __Pyx_PyObject_Unicode(__pyx_v_val); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 644, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_9 = PyUnicode_Format(__pyx_mstate_global->__pyx_kp_u_missing_user_values_supports_val, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 644, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_v_msg = ((PyObject*)__pyx_t_9);
          __pyx_t_9 = 0;

          /* "pyreadstat/_readstat_writer.pyx":645
 *                 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 len(col_names) != len(set(col_names)):
*/
          __pyx_t_3 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 645, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_10);
            assert(__pyx_t_3);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_10, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_msg};
            __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 645, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
          }
          __Pyx_Raise(__pyx_t_9, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __PYX_ERR(0, 645, __pyx_L1_error)

          /* "pyreadstat/_readstat_writer.pyx":643
 *                 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":642
 *                 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_5); __pyx_t_5 = 0;

      /* "pyreadstat/_readstat_writer.pyx":638
 *             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_4); __pyx_t_4 = 0;

    /* "pyreadstat/_readstat_writer.pyx":632
 * 
 *     cdef list valid_user_missing
 *     if missing_user_values:             # <<<<<<<<<<<<<<
 *         if file_format == FILE_FORMAT_DTA:
 *             valid_user_missing = valid_user_missing_stata
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":647
 *                     raise PyreadstatError(msg)
 * 
 *     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, 647, __pyx_L1_error)
  }
  __pyx_t_7 = __Pyx_PyList_GET_SIZE(__pyx_v_col_names); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 647, __pyx_L1_error)
  __pyx_t_4 = PySet_New(__pyx_v_col_names); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_13 = __Pyx_PySet_GET_SIZE(__pyx_t_4); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_7 != __pyx_t_13);
  if (unlikely(__pyx_t_2)) {

    /* "pyreadstat/_readstat_writer.pyx":648
 * 
 *     if len(col_names) != len(set(col_names)):
 *         msg = "Non unique column names detected in the dataframe!"             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(msg)
 * 
*/
    __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_Non_unique_column_names_detected);
    __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_Non_unique_column_names_detected;

    /* "pyreadstat/_readstat_writer.pyx":649
 *     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_t_5 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 649, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_6 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
      assert(__pyx_t_5);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_9, __pyx__function);
      __pyx_t_6 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 649, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 649, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":647
 *                     raise PyreadstatError(msg)
 * 
 *     if len(col_names) != len(set(col_names)):             # <<<<<<<<<<<<<<
 *         msg = "Non unique column names detected in the dataframe!"
 *         raise PyreadstatError(msg)
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":651
 *         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, 651, __pyx_L1_error)
  }
  __pyx_t_4 = __pyx_v_col_names; __Pyx_INCREF(__pyx_t_4);
  __pyx_t_13 = 0;
  for (;;) {
    {
      Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_4);
      #if !CYTHON_ASSUME_SAFE_SIZE
      if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 651, __pyx_L1_error)
      #endif
      if (__pyx_t_13 >= __pyx_temp) break;
    }
    __pyx_t_9 = __Pyx_PyList_GetItemRef(__pyx_t_4, __pyx_t_13);
    ++__pyx_t_13;
    if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_XDECREF_SET(__pyx_v_variable_name, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pyreadstat/_readstat_writer.pyx":652
 * 
 *     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 len(variable_name) == 0:
*/
    __pyx_t_9 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_variable_name)), ((PyObject *)(&PyUnicode_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 652, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 652, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "pyreadstat/_readstat_writer.pyx":653
 *     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 len(variable_name) == 0:
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")
*/
      __pyx_t_5 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_v_variable_name), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_15 = __Pyx_PyObject_Unicode(((PyObject *)Py_TYPE(__pyx_v_variable_name))); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_16[0] = __pyx_mstate_global->__pyx_kp_u_variable_name;
      __pyx_t_16[1] = __pyx_t_3;
      __pyx_t_16[2] = __pyx_mstate_global->__pyx_kp_u_is_of_type;
      __pyx_t_16[3] = __pyx_t_15;
      __pyx_t_16[4] = __pyx_mstate_global->__pyx_kp_u_and_it_must_be_str_not_starting;
      __pyx_t_17 = __Pyx_PyUnicode_Join(__pyx_t_16, 5, 15 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 13 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_15) + 48, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_15));
      if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_10);
        assert(__pyx_t_5);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_10, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_17};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 653, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
      }
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 653, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":652
 * 
 *     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 len(variable_name) == 0:
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":654
 *         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 len(variable_name) == 0:             # <<<<<<<<<<<<<<
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")
 *         if not variable_name[0].isalpha():
*/
    __pyx_t_7 = PyObject_Length(__pyx_v_variable_name); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 654, __pyx_L1_error)
    __pyx_t_2 = (__pyx_t_7 == 0);
    if (unlikely(__pyx_t_2)) {

      /* "pyreadstat/_readstat_writer.pyx":655
 *                 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 len(variable_name) == 0:
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")             # <<<<<<<<<<<<<<
 *         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_t_10 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 655, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_17))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_17);
        assert(__pyx_t_10);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_17);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_17, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_mstate_global->__pyx_kp_u_variable_names_must_be_non_empty};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 655, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
      }
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 655, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":654
 *         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 len(variable_name) == 0:             # <<<<<<<<<<<<<<
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")
 *         if not variable_name[0].isalpha():
*/
    }

    /* "pyreadstat/_readstat_writer.pyx":656
 *         if len(variable_name) == 0:
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")
 *         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_10 = __Pyx_GetItemInt(__pyx_v_variable_name, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 656, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_17 = __pyx_t_10;
    __Pyx_INCREF(__pyx_t_17);
    __pyx_t_6 = 0;
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_17, NULL};
      __pyx_t_9 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isalpha, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    }
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 656, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_1 = (!__pyx_t_2);
    if (unlikely(__pyx_t_1)) {

      /* "pyreadstat/_readstat_writer.pyx":657
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")
 *         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_10 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_v_variable_name), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_variable_name, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_t_15), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_variable_name, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_18 = __Pyx_PyObject_Ord(__pyx_t_15); if (unlikely(__pyx_t_18 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = __Pyx_PyUnicode_From_long(__pyx_t_18, 0, ' ', 'd'); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_19[0] = __pyx_mstate_global->__pyx_kp_u_variable_name;
      __pyx_t_19[1] = __pyx_t_5;
      __pyx_t_19[2] = __pyx_mstate_global->__pyx_kp_u_starts_with_an_illegal_non_alph;
      __pyx_t_19[3] = __pyx_t_3;
      __pyx_t_19[4] = __pyx_mstate_global->__pyx_kp_u_ordinal_2;
      __pyx_t_19[5] = __pyx_t_15;
      __pyx_t_19[6] = __pyx_mstate_global->__pyx_kp_u_;
      __pyx_t_20 = __Pyx_PyUnicode_Join(__pyx_t_19, 7, 15 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5) + 54 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 11 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_15) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3));
      if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_17))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_17);
        assert(__pyx_t_10);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_17);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_17, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_20};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 657, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
      }
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 657, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":656
 *         if len(variable_name) == 0:
 *             raise PyreadstatError("variable names must be non-empty strings, not starting with numbers")
 *         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":658
 *         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_1 = (__Pyx_PySequence_ContainsTF(__pyx_mstate_global->__pyx_kp_u__2, __pyx_v_variable_name, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 658, __pyx_L1_error)
    if (unlikely(__pyx_t_1)) {

      /* "pyreadstat/_readstat_writer.pyx":659
 *             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)             # <<<<<<<<<<<<<<
 * 
 *     dirname = os.path.dirname(filename_bytes)
*/
      __pyx_t_17 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_20, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_10 = __Pyx_PyUnicode_FormatSafe(__pyx_mstate_global->__pyx_kp_u_variable_name_s_contains_a_space, __pyx_v_variable_name); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_20))) {
        __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_20);
        assert(__pyx_t_17);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_20);
        __Pyx_INCREF(__pyx_t_17);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_20, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_10};
        __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_20, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
      }
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 659, __pyx_L1_error)

      /* "pyreadstat/_readstat_writer.pyx":658
 *         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":651
 *         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_4); __pyx_t_4 = 0;

  /* "pyreadstat/_readstat_writer.pyx":661
 *             raise PyreadstatError("variable name '%s' contains a space, which is not allowed" % variable_name)
 * 
 *     dirname = os.path.dirname(filename_bytes)             # <<<<<<<<<<<<<<
 *     if dirname and  not os.path.isdir(dirname):
 *         raise PyreadstatError(f"the destination folder {dirname} does not exist!")
*/
  __Pyx_GetModuleGlobalName(__pyx_t_20, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_mstate_global->__pyx_n_u_path); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  __pyx_t_9 = __pyx_t_10;
  __Pyx_INCREF(__pyx_t_9);
  __pyx_t_6 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_filename_bytes};
    __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_dirname, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 661, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  }
  __pyx_v_dirname = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pyreadstat/_readstat_writer.pyx":662
 * 
 *     dirname = os.path.dirname(filename_bytes)
 *     if dirname and  not os.path.isdir(dirname):             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(f"the destination folder {dirname} does not exist!")
 * 
*/
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_dirname); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 662, __pyx_L1_error)
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L33_bool_binop_done;
  }
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 662, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_path); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 662, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_10 = __pyx_t_20;
  __Pyx_INCREF(__pyx_t_10);
  __pyx_t_6 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_v_dirname};
    __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isdir, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  }
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 662, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_21 = (!__pyx_t_2);
  __pyx_t_1 = __pyx_t_21;
  __pyx_L33_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "pyreadstat/_readstat_writer.pyx":663
 *     dirname = os.path.dirname(filename_bytes)
 *     if dirname and  not os.path.isdir(dirname):
 *         raise PyreadstatError(f"the destination folder {dirname} does not exist!")             # <<<<<<<<<<<<<<
 * 
 * cdef bytes filepath_to_bytes(object filename_path):
*/
    __pyx_t_20 = NULL;
    __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_dirname, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_22[0] = __pyx_mstate_global->__pyx_kp_u_the_destination_folder;
    __pyx_t_22[1] = __pyx_t_9;
    __pyx_t_22[2] = __pyx_mstate_global->__pyx_kp_u_does_not_exist;
    __pyx_t_17 = __Pyx_PyUnicode_Join(__pyx_t_22, 3, 23 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9) + 16, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9));
    if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_6 = 1;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_10);
      assert(__pyx_t_20);
      PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(__pyx__function);
      __Pyx_DECREF_SET(__pyx_t_10, __pyx__function);
      __pyx_t_6 = 0;
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_20, __pyx_t_17};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 663, __pyx_L1_error)

    /* "pyreadstat/_readstat_writer.pyx":662
 * 
 *     dirname = os.path.dirname(filename_bytes)
 *     if dirname and  not os.path.isdir(dirname):             # <<<<<<<<<<<<<<
 *         raise PyreadstatError(f"the destination folder {dirname} does not exist!")
 * 
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":615
 *         return close(fd)
 * 
 * cdef void initial_checks(bint is_pandas, bint is_polars, dict variable_value_labels, dict missing_user_values,             # <<<<<<<<<<<<<<
 *                         dst_file_format file_format, list col_names, bytes filename_bytes) except *:
 *     """
*/

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.initial_checks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_k);
  __Pyx_XDECREF(__pyx_v_v);
  __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_variable_name);
  __Pyx_XDECREF(__pyx_v_dirname);
  __Pyx_RefNannyFinishContext();
}

/* "pyreadstat/_readstat_writer.pyx":665
 *         raise PyreadstatError(f"the destination folder {dirname} does not exist!")
 * 
 * cdef bytes filepath_to_bytes(object filename_path):             # <<<<<<<<<<<<<<
 *     """
 *     transforms an object with the path to the filename to bytes
*/

static PyObject *__pyx_f_10pyreadstat_16_readstat_writer_filepath_to_bytes(PyObject *__pyx_v_filename_path) {
  PyObject *__pyx_v_filename_bytes = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  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;
  size_t __pyx_t_9;
  int __pyx_t_10;
  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;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("filepath_to_bytes", 0);

  /* "pyreadstat/_readstat_writer.pyx":669
 *     transforms an object with the path to the filename to bytes
 *     """
 *     if hasattr(os, 'fsencode'):             # <<<<<<<<<<<<<<
 *         try:
 *             filename_bytes = os.fsencode(filename_path)
*/
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_HasAttr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_fsencode); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 669, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pyreadstat/_readstat_writer.pyx":670
 *     """
 *     if hasattr(os, 'fsencode'):
 *         try:             # <<<<<<<<<<<<<<
 *             filename_bytes = os.fsencode(filename_path)
 *         except UnicodeError:
*/
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "pyreadstat/_readstat_writer.pyx":671
 *     if hasattr(os, 'fsencode'):
 *         try:
 *             filename_bytes = 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_t_6 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 671, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_fsencode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 671, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_9 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_6);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_9 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_filename_path};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 671, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_1);
        }
        __pyx_v_filename_bytes = __pyx_t_1;
        __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":670
 *     """
 *     if hasattr(os, 'fsencode'):
 *         try:             # <<<<<<<<<<<<<<
 *             filename_bytes = os.fsencode(filename_path)
 *         except UnicodeError:
*/
      }
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pyreadstat/_readstat_writer.pyx":672
 *         try:
 *             filename_bytes = 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_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("pyreadstat._readstat_writer.filepath_to_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(0, 672, __pyx_L6_except_error)
        __Pyx_XGOTREF(__pyx_t_1);
        __Pyx_XGOTREF(__pyx_t_8);
        __Pyx_XGOTREF(__pyx_t_6);

        /* "pyreadstat/_readstat_writer.pyx":673
 *             filename_bytes = 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_t_11 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_warnings); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 673, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_warn); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 673, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_14 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_mstate_global->__pyx_n_u_sys); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 673, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_mstate_global->__pyx_n_u_getfilesystemencoding); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 673, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_9 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_16))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_16);
          assert(__pyx_t_14);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_16);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_16, __pyx__function);
          __pyx_t_9 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_14, NULL};
          __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+__pyx_t_9, (1-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 673, __pyx_L6_except_error)
          __Pyx_GOTREF(__pyx_t_12);
        }
        __pyx_t_16 = __Pyx_PyUnicode_FormatSafe(__pyx_mstate_global->__pyx_kp_u_file_path_could_not_be_encoded_w, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 673, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_9 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_13))) {
          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13);
          assert(__pyx_t_11);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_13, __pyx__function);
          __pyx_t_9 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_t_16};
          __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 673, __pyx_L6_except_error)
          __Pyx_GOTREF(__pyx_t_7);
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pyreadstat/_readstat_writer.pyx":674
 *         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_t_13 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 674, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_mstate_global->__pyx_n_u_fsdecode); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 674, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_9 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11);
          assert(__pyx_t_13);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_11, __pyx__function);
          __pyx_t_9 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_v_filename_path};
          __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_11, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 674, __pyx_L6_except_error)
          __Pyx_GOTREF(__pyx_t_7);
        }
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_encode); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 674, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 674, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF_SET(__pyx_v_filename_bytes, __pyx_t_7);
        __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;

      /* "pyreadstat/_readstat_writer.pyx":670
 *     """
 *     if hasattr(os, 'fsencode'):
 *         try:             # <<<<<<<<<<<<<<
 *             filename_bytes = os.fsencode(filename_path)
 *         except UnicodeError:
*/
      __pyx_L6_except_error:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      __pyx_L9_try_end:;
    }

    /* "pyreadstat/_readstat_writer.pyx":669
 *     transforms an object with the path to the filename to bytes
 *     """
 *     if hasattr(os, 'fsencode'):             # <<<<<<<<<<<<<<
 *         try:
 *             filename_bytes = os.fsencode(filename_path)
*/
    goto __pyx_L3;
  }

  /* "pyreadstat/_readstat_writer.pyx":676
 *             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_6 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_filename_path)), ((PyObject *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 676, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 676, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_2) {

      /* "pyreadstat/_readstat_writer.pyx":677
 *     else:
 *         if type(filename_path) == str:
 *             filename_bytes = filename_path.encode('utf-8')             # <<<<<<<<<<<<<<
 *         elif type(filename_path) == bytes:
 *             filename_bytes = filename_path
*/
      __pyx_t_8 = __pyx_v_filename_path;
      __Pyx_INCREF(__pyx_t_8);
      __pyx_t_9 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_mstate_global->__pyx_kp_u_utf_8};
        __pyx_t_6 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 677, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
      }
      __pyx_v_filename_bytes = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pyreadstat/_readstat_writer.pyx":676
 *             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_L12;
    }

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

      /* "pyreadstat/_readstat_writer.pyx":679
 *             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":678
 *         if type(filename_path) == str:
 *             filename_bytes = filename_path.encode('utf-8')
 *         elif type(filename_path) == bytes:             # <<<<<<<<<<<<<<
 *             filename_bytes = filename_path
 *         else:
*/
      goto __pyx_L12;
    }

    /* "pyreadstat/_readstat_writer.pyx":681
 *             filename_bytes = filename_path
 *         else:
 *             raise PyreadstatError("path must be either str or bytes")             # <<<<<<<<<<<<<<
 *     return filename_bytes
 * 
*/
    /*else*/ {
      __pyx_t_8 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
        assert(__pyx_t_8);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_1, __pyx__function);
        __pyx_t_9 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_mstate_global->__pyx_kp_u_path_must_be_either_str_or_bytes};
        __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 681, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(0, 681, __pyx_L1_error)
    }
    __pyx_L12:;
  }
  __pyx_L3:;

  /* "pyreadstat/_readstat_writer.pyx":682
 *         else:
 *             raise PyreadstatError("path must be either str or bytes")
 *     return filename_bytes             # <<<<<<<<<<<<<<
 * 
 * 
*/
  __Pyx_XDECREF(__pyx_r);
  if (!(likely(PyBytes_CheckExact(__pyx_v_filename_bytes))||((__pyx_v_filename_bytes) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_v_filename_bytes))) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_INCREF(__pyx_v_filename_bytes);
  __pyx_r = ((PyObject*)__pyx_v_filename_bytes);
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":665
 *         raise PyreadstatError(f"the destination folder {dirname} does not exist!")
 * 
 * cdef bytes filepath_to_bytes(object filename_path):             # <<<<<<<<<<<<<<
 *     """
 *     transforms an object with the path to the filename to bytes
*/

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __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);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.filepath_to_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_filename_bytes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyreadstat/_readstat_writer.pyx":685
 * 
 * 
 * cdef int run_write(df, object filename_path, dst_file_format file_format, str file_label, object column_labels,             # <<<<<<<<<<<<<<
 *                    int file_format_version, object 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_natnamespace = 0;
  PyObject *__pyx_v_pd = 0;
  int __pyx_v_is_pandas;
  int __pyx_v_is_polars;
  PyObject *__pyx_v_filename_bytes = 0;
  PyObject *__pyx_v_col_names = 0;
  readstat_writer_t *__pyx_v_writer;
  PyObject *__pyx_v_file_label_bytes = 0;
  char *__pyx_v_file_labl;
  int __pyx_v_dta_str_max_len;
  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_pywriter_timeunits = 0;
  PyObject *__pyx_v_df2 = 0;
  readstat_string_ref_t *__pyx_v_strref;
  PyObject *__pyx_v_strref_map = 0;
  int __pyx_v_strref_cnt;
  PyObject *__pyx_v_strref_indx = 0;
  int __pyx_v_fd;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_table_name_bytes = NULL;
  char *__pyx_v_tab_name;
  PyObject *__pyx_v_variable_name = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_curval = NULL;
  PyObject *__pyx_v_labelset_name = NULL;
  PyObject *__pyx_v_curuser_missing = NULL;
  PyObject *__pyx_v_cur_ranges = NULL;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_cur_alignment = NULL;
  PyObject *__pyx_v_cur_display_width = NULL;
  PyObject *__pyx_v_cur_measure = NULL;
  PyObject *__pyx_v_hasdate64 = NULL;
  PyObject *__pyx_v_hastime64 = NULL;
  PyObject *__pyx_v_rowcnt = NULL;
  PyObject *__pyx_v_row = NULL;
  PyObject *__pyx_v_is_missing = NULL;
  PyObject *__pyx_v_check_if_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;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  size_t __pyx_t_5;
  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 *);
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  char *__pyx_t_16;
  char const *__pyx_t_17;
  int __pyx_t_18;
  int __pyx_t_19;
  int __pyx_t_20;
  int __pyx_t_21;
  __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __pyx_t_22;
  int __pyx_t_23;
  char const *__pyx_t_24;
  readstat_type_t __pyx_t_25;
  char const *__pyx_t_26;
  char const *__pyx_t_27;
  char const *__pyx_t_28;
  readstat_label_set_t *__pyx_t_29;
  long __pyx_t_30;
  double __pyx_t_31;
  int32_t __pyx_t_32;
  char const *__pyx_t_33;
  char const *__pyx_t_34;
  PyObject *__pyx_t_35 = NULL;
  PyObject *__pyx_t_36 = NULL;
  PyObject *__pyx_t_37 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("run_write", 0);
  __Pyx_INCREF(__pyx_v_df);
  __Pyx_INCREF(__pyx_v_column_labels);
  __Pyx_INCREF(__pyx_v_note);

  /* "pyreadstat/_readstat_writer.pyx":696
 * 
 *     cdef object natnamespace
 *     cdef object pd = None             # <<<<<<<<<<<<<<
 *     cdef bint is_pandas, is_polars
 *     cdef bytes filename_bytes
*/
  __Pyx_INCREF(Py_None);
  __pyx_v_pd = Py_None;

  /* "pyreadstat/_readstat_writer.pyx":701
 *     cdef list col_names
 * 
 *     filename_bytes = filepath_to_bytes(filename_path)             # <<<<<<<<<<<<<<
 *     filename_bytes = os.path.expanduser(filename_bytes)
 * 
*/
  __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_writer_filepath_to_bytes(__pyx_v_filename_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_filename_bytes = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":702
 * 
 *     filename_bytes = filepath_to_bytes(filename_path)
 *     filename_bytes = os.path.expanduser(filename_bytes)             # <<<<<<<<<<<<<<
 * 
 *     df = nw.from_native(df, eager_only=True)
*/
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_2 = __pyx_t_4;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_5 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_filename_bytes};
    __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_expanduser, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 702, __pyx_L1_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, 702, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_filename_bytes, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":704
 *     filename_bytes = os.path.expanduser(filename_bytes)
 * 
 *     df = nw.from_native(df, eager_only=True)             # <<<<<<<<<<<<<<
 *     natnamespace = nw.get_native_namespace(df)
 *     is_pandas = df.implementation.is_pandas()
*/
  __pyx_t_4 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 704, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_from_native); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 704, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    assert(__pyx_t_4);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_v_df};
    __pyx_t_2 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 704, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_eager_only, Py_True, __pyx_t_2, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 704, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 704, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":705
 * 
 *     df = nw.from_native(df, eager_only=True)
 *     natnamespace = nw.get_native_namespace(df)             # <<<<<<<<<<<<<<
 *     is_pandas = df.implementation.is_pandas()
 *     is_polars = df.implementation.is_polars()
*/
  __pyx_t_3 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_get_native_namespace); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 705, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_3);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_df};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __pyx_v_natnamespace = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":706
 *     df = nw.from_native(df, eager_only=True)
 *     natnamespace = nw.get_native_namespace(df)
 *     is_pandas = df.implementation.is_pandas()             # <<<<<<<<<<<<<<
 *     is_polars = df.implementation.is_polars()
 *     col_names = df.columns
*/
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_mstate_global->__pyx_n_u_implementation); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __pyx_t_3;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_5 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_pandas, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 706, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_pandas = __pyx_t_6;

  /* "pyreadstat/_readstat_writer.pyx":707
 *     natnamespace = nw.get_native_namespace(df)
 *     is_pandas = df.implementation.is_pandas()
 *     is_polars = df.implementation.is_polars()             # <<<<<<<<<<<<<<
 *     col_names = df.columns
 *     if is_pandas:
*/
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_mstate_global->__pyx_n_u_implementation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __pyx_t_4;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_5 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_polars, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 707, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_polars = __pyx_t_6;

  /* "pyreadstat/_readstat_writer.pyx":708
 *     is_pandas = df.implementation.is_pandas()
 *     is_polars = df.implementation.is_polars()
 *     col_names = df.columns             # <<<<<<<<<<<<<<
 *     if is_pandas:
 *         pd = natnamespace
*/
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_mstate_global->__pyx_n_u_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_1))) __PYX_ERR(0, 708, __pyx_L1_error)
  __pyx_v_col_names = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":709
 *     is_polars = df.implementation.is_polars()
 *     col_names = df.columns
 *     if is_pandas:             # <<<<<<<<<<<<<<
 *         pd = natnamespace
 * 
*/
  if (__pyx_v_is_pandas) {

    /* "pyreadstat/_readstat_writer.pyx":710
 *     col_names = df.columns
 *     if is_pandas:
 *         pd = natnamespace             # <<<<<<<<<<<<<<
 * 
 *     initial_checks(is_pandas, is_polars, variable_value_labels, missing_user_values, file_format,
*/
    __Pyx_INCREF(__pyx_v_natnamespace);
    __Pyx_DECREF_SET(__pyx_v_pd, __pyx_v_natnamespace);

    /* "pyreadstat/_readstat_writer.pyx":709
 *     is_polars = df.implementation.is_polars()
 *     col_names = df.columns
 *     if is_pandas:             # <<<<<<<<<<<<<<
 *         pd = natnamespace
 * 
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":712
 *         pd = natnamespace
 * 
 *     initial_checks(is_pandas, is_polars, variable_value_labels, missing_user_values, file_format,             # <<<<<<<<<<<<<<
 *                          col_names, filename_bytes)
 * 
*/
  __pyx_f_10pyreadstat_16_readstat_writer_initial_checks(__pyx_v_is_pandas, __pyx_v_is_polars, __pyx_v_variable_value_labels, __pyx_v_missing_user_values, __pyx_v_file_format, __pyx_v_col_names, __pyx_v_filename_bytes); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 712, __pyx_L1_error)

  /* "pyreadstat/_readstat_writer.pyx":723
 *     cdef bytes file_label_bytes
 *     cdef char *file_labl
 *     cdef int dta_str_max_len = 0             # <<<<<<<<<<<<<<
 * 
 * 
*/
  __pyx_v_dta_str_max_len = 0;

  /* "pyreadstat/_readstat_writer.pyx":726
 * 
 * 
 *     if file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         col_names = [x.upper() for x in col_names]
 * 
*/
  __pyx_t_6 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR);
  if (__pyx_t_6) {

    /* "pyreadstat/_readstat_writer.pyx":727
 * 
 *     if file_format == FILE_FORMAT_POR:
 *         col_names = [x.upper() for x in col_names]             # <<<<<<<<<<<<<<
 * 
 *     if file_format == FILE_FORMAT_DTA:
*/
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(__pyx_v_col_names == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 727, __pyx_L1_error)
    }
    __pyx_t_4 = __pyx_v_col_names; __Pyx_INCREF(__pyx_t_4);
    __pyx_t_7 = 0;
    for (;;) {
      {
        Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_4);
        #if !CYTHON_ASSUME_SAFE_SIZE
        if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 727, __pyx_L1_error)
        #endif
        if (__pyx_t_7 >= __pyx_temp) break;
      }
      __pyx_t_3 = __Pyx_PyList_GetItemRef(__pyx_t_4, __pyx_t_7);
      ++__pyx_t_7;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_v_x;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_5 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_upper, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_col_names, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyreadstat/_readstat_writer.pyx":726
 * 
 * 
 *     if file_format == FILE_FORMAT_POR:             # <<<<<<<<<<<<<<
 *         col_names = [x.upper() for x in col_names]
 * 
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":729
 *         col_names = [x.upper() for x in col_names]
 * 
 *     if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *         if file_format_version >= 117:
 *             dta_str_max_len = dta_117_max_width
*/
  __pyx_t_6 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA);
  if (__pyx_t_6) {

    /* "pyreadstat/_readstat_writer.pyx":730
 * 
 *     if file_format == FILE_FORMAT_DTA:
 *         if file_format_version >= 117:             # <<<<<<<<<<<<<<
 *             dta_str_max_len = dta_117_max_width
 *         elif file_format_version >= 111:
*/
    __pyx_t_6 = (__pyx_v_file_format_version >= 0x75);
    if (__pyx_t_6) {

      /* "pyreadstat/_readstat_writer.pyx":731
 *     if file_format == FILE_FORMAT_DTA:
 *         if file_format_version >= 117:
 *             dta_str_max_len = dta_117_max_width             # <<<<<<<<<<<<<<
 *         elif file_format_version >= 111:
 *             dta_str_max_len = dta_111_max_width
*/
      __pyx_v_dta_str_max_len = __pyx_v_10pyreadstat_16_readstat_writer_dta_117_max_width;

      /* "pyreadstat/_readstat_writer.pyx":730
 * 
 *     if file_format == FILE_FORMAT_DTA:
 *         if file_format_version >= 117:             # <<<<<<<<<<<<<<
 *             dta_str_max_len = dta_117_max_width
 *         elif file_format_version >= 111:
*/
      goto __pyx_L9;
    }

    /* "pyreadstat/_readstat_writer.pyx":732
 *         if file_format_version >= 117:
 *             dta_str_max_len = dta_117_max_width
 *         elif file_format_version >= 111:             # <<<<<<<<<<<<<<
 *             dta_str_max_len = dta_111_max_width
 *         else:
*/
    __pyx_t_6 = (__pyx_v_file_format_version >= 0x6F);
    if (__pyx_t_6) {

      /* "pyreadstat/_readstat_writer.pyx":733
 *             dta_str_max_len = dta_117_max_width
 *         elif file_format_version >= 111:
 *             dta_str_max_len = dta_111_max_width             # <<<<<<<<<<<<<<
 *         else:
 *             dta_str_max_len = dta_old_max_width
*/
      __pyx_v_dta_str_max_len = __pyx_v_10pyreadstat_16_readstat_writer_dta_111_max_width;

      /* "pyreadstat/_readstat_writer.pyx":732
 *         if file_format_version >= 117:
 *             dta_str_max_len = dta_117_max_width
 *         elif file_format_version >= 111:             # <<<<<<<<<<<<<<
 *             dta_str_max_len = dta_111_max_width
 *         else:
*/
      goto __pyx_L9;
    }

    /* "pyreadstat/_readstat_writer.pyx":735
 *             dta_str_max_len = dta_111_max_width
 *         else:
 *             dta_str_max_len = dta_old_max_width             # <<<<<<<<<<<<<<
 * 
 *     cdef list col_types = get_narwhals_column_types(df, missing_user_values, variable_value_labels, dta_str_max_len)
*/
    /*else*/ {
      __pyx_v_dta_str_max_len = __pyx_v_10pyreadstat_16_readstat_writer_dta_old_max_width;
    }
    __pyx_L9:;

    /* "pyreadstat/_readstat_writer.pyx":729
 *         col_names = [x.upper() for x in col_names]
 * 
 *     if file_format == FILE_FORMAT_DTA:             # <<<<<<<<<<<<<<
 *         if file_format_version >= 117:
 *             dta_str_max_len = dta_117_max_width
*/
  }

  /* "pyreadstat/_readstat_writer.pyx":737
 *             dta_str_max_len = dta_old_max_width
 * 
 *     cdef list col_types = get_narwhals_column_types(df, missing_user_values, variable_value_labels, dta_str_max_len)             # <<<<<<<<<<<<<<
 *     cdef int row_count = len(df)
 *     cdef int col_count = len(col_names)
*/
  __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_writer_get_narwhals_column_types(__pyx_v_df, __pyx_v_missing_user_values, __pyx_v_variable_value_labels, __pyx_v_dta_str_max_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_col_types = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":738
 * 
 *     cdef list col_types = get_narwhals_column_types(df, missing_user_values, variable_value_labels, dta_str_max_len)
 *     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_7 = PyObject_Length(__pyx_v_df); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 738, __pyx_L1_error)
  __pyx_v_row_count = __pyx_t_7;

  /* "pyreadstat/_readstat_writer.pyx":739
 *     cdef list col_types = get_narwhals_column_types(df, missing_user_values, variable_value_labels, dta_str_max_len)
 *     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, 739, __pyx_L1_error)
  }
  __pyx_t_7 = __Pyx_PyList_GET_SIZE(__pyx_v_col_names); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 739, __pyx_L1_error)
  __pyx_v_col_count = __pyx_t_7;

  /* "pyreadstat/_readstat_writer.pyx":740
 *     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_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 740, __pyx_L12_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_builtin_zip);
    __pyx_t_2 = __pyx_builtin_zip; 
    __pyx_t_5 = 1;
    {
      PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_v_col_names, __pyx_v_col_types};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_5, (3-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 740, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
      __pyx_t_2 = __pyx_t_4; __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_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 740, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 740, __pyx_L12_error)
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 740, __pyx_L12_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          __pyx_t_4 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_7);
          ++__pyx_t_7;
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 740, __pyx_L12_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_4 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7));
          #else
          __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_7);
          #endif
          ++__pyx_t_7;
        }
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 740, __pyx_L12_error)
      } else {
        __pyx_t_4 = __pyx_t_8(__pyx_t_2);
        if (unlikely(!__pyx_t_4)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 740, __pyx_L12_error)
            PyErr_Clear();
          }
          break;
        }
      }
      __Pyx_GOTREF(__pyx_t_4);
      if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
        PyObject* sequence = __pyx_t_4;
        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, 740, __pyx_L12_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0);
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1);
          __Pyx_INCREF(__pyx_t_9);
        } else {
          __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0);
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 740, __pyx_L12_error)
          __Pyx_XGOTREF(__pyx_t_3);
          __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1);
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 740, __pyx_L12_error)
          __Pyx_XGOTREF(__pyx_t_9);
        }
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 740, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 740, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 740, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
        index = 0; __pyx_t_3 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_3)) goto __pyx_L15_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L15_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 740, __pyx_L12_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L16_unpacking_done;
        __pyx_L15_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, 740, __pyx_L12_error)
        __pyx_L16_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_k, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_v, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_7genexpr__pyx_v_v, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 740, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_7genexpr__pyx_v_k, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 740, __pyx_L12_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_L18_exit_scope;
    __pyx_L12_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_L18_exit_scope:;
  } /* exit inner scope */
  __pyx_v_col_names_to_types = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":749
 *     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":758
 *     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":766
 *     cdef float mulfac, conv2secs
 *     cdef readstat_string_ref_t* strref
 *     cdef dict strref_map = dict()             # <<<<<<<<<<<<<<
 *     cdef int strref_cnt
 *     cdef object strref_indx
*/
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 766, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_strref_map = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyreadstat/_readstat_writer.pyx":771
 * 
 * 
 *     cdef int fd = open_file(filename_bytes)             # <<<<<<<<<<<<<<
 *     writer = readstat_writer_init()
 * 
*/
  __pyx_t_12 = __pyx_f_10pyreadstat_16_readstat_writer_open_file(__pyx_v_filename_bytes); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 771, __pyx_L1_error)
  __pyx_v_fd = __pyx_t_12;

  /* "pyreadstat/_readstat_writer.pyx":772
 * 
 *     cdef int fd = open_file(filename_bytes)
 *     writer = readstat_writer_init()             # <<<<<<<<<<<<<<
 * 
 *     try:
*/
  __pyx_v_writer = readstat_writer_init();

  /* "pyreadstat/_readstat_writer.pyx":774
 *     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_13, &__pyx_t_14, &__pyx_t_15);
      __Pyx_XGOTREF(__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_14);
      __Pyx_XGOTREF(__pyx_t_15);
      /*try:*/ {

        /* "pyreadstat/_readstat_writer.pyx":776
 *     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, 776, __pyx_L22_error)

        /* "pyreadstat/_readstat_writer.pyx":778
 *         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_6 = (__pyx_v_file_label != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_file_label) != 0);
        if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_6 < 0))) __PYX_ERR(0, 778, __pyx_L22_error)
        if (__pyx_t_6) {

          /* "pyreadstat/_readstat_writer.pyx":779
 * 
 *         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 == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
            __PYX_ERR(0, 779, __pyx_L22_error)
          }
          __pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_file_label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 779, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_v_file_label_bytes = ((PyObject*)__pyx_t_1);
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":780
 *         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_16 = __Pyx_PyBytes_AsWritableString(__pyx_v_file_label_bytes); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 780, __pyx_L22_error)
          __pyx_v_file_labl = ((char *)__pyx_t_16);

          /* "pyreadstat/_readstat_writer.pyx":781
 *             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, 781, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":778
 *         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":783
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))
 * 
 *         if note:             # <<<<<<<<<<<<<<
 *             if type(note) == str:
 *                 note = [note]
*/
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_note); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 783, __pyx_L22_error)
        if (__pyx_t_6) {

          /* "pyreadstat/_readstat_writer.pyx":784
 * 
 *         if note:
 *             if type(note) == str:             # <<<<<<<<<<<<<<
 *                 note = [note]
 *             if type(note) == list:
*/
          __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_note)), ((PyObject *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L22_error)
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 784, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":785
 *         if note:
 *             if type(note) == str:
 *                 note = [note]             # <<<<<<<<<<<<<<
 *             if type(note) == list:
 *                 for line in note:
*/
            __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_INCREF(__pyx_v_note);
            __Pyx_GIVEREF(__pyx_v_note);
            if (__Pyx_PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_note) != (0)) __PYX_ERR(0, 785, __pyx_L22_error);
            __Pyx_DECREF_SET(__pyx_v_note, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":784
 * 
 *         if note:
 *             if type(note) == str:             # <<<<<<<<<<<<<<
 *                 note = [note]
 *             if type(note) == list:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":786
 *             if type(note) == str:
 *                 note = [note]
 *             if type(note) == list:             # <<<<<<<<<<<<<<
 *                 for line in note:
 *                     readstat_add_note(writer, line.encode("utf-8"))
*/
          __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_note)), ((PyObject *)(&PyList_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 786, __pyx_L22_error)
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 786, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (likely(__pyx_t_6)) {

            /* "pyreadstat/_readstat_writer.pyx":787
 *                 note = [note]
 *             if type(note) == list:
 *                 for line in note:             # <<<<<<<<<<<<<<
 *                     readstat_add_note(writer, line.encode("utf-8"))
 *             else:
*/
            if (likely(PyList_CheckExact(__pyx_v_note)) || PyTuple_CheckExact(__pyx_v_note)) {
              __pyx_t_1 = __pyx_v_note; __Pyx_INCREF(__pyx_t_1);
              __pyx_t_7 = 0;
              __pyx_t_8 = NULL;
            } else {
              __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_note); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 787, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 787, __pyx_L22_error)
            }
            for (;;) {
              if (likely(!__pyx_t_8)) {
                if (likely(PyList_CheckExact(__pyx_t_1))) {
                  {
                    Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
                    #if !CYTHON_ASSUME_SAFE_SIZE
                    if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 787, __pyx_L22_error)
                    #endif
                    if (__pyx_t_7 >= __pyx_temp) break;
                  }
                  __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_1, __pyx_t_7);
                  ++__pyx_t_7;
                } else {
                  {
                    Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
                    #if !CYTHON_ASSUME_SAFE_SIZE
                    if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 787, __pyx_L22_error)
                    #endif
                    if (__pyx_t_7 >= __pyx_temp) break;
                  }
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7));
                  #else
                  __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_7);
                  #endif
                  ++__pyx_t_7;
                }
                if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 787, __pyx_L22_error)
              } else {
                __pyx_t_2 = __pyx_t_8(__pyx_t_1);
                if (unlikely(!__pyx_t_2)) {
                  PyObject* exc_type = PyErr_Occurred();
                  if (exc_type) {
                    if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 787, __pyx_L22_error)
                    PyErr_Clear();
                  }
                  break;
                }
              }
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_2);
              __pyx_t_2 = 0;

              /* "pyreadstat/_readstat_writer.pyx":788
 *             if type(note) == list:
 *                 for line in note:
 *                     readstat_add_note(writer, line.encode("utf-8"))             # <<<<<<<<<<<<<<
 *             else:
 *                 raise PyreadstatError(f"note should be either str or list, got {type(note)}")
*/
              __pyx_t_4 = __pyx_v_line;
              __Pyx_INCREF(__pyx_t_4);
              __pyx_t_5 = 0;
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_utf_8};
                __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 788, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_2);
              }
              __pyx_t_17 = __Pyx_PyObject_AsString(__pyx_t_2); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 788, __pyx_L22_error)
              readstat_add_note(__pyx_v_writer, __pyx_t_17);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

              /* "pyreadstat/_readstat_writer.pyx":787
 *                 note = [note]
 *             if type(note) == list:
 *                 for line in note:             # <<<<<<<<<<<<<<
 *                     readstat_add_note(writer, line.encode("utf-8"))
 *             else:
*/
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":786
 *             if type(note) == str:
 *                 note = [note]
 *             if type(note) == list:             # <<<<<<<<<<<<<<
 *                 for line in note:
 *                     readstat_add_note(writer, line.encode("utf-8"))
*/
            goto __pyx_L31;
          }

          /* "pyreadstat/_readstat_writer.pyx":790
 *                     readstat_add_note(writer, line.encode("utf-8"))
 *             else:
 *                 raise PyreadstatError(f"note should be either str or list, got {type(note)}")             # <<<<<<<<<<<<<<
 * 
 *         if file_format_version > -1:
*/
          /*else*/ {
            __pyx_t_2 = NULL;
            __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 790, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_9 = __Pyx_PyObject_FormatSimple(((PyObject *)Py_TYPE(__pyx_v_note)), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 790, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_3 = __Pyx_PyUnicode_Concat(__pyx_mstate_global->__pyx_kp_u_note_should_be_either_str_or_lis, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 790, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_2);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_3};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 790, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
            }
            __Pyx_Raise(__pyx_t_1, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __PYX_ERR(0, 790, __pyx_L22_error)
          }
          __pyx_L31:;

          /* "pyreadstat/_readstat_writer.pyx":783
 *             check_exit_status(readstat_writer_set_file_label(writer, file_labl))
 * 
 *         if note:             # <<<<<<<<<<<<<<
 *             if type(note) == str:
 *                 note = [note]
*/
        }

        /* "pyreadstat/_readstat_writer.pyx":792
 *                 raise PyreadstatError(f"note should be either str or list, got {type(note)}")
 * 
 *         if file_format_version > -1:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))
 * 
*/
        __pyx_t_6 = (__pyx_v_file_format_version > -1L);
        if (__pyx_t_6) {

          /* "pyreadstat/_readstat_writer.pyx":793
 * 
 *         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, 793, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":792
 *                 raise PyreadstatError(f"note should be either str or list, got {type(note)}")
 * 
 *         if file_format_version > -1:             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version))
 * 
*/
        }

        /* "pyreadstat/_readstat_writer.pyx":795
 *             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":796
 * 
 *         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, 796, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":795
 *             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":799
 * 
 *         # 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_6 = (__pyx_v_table_name != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_table_name) != 0);
        if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_6 < 0))) __PYX_ERR(0, 799, __pyx_L22_error)
        if (__pyx_t_6) {

          /* "pyreadstat/_readstat_writer.pyx":800
 *         # 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))
*/
          if (unlikely(__pyx_v_table_name == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
            __PYX_ERR(0, 800, __pyx_L22_error)
          }
          __pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 800, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_v_table_name_bytes = ((PyObject*)__pyx_t_1);
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":801
 *         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_16 = __Pyx_PyBytes_AsWritableString(__pyx_v_table_name_bytes); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 801, __pyx_L22_error)
          __pyx_v_tab_name = ((char *)__pyx_t_16);

          /* "pyreadstat/_readstat_writer.pyx":802
 *             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, 802, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":799
 * 
 *         # 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":805
 * 
 *         # 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_6 = __Pyx_PyObject_IsTrue(__pyx_v_column_labels); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 805, __pyx_L22_error)
        if (__pyx_t_6) {

          /* "pyreadstat/_readstat_writer.pyx":806
 *         # 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, 806, __pyx_L22_error)
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 806, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_18) {
          } else {
            __pyx_t_6 = __pyx_t_18;
            goto __pyx_L40_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, 806, __pyx_L22_error)
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 806, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_6 = __pyx_t_18;
          __pyx_L40_bool_binop_done:;
          if (unlikely(__pyx_t_6)) {

            /* "pyreadstat/_readstat_writer.pyx":807
 *         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_t_4 = NULL;
            __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 807, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              assert(__pyx_t_4);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_column_labels_must_be_either_lis};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 807, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
            }
            __Pyx_Raise(__pyx_t_1, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __PYX_ERR(0, 807, __pyx_L22_error)

            /* "pyreadstat/_readstat_writer.pyx":806
 *         # 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":808
 *             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, 808, __pyx_L22_error)
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 808, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":809
 *                 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, 809, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_v_col_label_temp = ((PyObject*)__pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":810
 *             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_12 = __pyx_v_col_count;
            __pyx_t_19 = __pyx_t_12;
            for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
              __pyx_v_col_indx = __pyx_t_20;

              /* "pyreadstat/_readstat_writer.pyx":811
 *                 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, 811, __pyx_L22_error)
              }
              __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_names, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_XDECREF_SET(__pyx_v_variable_name, __pyx_t_1);
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":812
 *                 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_3 = __pyx_v_column_labels;
              __Pyx_INCREF(__pyx_t_3);
              __pyx_t_5 = 0;
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
                __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_keys, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
              }
              __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_v_variable_name, __pyx_t_1, Py_EQ)); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 812, __pyx_L22_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              if (__pyx_t_6) {

                /* "pyreadstat/_readstat_writer.pyx":813
 *                     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, 813, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
                __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_col_label_temp, __pyx_t_1); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 813, __pyx_L22_error)
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":812
 *                 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_L45;
              }

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

            /* "pyreadstat/_readstat_writer.pyx":816
 *                     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":808
 *             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":818
 *                 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_7 = PyObject_Length(__pyx_v_column_labels); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 818, __pyx_L22_error)
          __pyx_v_col_label_count = __pyx_t_7;

          /* "pyreadstat/_readstat_writer.pyx":819
 * 
 *             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_6 = (__pyx_v_col_label_count != __pyx_v_col_count);
          if (unlikely(__pyx_t_6)) {

            /* "pyreadstat/_readstat_writer.pyx":820
 *             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")             # <<<<<<<<<<<<<<
 * 
 *         strref_cnt = 0
*/
            __pyx_t_3 = NULL;
            __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 820, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_length_of_column_labels_must_be};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 820, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
            }
            __Pyx_Raise(__pyx_t_1, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __PYX_ERR(0, 820, __pyx_L22_error)

            /* "pyreadstat/_readstat_writer.pyx":819
 * 
 *             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":805
 * 
 *         # 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":822
 *                 raise PyreadstatError("length of column labels must be the same as number of columns")
 * 
 *         strref_cnt = 0             # <<<<<<<<<<<<<<
 *         for col_indx in range(col_count):
 *             curtype, max_length, _,_ = col_types[col_indx]
*/
        __pyx_v_strref_cnt = 0;

        /* "pyreadstat/_readstat_writer.pyx":823
 * 
 *         strref_cnt = 0
 *         for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 *             curtype, max_length, _,_ = col_types[col_indx]
 *             variable_name = col_names[col_indx]
*/
        __pyx_t_12 = __pyx_v_col_count;
        __pyx_t_19 = __pyx_t_12;
        for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
          __pyx_v_col_indx = __pyx_t_20;

          /* "pyreadstat/_readstat_writer.pyx":824
 *         strref_cnt = 0
 *         for col_indx in range(col_count):
 *             curtype, max_length, _,_ = col_types[col_indx]             # <<<<<<<<<<<<<<
 *             variable_name = col_names[col_indx]
 *             # add variable
*/
          if (unlikely(__pyx_v_col_types == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 824, __pyx_L22_error)
          }
          __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_types, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 824, __pyx_L22_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 != 4)) {
              if (size > 4) __Pyx_RaiseTooManyValuesError(4);
              else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
              __PYX_ERR(0, 824, __pyx_L22_error)
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0);
              __Pyx_INCREF(__pyx_t_4);
              __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1);
              __Pyx_INCREF(__pyx_t_3);
              __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2);
              __Pyx_INCREF(__pyx_t_2);
              __pyx_t_9 = PyTuple_GET_ITEM(sequence, 3);
              __Pyx_INCREF(__pyx_t_9);
            } else {
              __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 0);
              if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 824, __pyx_L22_error)
              __Pyx_XGOTREF(__pyx_t_4);
              __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1);
              if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 824, __pyx_L22_error)
              __Pyx_XGOTREF(__pyx_t_3);
              __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 2);
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 824, __pyx_L22_error)
              __Pyx_XGOTREF(__pyx_t_2);
              __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 3);
              if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 824, __pyx_L22_error)
              __Pyx_XGOTREF(__pyx_t_9);
            }
            #else
            {
              Py_ssize_t i;
              PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_3,&__pyx_t_2,&__pyx_t_9};
              for (i=0; i < 4; i++) {
                PyObject* item = __Pyx_PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 824, __pyx_L22_error)
                __Pyx_GOTREF(item);
                *(temps[i]) = item;
              }
            }
            #endif
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else {
            Py_ssize_t index = -1;
            PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_3,&__pyx_t_2,&__pyx_t_9};
            __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 824, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_10);
            for (index=0; index < 4; index++) {
              PyObject* item = __pyx_t_11(__pyx_t_10); if (unlikely(!item)) goto __pyx_L49_unpacking_failed;
              __Pyx_GOTREF(item);
              *(temps[index]) = item;
            }
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 4) < 0) __PYX_ERR(0, 824, __pyx_L22_error)
            __pyx_t_11 = NULL;
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            goto __pyx_L50_unpacking_done;
            __pyx_L49_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, 824, __pyx_L22_error)
            __pyx_L50_unpacking_done:;
          }
          __pyx_t_22 = ((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)__Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_4)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 824, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_23 = __Pyx_PyLong_As_int(__pyx_t_3); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 824, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_v_curtype = __pyx_t_22;
          __pyx_v_max_length = __pyx_t_23;
          __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_2);
          __pyx_t_2 = 0;
          __Pyx_DECREF_SET(__pyx_v__, __pyx_t_9);
          __pyx_t_9 = 0;

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

          /* "pyreadstat/_readstat_writer.pyx":827
 *             variable_name = col_names[col_indx]
 *             # add variable
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), narwhals_to_readstat_types[curtype], max_length)             # <<<<<<<<<<<<<<
 *             # add format
 *             if variable_format:
*/
          __pyx_t_9 = __pyx_v_variable_name;
          __Pyx_INCREF(__pyx_t_9);
          __pyx_t_5 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_utf_8};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 827, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __pyx_t_24 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_24) && PyErr_Occurred())) __PYX_ERR(0, 827, __pyx_L22_error)
          if (unlikely(__pyx_v_10pyreadstat_16_readstat_writer_narwhals_to_readstat_types == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 827, __pyx_L22_error)
          }
          __pyx_t_9 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 827, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_10pyreadstat_16_readstat_writer_narwhals_to_readstat_types, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 827, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_25 = ((readstat_type_t)__Pyx_PyLong_As_readstat_type_t(__pyx_t_2)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 827, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_v_variable = readstat_add_variable(__pyx_v_writer, __pyx_t_24, __pyx_t_25, __pyx_v_max_length);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":829
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), narwhals_to_readstat_types[curtype], max_length)
 *             # add format
 *             if variable_format:             # <<<<<<<<<<<<<<
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:
*/
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_variable_format); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 829, __pyx_L22_error)
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":830
 *             # add format
 *             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, 830, __pyx_L22_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, 830, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_1))) __PYX_ERR(0, 830, __pyx_L22_error)
            __Pyx_XDECREF_SET(__pyx_v_tempformat, ((PyObject*)__pyx_t_1));
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":831
 *             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_6 = (__pyx_v_tempformat != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_tempformat) != 0);
            if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_6 < 0))) __PYX_ERR(0, 831, __pyx_L22_error)
            if (__pyx_t_6) {

              /* "pyreadstat/_readstat_writer.pyx":832
 *                 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)
*/
              if (unlikely(__pyx_v_tempformat == Py_None)) {
                PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
                __PYX_ERR(0, 832, __pyx_L22_error)
              }
              __pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_tempformat); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 832, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_26 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_26) && PyErr_Occurred())) __PYX_ERR(0, 832, __pyx_L22_error)
              readstat_variable_set_format(__pyx_v_variable, __pyx_t_26);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":831
 *             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":829
 *             variable = readstat_add_variable(writer, variable_name.encode("utf-8"), narwhals_to_readstat_types[curtype], max_length)
 *             # add format
 *             if variable_format:             # <<<<<<<<<<<<<<
 *                 tempformat = variable_format.get(variable_name)
 *                 if tempformat:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":833
 *                 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_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 833, __pyx_L22_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, 833, __pyx_L22_error)
          }
          __pyx_t_18 = (__Pyx_PySet_ContainsTF(__pyx_t_1, __pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types, Py_EQ)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 833, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_18) {
          } else {
            __pyx_t_6 = __pyx_t_18;
            goto __pyx_L54_bool_binop_done;
          }
          __pyx_t_18 = (__pyx_v_variable_format == ((PyObject*)Py_None));
          if (!__pyx_t_18) {
          } else {
            __pyx_t_6 = __pyx_t_18;
            goto __pyx_L54_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, 833, __pyx_L22_error)
          }
          __pyx_t_1 = __Pyx_PyDict_Keys(__pyx_v_variable_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 833, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_18 = (__Pyx_PySequence_ContainsTF(__pyx_v_variable_name, __pyx_t_1, Py_NE)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 833, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_6 = __pyx_t_18;
          __pyx_L54_bool_binop_done:;
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":834
 *                    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)
 *             # prepare string_ref
*/
            __pyx_t_16 = __pyx_f_10pyreadstat_16_readstat_writer_get_datetimelike_format_for_readstat(__pyx_v_file_format, __pyx_v_curtype); if (unlikely(__pyx_t_16 == ((char *)0) && PyErr_Occurred())) __PYX_ERR(0, 834, __pyx_L22_error)
            __pyx_v_curformat = __pyx_t_16;

            /* "pyreadstat/_readstat_writer.pyx":835
 *             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)             # <<<<<<<<<<<<<<
 *             # prepare string_ref
 *             # for STRING_REF we have to add to a dict here before start writing
*/
            readstat_variable_set_format(__pyx_v_variable, __pyx_v_curformat);

            /* "pyreadstat/_readstat_writer.pyx":833
 *                 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":838
 *             # prepare string_ref
 *             # for STRING_REF we have to add to a dict here before start writing
 *             if curtype == PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                 for curval in df[variable_name]:
 *                     if curval not in strref_map:
*/
          __pyx_t_6 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF);
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":839
 *             # for STRING_REF we have to add to a dict here before start writing
 *             if curtype == PYWRITER_DTA_STR_REF:
 *                 for curval in df[variable_name]:             # <<<<<<<<<<<<<<
 *                     if curval not in strref_map:
 *                         curvalstr = str(curval)
*/
            __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_df, __pyx_v_variable_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 839, __pyx_L22_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, 839, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 839, __pyx_L22_error)
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            for (;;) {
              if (likely(!__pyx_t_8)) {
                if (likely(PyList_CheckExact(__pyx_t_2))) {
                  {
                    Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
                    #if !CYTHON_ASSUME_SAFE_SIZE
                    if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 839, __pyx_L22_error)
                    #endif
                    if (__pyx_t_7 >= __pyx_temp) break;
                  }
                  __pyx_t_1 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_7);
                  ++__pyx_t_7;
                } else {
                  {
                    Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
                    #if !CYTHON_ASSUME_SAFE_SIZE
                    if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 839, __pyx_L22_error)
                    #endif
                    if (__pyx_t_7 >= __pyx_temp) break;
                  }
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_1 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7));
                  #else
                  __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_7);
                  #endif
                  ++__pyx_t_7;
                }
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 839, __pyx_L22_error)
              } else {
                __pyx_t_1 = __pyx_t_8(__pyx_t_2);
                if (unlikely(!__pyx_t_1)) {
                  PyObject* exc_type = PyErr_Occurred();
                  if (exc_type) {
                    if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 839, __pyx_L22_error)
                    PyErr_Clear();
                  }
                  break;
                }
              }
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_XDECREF_SET(__pyx_v_curval, __pyx_t_1);
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":840
 *             if curtype == PYWRITER_DTA_STR_REF:
 *                 for curval in df[variable_name]:
 *                     if curval not in strref_map:             # <<<<<<<<<<<<<<
 *                         curvalstr = str(curval)
 *                         strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8"))
*/
              __pyx_t_6 = (__Pyx_PyDict_ContainsTF(__pyx_v_curval, __pyx_v_strref_map, Py_NE)); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 840, __pyx_L22_error)
              if (__pyx_t_6) {

                /* "pyreadstat/_readstat_writer.pyx":841
 *                 for curval in df[variable_name]:
 *                     if curval not in strref_map:
 *                         curvalstr = str(curval)             # <<<<<<<<<<<<<<
 *                         strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8"))
 *                         strref_map[curvalstr] = strref_cnt
*/
                __pyx_t_1 = __Pyx_PyObject_Unicode(__pyx_v_curval); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 841, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_XDECREF_SET(__pyx_v_curvalstr, ((PyObject*)__pyx_t_1));
                __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":842
 *                     if curval not in strref_map:
 *                         curvalstr = str(curval)
 *                         strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8"))             # <<<<<<<<<<<<<<
 *                         strref_map[curvalstr] = strref_cnt
 *                         strref_cnt += 1
*/
                __pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_curvalstr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 842, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
                __pyx_t_27 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_27) && PyErr_Occurred())) __PYX_ERR(0, 842, __pyx_L22_error)
                __pyx_v_strref = readstat_add_string_ref(__pyx_v_writer, __pyx_t_27);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":843
 *                         curvalstr = str(curval)
 *                         strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8"))
 *                         strref_map[curvalstr] = strref_cnt             # <<<<<<<<<<<<<<
 *                         strref_cnt += 1
 *             # labels
*/
                __pyx_t_1 = __Pyx_PyLong_From_int(__pyx_v_strref_cnt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 843, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
                if (unlikely((PyDict_SetItem(__pyx_v_strref_map, __pyx_v_curvalstr, __pyx_t_1) < 0))) __PYX_ERR(0, 843, __pyx_L22_error)
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":844
 *                         strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8"))
 *                         strref_map[curvalstr] = strref_cnt
 *                         strref_cnt += 1             # <<<<<<<<<<<<<<
 *             # labels
 *             if col_label_count:
*/
                __pyx_v_strref_cnt = (__pyx_v_strref_cnt + 1);

                /* "pyreadstat/_readstat_writer.pyx":840
 *             if curtype == PYWRITER_DTA_STR_REF:
 *                 for curval in df[variable_name]:
 *                     if curval not in strref_map:             # <<<<<<<<<<<<<<
 *                         curvalstr = str(curval)
 *                         strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8"))
*/
              }

              /* "pyreadstat/_readstat_writer.pyx":839
 *             # for STRING_REF we have to add to a dict here before start writing
 *             if curtype == PYWRITER_DTA_STR_REF:
 *                 for curval in df[variable_name]:             # <<<<<<<<<<<<<<
 *                     if curval not in strref_map:
 *                         curvalstr = str(curval)
*/
            }
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

            /* "pyreadstat/_readstat_writer.pyx":838
 *             # prepare string_ref
 *             # for STRING_REF we have to add to a dict here before start writing
 *             if curtype == PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                 for curval in df[variable_name]:
 *                     if curval not in strref_map:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":846
 *                         strref_cnt += 1
 *             # labels
 *             if col_label_count:             # <<<<<<<<<<<<<<
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:
*/
          __pyx_t_6 = (__pyx_v_col_label_count != 0);
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":847
 *             # labels
 *             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_2 = __Pyx_GetItemInt(__pyx_v_column_labels, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 847, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_6 = (__pyx_t_2 != Py_None);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (__pyx_t_6) {

              /* "pyreadstat/_readstat_writer.pyx":848
 *             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_2 = __Pyx_GetItemInt(__pyx_v_column_labels, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 848, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_t_2)), ((PyObject *)(&PyUnicode_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 848, __pyx_L22_error)
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 848, __pyx_L22_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              if (unlikely(__pyx_t_6)) {

                /* "pyreadstat/_readstat_writer.pyx":849
 *                 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_t_2 = NULL;
                __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 849, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_5 = 1;
                #if CYTHON_UNPACK_METHODS
                if (unlikely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
                  assert(__pyx_t_2);
                  PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_2);
                  __Pyx_INCREF(__pyx__function);
                  __Pyx_DECREF_SET(__pyx_t_9, __pyx__function);
                  __pyx_t_5 = 0;
                }
                #endif
                {
                  PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Column_labels_must_be_strings};
                  __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L22_error)
                  __Pyx_GOTREF(__pyx_t_1);
                }
                __Pyx_Raise(__pyx_t_1, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                __PYX_ERR(0, 849, __pyx_L22_error)

                /* "pyreadstat/_readstat_writer.pyx":848
 *             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":850
 *                     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_2 = __Pyx_GetItemInt(__pyx_v_column_labels, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 850, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_9 = __pyx_t_2;
              __Pyx_INCREF(__pyx_t_9);
              __pyx_t_5 = 0;
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_utf_8};
                __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L22_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, 850, __pyx_L22_error)
              __Pyx_XDECREF_SET(__pyx_v_cur_col_label, ((PyObject*)__pyx_t_1));
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":851
 *                         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, 851, __pyx_L22_error)
              }
              __pyx_t_28 = __Pyx_PyBytes_AsString(__pyx_v_cur_col_label); if (unlikely((!__pyx_t_28) && PyErr_Occurred())) __PYX_ERR(0, 851, __pyx_L22_error)
              readstat_variable_set_label(__pyx_v_variable, __pyx_t_28);

              /* "pyreadstat/_readstat_writer.pyx":847
 *             # labels
 *             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":846
 *                         strref_cnt += 1
 *             # labels
 *             if col_label_count:             # <<<<<<<<<<<<<<
 *                 if column_labels[col_indx] is not None:
 *                     if type(column_labels[col_indx]) != str:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":852
 *                     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_6 = __Pyx_PyObject_IsTrue(__pyx_v_variable_value_labels); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 852, __pyx_L22_error)
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":853
 *                     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, 853, __pyx_L22_error)
            }
            __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_value_labels, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 853, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_1))) __PYX_ERR(0, 853, __pyx_L22_error)
            __Pyx_XDECREF_SET(__pyx_v_value_labels, ((PyObject*)__pyx_t_1));
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":854
 *             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_6 = __Pyx_PyObject_IsTrue(__pyx_v_value_labels); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 854, __pyx_L22_error)
            if (__pyx_t_6) {

              /* "pyreadstat/_readstat_writer.pyx":855
 *                 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_1 = __Pyx_PyLong_From_int(__pyx_v_lblset_cnt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_2 = __Pyx_PyObject_Unicode(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __pyx_t_1 = PyNumber_Add(__pyx_v_variable_name, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_XDECREF_SET(__pyx_v_labelset_name, __pyx_t_1);
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":856
 *                 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":857
 *                     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":858
 *                     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_6 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 858, __pyx_L22_error)
              if (__pyx_t_6) {

                /* "pyreadstat/_readstat_writer.pyx":859
 *                     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, 859, __pyx_L22_error)
                }
                __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_user_values, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_DECREF_SET(__pyx_v_curuser_missing, __pyx_t_1);
                __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":858
 *                     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":860
 *                     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(PyUnicode_CheckExact(__pyx_v_labelset_name))||((__pyx_v_labelset_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_labelset_name))) __PYX_ERR(0, 860, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":861
 *                         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)
 *             # missing ranges
*/
              __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_col_names_to_types, __pyx_v_variable_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 861, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_22 = ((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)__Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 861, __pyx_L22_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              if (!(likely(PyUnicode_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 861, __pyx_L22_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, 861, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":860
 *                     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_29 = __pyx_f_10pyreadstat_16_readstat_writer_set_value_label(__pyx_v_writer, __pyx_v_value_labels, ((PyObject*)__pyx_v_labelset_name), __pyx_t_22, __pyx_v_file_format, ((PyObject*)__pyx_v_variable_name), ((PyObject*)__pyx_v_curuser_missing)); if (unlikely(__pyx_t_29 == ((readstat_label_set_t *)0) && PyErr_Occurred())) __PYX_ERR(0, 860, __pyx_L22_error)
              __pyx_v_label_set = __pyx_t_29;

              /* "pyreadstat/_readstat_writer.pyx":862
 *                     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)             # <<<<<<<<<<<<<<
 *             # missing ranges
 *             if missing_ranges:
*/
              readstat_variable_set_label_set(__pyx_v_variable, __pyx_v_label_set);

              /* "pyreadstat/_readstat_writer.pyx":854
 *             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":852
 *                     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":864
 *                     readstat_variable_set_label_set(variable, label_set)
 *             # missing ranges
 *             if missing_ranges:             # <<<<<<<<<<<<<<
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:
*/
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_missing_ranges); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 864, __pyx_L22_error)
          if (__pyx_t_6) {

            /* "pyreadstat/_readstat_writer.pyx":865
 *             # missing ranges
 *             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, 865, __pyx_L22_error)
            }
            __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_ranges, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_XDECREF_SET(__pyx_v_cur_ranges, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":866
 *             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_6 = __Pyx_PyObject_IsTrue(__pyx_v_cur_ranges); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 866, __pyx_L22_error)
            if (__pyx_t_6) {

              /* "pyreadstat/_readstat_writer.pyx":867
 *                 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_6 = PyList_Check(__pyx_v_cur_ranges); 
              __pyx_t_18 = (!__pyx_t_6);
              if (unlikely(__pyx_t_18)) {

                /* "pyreadstat/_readstat_writer.pyx":868
 *                 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_mstate_global->__pyx_kp_u_missing_ranges_values_in_diction);
                __pyx_v_msg = __pyx_mstate_global->__pyx_kp_u_missing_ranges_values_in_diction;

                /* "pyreadstat/_readstat_writer.pyx":869
 *                     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_t_2 = NULL;
                __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 869, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_5 = 1;
                #if CYTHON_UNPACK_METHODS
                if (unlikely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
                  assert(__pyx_t_2);
                  PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9);
                  __Pyx_INCREF(__pyx_t_2);
                  __Pyx_INCREF(__pyx__function);
                  __Pyx_DECREF_SET(__pyx_t_9, __pyx__function);
                  __pyx_t_5 = 0;
                }
                #endif
                {
                  PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_msg};
                  __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 869, __pyx_L22_error)
                  __Pyx_GOTREF(__pyx_t_1);
                }
                __Pyx_Raise(__pyx_t_1, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                __PYX_ERR(0, 869, __pyx_L22_error)

                /* "pyreadstat/_readstat_writer.pyx":867
 *                 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":870
 *                         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, 870, __pyx_L22_error)
              if (!(likely(PyUnicode_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 870, __pyx_L22_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, 870, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":866
 *             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":864
 *                     readstat_variable_set_label_set(variable, label_set)
 *             # missing ranges
 *             if missing_ranges:             # <<<<<<<<<<<<<<
 *                 cur_ranges = missing_ranges.get(variable_name)
 *                 if cur_ranges:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":871
 *                         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_18 = __Pyx_PyObject_IsTrue(__pyx_v_variable_alignment); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 871, __pyx_L22_error)
          if (__pyx_t_18) {

            /* "pyreadstat/_readstat_writer.pyx":874
 *                 # 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, 874, __pyx_L22_error)
            }
            __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_alignment, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 874, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_XDECREF_SET(__pyx_v_cur_alignment, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":875
 *                 # 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_18 = __Pyx_PyObject_IsTrue(__pyx_v_cur_alignment); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 875, __pyx_L22_error)
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":876
 *                 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(PyUnicode_CheckExact(__pyx_v_cur_alignment))||((__pyx_v_cur_alignment) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_cur_alignment))) __PYX_ERR(0, 876, __pyx_L22_error)
              if (!(likely(PyUnicode_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 876, __pyx_L22_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, 876, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":875
 *                 # 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":871
 *                         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":877
 *                 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_18 = __Pyx_PyObject_IsTrue(__pyx_v_variable_display_width); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 877, __pyx_L22_error)
          if (__pyx_t_18) {

            /* "pyreadstat/_readstat_writer.pyx":878
 *                     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, 878, __pyx_L22_error)
            }
            __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_display_width, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_XDECREF_SET(__pyx_v_cur_display_width, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":879
 *             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_18 = __Pyx_PyObject_IsTrue(__pyx_v_cur_display_width); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 879, __pyx_L22_error)
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":880
 *                 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_23 = __Pyx_PyLong_As_int(__pyx_v_cur_display_width); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 880, __pyx_L22_error)
              if (!(likely(PyUnicode_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 880, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_writer_set_variable_display_width(__pyx_v_variable, __pyx_t_23, ((PyObject*)__pyx_v_variable_name)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 880, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":879
 *             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":877
 *                 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":881
 *                 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_18 = __Pyx_PyObject_IsTrue(__pyx_v_variable_measure); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 881, __pyx_L22_error)
          if (__pyx_t_18) {

            /* "pyreadstat/_readstat_writer.pyx":882
 *                     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, 882, __pyx_L22_error)
            }
            __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_variable_measure, __pyx_v_variable_name, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_XDECREF_SET(__pyx_v_cur_measure, __pyx_t_1);
            __pyx_t_1 = 0;

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

              /* "pyreadstat/_readstat_writer.pyx":884
 *                 cur_measure = variable_measure.get(variable_name)
 *                 if cur_measure:
 *                     set_variable_measure(variable, cur_measure, variable_name)             # <<<<<<<<<<<<<<
 * 
 *         # start writing
*/
              if (!(likely(PyUnicode_CheckExact(__pyx_v_cur_measure))||((__pyx_v_cur_measure) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_cur_measure))) __PYX_ERR(0, 884, __pyx_L22_error)
              if (!(likely(PyUnicode_CheckExact(__pyx_v_variable_name))||((__pyx_v_variable_name) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_variable_name))) __PYX_ERR(0, 884, __pyx_L22_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, 884, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":883
 *             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":881
 *                 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":887
 * 
 *         # 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":888
 *         # 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, 888, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":887
 * 
 *         # 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":890
 *             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, 890, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":889
 *         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":892
 *             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, 892, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":891
 *         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":894
 *             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, 894, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":893
 *         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":896
 *             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, 896, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":895
 *         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":898
 *             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, 898, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":897
 *         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":900
 *             check_exit_status(readstat_begin_writing_xport(writer, &fd, row_count))
 *         else:
 *             raise PyreadstatError("unknown file format")             # <<<<<<<<<<<<<<
 * 
 *         # validation
*/
          __pyx_t_9 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 900, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_5 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
            assert(__pyx_t_9);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
            __pyx_t_5 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_unknown_file_format};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 900, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_Raise(__pyx_t_1, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __PYX_ERR(0, 900, __pyx_L22_error)
          break;
        }

        /* "pyreadstat/_readstat_writer.pyx":903
 * 
 *         # 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, 903, __pyx_L22_error)

        /* "pyreadstat/_readstat_writer.pyx":904
 *         # 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_12 = __pyx_v_col_count;
        __pyx_t_19 = __pyx_t_12;
        for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
          __pyx_v_col_indx = __pyx_t_20;

          /* "pyreadstat/_readstat_writer.pyx":905
 *         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":906
 *         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, 906, __pyx_L22_error)
        }

        /* "pyreadstat/_readstat_writer.pyx":909
 * 
 *         # vectorized transform of datetime64ns columns
 *         pywriter_types = [x[0] for x in col_types]             # <<<<<<<<<<<<<<
 *         pywriter_timeunits = [x[3] for x in col_types]
 *         hasdatetime64 = PYWRITER_DATETIME64 in pywriter_types
*/
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 909, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__pyx_v_col_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 909, __pyx_L22_error)
        }
        __pyx_t_2 = __pyx_v_col_types; __Pyx_INCREF(__pyx_t_2);
        __pyx_t_7 = 0;
        for (;;) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 909, __pyx_L22_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          __pyx_t_9 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_7);
          ++__pyx_t_7;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 909, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
          __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_x, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 909, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 909, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_pywriter_types = ((PyObject*)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":910
 *         # vectorized transform of datetime64ns columns
 *         pywriter_types = [x[0] for x in col_types]
 *         pywriter_timeunits = [x[3] for x in col_types]             # <<<<<<<<<<<<<<
 *         hasdatetime64 = PYWRITER_DATETIME64 in pywriter_types
 *         hasdate64 = PYWRITER_DATE64 in pywriter_types
*/
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__pyx_v_col_types == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 910, __pyx_L22_error)
        }
        __pyx_t_2 = __pyx_v_col_types; __Pyx_INCREF(__pyx_t_2);
        __pyx_t_7 = 0;
        for (;;) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
            #if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 910, __pyx_L22_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          __pyx_t_9 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_7);
          ++__pyx_t_7;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 910, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
          __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_x, 3, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 910, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 910, __pyx_L22_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_pywriter_timeunits = ((PyObject*)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":911
 *         pywriter_types = [x[0] for x in col_types]
 *         pywriter_timeunits = [x[3] for x in col_types]
 *         hasdatetime64 = PYWRITER_DATETIME64 in pywriter_types             # <<<<<<<<<<<<<<
 *         hasdate64 = PYWRITER_DATE64 in pywriter_types
 *         hastime64 = PYWRITER_TIME64 in pywriter_types
*/
        __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 911, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_18 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_v_pywriter_types, Py_EQ)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 911, __pyx_L22_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_v_hasdatetime64 = __pyx_t_18;

        /* "pyreadstat/_readstat_writer.pyx":912
 *         pywriter_timeunits = [x[3] for x in col_types]
 *         hasdatetime64 = PYWRITER_DATETIME64 in pywriter_types
 *         hasdate64 = PYWRITER_DATE64 in pywriter_types             # <<<<<<<<<<<<<<
 *         hastime64 = PYWRITER_TIME64 in pywriter_types
 *         if hasdatetime64 or hasdate64 or hastime64:
*/
        __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 912, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_18 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_v_pywriter_types, Py_EQ)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 912, __pyx_L22_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 912, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_v_hasdate64 = __pyx_t_1;
        __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":913
 *         hasdatetime64 = PYWRITER_DATETIME64 in pywriter_types
 *         hasdate64 = PYWRITER_DATE64 in pywriter_types
 *         hastime64 = PYWRITER_TIME64 in pywriter_types             # <<<<<<<<<<<<<<
 *         if hasdatetime64 or hasdate64 or hastime64:
 *             df2 = df.clone()
*/
        __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 913, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_18 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_v_pywriter_types, Py_EQ)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 913, __pyx_L22_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 913, __pyx_L22_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_v_hastime64 = __pyx_t_1;
        __pyx_t_1 = 0;

        /* "pyreadstat/_readstat_writer.pyx":914
 *         hasdate64 = PYWRITER_DATE64 in pywriter_types
 *         hastime64 = PYWRITER_TIME64 in pywriter_types
 *         if hasdatetime64 or hasdate64 or hastime64:             # <<<<<<<<<<<<<<
 *             df2 = df.clone()
 *             if hasdatetime64:
*/
        if (!__pyx_v_hasdatetime64) {
        } else {
          __pyx_t_18 = __pyx_v_hasdatetime64;
          goto __pyx_L86_bool_binop_done;
        }
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_hasdate64); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 914, __pyx_L22_error)
        if (!__pyx_t_6) {
        } else {
          __pyx_t_18 = __pyx_t_6;
          goto __pyx_L86_bool_binop_done;
        }
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_hastime64); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 914, __pyx_L22_error)
        __pyx_t_18 = __pyx_t_6;
        __pyx_L86_bool_binop_done:;
        if (__pyx_t_18) {

          /* "pyreadstat/_readstat_writer.pyx":915
 *         hastime64 = PYWRITER_TIME64 in pywriter_types
 *         if hasdatetime64 or hasdate64 or hastime64:
 *             df2 = df.clone()             # <<<<<<<<<<<<<<
 *             if hasdatetime64:
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)
*/
          __pyx_t_2 = __pyx_v_df;
          __Pyx_INCREF(__pyx_t_2);
          __pyx_t_5 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_clone, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 915, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __pyx_v_df2 = __pyx_t_1;
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":916
 *         if hasdatetime64 or hasdate64 or hastime64:
 *             df2 = df.clone()
 *             if hasdatetime64:             # <<<<<<<<<<<<<<
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)
 *             if hasdate64:
*/
          if (__pyx_v_hasdatetime64) {

            /* "pyreadstat/_readstat_writer.pyx":917
 *             df2 = df.clone()
 *             if hasdatetime64:
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)             # <<<<<<<<<<<<<<
 *             if hasdate64:
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)
*/
            __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_datetime_to_number(__pyx_v_df2, __pyx_v_file_format, __pyx_v_pywriter_types, __pyx_v_pywriter_timeunits, __pyx_v_col_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF_SET(__pyx_v_df2, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":916
 *         if hasdatetime64 or hasdate64 or hastime64:
 *             df2 = df.clone()
 *             if hasdatetime64:             # <<<<<<<<<<<<<<
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)
 *             if hasdate64:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":918
 *             if hasdatetime64:
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)
 *             if hasdate64:             # <<<<<<<<<<<<<<
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)
 *             if hastime64:
*/
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_hasdate64); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 918, __pyx_L22_error)
          if (__pyx_t_18) {

            /* "pyreadstat/_readstat_writer.pyx":919
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)
 *             if hasdate64:
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)             # <<<<<<<<<<<<<<
 *             if hastime64:
 *                 df2 = vectorized_convert_time_to_number(df2, file_format, pywriter_types, col_count)
*/
            __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_date_to_number(__pyx_v_df2, __pyx_v_file_format, __pyx_v_pywriter_types, __pyx_v_col_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 919, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF_SET(__pyx_v_df2, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":918
 *             if hasdatetime64:
 *                 df2 = vectorized_convert_datetime_to_number(df2, file_format, pywriter_types, pywriter_timeunits, col_count)
 *             if hasdate64:             # <<<<<<<<<<<<<<
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)
 *             if hastime64:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":920
 *             if hasdate64:
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)
 *             if hastime64:             # <<<<<<<<<<<<<<
 *                 df2 = vectorized_convert_time_to_number(df2, file_format, pywriter_types, col_count)
 *         else:
*/
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_hastime64); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 920, __pyx_L22_error)
          if (__pyx_t_18) {

            /* "pyreadstat/_readstat_writer.pyx":921
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)
 *             if hastime64:
 *                 df2 = vectorized_convert_time_to_number(df2, file_format, pywriter_types, col_count)             # <<<<<<<<<<<<<<
 *         else:
 *             df2 = df
*/
            __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_time_to_number(__pyx_v_df2, __pyx_v_file_format, __pyx_v_pywriter_types, __pyx_v_col_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 921, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF_SET(__pyx_v_df2, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":920
 *             if hasdate64:
 *                 df2 = vectorized_convert_date_to_number(df2, file_format, pywriter_types, col_count)
 *             if hastime64:             # <<<<<<<<<<<<<<
 *                 df2 = vectorized_convert_time_to_number(df2, file_format, pywriter_types, col_count)
 *         else:
*/
          }

          /* "pyreadstat/_readstat_writer.pyx":914
 *         hasdate64 = PYWRITER_DATE64 in pywriter_types
 *         hastime64 = PYWRITER_TIME64 in pywriter_types
 *         if hasdatetime64 or hasdate64 or hastime64:             # <<<<<<<<<<<<<<
 *             df2 = df.clone()
 *             if hasdatetime64:
*/
          goto __pyx_L85;
        }

        /* "pyreadstat/_readstat_writer.pyx":923
 *                 df2 = vectorized_convert_time_to_number(df2, file_format, pywriter_types, col_count)
 *         else:
 *             df2 = df             # <<<<<<<<<<<<<<
 * 
 * 
*/
        /*else*/ {
          __Pyx_INCREF(__pyx_v_df);
          __pyx_v_df2 = __pyx_v_df;
        }
        __pyx_L85:;

        /* "pyreadstat/_readstat_writer.pyx":927
 * 
 *         # inserting
 *         rowcnt = 0             # <<<<<<<<<<<<<<
 * 
 *         for row in df2.iter_rows():
*/
        __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
        __pyx_v_rowcnt = __pyx_mstate_global->__pyx_int_0;

        /* "pyreadstat/_readstat_writer.pyx":929
 *         rowcnt = 0
 * 
 *         for row in df2.iter_rows():             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_row(writer))
 * 
*/
        __pyx_t_2 = __pyx_v_df2;
        __Pyx_INCREF(__pyx_t_2);
        __pyx_t_5 = 0;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
          __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_iter_rows, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 929, __pyx_L22_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, 929, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 929, __pyx_L22_error)
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        for (;;) {
          if (likely(!__pyx_t_8)) {
            if (likely(PyList_CheckExact(__pyx_t_2))) {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
                #if !CYTHON_ASSUME_SAFE_SIZE
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 929, __pyx_L22_error)
                #endif
                if (__pyx_t_7 >= __pyx_temp) break;
              }
              __pyx_t_1 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_7);
              ++__pyx_t_7;
            } else {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
                #if !CYTHON_ASSUME_SAFE_SIZE
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 929, __pyx_L22_error)
                #endif
                if (__pyx_t_7 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7));
              #else
              __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_7);
              #endif
              ++__pyx_t_7;
            }
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 929, __pyx_L22_error)
          } else {
            __pyx_t_1 = __pyx_t_8(__pyx_t_2);
            if (unlikely(!__pyx_t_1)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 929, __pyx_L22_error)
                PyErr_Clear();
              }
              break;
            }
          }
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":930
 * 
 *         for row in df2.iter_rows():
 *             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, 930, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":932
 *             check_exit_status(readstat_begin_row(writer))
 * 
 *             for col_indx in range(col_count):             # <<<<<<<<<<<<<<
 * 
 *                 tempvar = readstat_get_variable(writer, col_indx)
*/
          __pyx_t_12 = __pyx_v_col_count;
          __pyx_t_19 = __pyx_t_12;
          for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
            __pyx_v_col_indx = __pyx_t_20;

            /* "pyreadstat/_readstat_writer.pyx":934
 *             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":935
 * 
 *                 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_1 = __Pyx_GetItemInt(__pyx_v_row, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 935, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_XDECREF_SET(__pyx_v_curval, __pyx_t_1);
            __pyx_t_1 = 0;

            /* "pyreadstat/_readstat_writer.pyx":936
 *                 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_1 = __Pyx_GetItemInt_List(__pyx_v_pywriter_types, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 936, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_22 = ((__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type)__Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 936, __pyx_L22_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_v_curtype = __pyx_t_22;

            /* "pyreadstat/_readstat_writer.pyx":937
 *                 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, 937, __pyx_L22_error)
            }
            __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_types, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 937, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_1, 2, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 937, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_XDECREF_SET(__pyx_v_is_missing, __pyx_t_9);
            __pyx_t_9 = 0;

            /* "pyreadstat/_readstat_writer.pyx":938
 *                 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":939
 *                 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_18 = __Pyx_PyObject_IsTrue(__pyx_v_missing_user_values); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 939, __pyx_L22_error)
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":940
 *                 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, 940, __pyx_L22_error)
              }
              if (unlikely(__pyx_v_col_names == Py_None)) {
                PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                __PYX_ERR(0, 940, __pyx_L22_error)
              }
              __pyx_t_9 = __Pyx_GetItemInt_List(__pyx_v_col_names, __pyx_v_col_indx, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 940, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_missing_user_values, __pyx_t_9, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 940, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_DECREF_SET(__pyx_v_curuser_missing, __pyx_t_1);
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":939
 *                 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":942
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 * 
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     # For pandas we need isna because values can be Nan, NA, NAT, None
 *                     if is_pandas:
*/
            __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_is_missing); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 942, __pyx_L22_error)
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":944
 *                 if is_missing:
 *                     # For pandas we need isna because values can be Nan, NA, NAT, None
 *                     if is_pandas:             # <<<<<<<<<<<<<<
 *                         check_if_missing = pd.isna(curval)
 *                     # for other libraries the value would be None
*/
              if (__pyx_v_is_pandas) {

                /* "pyreadstat/_readstat_writer.pyx":945
 *                     # For pandas we need isna because values can be Nan, NA, NAT, None
 *                     if is_pandas:
 *                         check_if_missing = pd.isna(curval)             # <<<<<<<<<<<<<<
 *                     # for other libraries the value would be None
 *                     else:
*/
                __pyx_t_9 = __pyx_v_pd;
                __Pyx_INCREF(__pyx_t_9);
                __pyx_t_5 = 0;
                {
                  PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_curval};
                  __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isna, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                  __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
                  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 945, __pyx_L22_error)
                  __Pyx_GOTREF(__pyx_t_1);
                }
                __Pyx_XDECREF_SET(__pyx_v_check_if_missing, __pyx_t_1);
                __pyx_t_1 = 0;

                /* "pyreadstat/_readstat_writer.pyx":944
 *                 if is_missing:
 *                     # For pandas we need isna because values can be Nan, NA, NAT, None
 *                     if is_pandas:             # <<<<<<<<<<<<<<
 *                         check_if_missing = pd.isna(curval)
 *                     # for other libraries the value would be None
*/
                goto __pyx_L98;
              }

              /* "pyreadstat/_readstat_writer.pyx":948
 *                     # for other libraries the value would be None
 *                     else:
 *                         check_if_missing = curval is None             # <<<<<<<<<<<<<<
 *                     if check_if_missing:
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
*/
              /*else*/ {
                __pyx_t_18 = (__pyx_v_curval == Py_None);
                __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 948, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_XDECREF_SET(__pyx_v_check_if_missing, __pyx_t_1);
                __pyx_t_1 = 0;
              }
              __pyx_L98:;

              /* "pyreadstat/_readstat_writer.pyx":949
 *                     else:
 *                         check_if_missing = curval is None
 *                     if check_if_missing:             # <<<<<<<<<<<<<<
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
 *                         continue
*/
              __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_check_if_missing); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 949, __pyx_L22_error)
              if (__pyx_t_18) {

                /* "pyreadstat/_readstat_writer.pyx":950
 *                         check_if_missing = curval is None
 *                     if check_if_missing:
 *                         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, 950, __pyx_L22_error)

                /* "pyreadstat/_readstat_writer.pyx":951
 *                     if check_if_missing:
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                 if curuser_missing and curtype in pywriter_numeric_types:
*/
                goto __pyx_L94_continue;

                /* "pyreadstat/_readstat_writer.pyx":949
 *                     else:
 *                         check_if_missing = curval is None
 *                     if check_if_missing:             # <<<<<<<<<<<<<<
 *                         check_exit_status(readstat_insert_missing_value(writer, tempvar))
 *                         continue
*/
              }

              /* "pyreadstat/_readstat_writer.pyx":942
 *                     curuser_missing = missing_user_values.get(col_names[col_indx])
 * 
 *                 if is_missing:             # <<<<<<<<<<<<<<
 *                     # For pandas we need isna because values can be Nan, NA, NAT, None
 *                     if is_pandas:
*/
            }

            /* "pyreadstat/_readstat_writer.pyx":953
 *                         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_6 = __Pyx_PyObject_IsTrue(__pyx_v_curuser_missing); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 953, __pyx_L22_error)
            if (__pyx_t_6) {
            } else {
              __pyx_t_18 = __pyx_t_6;
              goto __pyx_L101_bool_binop_done;
            }
            __pyx_t_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 953, __pyx_L22_error)
            __Pyx_GOTREF(__pyx_t_1);
            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, 953, __pyx_L22_error)
            }
            __pyx_t_6 = (__Pyx_PySet_ContainsTF(__pyx_t_1, __pyx_v_10pyreadstat_16_readstat_writer_pywriter_numeric_types, Py_EQ)); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 953, __pyx_L22_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_18 = __pyx_t_6;
            __pyx_L101_bool_binop_done:;
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":954
 * 
 *                 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_18 = (__Pyx_PySequence_ContainsTF(__pyx_v_curval, __pyx_v_curuser_missing, Py_EQ)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 954, __pyx_L22_error)
              if (__pyx_t_18) {

                /* "pyreadstat/_readstat_writer.pyx":955
 *                 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_30 = __Pyx_PyObject_Ord(__pyx_v_curval); if (unlikely(__pyx_t_30 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 955, __pyx_L22_error)
                __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_tagged_missing_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_30)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 955, __pyx_L22_error)

                /* "pyreadstat/_readstat_writer.pyx":956
 *                     if curval in curuser_missing:
 *                         check_exit_status(readstat_insert_tagged_missing_value(writer, tempvar, ord(curval)))
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                 if curtype == PYWRITER_DOUBLE:
*/
                goto __pyx_L94_continue;

                /* "pyreadstat/_readstat_writer.pyx":954
 * 
 *                 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":953
 *                         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":958
 *                         continue
 * 
 *                 if curtype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:
*/
            __pyx_t_18 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE);
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":959
 * 
 *                 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_31 = __Pyx_PyFloat_AsDouble(__pyx_v_curval); if (unlikely((__pyx_t_31 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 959, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_double_value(__pyx_v_writer, __pyx_v_tempvar, ((double)__pyx_t_31))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 959, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":958
 *                         continue
 * 
 *                 if curtype == PYWRITER_DOUBLE:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype == PYWRITER_INTEGER:
*/
              goto __pyx_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":960
 *                 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_18 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER);
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":961
 *                     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_32 = __Pyx_PyLong_As_int32_t(__pyx_v_curval); if (unlikely((__pyx_t_32 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 961, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_int32_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_32)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 961, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":960
 *                 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_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":962
 *                 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_18 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL);
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":963
 *                     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_23 = __Pyx_PyLong_As_int(__pyx_v_curval); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 963, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_int32_value(__pyx_v_writer, __pyx_v_tempvar, ((int)__pyx_t_23))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 963, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":962
 *                 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_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":964
 *                 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_18 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER);
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":965
 *                     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_v_curval;
              __Pyx_INCREF(__pyx_t_9);
              __pyx_t_5 = 0;
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_utf_8};
                __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 965, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
              }
              __pyx_t_33 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_33) && PyErr_Occurred())) __PYX_ERR(0, 965, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_string_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_33)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 965, __pyx_L22_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":964
 *                 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_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":966
 *                 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_18 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT);
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":967
 *                     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_DTA_STR_REF:
*/
              __pyx_t_1 = __Pyx_PyObject_Unicode(__pyx_v_curval); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 967, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_XDECREF_SET(__pyx_v_curvalstr, ((PyObject*)__pyx_t_1));
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":968
 *                 elif curtype == PYWRITER_OBJECT:
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_DTA_STR_REF:
 *                     curvalstr = str(curval)
*/
              __pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_curvalstr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 968, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_33 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_33) && PyErr_Occurred())) __PYX_ERR(0, 968, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_string_value(__pyx_v_writer, __pyx_v_tempvar, __pyx_t_33)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 968, __pyx_L22_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":966
 *                 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_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":969
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                     curvalstr = str(curval)
 *                     strref_indx = strref_map[curvalstr]
*/
            __pyx_t_18 = (__pyx_v_curtype == __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF);
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":970
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DTA_STR_REF:
 *                     curvalstr = str(curval)             # <<<<<<<<<<<<<<
 *                     strref_indx = strref_map[curvalstr]
 *                     strref = readstat_get_string_ref(writer, strref_indx)
*/
              __pyx_t_1 = __Pyx_PyObject_Unicode(__pyx_v_curval); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 970, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_XDECREF_SET(__pyx_v_curvalstr, ((PyObject*)__pyx_t_1));
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":971
 *                 elif curtype == PYWRITER_DTA_STR_REF:
 *                     curvalstr = str(curval)
 *                     strref_indx = strref_map[curvalstr]             # <<<<<<<<<<<<<<
 *                     strref = readstat_get_string_ref(writer, strref_indx)
 *                     check_exit_status(readstat_insert_string_ref(writer, tempvar, strref))
*/
              __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_strref_map, __pyx_v_curvalstr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 971, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_XDECREF_SET(__pyx_v_strref_indx, __pyx_t_1);
              __pyx_t_1 = 0;

              /* "pyreadstat/_readstat_writer.pyx":972
 *                     curvalstr = str(curval)
 *                     strref_indx = strref_map[curvalstr]
 *                     strref = readstat_get_string_ref(writer, strref_indx)             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_string_ref(writer, tempvar, strref))
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:
*/
              __pyx_t_23 = __Pyx_PyLong_As_int(__pyx_v_strref_indx); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 972, __pyx_L22_error)
              __pyx_v_strref = readstat_get_string_ref(__pyx_v_writer, __pyx_t_23);

              /* "pyreadstat/_readstat_writer.pyx":973
 *                     strref_indx = strref_map[curvalstr]
 *                     strref = readstat_get_string_ref(writer, strref_indx)
 *                     check_exit_status(readstat_insert_string_ref(writer, tempvar, strref))             # <<<<<<<<<<<<<<
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
*/
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_string_ref(__pyx_v_writer, __pyx_v_tempvar, __pyx_v_strref)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 973, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":969
 *                     curvalstr = str(curval)
 *                     check_exit_status(readstat_insert_string_value(writer, tempvar, curvalstr.encode("utf-8")))
 *                 elif curtype == PYWRITER_DTA_STR_REF:             # <<<<<<<<<<<<<<
 *                     curvalstr = str(curval)
 *                     strref_indx = strref_map[curvalstr]
*/
              goto __pyx_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":974
 *                     strref = readstat_get_string_ref(writer, strref_indx)
 *                     check_exit_status(readstat_insert_string_ref(writer, tempvar, strref))
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:             # <<<<<<<<<<<<<<
 *                     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:
              case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64:
              case __pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64:
              __pyx_t_18 = 1;
              break;
              default:
              __pyx_t_18 = 0;
              break;
            }
            if (__pyx_t_18) {

              /* "pyreadstat/_readstat_writer.pyx":975
 *                     check_exit_status(readstat_insert_string_ref(writer, tempvar, strref))
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:
 *                     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_31 = __Pyx_PyFloat_AsDouble(__pyx_v_curval); if (unlikely((__pyx_t_31 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 975, __pyx_L22_error)
              __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_insert_double_value(__pyx_v_writer, __pyx_v_tempvar, ((double)__pyx_t_31))); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 975, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":974
 *                     strref = readstat_get_string_ref(writer, strref_indx)
 *                     check_exit_status(readstat_insert_string_ref(writer, tempvar, strref))
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:             # <<<<<<<<<<<<<<
 *                     check_exit_status(readstat_insert_double_value(writer, tempvar, <double>curval))
 *                 elif curtype in pyrwriter_datetimelike_types:
*/
              goto __pyx_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":976
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:
 *                     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_1 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_v_curtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 976, __pyx_L22_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, 976, __pyx_L22_error)
            }
            __pyx_t_18 = (__Pyx_PySet_ContainsTF(__pyx_t_1, __pyx_v_10pyreadstat_16_readstat_writer_pyrwriter_datetimelike_types, Py_EQ)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 976, __pyx_L22_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (likely(__pyx_t_18)) {

              /* "pyreadstat/_readstat_writer.pyx":977
 *                     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_31 = __pyx_f_10pyreadstat_16_readstat_writer_convert_datetimelike_to_number(__pyx_v_file_format, __pyx_v_curtype, __pyx_v_curval); if (unlikely(__pyx_t_31 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 977, __pyx_L22_error)
              __pyx_v_dtimelikeval = __pyx_t_31;

              /* "pyreadstat/_readstat_writer.pyx":978
 *                 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, 978, __pyx_L22_error)

              /* "pyreadstat/_readstat_writer.pyx":976
 *                 elif curtype == PYWRITER_DATETIME64 or curtype == PYWRITER_DATE64 or curtype == PYWRITER_TIME64:
 *                     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_L104;
            }

            /* "pyreadstat/_readstat_writer.pyx":980
 *                     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_t_9 = NULL;
              __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 980, __pyx_L22_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_5 = 1;
              #if CYTHON_UNPACK_METHODS
              if (unlikely(PyMethod_Check(__pyx_t_3))) {
                __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
                assert(__pyx_t_9);
                PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_9);
                __Pyx_INCREF(__pyx__function);
                __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
                __pyx_t_5 = 0;
              }
              #endif
              {
                PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_Unknown_data_format_to_insert};
                __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
                __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 980, __pyx_L22_error)
                __Pyx_GOTREF(__pyx_t_1);
              }
              __Pyx_Raise(__pyx_t_1, 0, 0, 0);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __PYX_ERR(0, 980, __pyx_L22_error)
            }
            __pyx_L104:;
            __pyx_L94_continue:;
          }

          /* "pyreadstat/_readstat_writer.pyx":982
 *                     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, 982, __pyx_L22_error)

          /* "pyreadstat/_readstat_writer.pyx":983
 * 
 *             check_exit_status(readstat_end_row(writer))
 *             rowcnt += 1             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_end_writing(writer))
*/
          __pyx_t_1 = __Pyx_PyLong_AddObjC(__pyx_v_rowcnt, __pyx_mstate_global->__pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 983, __pyx_L22_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF_SET(__pyx_v_rowcnt, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "pyreadstat/_readstat_writer.pyx":929
 *         rowcnt = 0
 * 
 *         for row in df2.iter_rows():             # <<<<<<<<<<<<<<
 *             check_exit_status(readstat_begin_row(writer))
 * 
*/
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pyreadstat/_readstat_writer.pyx":985
 *             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, 985, __pyx_L22_error)

        /* "pyreadstat/_readstat_writer.pyx":774
 *     writer = readstat_writer_init()
 * 
 *     try:             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
*/
      }
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      goto __pyx_L27_try_end;
      __pyx_L22_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pyreadstat/_readstat_writer.pyx":987
 *         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_2, &__pyx_t_1, &__pyx_t_3) < 0) __PYX_ERR(0, 987, __pyx_L24_except_error)
        __Pyx_XGOTREF(__pyx_t_2);
        __Pyx_XGOTREF(__pyx_t_1);
        __Pyx_XGOTREF(__pyx_t_3);

        /* "pyreadstat/_readstat_writer.pyx":988
 * 
 *     except:
 *         raise             # <<<<<<<<<<<<<<
 *     finally:
 *         readstat_writer_free(writer)
*/
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_1);
        __Pyx_XGIVEREF(__pyx_t_3);
        __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_1, __pyx_t_3);
        __pyx_t_2 = 0;  __pyx_t_1 = 0;  __pyx_t_3 = 0; 
        __PYX_ERR(0, 988, __pyx_L24_except_error)
      }

      /* "pyreadstat/_readstat_writer.pyx":774
 *     writer = readstat_writer_init()
 * 
 *     try:             # <<<<<<<<<<<<<<
 * 
 *         check_exit_status(readstat_set_data_writer(writer, write_bytes))
*/
      __pyx_L24_except_error:;
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_XGIVEREF(__pyx_t_14);
      __Pyx_XGIVEREF(__pyx_t_15);
      __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
      goto __pyx_L20_error;
      __pyx_L27_try_end:;
    }
  }

  /* "pyreadstat/_readstat_writer.pyx":990
 *         raise
 *     finally:
 *         readstat_writer_free(writer)             # <<<<<<<<<<<<<<
 *         close_file(fd)
 * 
*/
  /*finally:*/ {
    /*normal exit:*/{
      readstat_writer_free(__pyx_v_writer);

      /* "pyreadstat/_readstat_writer.pyx":991
 *     finally:
 *         readstat_writer_free(writer)
 *         close_file(fd)             # <<<<<<<<<<<<<<
 * 
 *     return 0
*/
      __pyx_t_12 = __pyx_f_10pyreadstat_16_readstat_writer_close_file(__pyx_v_fd); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 991, __pyx_L1_error)
      goto __pyx_L21;
    }
    __pyx_L20_error:;
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_13 = 0; __pyx_t_35 = 0; __pyx_t_36 = 0; __pyx_t_37 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
       __Pyx_ExceptionSwap(&__pyx_t_35, &__pyx_t_36, &__pyx_t_37);
      if ( unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_15);
      __Pyx_XGOTREF(__pyx_t_14);
      __Pyx_XGOTREF(__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_35);
      __Pyx_XGOTREF(__pyx_t_36);
      __Pyx_XGOTREF(__pyx_t_37);
      __pyx_t_12 = __pyx_lineno; __pyx_t_19 = __pyx_clineno; __pyx_t_34 = __pyx_filename;
      {

        /* "pyreadstat/_readstat_writer.pyx":990
 *         raise
 *     finally:
 *         readstat_writer_free(writer)             # <<<<<<<<<<<<<<
 *         close_file(fd)
 * 
*/
        readstat_writer_free(__pyx_v_writer);

        /* "pyreadstat/_readstat_writer.pyx":991
 *     finally:
 *         readstat_writer_free(writer)
 *         close_file(fd)             # <<<<<<<<<<<<<<
 * 
 *     return 0
*/
        __pyx_t_20 = __pyx_f_10pyreadstat_16_readstat_writer_close_file(__pyx_v_fd); if (unlikely(__pyx_t_20 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 991, __pyx_L109_error)
      }
      __Pyx_XGIVEREF(__pyx_t_35);
      __Pyx_XGIVEREF(__pyx_t_36);
      __Pyx_XGIVEREF(__pyx_t_37);
      __Pyx_ExceptionReset(__pyx_t_35, __pyx_t_36, __pyx_t_37);
      __Pyx_XGIVEREF(__pyx_t_15);
      __Pyx_XGIVEREF(__pyx_t_14);
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_ErrRestore(__pyx_t_15, __pyx_t_14, __pyx_t_13);
      __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_13 = 0; __pyx_t_35 = 0; __pyx_t_36 = 0; __pyx_t_37 = 0;
      __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_19; __pyx_filename = __pyx_t_34;
      goto __pyx_L1_error;
      __pyx_L109_error:;
      __Pyx_XGIVEREF(__pyx_t_35);
      __Pyx_XGIVEREF(__pyx_t_36);
      __Pyx_XGIVEREF(__pyx_t_37);
      __Pyx_ExceptionReset(__pyx_t_35, __pyx_t_36, __pyx_t_37);
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_35 = 0; __pyx_t_36 = 0; __pyx_t_37 = 0;
      goto __pyx_L1_error;
    }
    __pyx_L21:;
  }

  /* "pyreadstat/_readstat_writer.pyx":993
 *         close_file(fd)
 * 
 *     return 0             # <<<<<<<<<<<<<<
*/
  __pyx_r = 0;
  goto __pyx_L0;

  /* "pyreadstat/_readstat_writer.pyx":685
 * 
 * 
 * cdef int run_write(df, object filename_path, dst_file_format file_format, str file_label, object column_labels,             # <<<<<<<<<<<<<<
 *                    int file_format_version, object 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_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pyreadstat._readstat_writer.run_write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_natnamespace);
  __Pyx_XDECREF(__pyx_v_pd);
  __Pyx_XDECREF(__pyx_v_filename_bytes);
  __Pyx_XDECREF(__pyx_v_col_names);
  __Pyx_XDECREF(__pyx_v_file_label_bytes);
  __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_pywriter_timeunits);
  __Pyx_XDECREF(__pyx_v_df2);
  __Pyx_XDECREF(__pyx_v_strref_map);
  __Pyx_XDECREF(__pyx_v_strref_indx);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_table_name_bytes);
  __Pyx_XDECREF(__pyx_v_variable_name);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_curval);
  __Pyx_XDECREF(__pyx_v_labelset_name);
  __Pyx_XDECREF(__pyx_v_curuser_missing);
  __Pyx_XDECREF(__pyx_v_cur_ranges);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_cur_alignment);
  __Pyx_XDECREF(__pyx_v_cur_display_width);
  __Pyx_XDECREF(__pyx_v_cur_measure);
  __Pyx_XDECREF(__pyx_v_hasdate64);
  __Pyx_XDECREF(__pyx_v_hastime64);
  __Pyx_XDECREF(__pyx_v_rowcnt);
  __Pyx_XDECREF(__pyx_v_row);
  __Pyx_XDECREF(__pyx_v_is_missing);
  __Pyx_XDECREF(__pyx_v_check_if_missing);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_k);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v);
  __Pyx_XDECREF(__pyx_v_df);
  __Pyx_XDECREF(__pyx_v_column_labels);
  __Pyx_XDECREF(__pyx_v_note);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* #### Code section: module_exttypes ### */

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};
/* #### Code section: initfunc_declarations ### */
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_InitConstants(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(__pyx_mstatetype *__pyx_mstate); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_CreateCodeObjects(__pyx_mstatetype *__pyx_mstate); /*proto*/
/* #### Code section: init_module ### */

static int __Pyx_modinit_global_init_code(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  __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_float_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_narwhals_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(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  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("vectorized_convert_datetime_to_number", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_datetime_to_number, "PyObject *(PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("vectorized_convert_date_to_number", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_date_to_number, "PyObject *(PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("vectorized_convert_time_to_number", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_vectorized_convert_time_to_number, "PyObject *(PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  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_narwhals_str_series_max_length", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_get_narwhals_str_series_max_length, "int (PyObject *, PyObject *, int)") < 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_narwhals_column_types", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_get_narwhals_column_types, "PyObject *(PyObject *, PyObject *, PyObject *, int)") < 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("filepath_to_bytes", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_filepath_to_bytes, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("initial_checks", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_writer_initial_checks, "void (int, int, PyObject *, PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *)") < 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(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_import_code(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  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_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container = __Pyx_ImportType_3_1_2(__pyx_t_1, "pyreadstat._readstat_parser", "data_container",
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container),
  #elif CYTHON_COMPILING_IN_LIMITED_API
  sizeof(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container),
  #else
  sizeof(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container),
  #endif
  __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__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(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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_1_2(__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(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  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_1_2(__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 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},
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
  {Py_mod_gil, Py_MOD_GIL_USED},
  #endif
  #if PY_VERSION_HEX >= 0x030C0000 && CYTHON_USE_MODULE_STATE
  {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
  #endif
  {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_USE_MODULE_STATE
      sizeof(__pyx_mstatetype), /* m_size */
    #else
      (CYTHON_PEP489_MULTI_PHASE_INIT) ? 0 : -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

/* PyModInitFuncType */
#ifndef CYTHON_NO_PYINIT_EXPORT
  #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#else
  #ifdef __cplusplus
  #define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
  #else
  #define __Pyx_PyMODINIT_FUNC PyObject *
  #endif
#endif

__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);
}
/* ModuleCreationPEP489 */
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03090000
static PY_INT64_T __Pyx_GetCurrentInterpreterId(void) {
    {
        PyObject *module = PyImport_ImportModule("_interpreters"); // 3.13+ I think
        if (!module) {
            PyErr_Clear(); // just try the 3.8-3.12 version
            module = PyImport_ImportModule("_xxsubinterpreters");
            if (!module) goto bad;
        }
        PyObject *current = PyObject_CallMethod(module, "get_current", NULL);
        Py_DECREF(module);
        if (!current) goto bad;
        if (PyTuple_Check(current)) {
            PyObject *new_current = PySequence_GetItem(current, 0);
            Py_DECREF(current);
            current = new_current;
            if (!new_current) goto bad;
        }
        long long as_c_int = PyLong_AsLongLong(current);
        Py_DECREF(current);
        return as_c_int;
    }
  bad:
    PySys_WriteStderr("__Pyx_GetCurrentInterpreterId failed. Try setting the C define CYTHON_PEP489_MULTI_PHASE_INIT=0\n");
    return -1;
}
#endif
#if !CYTHON_USE_MODULE_STATE
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    static PY_INT64_T main_interpreter_id = -1;
#if CYTHON_COMPILING_IN_GRAAL
    PY_INT64_T current_id = PyInterpreterState_GetIDFromThreadState(PyThreadState_Get());
#elif CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX >= 0x03090000
    PY_INT64_T current_id = PyInterpreterState_GetID(PyInterpreterState_Get());
#elif CYTHON_COMPILING_IN_LIMITED_API
    PY_INT64_T current_id = __Pyx_GetCurrentInterpreterId();
#else
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
#endif
    if (unlikely(current_id == -1)) {
        return -1;
    }
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return 0;
    } else if (unlikely(main_interpreter_id != current_id)) {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
#endif
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)
{
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        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 !CYTHON_USE_MODULE_STATE
    if (__Pyx_check_single_interpreter())
        return NULL;
    #endif
    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;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    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
{
  int stringtab_initialized = 0;
  #if CYTHON_USE_MODULE_STATE
  int pystate_addmodule_run = 0;
  #endif
  __pyx_mstatetype *__pyx_mstate = NULL;
  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;
  size_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  int __pyx_t_15;
  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;
  }
  #else
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_t_1 = __pyx_pyinit_module;
  Py_INCREF(__pyx_t_1);
  #else
  __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #if CYTHON_USE_MODULE_STATE
  {
    int add_module_result = __Pyx_State_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 = __pyx_t_1;
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
  PyUnstable_Module_SetGIL(__pyx_m, Py_MOD_GIL_USED);
  #endif
  __pyx_mstate = __pyx_mstate_global;
  CYTHON_UNUSED_VAR(__pyx_t_1);
  __pyx_mstate->__pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_mstate->__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_mstate->__pyx_d);
  __pyx_mstate->__pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_mstate->__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_cython_runtime = __Pyx_PyImport_AddModuleRef("cython_runtime"); if (unlikely(!__pyx_mstate->__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_mstate->__pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /* ImportRefnannyAPI */
  #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("PyInit__readstat_writer", 0);
  if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_mstate->__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_mstate->__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_mstate->__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_mstate->__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitConstants(__pyx_mstate) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  stringtab_initialized = 1;
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if 0 || defined(__Pyx_CyFunction_USED) || defined(__Pyx_FusedFunction_USED) || defined(__Pyx_Coroutine_USED) || defined(__Pyx_Generator_USED) || defined(__Pyx_AsyncGen_USED)
  if (__pyx_CommonTypesMetaclass_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #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
  /*--- Library function declarations ---*/
  if (__pyx_module_is_main_pyreadstat___readstat_writer) {
    if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_name_2, __pyx_mstate_global->__pyx_n_u_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  {
    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)
    }
  }
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins(__pyx_mstate) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants(__pyx_mstate) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_CreateCodeObjects(__pyx_mstate) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code(__pyx_mstate);
  (void)__Pyx_modinit_variable_export_code(__pyx_mstate);
  if (unlikely((__Pyx_modinit_function_export_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_type_init_code(__pyx_mstate);
  if (unlikely((__Pyx_modinit_type_import_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely((__Pyx_modinit_variable_import_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely((__Pyx_modinit_function_import_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/

  /* "pyreadstat/_readstat_writer.pyx":18
 * # limitations under the License.
 * # #############################################################################
 * import os             # <<<<<<<<<<<<<<
 * import warnings
 * import sys
*/
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_os, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_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
 * import datetime
*/
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_warnings, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_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 datetime
 * #import calendar
*/
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_sys, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_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":21
 * import warnings
 * import sys
 * import datetime             # <<<<<<<<<<<<<<
 * #import calendar
 * from datetime import timezone
*/
  __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_datetime, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_datetime, __pyx_t_2) < 0) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":23
 * import datetime
 * #import calendar
 * from datetime import timezone             # <<<<<<<<<<<<<<
 * #from datetime import timezone as _timezone
 * #from libc.math cimport round, NAN
*/
  __pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_timezone); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_datetime, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 23, __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_mstate_global->__pyx_n_u_timezone); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_timezone, __pyx_t_2) < 0) __PYX_ERR(0, 23, __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":27
 * #from libc.math cimport round, NAN
 * 
 * import numpy as np             # <<<<<<<<<<<<<<
 * import narwhals.stable.v2 as nw
 * 
*/
  __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_numpy, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_np, __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 numpy as np
 * import narwhals.stable.v2 as nw             # <<<<<<<<<<<<<<
 * 
 * from readstat_api cimport *
*/
  __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_narwhals_stable_v2, __pyx_mstate_global->__pyx_tuple[1]); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_nw, __pyx_t_3) < 0) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyreadstat/_readstat_writer.pyx":31
 * 
 * from readstat_api cimport *
 * from _readstat_parser import ReadstatError, PyreadstatError             # <<<<<<<<<<<<<<
 * from _readstat_parser cimport check_exit_status
 * 
*/
  __pyx_t_3 = __Pyx_PyList_Pack(2, __pyx_mstate_global->__pyx_n_u_ReadstatError, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_readstat_parser, __pyx_t_3, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __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_mstate_global->__pyx_n_u_ReadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_ReadstatError, __pyx_t_3) < 0) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_PyreadstatError, __pyx_t_3) < 0) __PYX_ERR(0, 31, __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":34
 * from _readstat_parser cimport check_exit_status
 * 
 * cdef set int_types = {nw.Int32, nw.Int16, nw.Int8, nw.UInt16, nw.UInt8, }             # <<<<<<<<<<<<<<
 * cdef set float_types = {nw.Float64, nw.Float32, nw.Decimal, nw.Int128, nw.Int64, nw.UInt128, nw.UInt64, nw.UInt32}
 * cdef set nat_types = {datetime.datetime, np.datetime64, datetime.time, datetime.date} #pd._libs.tslibs.timestamps.Timestamp,
*/
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Int16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Int8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_UInt16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_UInt8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PySet_Add(__pyx_t_2, __pyx_t_3) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_4) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_5) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_6) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_7) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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_2));
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":35
 * 
 * cdef set int_types = {nw.Int32, nw.Int16, nw.Int8, nw.UInt16, nw.UInt8, }
 * cdef set float_types = {nw.Float64, nw.Float32, nw.Decimal, nw.Int128, nw.Int64, nw.UInt128, nw.UInt64, nw.UInt32}             # <<<<<<<<<<<<<<
 * cdef set nat_types = {datetime.datetime, np.datetime64, datetime.time, datetime.date} #pd._libs.tslibs.timestamps.Timestamp,
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64}
*/
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Decimal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); 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_mstate_global->__pyx_n_u_Int128); 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_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Int64); 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_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_UInt128); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_UInt64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_UInt32); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PySet_Add(__pyx_t_2, __pyx_t_7) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PySet_Add(__pyx_t_2, __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_2, __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_2, __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_2, __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_2, __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_2, __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_2, __pyx_t_10) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 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_2));
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":36
 * cdef set int_types = {nw.Int32, nw.Int16, nw.Int8, nw.UInt16, nw.UInt8, }
 * cdef set float_types = {nw.Float64, nw.Float32, nw.Decimal, nw.Int128, nw.Int64, nw.UInt128, nw.UInt64, nw.UInt32}
 * cdef set nat_types = {datetime.datetime, np.datetime64, datetime.time, datetime.date} #pd._libs.tslibs.timestamps.Timestamp,             # <<<<<<<<<<<<<<
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64}
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME,
*/
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_date); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PySet_Add(__pyx_t_2, __pyx_t_10) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_9) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_8) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PySet_Add(__pyx_t_2, __pyx_t_3) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_2));
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyreadstat/_readstat_writer.pyx":37
 * cdef set float_types = {nw.Float64, nw.Float32, nw.Decimal, nw.Int128, nw.Int64, nw.UInt128, nw.UInt64, nw.UInt32}
 * cdef set nat_types = {datetime.datetime, np.datetime64, datetime.time, datetime.date} #pd._libs.tslibs.timestamps.Timestamp,
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64}             # <<<<<<<<<<<<<<
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME,
 *                                    PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64 }
*/
  __pyx_t_2 = __Pyx_PyLong_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, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyLong_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, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_4 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PySet_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PySet_Add(__pyx_t_5, __pyx_t_2) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PySet_Add(__pyx_t_5, __pyx_t_3) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PySet_Add(__pyx_t_5, __pyx_t_8) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PySet_Add(__pyx_t_5, __pyx_t_9) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PySet_Add(__pyx_t_5, __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_5, __pyx_t_4) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_5));
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyreadstat/_readstat_writer.pyx":38
 * cdef set nat_types = {datetime.datetime, np.datetime64, datetime.time, datetime.date} #pd._libs.tslibs.timestamps.Timestamp,
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64}
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME,             # <<<<<<<<<<<<<<
 *                                    PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64 }
 * cdef dict narwhals_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
*/
  __pyx_t_5 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_10 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = __Pyx_PyLong_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, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "pyreadstat/_readstat_writer.pyx":39
 * cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64}
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME,
 *                                    PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64 }             # <<<<<<<<<<<<<<
 * cdef dict narwhals_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_2 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_11 = PySet_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  if (PySet_Add(__pyx_t_11, __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_11, __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_11, __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_11, __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_11, __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_11, __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_11, __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_11, __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_11, __pyx_t_7) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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_11));
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_11 = 0;

  /* "pyreadstat/_readstat_writer.pyx":40
 * cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME,
 *                                    PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64 }
 * cdef dict narwhals_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 *                                       PYWRITER_DTA_STR_REF: READSTAT_TYPE_STRING_REF,
*/
  __pyx_t_11 = __Pyx_PyDict_NewPresized(12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_INTEGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_INT32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_6, __pyx_t_7) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":41
 *                                    PYWRITER_DATETIME64, PYWRITER_DATE64, PYWRITER_TIME64 }
 * cdef dict narwhals_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_DTA_STR_REF: READSTAT_TYPE_STRING_REF,
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
*/
  __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_CHARACTER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_STRING); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_LOGICAL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_INT32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_6, __pyx_t_7) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pyreadstat/_readstat_writer.pyx":42
 * cdef dict narwhals_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32,
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 *                                       PYWRITER_DTA_STR_REF: READSTAT_TYPE_STRING_REF,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
*/
  __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DTA_STR_REF); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_STRING_REF); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":43
 *                                       PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32,
 *                                       PYWRITER_DTA_STR_REF: READSTAT_TYPE_STRING_REF,
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME64: READSTAT_TYPE_DOUBLE, PYWRITER_DATE64: READSTAT_TYPE_DOUBLE,
*/
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_OBJECT); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_STRING); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_6, __pyx_t_7) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyLong_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, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":44
 *                                       PYWRITER_DTA_STR_REF: READSTAT_TYPE_STRING_REF,
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_DATETIME64: READSTAT_TYPE_DOUBLE, PYWRITER_DATE64: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_TIME64: READSTAT_TYPE_DOUBLE, }
*/
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_6, __pyx_t_7) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyLong_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, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":45
 *                                       PYWRITER_OBJECT: READSTAT_TYPE_STRING, PYWRITER_DATE: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME64: READSTAT_TYPE_DOUBLE, PYWRITER_DATE64: READSTAT_TYPE_DOUBLE,             # <<<<<<<<<<<<<<
 *                                       PYWRITER_TIME64: READSTAT_TYPE_DOUBLE, }
 * 
*/
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATETIME64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_6, __pyx_t_7) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_DATE64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_6) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":46
 *                                       PYWRITER_DATETIME: READSTAT_TYPE_DOUBLE, PYWRITER_TIME: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_DATETIME64: READSTAT_TYPE_DOUBLE, PYWRITER_DATE64: READSTAT_TYPE_DOUBLE,
 *                                       PYWRITER_TIME64: READSTAT_TYPE_DOUBLE, }             # <<<<<<<<<<<<<<
 * 
 * cdef double spss_offset_secs = 12219379200
*/
  __pyx_t_6 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(__pyx_e_10pyreadstat_16_readstat_writer_PYWRITER_TIME64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_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_11, __pyx_t_6, __pyx_t_7) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_narwhals_to_readstat_types);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_narwhals_to_readstat_types, ((PyObject*)__pyx_t_11));
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_11 = 0;

  /* "pyreadstat/_readstat_writer.pyx":48
 *                                       PYWRITER_TIME64: 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":49
 * 
 * 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":50
 * 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":51
 * 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":52
 * 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_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_mstate_global->__pyx_tuple[2], NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __pyx_t_6;
  __Pyx_INCREF(__pyx_t_7);
  __pyx_t_12 = 0;
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL};
    __pyx_t_11 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_date, __pyx_callargs+__pyx_t_12, (1-__pyx_t_12) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 52, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
  }
  __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_writer_date_0);
  __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_writer_date_0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_11 = 0;

  /* "pyreadstat/_readstat_writer.pyx":54
 * 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_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_7 = NULL;
  __Pyx_INCREF(__pyx_builtin_range);
  __pyx_t_2 = __pyx_builtin_range; 
  __pyx_t_3 = __Pyx_PyLong_From_long((90 + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_12 = 1;
  {
    PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_mstate_global->__pyx_int_65, __pyx_t_3};
    __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_12, (3-__pyx_t_12) | (__pyx_t_12*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
  }
  if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
    __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2);
    __pyx_t_13 = 0;
    __pyx_t_14 = NULL;
  } else {
    __pyx_t_13 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_14 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 54, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  for (;;) {
    if (likely(!__pyx_t_14)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 54, __pyx_L1_error)
          #endif
          if (__pyx_t_13 >= __pyx_temp) break;
        }
        __pyx_t_6 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_13);
        ++__pyx_t_13;
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 54, __pyx_L1_error)
          #endif
          if (__pyx_t_13 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_6 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_13));
        #else
        __pyx_t_6 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_13);
        #endif
        ++__pyx_t_13;
      }
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
    } else {
      __pyx_t_6 = __pyx_t_14(__pyx_t_2);
      if (unlikely(!__pyx_t_6)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 54, __pyx_L1_error)
          PyErr_Clear();
        }
        break;
      }
    }
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_x, __pyx_t_6) < 0) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_15 = __Pyx_PyLong_As_int(__pyx_t_6); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyUnicode_FromOrdinal(__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_11, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 54, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u__4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = PyNumber_Add(__pyx_t_11, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":55
 * 
 * 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)]             # <<<<<<<<<<<<<<
 * 
 * # max lenght of a string in dta before it has to use string_ref
*/
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = NULL;
  __Pyx_INCREF(__pyx_builtin_range);
  __pyx_t_3 = __pyx_builtin_range; 
  __pyx_t_7 = __Pyx_PyLong_From_long((0x7A + 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_12 = 1;
  {
    PyObject *__pyx_callargs[3] = {__pyx_t_11, __pyx_mstate_global->__pyx_int_97, __pyx_t_7};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_12, (3-__pyx_t_12) | (__pyx_t_12*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  }
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3);
    __pyx_t_13 = 0;
    __pyx_t_14 = NULL;
  } else {
    __pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_14 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 55, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_14)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_3);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 55, __pyx_L1_error)
          #endif
          if (__pyx_t_13 >= __pyx_temp) break;
        }
        __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_3, __pyx_t_13);
        ++__pyx_t_13;
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_3);
          #if !CYTHON_ASSUME_SAFE_SIZE
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 55, __pyx_L1_error)
          #endif
          if (__pyx_t_13 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13));
        #else
        __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_13);
        #endif
        ++__pyx_t_13;
      }
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
    } else {
      __pyx_t_2 = __pyx_t_14(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 55, __pyx_L1_error)
          PyErr_Clear();
        }
        break;
      }
    }
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_x, __pyx_t_2) < 0) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_15 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyUnicode_FromOrdinal(__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_6, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pyreadstat/_readstat_writer.pyx":58
 * 
 * # max lenght of a string in dta before it has to use string_ref
 * cdef int dta_old_max_width = 128             # <<<<<<<<<<<<<<
 * cdef int dta_111_max_width = 244
 * cdef int dta_117_max_width = 2045
*/
  __pyx_v_10pyreadstat_16_readstat_writer_dta_old_max_width = 0x80;

  /* "pyreadstat/_readstat_writer.pyx":59
 * # max lenght of a string in dta before it has to use string_ref
 * cdef int dta_old_max_width = 128
 * cdef int dta_111_max_width = 244             # <<<<<<<<<<<<<<
 * cdef int dta_117_max_width = 2045
 * 
*/
  __pyx_v_10pyreadstat_16_readstat_writer_dta_111_max_width = 0xF4;

  /* "pyreadstat/_readstat_writer.pyx":60
 * cdef int dta_old_max_width = 128
 * cdef int dta_111_max_width = 244
 * cdef int dta_117_max_width = 2045             # <<<<<<<<<<<<<<
 * 
 * cdef object vectorized_convert_datetime_to_number(object df, dst_file_format file_format, list pywriter_types, list pywriter_timeunits, int col_count):
*/
  __pyx_v_10pyreadstat_16_readstat_writer_dta_117_max_width = 0x7FD;

  /* "pyreadstat/_readstat_writer.pyx":1
 * # cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2             # <<<<<<<<<<<<<<
 * # ###cython: profile=True
 * # #############################################################################
*/
  __pyx_t_6 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_6) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 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);
  if (__pyx_m) {
    if (__pyx_mstate->__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;
  #else
  return __pyx_m;
  #endif
}
/* #### Code section: pystring_table ### */

typedef struct {
    const char *s;
#if 149 <= 65535
    const unsigned short n;
#elif 149 / 2 < INT_MAX
    const unsigned int n;
#elif 149 / 2 < LONG_MAX
    const unsigned long n;
#else
    const Py_ssize_t n;
#endif
#if 1 <= 31
    const unsigned int encoding : 5;
#elif 1 <= 255
    const unsigned char encoding;
#elif 1 <= 65535
    const unsigned short encoding;
#else
    const Py_ssize_t encoding;
#endif
    const unsigned int is_unicode : 1;
    const unsigned int intern : 1;
} __Pyx_StringTabEntry;
static const char * const __pyx_string_tab_encodings[] = { 0 };
static const __Pyx_StringTabEntry __pyx_string_tab[] = {
  {__pyx_k_, sizeof(__pyx_k_), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_ */
  {__pyx_k_Boolean, sizeof(__pyx_k_Boolean), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Boolean */
  {__pyx_k_Categorical, sizeof(__pyx_k_Categorical), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Categorical */
  {__pyx_k_Column_labels_must_be_strings, sizeof(__pyx_k_Column_labels_must_be_strings), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Column_labels_must_be_strings */
  {__pyx_k_Date, sizeof(__pyx_k_Date), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Date */
  {__pyx_k_Datetime, sizeof(__pyx_k_Datetime), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Datetime */
  {__pyx_k_Decimal, sizeof(__pyx_k_Decimal), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Decimal */
  {__pyx_k_Enum, sizeof(__pyx_k_Enum), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Enum */
  {__pyx_k_Float32, sizeof(__pyx_k_Float32), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Float32 */
  {__pyx_k_Float64, sizeof(__pyx_k_Float64), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Float64 */
  {__pyx_k_Int128, sizeof(__pyx_k_Int128), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Int128 */
  {__pyx_k_Int16, sizeof(__pyx_k_Int16), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Int16 */
  {__pyx_k_Int32, sizeof(__pyx_k_Int32), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Int32 */
  {__pyx_k_Int64, sizeof(__pyx_k_Int64), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Int64 */
  {__pyx_k_Int8, sizeof(__pyx_k_Int8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Int8 */
  {__pyx_k_Non_unique_column_names_detected, sizeof(__pyx_k_Non_unique_column_names_detected), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Non_unique_column_names_detected */
  {__pyx_k_None, sizeof(__pyx_k_None), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_None */
  {__pyx_k_Object, sizeof(__pyx_k_Object), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Object */
  {__pyx_k_PyreadstatError, sizeof(__pyx_k_PyreadstatError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_PyreadstatError */
  {__pyx_k_ReadstatError, sizeof(__pyx_k_ReadstatError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ReadstatError */
  {__pyx_k_String, sizeof(__pyx_k_String), 0, 1, 1}, /* PyObject cname: __pyx_n_u_String */
  {__pyx_k_Time, sizeof(__pyx_k_Time), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Time */
  {__pyx_k_UInt128, sizeof(__pyx_k_UInt128), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UInt128 */
  {__pyx_k_UInt16, sizeof(__pyx_k_UInt16), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UInt16 */
  {__pyx_k_UInt32, sizeof(__pyx_k_UInt32), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UInt32 */
  {__pyx_k_UInt64, sizeof(__pyx_k_UInt64), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UInt64 */
  {__pyx_k_UInt8, sizeof(__pyx_k_UInt8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UInt8 */
  {__pyx_k_UnicodeError, sizeof(__pyx_k_UnicodeError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UnicodeError */
  {__pyx_k_Unknown_data_format_to_insert, sizeof(__pyx_k_Unknown_data_format_to_insert), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Unknown_data_format_to_insert */
  {__pyx_k_Unknown_pywriter_variable_format, sizeof(__pyx_k_Unknown_pywriter_variable_format), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Unknown_pywriter_variable_format */
  {__pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u__2 */
  {__pyx_k__3, sizeof(__pyx_k__3), 0, 1, 0}, /* PyObject cname: __pyx_kp_u__3 */
  {__pyx_k__4, sizeof(__pyx_k__4), 0, 1, 1}, /* PyObject cname: __pyx_n_u__4 */
  {__pyx_k__5, sizeof(__pyx_k__5), 0, 1, 0}, /* PyObject cname: __pyx_kp_u__5 */
  {__pyx_k_alignment_for_variable, sizeof(__pyx_k_alignment_for_variable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_alignment_for_variable */
  {__pyx_k_and_it_must_be_str_not_starting, sizeof(__pyx_k_and_it_must_be_str_not_starting), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_and_it_must_be_str_not_starting */
  {__pyx_k_cast, sizeof(__pyx_k_cast), 0, 1, 1}, /* PyObject cname: __pyx_n_u_cast */
  {__pyx_k_cat, sizeof(__pyx_k_cat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_cat */
  {__pyx_k_center, sizeof(__pyx_k_center), 0, 1, 1}, /* PyObject cname: __pyx_n_u_center */
  {__pyx_k_character_missing_ranges_value_g, sizeof(__pyx_k_character_missing_ranges_value_g), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_character_missing_ranges_value_g */
  {__pyx_k_class_getitem, sizeof(__pyx_k_class_getitem), 0, 1, 1}, /* PyObject cname: __pyx_n_u_class_getitem */
  {__pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 1, 1}, /* PyObject cname: __pyx_n_u_cline_in_traceback */
  {__pyx_k_clone, sizeof(__pyx_k_clone), 0, 1, 1}, /* PyObject cname: __pyx_n_u_clone */
  {__pyx_k_column_labels_must_be_either_lis, sizeof(__pyx_k_column_labels_must_be_either_lis), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_column_labels_must_be_either_lis */
  {__pyx_k_columns, sizeof(__pyx_k_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_columns */
  {__pyx_k_combine, sizeof(__pyx_k_combine), 0, 1, 1}, /* PyObject cname: __pyx_n_u_combine */
  {__pyx_k_dataframe_must_be_pandas_or_pola, sizeof(__pyx_k_dataframe_must_be_pandas_or_pola), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_dataframe_must_be_pandas_or_pola */
  {__pyx_k_date, sizeof(__pyx_k_date), 0, 1, 1}, /* PyObject cname: __pyx_n_u_date */
  {__pyx_k_datetime, sizeof(__pyx_k_datetime), 0, 1, 1}, /* PyObject cname: __pyx_n_u_datetime */
  {__pyx_k_datetime64, sizeof(__pyx_k_datetime64), 0, 1, 1}, /* PyObject cname: __pyx_n_u_datetime64 */
  {__pyx_k_days, sizeof(__pyx_k_days), 0, 1, 1}, /* PyObject cname: __pyx_n_u_days */
  {__pyx_k_dictionaries_in_missing_ranges_m, sizeof(__pyx_k_dictionaries_in_missing_ranges_m), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_dictionaries_in_missing_ranges_m */
  {__pyx_k_dirname, sizeof(__pyx_k_dirname), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dirname */
  {__pyx_k_does_not_exist, sizeof(__pyx_k_does_not_exist), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_does_not_exist */
  {__pyx_k_drop_nulls, sizeof(__pyx_k_drop_nulls), 0, 1, 1}, /* PyObject cname: __pyx_n_u_drop_nulls */
  {__pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dtype */
  {__pyx_k_eager_only, sizeof(__pyx_k_eager_only), 0, 1, 1}, /* PyObject cname: __pyx_n_u_eager_only */
  {__pyx_k_encode, sizeof(__pyx_k_encode), 0, 1, 1}, /* PyObject cname: __pyx_n_u_encode */
  {__pyx_k_expanduser, sizeof(__pyx_k_expanduser), 0, 1, 1}, /* PyObject cname: __pyx_n_u_expanduser */
  {__pyx_k_file_path_could_not_be_encoded_w, sizeof(__pyx_k_file_path_could_not_be_encoded_w), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_file_path_could_not_be_encoded_w */
  {__pyx_k_filter, sizeof(__pyx_k_filter), 0, 1, 1}, /* PyObject cname: __pyx_n_u_filter */
  {__pyx_k_from_native, sizeof(__pyx_k_from_native), 0, 1, 1}, /* PyObject cname: __pyx_n_u_from_native */
  {__pyx_k_fsdecode, sizeof(__pyx_k_fsdecode), 0, 1, 1}, /* PyObject cname: __pyx_n_u_fsdecode */
  {__pyx_k_fsencode, sizeof(__pyx_k_fsencode), 0, 1, 1}, /* PyObject cname: __pyx_n_u_fsencode */
  {__pyx_k_get, sizeof(__pyx_k_get), 0, 1, 1}, /* PyObject cname: __pyx_n_u_get */
  {__pyx_k_get_categories, sizeof(__pyx_k_get_categories), 0, 1, 1}, /* PyObject cname: __pyx_n_u_get_categories */
  {__pyx_k_get_native_namespace, sizeof(__pyx_k_get_native_namespace), 0, 1, 1}, /* PyObject cname: __pyx_n_u_get_native_namespace */
  {__pyx_k_getfilesystemencoding, sizeof(__pyx_k_getfilesystemencoding), 0, 1, 1}, /* PyObject cname: __pyx_n_u_getfilesystemencoding */
  {__pyx_k_hi, sizeof(__pyx_k_hi), 0, 1, 1}, /* PyObject cname: __pyx_n_u_hi */
  {__pyx_k_implementation, sizeof(__pyx_k_implementation), 0, 1, 1}, /* PyObject cname: __pyx_n_u_implementation */
  {__pyx_k_in_variable, sizeof(__pyx_k_in_variable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_in_variable */
  {__pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 1, 1}, /* PyObject cname: __pyx_n_u_initializing */
  {__pyx_k_instead, sizeof(__pyx_k_instead), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_instead */
  {__pyx_k_is_in, sizeof(__pyx_k_is_in), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_in */
  {__pyx_k_is_of_type, sizeof(__pyx_k_is_of_type), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_is_of_type */
  {__pyx_k_is_pandas, sizeof(__pyx_k_is_pandas), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_pandas */
  {__pyx_k_is_polars, sizeof(__pyx_k_is_polars), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_polars */
  {__pyx_k_isalpha, sizeof(__pyx_k_isalpha), 0, 1, 1}, /* PyObject cname: __pyx_n_u_isalpha */
  {__pyx_k_isdir, sizeof(__pyx_k_isdir), 0, 1, 1}, /* PyObject cname: __pyx_n_u_isdir */
  {__pyx_k_isna, sizeof(__pyx_k_isna), 0, 1, 1}, /* PyObject cname: __pyx_n_u_isna */
  {__pyx_k_items, sizeof(__pyx_k_items), 0, 1, 1}, /* PyObject cname: __pyx_n_u_items */
  {__pyx_k_iter_columns, sizeof(__pyx_k_iter_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_iter_columns */
  {__pyx_k_iter_rows, sizeof(__pyx_k_iter_rows), 0, 1, 1}, /* PyObject cname: __pyx_n_u_iter_rows */
  {__pyx_k_keys, sizeof(__pyx_k_keys), 0, 1, 1}, /* PyObject cname: __pyx_n_u_keys */
  {__pyx_k_left, sizeof(__pyx_k_left), 0, 1, 1}, /* PyObject cname: __pyx_n_u_left */
  {__pyx_k_length_of_column_labels_must_be, sizeof(__pyx_k_length_of_column_labels_must_be), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_length_of_column_labels_must_be */
  {__pyx_k_lo, sizeof(__pyx_k_lo), 0, 1, 1}, /* PyObject cname: __pyx_n_u_lo */
  {__pyx_k_main, sizeof(__pyx_k_main), 0, 1, 1}, /* PyObject cname: __pyx_n_u_main */
  {__pyx_k_measure_for_variable, sizeof(__pyx_k_measure_for_variable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_measure_for_variable */
  {__pyx_k_min, sizeof(__pyx_k_min), 0, 1, 1}, /* PyObject cname: __pyx_n_u_min */
  {__pyx_k_missing_ranges_hi_and_lo_values, sizeof(__pyx_k_missing_ranges_hi_and_lo_values), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_hi_and_lo_values */
  {__pyx_k_missing_ranges_hi_and_lo_values_2, sizeof(__pyx_k_missing_ranges_hi_and_lo_values_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_hi_and_lo_values_2 */
  {__pyx_k_missing_ranges_max_1_discrete_nu, sizeof(__pyx_k_missing_ranges_max_1_discrete_nu), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_max_1_discrete_nu */
  {__pyx_k_missing_ranges_max_1_range_value, sizeof(__pyx_k_missing_ranges_max_1_range_value), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_max_1_range_value */
  {__pyx_k_missing_ranges_max_3_discrete_nu, sizeof(__pyx_k_missing_ranges_max_3_discrete_nu), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_max_3_discrete_nu */
  {__pyx_k_missing_ranges_max_3_string_valu, sizeof(__pyx_k_missing_ranges_max_3_string_valu), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_max_3_string_valu */
  {__pyx_k_missing_ranges_string_values_len, sizeof(__pyx_k_missing_ranges_string_values_len), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_string_values_len */
  {__pyx_k_missing_ranges_values_in_diction, sizeof(__pyx_k_missing_ranges_values_in_diction), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_values_in_diction */
  {__pyx_k_missing_ranges_values_must_be_bo, sizeof(__pyx_k_missing_ranges_values_must_be_bo), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_ranges_values_must_be_bo */
  {__pyx_k_missing_user_values_not_allowed, sizeof(__pyx_k_missing_user_values_not_allowed), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_user_values_not_allowed */
  {__pyx_k_missing_user_values_supports_val, sizeof(__pyx_k_missing_user_values_supports_val), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_user_values_supports_val */
  {__pyx_k_missing_user_values_values_in_di, sizeof(__pyx_k_missing_user_values_values_in_di), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_missing_user_values_values_in_di */
  {__pyx_k_module, sizeof(__pyx_k_module), 0, 1, 1}, /* PyObject cname: __pyx_n_u_module */
  {__pyx_k_ms, sizeof(__pyx_k_ms), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ms */
  {__pyx_k_must_be_boolean_or_be_1_or_0, sizeof(__pyx_k_must_be_boolean_or_be_1_or_0), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_boolean_or_be_1_or_0 */
  {__pyx_k_must_be_dict_got, sizeof(__pyx_k_must_be_dict_got), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_dict_got */
  {__pyx_k_must_be_either_nominal_ordinal, sizeof(__pyx_k_must_be_either_nominal_ordinal), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_either_nominal_ordinal */
  {__pyx_k_must_be_either_right_center_lef, sizeof(__pyx_k_must_be_either_right_center_lef), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_either_right_center_lef */
  {__pyx_k_must_be_int, sizeof(__pyx_k_must_be_int), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_int */
  {__pyx_k_must_be_numeric, sizeof(__pyx_k_must_be_numeric), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_numeric */
  {__pyx_k_must_be_string, sizeof(__pyx_k_must_be_string), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_be_string */
  {__pyx_k_must_match_the_type_of_the_colu, sizeof(__pyx_k_must_match_the_type_of_the_colu), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_must_match_the_type_of_the_colu */
  {__pyx_k_name, sizeof(__pyx_k_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_name */
  {__pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 1, 1}, /* PyObject cname: __pyx_n_u_name_2 */
  {__pyx_k_narwhals, sizeof(__pyx_k_narwhals), 0, 1, 1}, /* PyObject cname: __pyx_n_u_narwhals */
  {__pyx_k_narwhals_stable_v2, sizeof(__pyx_k_narwhals_stable_v2), 0, 1, 1}, /* PyObject cname: __pyx_n_u_narwhals_stable_v2 */
  {__pyx_k_nominal, sizeof(__pyx_k_nominal), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nominal */
  {__pyx_k_note_should_be_either_str_or_lis, sizeof(__pyx_k_note_should_be_either_str_or_lis), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_note_should_be_either_str_or_lis */
  {__pyx_k_np, sizeof(__pyx_k_np), 0, 1, 1}, /* PyObject cname: __pyx_n_u_np */
  {__pyx_k_ns, sizeof(__pyx_k_ns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ns */
  {__pyx_k_nt, sizeof(__pyx_k_nt), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nt */
  {__pyx_k_nth, sizeof(__pyx_k_nth), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nth */
  {__pyx_k_null_count, sizeof(__pyx_k_null_count), 0, 1, 1}, /* PyObject cname: __pyx_n_u_null_count */
  {__pyx_k_numeric_missing_ranges_value_giv, sizeof(__pyx_k_numeric_missing_ranges_value_giv), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_numeric_missing_ranges_value_giv */
  {__pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 1, 1}, /* PyObject cname: __pyx_n_u_numpy */
  {__pyx_k_nw, sizeof(__pyx_k_nw), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nw */
  {__pyx_k_ordinal, sizeof(__pyx_k_ordinal), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ordinal */
  {__pyx_k_ordinal_2, sizeof(__pyx_k_ordinal_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_ordinal_2 */
  {__pyx_k_os, sizeof(__pyx_k_os), 0, 1, 1}, /* PyObject cname: __pyx_n_u_os */
  {__pyx_k_path, sizeof(__pyx_k_path), 0, 1, 1}, /* PyObject cname: __pyx_n_u_path */
  {__pyx_k_path_must_be_either_str_or_bytes, sizeof(__pyx_k_path_must_be_either_str_or_bytes), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_path_must_be_either_str_or_bytes */
  {__pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 1, 1}, /* PyObject cname: __pyx_n_u_qualname */
  {__pyx_k_range, sizeof(__pyx_k_range), 0, 1, 1}, /* PyObject cname: __pyx_n_u_range */
  {__pyx_k_readstat_parser, sizeof(__pyx_k_readstat_parser), 0, 1, 1}, /* PyObject cname: __pyx_n_u_readstat_parser */
  {__pyx_k_replace, sizeof(__pyx_k_replace), 0, 1, 1}, /* PyObject cname: __pyx_n_u_replace */
  {__pyx_k_right, sizeof(__pyx_k_right), 0, 1, 1}, /* PyObject cname: __pyx_n_u_right */
  {__pyx_k_round, sizeof(__pyx_k_round), 0, 1, 1}, /* PyObject cname: __pyx_n_u_round */
  {__pyx_k_scale, sizeof(__pyx_k_scale), 0, 1, 1}, /* PyObject cname: __pyx_n_u_scale */
  {__pyx_k_spec, sizeof(__pyx_k_spec), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spec */
  {__pyx_k_stable, sizeof(__pyx_k_stable), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stable */
  {__pyx_k_starts_with_an_illegal_non_alph, sizeof(__pyx_k_starts_with_an_illegal_non_alph), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_starts_with_an_illegal_non_alph */
  {__pyx_k_surrogateescape, sizeof(__pyx_k_surrogateescape), 0, 1, 1}, /* PyObject cname: __pyx_n_u_surrogateescape */
  {__pyx_k_sys, sizeof(__pyx_k_sys), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sys */
  {__pyx_k_test, sizeof(__pyx_k_test), 0, 1, 1}, /* PyObject cname: __pyx_n_u_test */
  {__pyx_k_the_destination_folder, sizeof(__pyx_k_the_destination_folder), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_the_destination_folder */
  {__pyx_k_then, sizeof(__pyx_k_then), 0, 1, 1}, /* PyObject cname: __pyx_n_u_then */
  {__pyx_k_time, sizeof(__pyx_k_time), 0, 1, 1}, /* PyObject cname: __pyx_n_u_time */
  {__pyx_k_time_unit, sizeof(__pyx_k_time_unit), 0, 1, 1}, /* PyObject cname: __pyx_n_u_time_unit */
  {__pyx_k_timestamp, sizeof(__pyx_k_timestamp), 0, 1, 1}, /* PyObject cname: __pyx_n_u_timestamp */
  {__pyx_k_timezone, sizeof(__pyx_k_timezone), 0, 1, 1}, /* PyObject cname: __pyx_n_u_timezone */
  {__pyx_k_total_seconds, sizeof(__pyx_k_total_seconds), 0, 1, 1}, /* PyObject cname: __pyx_n_u_total_seconds */
  {__pyx_k_tzinfo, sizeof(__pyx_k_tzinfo), 0, 1, 1}, /* PyObject cname: __pyx_n_u_tzinfo */
  {__pyx_k_unknown, sizeof(__pyx_k_unknown), 0, 1, 1}, /* PyObject cname: __pyx_n_u_unknown */
  {__pyx_k_unknown_file_format, sizeof(__pyx_k_unknown_file_format), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_unknown_file_format */
  {__pyx_k_upper, sizeof(__pyx_k_upper), 0, 1, 1}, /* PyObject cname: __pyx_n_u_upper */
  {__pyx_k_us, sizeof(__pyx_k_us), 0, 1, 1}, /* PyObject cname: __pyx_n_u_us */
  {__pyx_k_utc, sizeof(__pyx_k_utc), 0, 1, 1}, /* PyObject cname: __pyx_n_u_utc */
  {__pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_utf_8 */
  {__pyx_k_v2, sizeof(__pyx_k_v2), 0, 1, 1}, /* PyObject cname: __pyx_n_u_v2 */
  {__pyx_k_variable_name, sizeof(__pyx_k_variable_name), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_variable_name */
  {__pyx_k_variable_name_s_contains_a_space, sizeof(__pyx_k_variable_name_s_contains_a_space), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_variable_name_s_contains_a_space */
  {__pyx_k_variable_names_must_be_non_empty, sizeof(__pyx_k_variable_names_must_be_non_empty), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_variable_names_must_be_non_empty */
  {__pyx_k_variable_value_labels_type_of_La, sizeof(__pyx_k_variable_value_labels_type_of_La), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_variable_value_labels_type_of_La */
  {__pyx_k_variable_value_labels_type_of_Va, sizeof(__pyx_k_variable_value_labels_type_of_Va), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_variable_value_labels_type_of_Va */
  {__pyx_k_variable_value_labels_value_for, sizeof(__pyx_k_variable_value_labels_value_for), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_variable_value_labels_value_for */
  {__pyx_k_warn, sizeof(__pyx_k_warn), 0, 1, 1}, /* PyObject cname: __pyx_n_u_warn */
  {__pyx_k_warnings, sizeof(__pyx_k_warnings), 0, 1, 1}, /* PyObject cname: __pyx_n_u_warnings */
  {__pyx_k_when, sizeof(__pyx_k_when), 0, 1, 1}, /* PyObject cname: __pyx_n_u_when */
  {__pyx_k_with_columns, sizeof(__pyx_k_with_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_with_columns */
  {__pyx_k_x, sizeof(__pyx_k_x), 0, 1, 1}, /* PyObject cname: __pyx_n_u_x */
  {__pyx_k_zip, sizeof(__pyx_k_zip), 0, 1, 1}, /* PyObject cname: __pyx_n_u_zip */
  {0, 0, 0, 0, 0}
};
/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry const *t, PyObject **target, const char* const* encoding_names);

/* #### Code section: cached_builtins ### */

static int __Pyx_InitCachedBuiltins(__pyx_mstatetype *__pyx_mstate) {
  CYTHON_UNUSED_VAR(__pyx_mstate);
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_range); if (!__pyx_builtin_range) __PYX_ERR(0, 54, __pyx_L1_error)
  __pyx_builtin_UnicodeError = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_UnicodeError); if (!__pyx_builtin_UnicodeError) __PYX_ERR(0, 672, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 740, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: cached_constants ### */

static int __Pyx_InitCachedConstants(__pyx_mstatetype *__pyx_mstate) {
  __Pyx_RefNannyDeclarations
  CYTHON_UNUSED_VAR(__pyx_mstate);
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pyreadstat/_readstat_writer.pyx":674
 *         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_mstate_global->__pyx_tuple[0] = PyTuple_Pack(2, __pyx_mstate_global->__pyx_kp_u_utf_8, __pyx_mstate_global->__pyx_n_u_surrogateescape); if (unlikely(!__pyx_mstate_global->__pyx_tuple[0])) __PYX_ERR(0, 674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]);

  /* "pyreadstat/_readstat_writer.pyx":28
 * 
 * import numpy as np
 * import narwhals.stable.v2 as nw             # <<<<<<<<<<<<<<
 * 
 * from readstat_api cimport *
*/
  __pyx_mstate_global->__pyx_tuple[1] = PyTuple_Pack(3, __pyx_mstate_global->__pyx_n_u_narwhals, __pyx_mstate_global->__pyx_n_u_stable, __pyx_mstate_global->__pyx_n_u_v2); if (unlikely(!__pyx_mstate_global->__pyx_tuple[1])) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[1]);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[1]);

  /* "pyreadstat/_readstat_writer.pyx":52
 * 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_mstate_global->__pyx_tuple[2] = PyTuple_Pack(3, __pyx_mstate_global->__pyx_int_1970, __pyx_mstate_global->__pyx_int_1, __pyx_mstate_global->__pyx_int_1); if (unlikely(!__pyx_mstate_global->__pyx_tuple[2])) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[2]);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[2]);
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}
/* #### Code section: init_constants ### */

static int __Pyx_InitConstants(__pyx_mstatetype *__pyx_mstate) {
  CYTHON_UNUSED_VAR(__pyx_mstate);
  __pyx_mstate->__pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type;
  __pyx_mstate->__pyx_umethod_PyDict_Type_get.method_name = &__pyx_mstate->__pyx_n_u_get;
  __pyx_mstate->__pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type;
  __pyx_mstate->__pyx_umethod_PyDict_Type_items.method_name = &__pyx_mstate->__pyx_n_u_items;
  __pyx_mstate->__pyx_umethod_PyDict_Type_keys.type = (PyObject*)&PyDict_Type;
  __pyx_mstate->__pyx_umethod_PyDict_Type_keys.method_name = &__pyx_mstate->__pyx_n_u_keys;
  if (__Pyx_InitStrings(__pyx_string_tab, __pyx_mstate->__pyx_string_tab, __pyx_string_tab_encodings) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_mstate->__pyx_float_1e3 = PyFloat_FromDouble(1e3); if (unlikely(!__pyx_mstate->__pyx_float_1e3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_float_1e6 = PyFloat_FromDouble(1e6); if (unlikely(!__pyx_mstate->__pyx_float_1e6)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_float_1e9 = PyFloat_FromDouble(1e9); if (unlikely(!__pyx_mstate->__pyx_float_1e9)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_int_0 = PyLong_FromLong(0); if (unlikely(!__pyx_mstate->__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_int_1 = PyLong_FromLong(1); if (unlikely(!__pyx_mstate->__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_int_65 = PyLong_FromLong(65); if (unlikely(!__pyx_mstate->__pyx_int_65)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_int_97 = PyLong_FromLong(97); if (unlikely(!__pyx_mstate->__pyx_int_97)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_int_1970 = PyLong_FromLong(1970); if (unlikely(!__pyx_mstate->__pyx_int_1970)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_mstate->__pyx_int_neg_9223372036854775808 = PyLong_FromString("-9223372036854775808", 0, 0); if (unlikely(!__pyx_mstate->__pyx_int_neg_9223372036854775808)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: init_codeobjects ### */

static int __Pyx_CreateCodeObjects(__pyx_mstatetype *__pyx_mstate) {
  CYTHON_UNUSED_VAR(__pyx_mstate);
  return 0;
}
/* #### Code section: init_globals ### */

static int __Pyx_InitGlobals(void) {
  /* PythonCompatibility.init */
  if (likely(__Pyx_init_co_variables() == 0)); else

if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1, __pyx_L1_error)

  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### 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);
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
    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);
    Py_XDECREF(type);
    Py_XDECREF(tb);
#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);
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* PyObjectGetAttrStrNoError */
#if __PYX_LIMITED_VERSION_HEX < 0x030d0000
static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
#endif
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
    (void) PyObject_GetOptionalAttr(obj, attr_name, &result);
    return result;
#else
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS
    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;
#endif
}

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_mstate_global->__pyx_b, name);
    if (unlikely(!result) && !PyErr_Occurred()) {
        PyErr_Format(PyExc_NameError,
            "name '%U' is not defined", name);
    }
    return result;
}

/* 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_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS && !CYTHON_AVOID_THREAD_UNSAFE_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, PyLong_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_ASSUME_SAFE_SIZE && !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, PyLong_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_ASSUME_SAFE_SIZE && !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))))) {
            return __Pyx_PyList_GetItemRef(o, n);
        }
    }
    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 = PyLong_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 || !PyMapping_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyLong_FromSsize_t(i));
}

/* 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_COMPILING_IN_LIMITED_API
    if (unlikely(!__pyx_m)) {
        if (!PyErr_Occurred())
            PyErr_SetNone(PyExc_NameError);
        return NULL;
    }
    result = PyObject_GetAttr(__pyx_m, name);
    if (likely(result)) {
        return result;
    }
    PyErr_Clear();
#elif CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
    if (unlikely(__Pyx_PyDict_GetItemRef(__pyx_mstate_global->__pyx_d, name, &result) == -1)) PyErr_Clear();
    __PYX_UPDATE_DICT_CACHE(__pyx_mstate_global->__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return result;
    }
#else
    result = _PyDict_GetItem_KnownHash(__pyx_mstate_global->__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_mstate_global->__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject *const *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 *const *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;
    PyObject *kwdefs;
    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(" while calling a Python object"))) {
        return NULL;
    }
    if (
            co->co_kwonlyargcount == 0 &&
            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);
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif

/* 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(" 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

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func);
    self = __Pyx_CyOrPyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall(" 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 */
#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API
static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject * const*args, size_t nargs, PyObject *kwargs) {
    PyObject *argstuple;
    PyObject *result = 0;
    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]);
        if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) != (0)) goto bad;
    }
    result = __Pyx_PyObject_Call(func, argstuple, kwargs);
  bad:
    Py_DECREF(argstuple);
    return result;
}
#endif
#if CYTHON_VECTORCALL && !CYTHON_COMPILING_IN_LIMITED_API
  #if PY_VERSION_HEX < 0x03090000
    #define __Pyx_PyVectorcall_Function(callable) _PyVectorcall_Function(callable)
  #elif CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE vectorcallfunc __Pyx_PyVectorcall_Function(PyObject *callable) {
    PyTypeObject *tp = Py_TYPE(callable);
    #if defined(__Pyx_CyFunction_USED)
    if (__Pyx_CyFunction_CheckExact(callable)) {
        return __Pyx_CyFunction_func_vectorcall(callable);
    }
    #endif
    if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL)) {
        return NULL;
    }
    assert(PyCallable_Check(callable));
    Py_ssize_t offset = tp->tp_vectorcall_offset;
    assert(offset > 0);
    vectorcallfunc ptr;
    memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
    return ptr;
}
  #else
    #define __Pyx_PyVectorcall_Function(callable) PyVectorcall_Function(callable)
  #endif
#endif
static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject *const *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 (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS))
            return __Pyx_PyObject_CallMethO(func, NULL);
    }
    else if (nargs == 1 && kwargs == NULL) {
        if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_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 (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) {
        return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL);
    }
    #endif
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs);
    }
    #endif
    #endif
    if (kwargs == NULL) {
        #if CYTHON_VECTORCALL && !CYTHON_COMPILING_IN_LIMITED_API
        vectorcallfunc f = __Pyx_PyVectorcall_Function(func);
        if (f) {
            return f(func, args, _nargs, NULL);
        }
        #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, _nargs, NULL);
        }
        #elif CYTHON_COMPILING_IN_LIMITED_API && CYTHON_VECTORCALL
        return PyObject_Vectorcall(func, args, _nargs, NULL);
        #endif
    }
    if (nargs == 0) {
        return __Pyx_PyObject_Call(func, __pyx_mstate_global->__pyx_empty_tuple, kwargs);
    }
    #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API
    return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs);
    #else
    return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs);
    #endif
}

/* PyObjectFastCallMethod */
#if !CYTHON_VECTORCALL || PY_VERSION_HEX < 0x03090000
static PyObject *__Pyx_PyObject_FastCallMethod(PyObject *name, PyObject *const *args, size_t nargsf) {
    PyObject *result;
    PyObject *attr = PyObject_GetAttr(args[0], name);
    if (unlikely(!attr))
        return NULL;
    result = __Pyx_PyObject_FastCall(attr, args+1, nargsf - 1);
    Py_DECREF(attr);
    return result;
}
#endif

/* DictGetItem */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    if (unlikely(__Pyx_PyDict_GetItemRef(d, key, &value) == 0)) { // no value, no error
        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 value;
}
#endif

/* 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))) {
        a = __Pyx_PyFloat_AS_DOUBLE(op1);
        
    } else
    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));
    }
        result = a / b;
        return PyFloat_FromDouble(result);
}
#endif

/* PyObjectVectorCallKwBuilder */
#if CYTHON_VECTORCALL
static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) {
    (void)__Pyx_PyObject_FastCallDict;
    if (__Pyx_PyTuple_SET_ITEM(builder, n, key) != (0)) return -1;
    Py_INCREF(key);
    args[n] = value;
    return 0;
}
CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) {
    (void)__Pyx_VectorcallBuilder_AddArgStr;
    if (unlikely(!PyUnicode_Check(key))) {
        PyErr_SetString(PyExc_TypeError, "keywords must be strings");
        return -1;
    }
    return __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n);
}
static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n) {
    PyObject *pyKey = PyUnicode_FromString(key);
    if (!pyKey) return -1;
    return __Pyx_VectorcallBuilder_AddArg(pyKey, value, builder, args, n);
}
#else // CYTHON_VECTORCALL
CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, CYTHON_UNUSED PyObject **args, CYTHON_UNUSED int n) {
    if (unlikely(!PyUnicode_Check(key))) {
        PyErr_SetString(PyExc_TypeError, "keywords must be strings");
        return -1;
    }
    return PyDict_SetItem(builder, key, value);
}
#endif

/* PyObjectVectorCallMethodKwBuilder */
#if !CYTHON_VECTORCALL || PY_VERSION_HEX < 0x03090000
static PyObject *__Pyx_Object_VectorcallMethod_CallFromBuilder(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames) {
    PyObject *result;
    PyObject *obj = PyObject_GetAttr(args[0], name);
    if (unlikely(!obj))
        return NULL;
    result = __Pyx_Object_Vectorcall_CallFromBuilder(obj, args+1, nargsf-1, kwnames);
    Py_DECREF(obj);
    return result;
}
#endif

/* RaiseException */
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;
}

/* RaiseUnexpectedTypeError */
static int
__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj)
{
    __Pyx_TypeName obj_type_name = __Pyx_PyType_GetFullyQualifiedName(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;
}

/* 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);
}

/* UnpackUnboundCMethod */
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030C0000
static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *args, PyObject *kwargs) {
    PyObject *result;
    PyObject *selfless_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
    if (unlikely(!selfless_args)) return NULL;
    result = PyObject_Call(method, selfless_args, kwargs);
    Py_DECREF(selfless_args);
    return result;
}
#elif CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03090000
static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) {
        return _PyObject_Vectorcall
            (method, args ? args+1 : NULL, nargs ? nargs-1 : 0, kwnames);
}
#else
static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) {
    return
#if PY_VERSION_HEX < 0x03090000
    _PyObject_Vectorcall
#else
    PyObject_Vectorcall
#endif
        (method, args ? args+1 : NULL, nargs ? (size_t) nargs-1 : 0, kwnames);
}
#endif
static PyMethodDef __Pyx_UnboundCMethod_Def = {
     "CythonUnboundCMethod",
     __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_SelflessCall),
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030C0000
     METH_VARARGS | METH_KEYWORDS,
#else
     METH_FASTCALL | METH_KEYWORDS,
#endif
     NULL
};
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method, *result=NULL;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    result = method;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    {
        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 CYTHON_COMPILING_IN_PYPY
#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);
            result = unbound_method;
        }
    }
#if !CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    if (unlikely(target->method)) {
        Py_DECREF(result);
    } else
#endif
    target->method = result;
    return 0;
}

/* CallUnboundCMethod0 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    int was_initialized = __Pyx_CachedCFunction_GetAndSetInitializing(cfunc);
    if (likely(was_initialized == 2 && cfunc->func)) {
        if (likely(cfunc->flag == METH_NOARGS))
            return __Pyx_CallCFunction(cfunc, self, NULL);
        if (likely(cfunc->flag == METH_FASTCALL))
            return __Pyx_CallCFunctionFast(cfunc, self, NULL, 0);
        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
            return __Pyx_CallCFunctionFastWithKeywords(cfunc, self, NULL, 0, NULL);
        if (likely(cfunc->flag == (METH_VARARGS | METH_KEYWORDS)))
            return __Pyx_CallCFunctionWithKeywords(cfunc, self, __pyx_mstate_global->__pyx_empty_tuple, NULL);
        if (cfunc->flag == METH_VARARGS)
            return __Pyx_CallCFunction(cfunc, self, __pyx_mstate_global->__pyx_empty_tuple);
        return __Pyx__CallUnboundCMethod0(cfunc, self);
    }
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    else if (unlikely(was_initialized == 1)) {
        __Pyx_CachedCFunction tmp_cfunc = {
#ifndef __cplusplus
            0
#endif
        };
        tmp_cfunc.type = cfunc->type;
        tmp_cfunc.method_name = cfunc->method_name;
        return __Pyx__CallUnboundCMethod0(&tmp_cfunc, self);
    }
#endif
    PyObject *result = __Pyx__CallUnboundCMethod0(cfunc, self);
    __Pyx_CachedCFunction_SetFinishedInitializing(cfunc);
    return result;
}
#endif
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *result;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
    result = __Pyx_PyObject_CallOneArg(cfunc->method, self);
    return result;
}

/* py_dict_keys */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d) {
    return __Pyx_CallUnboundCMethod0(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_keys, d);
}

/* PyObjectCall2Args */
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args[3] = {NULL, arg1, arg2};
    return __Pyx_PyObject_FastCall(function, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* CallUnboundCMethod1 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
    int was_initialized =  __Pyx_CachedCFunction_GetAndSetInitializing(cfunc);
    if (likely(was_initialized == 2 && cfunc->func)) {
        int flag = cfunc->flag;
        if (flag == METH_O) {
            return __Pyx_CallCFunction(cfunc, self, arg);
        } else if (flag == METH_FASTCALL) {
            return __Pyx_CallCFunctionFast(cfunc, self, &arg, 1);
        } else if (flag == (METH_FASTCALL | METH_KEYWORDS)) {
            return __Pyx_CallCFunctionFastWithKeywords(cfunc, self, &arg, 1, NULL);
        }
    }
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    else if (unlikely(was_initialized == 1)) {
        __Pyx_CachedCFunction tmp_cfunc = {
#ifndef __cplusplus
            0
#endif
        };
        tmp_cfunc.type = cfunc->type;
        tmp_cfunc.method_name = cfunc->method_name;
        return __Pyx__CallUnboundCMethod1(&tmp_cfunc, self, arg);
    }
#endif
    PyObject* result = __Pyx__CallUnboundCMethod1(cfunc, self, arg);
    __Pyx_CachedCFunction_SetFinishedInitializing(cfunc);
    return result;
}
#endif
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
    PyObject *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)) {
        PyObject *args = PyTuple_New(1);
        if (unlikely(!args)) return NULL;
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 0, arg);
        if (cfunc->flag & METH_KEYWORDS)
            result = __Pyx_CallCFunctionWithKeywords(cfunc, self, args, NULL);
        else
            result = __Pyx_CallCFunction(cfunc, self, args);
        Py_DECREF(args);
    } else
#endif
    {
        result = __Pyx_PyObject_Call2Args(cfunc->method, self, arg);
    }
    return result;
}

/* CallUnboundCMethod2 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
    int was_initialized = __Pyx_CachedCFunction_GetAndSetInitializing(cfunc);
    if (likely(was_initialized == 2 && cfunc->func)) {
        PyObject *args[2] = {arg1, arg2};
        if (cfunc->flag == METH_FASTCALL) {
            return __Pyx_CallCFunctionFast(cfunc, self, args, 2);
        }
        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
            return __Pyx_CallCFunctionFastWithKeywords(cfunc, self, args, 2, NULL);
    }
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    else if (unlikely(was_initialized == 1)) {
        __Pyx_CachedCFunction tmp_cfunc = {
#ifndef __cplusplus
            0
#endif
        };
        tmp_cfunc.type = cfunc->type;
        tmp_cfunc.method_name = cfunc->method_name;
        return __Pyx__CallUnboundCMethod2(&tmp_cfunc, self, arg1, arg2);
    }
#endif
    PyObject *result = __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
    __Pyx_CachedCFunction_SetFinishedInitializing(cfunc);
    return result;
}
#endif
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
    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)) {
        PyObject *result = NULL;
        PyObject *args = PyTuple_New(2);
        if (unlikely(!args)) return NULL;
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 0, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 1, arg2);
        if (cfunc->flag & METH_KEYWORDS)
            result = __Pyx_CallCFunctionWithKeywords(cfunc, self, args, NULL);
        else
            result = __Pyx_CallCFunction(cfunc, self, args);
        Py_DECREF(args);
        return result;
    }
#endif
    {
        PyObject *args[4] = {NULL, self, arg1, arg2};
        return __Pyx_PyObject_FastCall(cfunc->method, args+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
    }
}

/* dict_getitem_default */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if !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 (PyBytes_CheckExact(key) || PyUnicode_CheckExact(key) || PyLong_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_mstate_global->__pyx_umethod_PyDict_Type_get, d, key);
        else
            value = __Pyx_CallUnboundCMethod2(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_get, d, key, default_value);
    }
    return value;
}

/* PyObjectCallNoArg */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
    PyObject *arg[2] = {NULL, NULL};
    return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* 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 ((__PYX_LIMITED_VERSION_HEX >= 0x030A0000)
#if CYTHON_COMPILING_IN_LIMITED_API
            || __Pyx_get_runtime_version() >= 0x030A0000
#endif
            )
            return result;
        {
            Py_ssize_t size = __Pyx_PySet_GET_SIZE(result);
            if (likely(size > 0))
                return result;
#if !CYTHON_ASSUME_SAFE_SIZE
            if (unlikely(size < 0)) {
                Py_DECREF(result);
                return NULL;
            }
#endif
        }
        Py_DECREF(result);
#endif
    }
    return __Pyx_PyObject_CallNoArg((PyObject*) &PyFrozenSet_Type);
}

/* 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));
}

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL ||\
        !(CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS)
    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 || CYTHON_COMPILING_IN_GRAAL
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    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 (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length, length2;
        int kind;
        void *data1, *data2;
        #if !CYTHON_COMPILING_IN_LIMITED_API
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        #endif
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        #if !CYTHON_ASSUME_SAFE_SIZE
        if (unlikely(length < 0)) return -1;
        #endif
        length2 = __Pyx_PyUnicode_GET_LENGTH(s2);
        #if !CYTHON_ASSUME_SAFE_SIZE
        if (unlikely(length2 < 0)) return -1;
        #endif
        if (length != length2) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
            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));
            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_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    return (equals == Py_EQ);
return_ne:
    return (equals == Py_NE);
#endif
}

/* py_dict_items */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
    return __Pyx_CallUnboundCMethod0(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_items, 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) {
    PyObject* exc_type;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    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();
}

/* PyUnicode_Unicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj) {
    if (unlikely(obj == Py_None))
        obj = __pyx_mstate_global->__pyx_kp_u_None;
    return __Pyx_NewRef(obj);
}

/* JoinPyUnicode */
static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char) {
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    PyObject *result_uval;
    int result_ukind, kind_shift;
    Py_ssize_t i, char_pos;
    void *result_udata;
    if (max_char > 1114111) max_char = 1114111;
    result_uval = PyUnicode_New(result_ulength, max_char);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
    kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1;
    result_udata = PyUnicode_DATA(result_uval);
    assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0);
    if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - result_ulength < 0))
        goto overflow;
    char_pos = 0;
    for (i=0; i < value_count; i++) {
        int ukind;
        Py_ssize_t ulength;
        void *udata;
        PyObject *uval = values[i];
        #if !CYTHON_COMPILING_IN_LIMITED_API
        if (__Pyx_PyUnicode_READY(uval) == (-1))
            goto bad;
        #endif
        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
        #if !CYTHON_ASSUME_SAFE_SIZE
        if (unlikely(ulength < 0)) goto bad;
        #endif
        if (unlikely(!ulength))
            continue;
        if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos))
            goto overflow;
        ukind = __Pyx_PyUnicode_KIND(uval);
        udata = __Pyx_PyUnicode_DATA(uval);
        if (ukind == result_ukind) {
            memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift));
        } else {
            #if PY_VERSION_HEX >= 0x030d0000
            if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad;
            #elif CYTHON_COMPILING_IN_CPYTHON || defined(_PyUnicode_FastCopyCharacters)
            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
            #else
            Py_ssize_t j;
            for (j=0; j < ulength; j++) {
                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
            }
            #endif
        }
        char_pos += ulength;
    }
    return result_uval;
overflow:
    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
bad:
    Py_DECREF(result_uval);
    return NULL;
#else
    Py_ssize_t i;
    PyObject *result = NULL;
    PyObject *value_tuple = PyTuple_New(value_count);
    if (unlikely(!value_tuple)) return NULL;
    CYTHON_UNUSED_VAR(max_char);
    CYTHON_UNUSED_VAR(result_ulength);
    for (i=0; i<value_count; i++) {
        if (__Pyx_PyTuple_SET_ITEM(value_tuple, i, values[i]) != (0)) goto bad;
        Py_INCREF(values[i]);
    }
    result = PyUnicode_Join(__pyx_mstate_global->__pyx_empty_unicode, value_tuple);
bad:
    Py_DECREF(value_tuple);
    return result;
#endif
}

/* UnicodeAsUCS4 */
static void __Pyx_PyUnicode_AsPy_UCS4_error(Py_ssize_t length) {
    if (likely(length >= 0)) {
        PyErr_Format(PyExc_ValueError,
                     "only single character unicode strings can be converted to Py_UCS4, "
                     "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
    }
}
static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
    Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(x);
    if (unlikely(length != 1)) {
        __Pyx_PyUnicode_AsPy_UCS4_error(length);
        return (Py_UCS4)-1;
    }
    return __Pyx_PyUnicode_READ_CHAR(x, 0);
}

/* object_ord */
static long __Pyx__PyObject_Ord(PyObject* c) {
    Py_ssize_t size;
    if (PyBytes_Check(c)) {
        size = __Pyx_PyBytes_GET_SIZE(c);
        if (likely(size == 1)) {
#if CYTHON_ASSUME_SAFE_MACROS
            return (unsigned char) PyBytes_AS_STRING(c)[0];
#else
            char *data = PyBytes_AsString(c);
            if (unlikely(!data)) return -1;
            return (unsigned char) data[0];
#endif
        }
#if !CYTHON_ASSUME_SAFE_SIZE
        else if (unlikely(size < 0)) return -1;
#endif
    } else if (PyByteArray_Check(c)) {
        size = __Pyx_PyByteArray_GET_SIZE(c);
        if (likely(size == 1)) {
#if CYTHON_ASSUME_SAFE_MACROS
            return (unsigned char) PyByteArray_AS_STRING(c)[0];
#else
            char *data = PyByteArray_AsString(c);
            if (unlikely(!data)) return -1;
            return (unsigned char) data[0];
#endif
        }
#if !CYTHON_ASSUME_SAFE_SIZE
        else if (unlikely(size < 0)) return -1;
#endif
    } else {
        __Pyx_TypeName c_type_name = __Pyx_PyType_GetFullyQualifiedName(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;
}

/* PyLongCompare */
static CYTHON_INLINE int __Pyx_PyLong_BoolNeObjC(PyObject *op1, PyObject *op2, long intval, long inplace) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_UNUSED_VAR(inplace);
    if (op1 == op2) {
        return 0;
    }
    #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;
        double a = __Pyx_PyFloat_AS_DOUBLE(op1);
        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
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
    else state = (PyGILState_STATE)0;
    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(0);
    }
    ctx = PyUnicode_FromString(name);
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
    if (nogil)
        PyGILState_Release(state);
}

/* PyObjectFormatAndDecref */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) {
    if (unlikely(!s)) return NULL;
    if (likely(PyUnicode_CheckExact(s))) return s;
    return __Pyx_PyObject_FormatAndDecref(s, f);
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) {
    PyObject *result;
    if (unlikely(!s)) return NULL;
    result = PyObject_Format(s, f);
    Py_DECREF(s);
    return result;
}

/* RaiseUnboundLocalError */
static void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* CIntToDigits */
static const char DIGIT_PAIRS_10[2*10*10+1] = {
    "00010203040506070809"
    "10111213141516171819"
    "20212223242526272829"
    "30313233343536373839"
    "40414243444546474849"
    "50515253545556575859"
    "60616263646566676869"
    "70717273747576777879"
    "80818283848586878889"
    "90919293949596979899"
};
static const char DIGIT_PAIRS_8[2*8*8+1] = {
    "0001020304050607"
    "1011121314151617"
    "2021222324252627"
    "3031323334353637"
    "4041424344454647"
    "5051525354555657"
    "6061626364656667"
    "7071727374757677"
};
static const char DIGITS_HEX[2*16+1] = {
    "0123456789abcdef"
    "0123456789ABCDEF"
};

/* BuildPyUnicode */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, const char* chars, int clength,
                                                int prepend_sign, char padding_char) {
    PyObject *uval;
    Py_ssize_t uoffset = ulength - clength;
#if CYTHON_USE_UNICODE_INTERNALS
    Py_ssize_t i;
    void *udata;
    uval = PyUnicode_New(ulength, 127);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_DATA(uval);
    if (uoffset > 0) {
        i = 0;
        if (prepend_sign) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
            i++;
        }
        for (; i < uoffset; i++) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
        }
    }
    for (i=0; i < clength; i++) {
        __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
    }
#else
    {
        PyObject *sign = NULL, *padding = NULL;
        uval = NULL;
        if (uoffset > 0) {
            prepend_sign = !!prepend_sign;
            if (uoffset > prepend_sign) {
                padding = PyUnicode_FromOrdinal(padding_char);
                if (likely(padding) && uoffset > prepend_sign + 1) {
                    PyObject *tmp = PySequence_Repeat(padding, uoffset - prepend_sign);
                    Py_DECREF(padding);
                    padding = tmp;
                }
                if (unlikely(!padding)) goto done_or_error;
            }
            if (prepend_sign) {
                sign = PyUnicode_FromOrdinal('-');
                if (unlikely(!sign)) goto done_or_error;
            }
        }
        uval = PyUnicode_DecodeASCII(chars, clength, NULL);
        if (likely(uval) && padding) {
            PyObject *tmp = PyUnicode_Concat(padding, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
        if (likely(uval) && sign) {
            PyObject *tmp = PyUnicode_Concat(sign, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
done_or_error:
        Py_XDECREF(padding);
        Py_XDECREF(sign);
    }
#endif
    return uval;
}

/* COrdinalToPyUnicode */
static CYTHON_INLINE int __Pyx_CheckUnicodeValue(int value) {
    return value <= 1114111;
}
static PyObject* __Pyx_PyUnicode_FromOrdinal_Padded(int value, Py_ssize_t ulength, char padding_char) {
    if (likely(ulength <= 250)) {
        char chars[256];
        if (value <= 255) {
            memset(chars, padding_char, (size_t) (ulength - 1));
            chars[ulength-1] = (char) value;
            return PyUnicode_DecodeLatin1(chars, ulength, NULL);
        }
        char *cpos = chars + sizeof(chars);
        if (value < 0x800) {
            *--cpos = (char) (0x80 | (value & 0x3f));
            value >>= 6;
            *--cpos = (char) (0xc0 | (value & 0x1f));
        } else if (value < 0x10000) {
            *--cpos = (char) (0x80 | (value & 0x3f));
            value >>= 6;
            *--cpos = (char) (0x80 | (value & 0x3f));
            value >>= 6;
            *--cpos = (char) (0xe0 | (value & 0x0f));
        } else {
            *--cpos = (char) (0x80 | (value & 0x3f));
            value >>= 6;
            *--cpos = (char) (0x80 | (value & 0x3f));
            value >>= 6;
            *--cpos = (char) (0x80 | (value & 0x3f));
            value >>= 6;
            *--cpos = (char) (0xf0 | (value & 0x07));
        }
        cpos -= ulength;
        memset(cpos, padding_char, (size_t) (ulength - 1));
        return PyUnicode_DecodeUTF8(cpos, chars + sizeof(chars) - cpos, NULL);
    }
    if (value <= 127 && CYTHON_USE_UNICODE_INTERNALS) {
        const char chars[1] = {(char) value};
        return __Pyx_PyUnicode_BuildFromAscii(ulength, chars, 1, 0, padding_char);
    }
    {
        PyObject *uchar, *padding_uchar, *padding, *result;
        padding_uchar = PyUnicode_FromOrdinal(padding_char);
        if (unlikely(!padding_uchar)) return NULL;
        padding = PySequence_Repeat(padding_uchar, ulength - 1);
        Py_DECREF(padding_uchar);
        if (unlikely(!padding)) return NULL;
        uchar = PyUnicode_FromOrdinal(value);
        if (unlikely(!uchar)) {
            Py_DECREF(padding);
            return NULL;
        }
        result = PyUnicode_Concat(padding, uchar);
        Py_DECREF(padding);
        Py_DECREF(uchar);
        return result;
    }
}

/* CIntToPyUnicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char) {
    char digits[sizeof(long)*3+2];
    char *dpos, *end = digits + sizeof(long)*3+2;
    const char *hex_digits = DIGITS_HEX;
    Py_ssize_t length, ulength;
    int prepend_sign, last_one_off;
    long remaining;
#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 (format_char == 'c') {
        if (unlikely(!(is_unsigned || value == 0 || value > 0) ||
                     !(sizeof(value) <= 2 || value & ~ (long) 0x01fffff || __Pyx_CheckUnicodeValue((int) value)))) {
            PyErr_SetString(PyExc_OverflowError, "%c arg not in range(0x110000)");
            return NULL;
        }
        if (width <= 1) {
            return PyUnicode_FromOrdinal((int) value);
        }
        return __Pyx_PyUnicode_FromOrdinal_Padded((int) value, width, padding_char);
    }
    if (format_char == 'X') {
        hex_digits += 16;
        format_char = 'x';
    }
    remaining = value;
    last_one_off = 0;
    dpos = end;
    do {
        int digit_pos;
        switch (format_char) {
        case 'o':
            digit_pos = abs((int)(remaining % (8*8)));
            remaining = (long) (remaining / (8*8));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 8);
            break;
        case 'd':
            digit_pos = abs((int)(remaining % (10*10)));
            remaining = (long) (remaining / (10*10));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 10);
            break;
        case 'x':
            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
            remaining = (long) (remaining / 16);
            break;
        default:
            assert(0);
            break;
        }
    } while (unlikely(remaining != 0));
    assert(!last_one_off || *dpos == '0');
    dpos += last_one_off;
    length = end - dpos;
    ulength = length;
    prepend_sign = 0;
    if (!is_unsigned && value <= neg_one) {
        if (padding_char == ' ' || width <= length + 1) {
            *(--dpos) = '-';
            ++length;
        } else {
            prepend_sign = 1;
        }
        ++ulength;
    }
    if (width > ulength) {
        ulength = width;
    }
    if (ulength == 1) {
        return PyUnicode_FromOrdinal(*dpos);
    }
    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
}

/* HasAttr */
#if __PYX_LIMITED_VERSION_HEX < 0x030d0000
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!PyUnicode_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_PyObject_GetAttrStrNoError(o, n);
    if (!r) {
        return (unlikely(PyErr_Occurred())) ? -1 : 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}
#endif

/* 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 >= 0x030C0000
    local_value = tstate->current_exception;
    tstate->current_exception = 0;
  #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
#elif __PYX_LIMITED_VERSION_HEX > 0x030C0000
    local_value = PyErr_GetRaisedException();
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
#if __PYX_LIMITED_VERSION_HEX > 0x030C0000
    if (likely(local_value)) {
        local_type = (PyObject*) Py_TYPE(local_value);
        Py_INCREF(local_type);
        local_tb = PyException_GetTraceback(local_value);
    }
#else
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
#endif // __PYX_LIMITED_VERSION_HEX > 0x030C0000
    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);
#elif __PYX_LIMITED_VERSION_HEX >= 0x030b0000
    PyErr_SetHandledException(local_value);
    Py_XDECREF(local_value);
    Py_XDECREF(local_type);
    Py_XDECREF(local_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
#if __PYX_LIMITED_VERSION_HEX <= 0x030C0000
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
#endif
}

/* 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_GetFullyQualifiedName(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_mstate_global->__pyx_n_u_class_getitem);
        if (!meth) {
            PyErr_Clear();
        } else {
            PyObject *result = __Pyx_PyObject_CallOneArg(meth, key);
            Py_DECREF(meth);
            return result;
        }
    }
    obj_type_name = __Pyx_PyType_GetFullyQualifiedName(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

/* PyLongBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_Fallback___Pyx_PyLong_AddObjC(PyObject *op1, PyObject *op2, int inplace) {
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#if CYTHON_USE_PYLONG_INTERNALS
static PyObject* __Pyx_Unpacked___Pyx_PyLong_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
    CYTHON_MAYBE_UNUSED_VAR(inplace);
    CYTHON_UNUSED_VAR(zerodivision_check);
    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
    return __Pyx_Fallback___Pyx_PyLong_AddObjC(op1, op2, inplace);
    
    
}
#endif
static PyObject* __Pyx_Float___Pyx_PyLong_AddObjC(PyObject *float_val, long intval, int zerodivision_check) {
    CYTHON_UNUSED_VAR(zerodivision_check);
    const long b = intval;
    double a = __Pyx_PyFloat_AS_DOUBLE(float_val);
        double result;
        
        result = ((double)a) + (double)b;
        return PyFloat_FromDouble(result);
}
static CYTHON_INLINE PyObject* __Pyx_PyLong_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_UNUSED_VAR(zerodivision_check);
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        return __Pyx_Unpacked___Pyx_PyLong_AddObjC(op1, op2, intval, inplace, zerodivision_check);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        return __Pyx_Float___Pyx_PyLong_AddObjC(op1, intval, zerodivision_check);
    }
    return __Pyx_Fallback___Pyx_PyLong_AddObjC(op1, op2, inplace);
}
#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_1_2
#define __PYX_HAVE_RT_ImportType_3_1_2
static PyTypeObject *__Pyx_ImportType_3_1_2(PyObject *module, const char *module_name, const char *class_name,
    size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_1_2 check_size)
{
    PyObject *result = 0;
    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
    if (size == 0) {
        return (PyTypeObject *)result;
    }
    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_1_2 &&
            ((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_1_2 && (size_t)basicsize > size) {
        if (PyErr_WarnFormat(NULL, 0,
                "%.200s.%.200s size changed, may indicate binary incompatibility. "
                "Expected %zd from C header, got %zd from PyObject",
                module_name, class_name, size, basicsize) < 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;
    empty_dict = PyDict_New();
    if (unlikely(!empty_dict))
        goto bad;
    if (level == -1) {
        const char* package_sep = strchr(__Pyx_MODULE_NAME, '.');
        if (package_sep != (0)) {
            module = PyImport_ImportModuleLevelObject(
                name, __pyx_mstate_global->__pyx_d, empty_dict, from_list, 1);
            if (unlikely(!module)) {
                if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
                    goto bad;
                PyErr_Clear();
            }
        }
        level = 0;
    }
    if (!module) {
        module = PyImport_ImportModuleLevelObject(
            name, __pyx_mstate_global->__pyx_d, empty_dict, from_list, level);
    }
bad:
    Py_XDECREF(empty_dict);
    Py_XDECREF(empty_list);
    return module;
}

/* ImportDottedModule */
static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) {
    PyObject *partial_name = NULL, *slice = NULL, *sep = NULL;
    Py_ssize_t size;
    if (unlikely(PyErr_Occurred())) {
        PyErr_Clear();
    }
#if CYTHON_ASSUME_SAFE_SIZE
    size = PyTuple_GET_SIZE(parts_tuple);
#else
    size = PyTuple_Size(parts_tuple);
    if (size < 0) goto bad;
#endif
    if (likely(size == 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(
        PyExc_ModuleNotFoundError,
        "No module named '%U'", partial_name);
bad:
    Py_XDECREF(sep);
    Py_XDECREF(slice);
    Py_XDECREF(partial_name);
    return NULL;
}
static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) {
    PyObject *imported_module;
#if (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM  < 0x07030400) ||\
        CYTHON_COMPILING_IN_GRAAL
    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;
}
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) {
    Py_ssize_t i, nparts;
#if CYTHON_ASSUME_SAFE_SIZE
    nparts = PyTuple_GET_SIZE(parts_tuple);
#else
    nparts = PyTuple_Size(parts_tuple);
    if (nparts < 0) return NULL;
#endif
    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 = __Pyx_PySequence_ITEM(parts_tuple, i);
        if (!part) return NULL;
#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;
}
static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
    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);
}
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *module = __Pyx__ImportDottedModule_Lookup(name);
    if (likely(module)) {
        PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_mstate_global->__pyx_n_u_spec);
        if (likely(spec)) {
            PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_mstate_global->__pyx_n_u_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;
    module = __Pyx_Import(name, from_list, -1);
    Py_XDECREF(from_list);
    if (module) {
        if (parts_tuple) {
            module = __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple);
        }
        return module;
    }
    if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
        return NULL;
    PyErr_Clear();
    return __Pyx_ImportDottedModule(name, parts_tuple);
}

/* ListPack */
static PyObject *__Pyx_PyList_Pack(Py_ssize_t n, ...) {
    va_list va;
    PyObject *l = PyList_New(n);
    va_start(va, n);
    if (unlikely(!l)) goto end;
    for (Py_ssize_t i=0; i<n; ++i) {
        PyObject *arg = va_arg(va, PyObject*);
        Py_INCREF(arg);
        if (__Pyx_PyList_SET_ITEM(l, i, arg) != (0)) {
            Py_CLEAR(l);
            goto end;
        }
    }
    end:
    va_end(va);
    return l;
}

/* 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_mstate_global->__pyx_kp_u__3);
        if (unlikely(!module_dot)) { goto modbad; }
        full_name = PyUnicode_Concat(module_dot, name);
        if (unlikely(!full_name)) { goto modbad; }
        #if (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM  < 0x07030400) ||\
                CYTHON_COMPILING_IN_GRAAL
        {
            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, "cannot import name %S", name);
    }
    return value;
}

/* CLineInTraceback */
#if CYTHON_CLINE_IN_TRACEBACK && CYTHON_CLINE_IN_TRACEBACK_RUNTIME
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_mstate_global->__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_mstate_global->__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __Pyx_BEGIN_CRITICAL_SECTION(*cython_runtime_dict);
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_mstate_global->__pyx_n_u_cline_in_traceback))
        Py_XINCREF(use_cline);
        __Pyx_END_CRITICAL_SECTION();
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_mstate_global->__pyx_cython_runtime, __pyx_mstate_global->__pyx_n_u_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_INCREF(use_cline);
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_mstate_global->__pyx_cython_runtime, __pyx_mstate_global->__pyx_n_u_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    Py_XDECREF(use_cline);
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
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 __Pyx_CachedCodeObjectType *__pyx__find_code_object(struct __Pyx_CodeObjectCache *code_cache, int code_line) {
    __Pyx_CachedCodeObjectType* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!code_cache->entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(code_cache->entries, code_cache->count, code_line);
    if (unlikely(pos >= code_cache->count) || unlikely(code_cache->entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = code_cache->entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static __Pyx_CachedCodeObjectType *__pyx_find_code_object(int code_line) {
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && !CYTHON_ATOMICS
    (void)__pyx__find_code_object;
    return NULL; // Most implementation should have atomics. But otherwise, don't make it thread-safe, just miss.
#else
    struct __Pyx_CodeObjectCache *code_cache = &__pyx_mstate_global->__pyx_code_cache;
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    __pyx_nonatomic_int_type old_count = __pyx_atomic_incr_acq_rel(&code_cache->accessor_count);
    if (old_count < 0) {
        __pyx_atomic_decr_acq_rel(&code_cache->accessor_count);
        return NULL;
    }
#endif
    __Pyx_CachedCodeObjectType *result = __pyx__find_code_object(code_cache, code_line);
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    __pyx_atomic_decr_acq_rel(&code_cache->accessor_count);
#endif
    return result;
#endif
}
static void __pyx__insert_code_object(struct __Pyx_CodeObjectCache *code_cache, int code_line, __Pyx_CachedCodeObjectType* code_object)
{
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = code_cache->entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            code_cache->entries = entries;
            code_cache->max_count = 64;
            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(code_cache->entries, code_cache->count, code_line);
    if ((pos < code_cache->count) && unlikely(code_cache->entries[pos].code_line == code_line)) {
        __Pyx_CachedCodeObjectType* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_INCREF(code_object);
        Py_DECREF(tmp);
        return;
    }
    if (code_cache->count == code_cache->max_count) {
        int new_max = code_cache->max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            code_cache->entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        code_cache->entries = entries;
        code_cache->max_count = new_max;
    }
    for (i=code_cache->count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    code_cache->count++;
    Py_INCREF(code_object);
}
static void __pyx_insert_code_object(int code_line, __Pyx_CachedCodeObjectType* code_object) {
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && !CYTHON_ATOMICS
    (void)__pyx__insert_code_object;
    return; // Most implementation should have atomics. But otherwise, don't make it thread-safe, just fail.
#else
    struct __Pyx_CodeObjectCache *code_cache = &__pyx_mstate_global->__pyx_code_cache;
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    __pyx_nonatomic_int_type expected = 0;
    if (!__pyx_atomic_int_cmp_exchange(&code_cache->accessor_count, &expected, INT_MIN)) {
        return;
    }
#endif
    __pyx__insert_code_object(code_cache, code_line, code_object);
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
    __pyx_atomic_sub(&code_cache->accessor_count, INT_MIN);
#endif
#endif
}

/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API && !defined(PYPY_VERSION)
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict,
                                                       PyObject *firstlineno, PyObject *name) {
    PyObject *replace = NULL;
    if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL;
    if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL;
    replace = PyObject_GetAttrString(code, "replace");
    if (likely(replace)) {
        PyObject *result = PyObject_Call(replace, __pyx_mstate_global->__pyx_empty_tuple, scratch_dict);
        Py_DECREF(replace);
        return result;
    }
    PyErr_Clear();
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL;
    PyObject *replace = NULL, *getframe = NULL, *frame = NULL;
    PyObject *exc_type, *exc_value, *exc_traceback;
    int success = 0;
    if (c_line) {
        (void) __pyx_cfilenm;
        (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line);
    }
    PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
    code_object = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!code_object) {
        code_object = Py_CompileString("_getframe()", filename, Py_eval_input);
        if (unlikely(!code_object)) goto bad;
        py_py_line = PyLong_FromLong(py_line);
        if (unlikely(!py_py_line)) goto bad;
        py_funcname = PyUnicode_FromString(funcname);
        if (unlikely(!py_funcname)) goto bad;
        dict = PyDict_New();
        if (unlikely(!dict)) goto bad;
        {
            PyObject *old_code_object = code_object;
            code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname);
            Py_DECREF(old_code_object);
        }
        if (unlikely(!code_object)) goto bad;
        __pyx_insert_code_object(c_line ? -c_line : py_line, code_object);
    } else {
        dict = PyDict_New();
    }
    getframe = PySys_GetObject("_getframe");
    if (unlikely(!getframe)) goto bad;
    if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad;
    frame = PyEval_EvalCode(code_object, dict, dict);
    if (unlikely(!frame) || frame == Py_None) goto bad;
    success = 1;
  bad:
    PyErr_Restore(exc_type, exc_value, exc_traceback);
    Py_XDECREF(code_object);
    Py_XDECREF(py_py_line);
    Py_XDECREF(py_funcname);
    Py_XDECREF(dict);
    Py_XDECREF(replace);
    if (success) {
        PyTraceBack_Here(
            (struct _frame*)frame);
    }
    Py_XDECREF(frame);
}
#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 (c_line) {
        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;
    }
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    Py_XDECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    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_mstate_global->__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_PyLong_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 PyLong_FromLong((long) value);
        } else if (sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY
        } 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 PyLong_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
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL, *kwds = NULL;
        PyObject *py_bytes = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        {
            PyObject *args[3+(CYTHON_VECTORCALL ? 1 : 0)] = { NULL, py_bytes, order_str };
            if (!is_unsigned) {
                kwds = __Pyx_MakeVectorcallBuilderKwds(1);
                if (!kwds) goto limited_bad;
                if (__Pyx_VectorcallBuilder_AddArgStr("signed", __Pyx_NewRef(Py_True), kwds, args+3, 0) < 0) goto limited_bad;
            }
            result = __Pyx_Object_Vectorcall_CallFromBuilder(from_bytes, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
        }
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyLong_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 PyLong_FromLong((long) value);
        } else if (sizeof(readstat_type_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY
        } 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 PyLong_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
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(readstat_type_t),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL, *kwds = NULL;
        PyObject *py_bytes = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(readstat_type_t));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        {
            PyObject *args[3+(CYTHON_VECTORCALL ? 1 : 0)] = { NULL, py_bytes, order_str };
            if (!is_unsigned) {
                kwds = __Pyx_MakeVectorcallBuilderKwds(1);
                if (!kwds) goto limited_bad;
                if (__Pyx_VectorcallBuilder_AddArgStr("signed", __Pyx_NewRef(Py_True), kwds, args+3, 0) < 0) goto limited_bad;
            }
            result = __Pyx_Object_Vectorcall_CallFromBuilder(from_bytes, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
        }
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyLong_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 PyLong_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY
        } 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 PyLong_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL, *kwds = NULL;
        PyObject *py_bytes = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        {
            PyObject *args[3+(CYTHON_VECTORCALL ? 1 : 0)] = { NULL, py_bytes, order_str };
            if (!is_unsigned) {
                kwds = __Pyx_MakeVectorcallBuilderKwds(1);
                if (!kwds) goto limited_bad;
                if (__Pyx_VectorcallBuilder_AddArgStr("signed", __Pyx_NewRef(Py_True), kwds, args+3, 0) < 0) goto limited_bad;
            }
            result = __Pyx_Object_Vectorcall_CallFromBuilder(from_bytes, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
        }
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyLong_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 (unlikely(!PyLong_Check(x))) {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Long(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyLong_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
    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;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(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 *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (int) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (int) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (int) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        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;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((int) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long 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 (!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
        if (unlikely(ret))
            return (int) -1;
        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;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyLong_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 PyLong_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY
        } 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 PyLong_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL, *kwds = NULL;
        PyObject *py_bytes = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(int));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        {
            PyObject *args[3+(CYTHON_VECTORCALL ? 1 : 0)] = { NULL, py_bytes, order_str };
            if (!is_unsigned) {
                kwds = __Pyx_MakeVectorcallBuilderKwds(1);
                if (!kwds) goto limited_bad;
                if (__Pyx_VectorcallBuilder_AddArgStr("signed", __Pyx_NewRef(Py_True), kwds, args+3, 0) < 0) goto limited_bad;
            }
            result = __Pyx_Object_Vectorcall_CallFromBuilder(from_bytes, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
        }
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE readstat_type_t __Pyx_PyLong_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 (unlikely(!PyLong_Check(x))) {
        readstat_type_t val;
        PyObject *tmp = __Pyx_PyNumber_Long(x);
        if (!tmp) return (readstat_type_t) -1;
        val = __Pyx_PyLong_As_readstat_type_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
    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
        }
    }
    {
        readstat_type_t val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(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 *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyErr_SetString(PyExc_RuntimeError,
                        "_PyLong_AsByteArray() or PyLong_AsNativeBytes() not available, cannot convert large enums");
        val = (readstat_type_t) -1;
#endif
        if (unlikely(ret))
            return (readstat_type_t) -1;
        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_PyLong_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 (unlikely(!PyLong_Check(x))) {
        int32_t val;
        PyObject *tmp = __Pyx_PyNumber_Long(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyLong_As_int32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
    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;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(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 *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (int32_t) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (int32_t) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (int32_t) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        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;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((int32_t) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long 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 (!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
        if (unlikely(ret))
            return (int32_t) -1;
        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 __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type __Pyx_PyLong_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 (unlikely(!PyLong_Check(x))) {
        __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type val;
        PyObject *tmp = __Pyx_PyNumber_Long(x);
        if (!tmp) return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
        val = __Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type(tmp);
        Py_DECREF(tmp);
        return val;
    }
    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
        }
    }
    {
        __pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(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 *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyErr_SetString(PyExc_RuntimeError,
                        "_PyLong_AsByteArray() or PyLong_AsNativeBytes() not available, cannot convert large enums");
        val = (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
#endif
        if (unlikely(ret))
            return (__pyx_t_10pyreadstat_16_readstat_writer_pywriter_variable_type) -1;
        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 && __PYX_LIMITED_VERSION_HEX < 0x030d0000
static __Pyx_TypeName
__Pyx_PyType_GetFullyQualifiedName(PyTypeObject* tp)
{
    PyObject *module = NULL, *name = NULL, *result = NULL;
    #if __PYX_LIMITED_VERSION_HEX < 0x030b0000
    name = __Pyx_PyObject_GetAttrStr((PyObject *)tp,
                                               __pyx_mstate_global->__pyx_n_u_qualname);
    #else
    name = PyType_GetQualName(tp);
    #endif
    if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) goto bad;
    module = __Pyx_PyObject_GetAttrStr((PyObject *)tp,
                                               __pyx_mstate_global->__pyx_n_u_module);
    if (unlikely(module == NULL) || unlikely(!PyUnicode_Check(module))) goto bad;
    if (PyUnicode_CompareWithASCIIString(module, "builtins") == 0) {
        result = name;
        name = NULL;
        goto done;
    }
    result = PyUnicode_FromFormat("%U.%U", module, name);
    if (unlikely(result == NULL)) goto bad;
  done:
    Py_XDECREF(name);
    Py_XDECREF(module);
    return result;
  bad:
    PyErr_Clear();
    if (name) {
        result = name;
        name = NULL;
    } else {
        result = __Pyx_NewRef(__pyx_mstate_global->__pyx_kp_u__5);
    }
    goto done;
}
#endif

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyLong_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 (unlikely(!PyLong_Check(x))) {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Long(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyLong_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
    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;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(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 *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (long) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (long) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (long) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        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;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((long) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long 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 (!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
        if (unlikely(ret))
            return (long) -1;
        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);
}
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);
    }
}
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);
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        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

/* GetRuntimeVersion */
static unsigned long __Pyx_get_runtime_version(void) {
#if __PYX_LIMITED_VERSION_HEX >= 0x030b0000
    return Py_Version & ~0xFFUL;
#else
    static unsigned long __Pyx_cached_runtime_version = 0;
    if (__Pyx_cached_runtime_version == 0) {
        const char* rt_version = Py_GetVersion();
        unsigned long version = 0;
        unsigned long factor = 0x01000000UL;
        unsigned int digit = 0;
        int i = 0;
        while (factor) {
            while ('0' <= rt_version[i] && rt_version[i] <= '9') {
                digit = digit * 10 + (unsigned int) (rt_version[i] - '0');
                ++i;
            }
            version += factor * digit;
            if (rt_version[i] != '.')
                break;
            digit = 0;
            factor >>= 8;
            ++i;
        }
        __Pyx_cached_runtime_version = version;
    }
    return __Pyx_cached_runtime_version;
#endif
}

/* CheckBinaryVersion */
static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) {
    const unsigned long MAJOR_MINOR = 0xFFFF0000UL;
    if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR))
        return 0;
    if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR)))
        return 1;
    {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compile time Python version %d.%d "
                      "of module '%.100s' "
                      "%s "
                      "runtime version %d.%d",
                       (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF),
                       __Pyx_MODULE_NAME,
                       (allow_newer) ? "was newer than" : "does not match",
                       (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF)
       );
        return PyErr_WarnEx(NULL, message, 1);
    }
}

/* 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, "__pyx_capi__");
    if (!d) {
        PyErr_Clear();
        d = PyDict_New();
        if (!d)
            goto bad;
        Py_INCREF(d);
        if (PyModule_AddObject(__pyx_m, "__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_1_2
#define __PYX_HAVE_RT_ImportVoidPtr_3_1_2
static int __Pyx_ImportVoidPtr_3_1_2(PyObject *module, const char *name, void **p, const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    d = PyObject_GetAttrString(module, "__pyx_capi__");
    if (!d)
        goto bad;
#if (defined(Py_LIMITED_API) && Py_LIMITED_API >= 0x030d0000) || (!defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030d0000)
    PyDict_GetItemStringRef(d, name, &cobj);
#else
    cobj = PyDict_GetItemString(d, name);
    Py_XINCREF(cobj);
#endif
    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);
    Py_DECREF(cobj);
    return 0;
bad:
    Py_XDECREF(d);
    Py_XDECREF(cobj);
    return -1;
}
#endif

/* FunctionImport */
#ifndef __PYX_HAVE_RT_ImportFunction_3_1_2
#define __PYX_HAVE_RT_ImportFunction_3_1_2
static int __Pyx_ImportFunction_3_1_2(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, "__pyx_capi__");
    if (!d)
        goto bad;
#if (defined(Py_LIMITED_API) && Py_LIMITED_API >= 0x030d0000) || (!defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030d0000)
    PyDict_GetItemStringRef(d, funcname, &cobj);
#else
    cobj = PyDict_GetItemString(d, funcname);
    Py_XINCREF(cobj);
#endif
    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);
    Py_DECREF(cobj);
    return 0;
bad:
    Py_XDECREF(d);
    Py_XDECREF(cobj);
    return -1;
}
#endif

/* InitStrings */
static int __Pyx_InitStrings(__Pyx_StringTabEntry const *t, PyObject **target, const char* const* encoding_names) {
    while (t->s) {
        PyObject *str;
        if (t->is_unicode) {
            if (t->intern) {
                str = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                str = PyUnicode_Decode(t->s, t->n - 1, encoding_names[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;
        *target = str;
        if (PyObject_Hash(str) == -1)
            return -1;
        ++t;
        ++target;
    }
    return 0;
}

#include <string.h>
static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) {
    size_t len = strlen(s);
    if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) {
        PyErr_SetString(PyExc_OverflowError, "byte string is too long");
        return -1;
    }
    return (Py_ssize_t) len;
}
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    Py_ssize_t len = __Pyx_ssize_strlen(c_str);
    if (unlikely(len < 0)) return NULL;
    return __Pyx_PyUnicode_FromStringAndSize(c_str, len);
}
static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) {
    Py_ssize_t len = __Pyx_ssize_strlen(c_str);
    if (unlikely(len < 0)) return NULL;
    return PyByteArray_FromStringAndSize(c_str, len);
}
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_UTF8
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if CYTHON_COMPILING_IN_LIMITED_API
    {
        const char* result;
        Py_ssize_t unicode_length;
        CYTHON_MAYBE_UNUSED_VAR(unicode_length); // only for __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        #if __PYX_LIMITED_VERSION_HEX < 0x030A0000
        if (unlikely(PyArg_Parse(o, "s#", &result, length) < 0)) return NULL;
        #else
        result = PyUnicode_AsUTF8AndSize(o, length);
        #endif
        #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        unicode_length = PyUnicode_GetLength(o);
        if (unlikely(unicode_length < 0)) return NULL;
        if (unlikely(unicode_length != *length)) {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
        #endif
        return result;
    }
#else
#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_UTF8
    if (PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
    if (PyByteArray_Check(o)) {
#if (CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS) || (CYTHON_COMPILING_IN_PYPY && (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)))
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
#else
        *length = PyByteArray_Size(o);
        if (*length == -1) return NULL;
        return PyByteArray_AsString(o);
#endif
    } else
    {
        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_LongWrongResultType(PyObject* result) {
    __Pyx_TypeName result_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(result));
    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;
    }
    PyErr_Format(PyExc_TypeError,
                 "__int__ returned non-int (type " __Pyx_FMT_TYPENAME ")",
                 result_type_name);
    __Pyx_DECREF_TypeName(result_type_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Long(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  PyObject *res = NULL;
  if (likely(PyLong_Check(x)))
      return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  if (likely(m && m->nb_int)) {
      res = m->nb_int(x);
  }
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
      res = PyNumber_Long(x);
  }
#endif
  if (likely(res)) {
      if (unlikely(!PyLong_CheckExact(res))) {
          return __Pyx_PyNumber_LongWrongResultType(res);
      }
  }
  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 (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 = PyLong_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);
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyLong_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject *__Pyx_Owned_Py_None(int b) {
    CYTHON_UNUSED_VAR(b);
    return __Pyx_NewRef(Py_None);
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyLong_FromSize_t(size_t ival) {
    return PyLong_FromSize_t(ival);
}


/* MultiPhaseInitModuleState */
#if CYTHON_PEP489_MULTI_PHASE_INIT && CYTHON_USE_MODULE_STATE
#ifndef CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
#if (CYTHON_COMPILING_IN_LIMITED_API || PY_VERSION_HEX >= 0x030C0000)
  #define CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE 1
#else
  #define CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE 0
#endif
#endif
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE && !CYTHON_ATOMICS
#error "Module state with PEP489 requires atomics. Currently that's one of\
 C11, C++11, gcc atomic intrinsics or MSVC atomic intrinsics"
#endif
#if !CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
#define __Pyx_ModuleStateLookup_Lock()
#define __Pyx_ModuleStateLookup_Unlock()
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d0000
static PyMutex __Pyx_ModuleStateLookup_mutex = {0};
#define __Pyx_ModuleStateLookup_Lock() PyMutex_Lock(&__Pyx_ModuleStateLookup_mutex)
#define __Pyx_ModuleStateLookup_Unlock() PyMutex_Unlock(&__Pyx_ModuleStateLookup_mutex)
#elif defined(__cplusplus) && __cplusplus >= 201103L
#include <mutex>
static std::mutex __Pyx_ModuleStateLookup_mutex;
#define __Pyx_ModuleStateLookup_Lock() __Pyx_ModuleStateLookup_mutex.lock()
#define __Pyx_ModuleStateLookup_Unlock() __Pyx_ModuleStateLookup_mutex.unlock()
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201112L) && !defined(__STDC_NO_THREADS__)
#include <threads.h>
static mtx_t __Pyx_ModuleStateLookup_mutex;
static once_flag __Pyx_ModuleStateLookup_mutex_once_flag = ONCE_FLAG_INIT;
static void __Pyx_ModuleStateLookup_initialize_mutex(void) {
    mtx_init(&__Pyx_ModuleStateLookup_mutex, mtx_plain);
}
#define __Pyx_ModuleStateLookup_Lock()\
  call_once(&__Pyx_ModuleStateLookup_mutex_once_flag, __Pyx_ModuleStateLookup_initialize_mutex);\
  mtx_lock(&__Pyx_ModuleStateLookup_mutex)
#define __Pyx_ModuleStateLookup_Unlock() mtx_unlock(&__Pyx_ModuleStateLookup_mutex)
#elif defined(HAVE_PTHREAD_H)
#include <pthread.h>
static pthread_mutex_t __Pyx_ModuleStateLookup_mutex = PTHREAD_MUTEX_INITIALIZER;
#define __Pyx_ModuleStateLookup_Lock() pthread_mutex_lock(&__Pyx_ModuleStateLookup_mutex)
#define __Pyx_ModuleStateLookup_Unlock() pthread_mutex_unlock(&__Pyx_ModuleStateLookup_mutex)
#elif defined(_WIN32)
#include <Windows.h>  // synchapi.h on its own doesn't work
static SRWLOCK __Pyx_ModuleStateLookup_mutex = SRWLOCK_INIT;
#define __Pyx_ModuleStateLookup_Lock() AcquireSRWLockExclusive(&__Pyx_ModuleStateLookup_mutex)
#define __Pyx_ModuleStateLookup_Unlock() ReleaseSRWLockExclusive(&__Pyx_ModuleStateLookup_mutex)
#else
#error "No suitable lock available for CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE.\
 Requires C standard >= C11, or C++ standard >= C++11,\
 or pthreads, or the Windows 32 API, or Python >= 3.13."
#endif
typedef struct {
    int64_t id;
    PyObject *module;
} __Pyx_InterpreterIdAndModule;
typedef struct {
    char interpreter_id_as_index;
    Py_ssize_t count;
    Py_ssize_t allocated;
    __Pyx_InterpreterIdAndModule table[1];
} __Pyx_ModuleStateLookupData;
#define __PYX_MODULE_STATE_LOOKUP_SMALL_SIZE 32
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
static __pyx_atomic_int_type __Pyx_ModuleStateLookup_read_counter = 0;
#endif
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
static __pyx_atomic_ptr_type __Pyx_ModuleStateLookup_data = 0;
#else
static __Pyx_ModuleStateLookupData* __Pyx_ModuleStateLookup_data = NULL;
#endif
static __Pyx_InterpreterIdAndModule* __Pyx_State_FindModuleStateLookupTableLowerBound(
        __Pyx_InterpreterIdAndModule* table,
        Py_ssize_t count,
        int64_t interpreterId) {
    __Pyx_InterpreterIdAndModule* begin = table;
    __Pyx_InterpreterIdAndModule* end = begin + count;
    if (begin->id == interpreterId) {
        return begin;
    }
    while ((end - begin) > __PYX_MODULE_STATE_LOOKUP_SMALL_SIZE) {
        __Pyx_InterpreterIdAndModule* halfway = begin + (end - begin)/2;
        if (halfway->id == interpreterId) {
            return halfway;
        }
        if (halfway->id < interpreterId) {
            begin = halfway;
        } else {
            end = halfway;
        }
    }
    for (; begin < end; ++begin) {
        if (begin->id >= interpreterId) return begin;
    }
    return begin;
}
static PyObject *__Pyx_State_FindModule(CYTHON_UNUSED void* dummy) {
    int64_t interpreter_id = PyInterpreterState_GetID(__Pyx_PyInterpreterState_Get());
    if (interpreter_id == -1) return NULL;
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
    __Pyx_ModuleStateLookupData* data = (__Pyx_ModuleStateLookupData*)__pyx_atomic_pointer_load_relaxed(&__Pyx_ModuleStateLookup_data);
    {
        __pyx_atomic_incr_acq_rel(&__Pyx_ModuleStateLookup_read_counter);
        if (likely(data)) {
            __Pyx_ModuleStateLookupData* new_data = (__Pyx_ModuleStateLookupData*)__pyx_atomic_pointer_load_acquire(&__Pyx_ModuleStateLookup_data);
            if (likely(data == new_data)) {
                goto read_finished;
            }
        }
        __pyx_atomic_decr_acq_rel(&__Pyx_ModuleStateLookup_read_counter);
        __Pyx_ModuleStateLookup_Lock();
        __pyx_atomic_incr_relaxed(&__Pyx_ModuleStateLookup_read_counter);
        data = (__Pyx_ModuleStateLookupData*)__pyx_atomic_pointer_load_relaxed(&__Pyx_ModuleStateLookup_data);
        __Pyx_ModuleStateLookup_Unlock();
    }
  read_finished:;
#else
    __Pyx_ModuleStateLookupData* data = __Pyx_ModuleStateLookup_data;
#endif
    __Pyx_InterpreterIdAndModule* found = NULL;
    if (unlikely(!data)) goto end;
    if (data->interpreter_id_as_index) {
        if (interpreter_id < data->count) {
            found = data->table+interpreter_id;
        }
    } else {
        found = __Pyx_State_FindModuleStateLookupTableLowerBound(
            data->table, data->count, interpreter_id);
    }
  end:
    {
        PyObject *result=NULL;
        if (found && found->id == interpreter_id) {
            result = found->module;
        }
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
        __pyx_atomic_decr_acq_rel(&__Pyx_ModuleStateLookup_read_counter);
#endif
        return result;
    }
}
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
static void __Pyx_ModuleStateLookup_wait_until_no_readers(void) {
    while (__pyx_atomic_load(&__Pyx_ModuleStateLookup_read_counter) != 0);
}
#else
#define __Pyx_ModuleStateLookup_wait_until_no_readers()
#endif
static int __Pyx_State_AddModuleInterpIdAsIndex(__Pyx_ModuleStateLookupData **old_data, PyObject* module, int64_t interpreter_id) {
    Py_ssize_t to_allocate = (*old_data)->allocated;
    while (to_allocate <= interpreter_id) {
        if (to_allocate == 0) to_allocate = 1;
        else to_allocate *= 2;
    }
    __Pyx_ModuleStateLookupData *new_data = *old_data;
    if (to_allocate != (*old_data)->allocated) {
         new_data = (__Pyx_ModuleStateLookupData *)realloc(
            *old_data,
            sizeof(__Pyx_ModuleStateLookupData)+(to_allocate-1)*sizeof(__Pyx_InterpreterIdAndModule));
        if (!new_data) {
            PyErr_NoMemory();
            return -1;
        }
        for (Py_ssize_t i = new_data->allocated; i < to_allocate; ++i) {
            new_data->table[i].id = i;
            new_data->table[i].module = NULL;
        }
        new_data->allocated = to_allocate;
    }
    new_data->table[interpreter_id].module = module;
    if (new_data->count < interpreter_id+1) {
        new_data->count = interpreter_id+1;
    }
    *old_data = new_data;
    return 0;
}
static void __Pyx_State_ConvertFromInterpIdAsIndex(__Pyx_ModuleStateLookupData *data) {
    __Pyx_InterpreterIdAndModule *read = data->table;
    __Pyx_InterpreterIdAndModule *write = data->table;
    __Pyx_InterpreterIdAndModule *end = read + data->count;
    for (; read<end; ++read) {
        if (read->module) {
            write->id = read->id;
            write->module = read->module;
            ++write;
        }
    }
    data->count = write - data->table;
    for (; write<end; ++write) {
        write->id = 0;
        write->module = NULL;
    }
    data->interpreter_id_as_index = 0;
}
static int __Pyx_State_AddModule(PyObject* module, CYTHON_UNUSED void* dummy) {
    int64_t interpreter_id = PyInterpreterState_GetID(__Pyx_PyInterpreterState_Get());
    if (interpreter_id == -1) return -1;
    int result = 0;
    __Pyx_ModuleStateLookup_Lock();
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
    __Pyx_ModuleStateLookupData *old_data = (__Pyx_ModuleStateLookupData *)
            __pyx_atomic_pointer_exchange(&__Pyx_ModuleStateLookup_data, 0);
#else
    __Pyx_ModuleStateLookupData *old_data = __Pyx_ModuleStateLookup_data;
#endif
    __Pyx_ModuleStateLookupData *new_data = old_data;
    if (!new_data) {
        new_data = (__Pyx_ModuleStateLookupData *)calloc(1, sizeof(__Pyx_ModuleStateLookupData));
        if (!new_data) {
            result = -1;
            PyErr_NoMemory();
            goto end;
        }
        new_data->allocated = 1;
        new_data->interpreter_id_as_index = 1;
    }
    __Pyx_ModuleStateLookup_wait_until_no_readers();
    if (new_data->interpreter_id_as_index) {
        if (interpreter_id < __PYX_MODULE_STATE_LOOKUP_SMALL_SIZE) {
            result = __Pyx_State_AddModuleInterpIdAsIndex(&new_data, module, interpreter_id);
            goto end;
        }
        __Pyx_State_ConvertFromInterpIdAsIndex(new_data);
    }
    {
        Py_ssize_t insert_at = 0;
        {
            __Pyx_InterpreterIdAndModule* lower_bound = __Pyx_State_FindModuleStateLookupTableLowerBound(
                new_data->table, new_data->count, interpreter_id);
            assert(lower_bound);
            insert_at = lower_bound - new_data->table;
            if (unlikely(insert_at < new_data->count && lower_bound->id == interpreter_id)) {
                lower_bound->module = module;
                goto end;  // already in table, nothing more to do
            }
        }
        if (new_data->count+1 >= new_data->allocated) {
            Py_ssize_t to_allocate = (new_data->count+1)*2;
            new_data =
                (__Pyx_ModuleStateLookupData*)realloc(
                    new_data,
                    sizeof(__Pyx_ModuleStateLookupData) +
                    (to_allocate-1)*sizeof(__Pyx_InterpreterIdAndModule));
            if (!new_data) {
                result = -1;
                new_data = old_data;
                PyErr_NoMemory();
                goto end;
            }
            new_data->allocated = to_allocate;
        }
        ++new_data->count;
        int64_t last_id = interpreter_id;
        PyObject *last_module = module;
        for (Py_ssize_t i=insert_at; i<new_data->count; ++i) {
            int64_t current_id = new_data->table[i].id;
            new_data->table[i].id = last_id;
            last_id = current_id;
            PyObject *current_module = new_data->table[i].module;
            new_data->table[i].module = last_module;
            last_module = current_module;
        }
    }
  end:
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
    __pyx_atomic_pointer_exchange(&__Pyx_ModuleStateLookup_data, new_data);
#else
    __Pyx_ModuleStateLookup_data = new_data;
#endif
    __Pyx_ModuleStateLookup_Unlock();
    return result;
}
static int __Pyx_State_RemoveModule(CYTHON_UNUSED void* dummy) {
    int64_t interpreter_id = PyInterpreterState_GetID(__Pyx_PyInterpreterState_Get());
    if (interpreter_id == -1) return -1;
    __Pyx_ModuleStateLookup_Lock();
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
    __Pyx_ModuleStateLookupData *data = (__Pyx_ModuleStateLookupData *)
            __pyx_atomic_pointer_exchange(&__Pyx_ModuleStateLookup_data, 0);
#else
    __Pyx_ModuleStateLookupData *data = __Pyx_ModuleStateLookup_data;
#endif
    if (data->interpreter_id_as_index) {
        if (interpreter_id < data->count) {
            data->table[interpreter_id].module = NULL;
        }
        goto done;
    }
    {
        __Pyx_ModuleStateLookup_wait_until_no_readers();
        __Pyx_InterpreterIdAndModule* lower_bound = __Pyx_State_FindModuleStateLookupTableLowerBound(
            data->table, data->count, interpreter_id);
        if (!lower_bound) goto done;
        if (lower_bound->id != interpreter_id) goto done;
        __Pyx_InterpreterIdAndModule *end = data->table+data->count;
        for (;lower_bound<end-1; ++lower_bound) {
            lower_bound->id = (lower_bound+1)->id;
            lower_bound->module = (lower_bound+1)->module;
        }
    }
    --data->count;
    if (data->count == 0) {
        free(data);
        data = NULL;
    }
  done:
#if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
    __pyx_atomic_pointer_exchange(&__Pyx_ModuleStateLookup_data, data);
#else
    __Pyx_ModuleStateLookup_data = data;
#endif
    __Pyx_ModuleStateLookup_Unlock();
    return 0;
}
#endif

/* #### Code section: utility_code_pragmas_end ### */
#ifdef _MSC_VER
#pragma warning( pop )
#endif



/* #### Code section: end ### */
#endif /* Py_PYTHON_H */
