././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/0000755000076500000240000000000015134706453012246 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316780.0 pyreadstat-1.3.3/LICENSE0000644000076500000240000003114714646232654013265 0ustar00dialoutThe pyreadstat package as a whole is distributed under Apache License Vesrion 2 (see below). The pyreadstat package also includes the following open source software components: - ReadStat; https://github.com/WizardMac/ReadStat, distributed under MIT license ReadStat license: --------------------------------------------------------------------------- Copyright (c) 2013-2016 Evan Miller (except where otherwise noted) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pyreadstat liscence: --------------------------------------------------------------------------- Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316780.0 pyreadstat-1.3.3/MANIFEST.in0000644000076500000240000000025214646232654014007 0ustar00dialoutinclude *.h recursive-include src *.h recursive-include pyreadstat *.h include *.pyx recursive-include pyreadstat *.pyx include *.pxd recursive-include pyreadstat *.pxd ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/PKG-INFO0000644000076500000240000000234015134706453013342 0ustar00dialoutMetadata-Version: 2.4 Name: pyreadstat Version: 1.3.3 Summary: Reads and Writes SAS, SPSS and Stata files into/from pandas and polars data frames. Home-page: https://github.com/Roche/pyreadstat Download-URL: https://github.com/Roche/pyreadstat/dist Author: Otto Fajardo Author-email: pleasecontactviagithub@notvalid.com License: Apache-2.0 Classifier: Programming Language :: Python Classifier: Programming Language :: Cython Classifier: Programming Language :: C Classifier: Intended Audience :: Science/Research Classifier: Topic :: Scientific/Engineering Classifier: Environment :: Console Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: narwhals>=2.10.1 Requires-Dist: numpy Dynamic: author Dynamic: author-email Dynamic: classifier Dynamic: description Dynamic: description-content-type Dynamic: download-url Dynamic: home-page Dynamic: license Dynamic: license-file Dynamic: requires-dist Dynamic: summary A Python package to read and write SAS (sas7bdat, sas7bcat, xport/xpt), SPSS (sav, zsav, por) and Stata (dta) files into/from pandas and polars data frames. It is a wrapper around the C library readstat.
Please visit out project home page for more information:
https://github.com/Roche/pyreadstat ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179331.0 pyreadstat-1.3.3/README.md0000644000076500000240000012606615134704303013530 0ustar00dialout# pyreadstat A python package to read and write sas (sas7bdat, sas7bcat, xport), spps (sav, zsav, por) and stata (dta) data files into/from pandas and polars dataframes.
This module is a wrapper around the excellent [Readstat](https://github.com/WizardMac/ReadStat) C library by [Evan Miller](https://www.evanmiller.org/). Readstat is the library used in the back of the R library [Haven](https://github.com/tidyverse/haven), meaning pyreadstat is a python equivalent to R Haven. Detailed documentation on all available methods is in the [Module documentation](https://ofajardo.github.io/pyreadstat_documentation/_build/html/index.html) If you would like to read R RData and Rds files into python in an easy way, take a look to [pyreadr](https://github.com/ofajardo/pyreadr), a wrapper around the C library [librdata](https://github.com/WizardMac/librdata) If you would like to effortlessly produce beautiful summaries from pandas dataframes take a look to [pysummaries](https://github.com/Genentech/pysummaries)! **DISCLAIMER** **Pyreadstat is not a validated package. The results may have inaccuracies deriving from the fact most of the data formats are not open. Do not use it for critical tasks such as reporting to the authorities. Pyreadstat is not meant to replace the original applications in this regard.** ## Table of Contents * [Motivation](#motivation) * [Dependencies](#dependencies) * [Installation](#installation) + [Using pip](#using-pip) + [Using conda](#using-conda) + [From the latest sources](#from-the-latest-sources) + [Compiling on Windows and Mac](#compiling-on-windows-and-mac) * [Usage](#usage) + [Basic Usage](#basic-usage) - [Reading Files](#reading-files) - [Writing Files](#writing-files) + [More reading options](#more-reading-options) - [Reading only the headers](#reading-only-the-headers) - [Reading selected columns](#reading-selected-columns) - [Reading files in parallel processes](#reading-files-in-parallel-processes) - [Reading rows in chunks](#reading-rows-in-chunks) - [Reading value labels](#reading-value-labels) - [Missing Values](#missing-values) + [SPSS](#spss) + [SAS and STATA](#sas-and-stata) - [Reading datetime and date columns](#reading-datetime-and-date-columns) - [Reading from file-like objects](#reading-from-file-like-objects) - [Other options](#other-options) + [More writing options](#more-writing-options) - [File specific options](#file-specific-options) - [Writing value labels](#writing-value-labels) - [Writing user defined missing values](#writing-user-defined-missing-values) - [Setting variable formats](#setting-variable-formats) - [Variable type conversion](#variable-type-conversion) * [Roadmap](#roadmap) * [CD/CI and wheels](#cdci_and_wheels) * [Known limitations](#known-limitations) * [Python 2.7 support.](#python-27-support) * [Change log](#change-log) * [License](#license) * [Contributing](#contributing) * [People](#people) ## Motivation The original motivation came from reading sas7bdat files in python. That is already possible using either the (pure python) package [sas7bdat](https://pypi.org/project/sas7bdat/) or the (cythonized) method [read_sas](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sas.html) from pandas. However, those methods are slow (important if you want to read several large files), do not give the possibility to recover value labels (stored in the file itself in the case of spss or stata, or in catalog files in sas), convert both dates and datetime variables to datetime, and you have to specify the encoding otherwise in python 3 instead of strings you get bytes. This package corrects those problems. **1. Good Performance:** Here a comparison of reading a 190 Mb sas7dat file having 202 K rows by 70 columns with numeric, character and date-like columns using different methods. As you can see pyreadstat is the fastest for python and matches the speeds of R Haven. | Method | time | | :----- | :-----------------: | | Python 3 - sas7bdat | 6 min | | Python 3- pandas | 42 s | | Python 3- pyreadstat | 7 s | | R - Haven | 7 s | **2. Reading Value Labels** Neither sas7bdat and pandas.read_sas gives the possibility to read sas7bcat catalog files. Pyreadstat can do that and also extract value labels from SPSS and STATA files. **3. Reading dates and datetimes** sas7bdat and pandas.read_sas convert both date and datetime variables into datetime. That means if you have a date such a '01-01-2018' it will be transformed to '01-01-2018 00:00:00' (it always inserts a time), making it impossible to know looking only at the data if the variable was originally a datetime (if it had a time) or not. Pyreadstat transforms dates to dates and datetimes to datetimes, so that you have a better correspondence with the original data. However, it is possible to keep the original pandas behavior and get always datetimes. **4. Encoding** On python 3, pandas.read_sas reads all strings as bytes. If you want strings you have to specify the encoding manually. pyreadstat read strings as str. Thas is possible because readstat extracts the original encoding and translates to utf-8, so that you don't have to care about that anymore. However it is still possible to manually set the encoding. In addition pyreadstat exposes the variable labels in an easy way (see later). As pandas dataframes cannot handle value labels, you as user will have to take the decision whether to use those values or not. Pandas read_sas reads those labels, but in order to recover them you have to work a bit harder. Compared to R Haven, pyreadstat offers the possibility to read only the headers: Sometimes you want to take a look to many (sas) files looking for the datasets that contain some specific columns, and you want to do it quick. This package offers the possibility to read only the metadata making it possible a very fast metadata scraping (Pandas read_sas can also do it if you pass the value iterator=True). In addition it offers the capability to read sas7bcat files separately from the sas7bdat files. More recently there has been a lot of interest from users on using pyreadstat to read SPSS sav files. After improvements in pyreadstat 1.0.3 below some benchmarks are presented. The small file is 200K rows x 100 columns (152 Mb) containing only numeric columns and the big file is 294K rows x 666 columns (1.5 Gb). There are two versions of the big file: one containing numeric columns only and one with a mix of numeric and character. Pyreadstat gives two ways to read files: reading in a single process using read_sav and reading it in multiple processes using read_file_multiprocessing (see later in the readme for more information). | Method | small | big numeric | big mixed | | :----- | :----: | :---------: | :-------: | | pyreadstat read_sav | 2.3 s | 28 s | 40 s | | pyreadstat read_file_multiprocessing | 0.8 s | 10 s | 21 s | As you see performance degrades in pyreadstat when reading a table with both numeric and character types. This is because numpy and pandas do not have a native type for strings but they use a generic object type which brings a big hit in performance. The situation can be improved tough by reading files in multiple processes. ## Dependencies The module depends on numpy and narwhals, a package to interface with pandas and polars. In addition you will need to have installed either pandas or polars. In order to compile from source you will need a C compiler (see installation). Only if you want to do changes to the cython source code, you will need cython (normally not necessary). If you want to compile for python 2.7 or windows, you will need cython (see python 2.7 support later). Readstat depends on the C library iconv to handle character encodings. On mac, the library is found on the system, but users have sometimes reported problems. In those cases it may help to install libiconv with conda (see later, compilation on mac). Readstat also depends on zlib; it was reported not to be installed by default on Lubuntu. If you face this problem installing the library solves it. ## Installation ### Using pip Probably the easiest way: from your conda, virtualenv or just base installation do: ``` pip install pyreadstat ``` If you are running on a machine without admin rights, and you want to install against your base installation you can do: ``` pip install pyreadstat --user ``` At the moment we offer pre-compiled wheels for windows, mac and linux. Look at the [pypi webpage](https://pypi.org/project/pyreadstat/) to find out which python versions are currently supported. If there is no pre-compiled wheel available, pip will attempt to compile the source code. ### Using conda The package is also available in [conda-forge](https://anaconda.org/conda-forge/pyreadstat) for windows, mac and linux 64 bit. Visit the Conda forge webpage to find out which python versions are currently supported. In order to install: ``` conda install -c conda-forge pyreadstat ``` ### From the latest sources Download or clone the repo, open a command window and type: ``` python3 setup.py install ``` If you don't have admin privileges to the machine (for example on Bee) do: ``` python3 setup.py install --user ``` You can also install from the github repo directly (without cloning). Use the flag --user if necessary. ``` pip install git+https://github.com/Roche/pyreadstat.git ``` You need a working C compiler and cython >=3.0.0. ### Compiling on Windows and Mac Compiling on linux is very easy, but on windows you need some extra preparation. Some instructions are found [here](https://github.com/Roche/pyreadstat/blob/master/windows_compilation.md) Compiling on mac is usually easy. Readstat depends however on the C library iconv to handle character encodings; while on linux is part of gclib, on mac it is a separated shared library found on the system (h file is in /usr/include and shared library on /usr/lib). While compiling against this usually works fine, some users have reported problems (for example missing symbol _iconv, or libiconv version too old). In those cases it helped to install libiconv with conda: ``` conda install libiconv ``` and then recompile again (be sure to delete any cache, if using pip do pip --no-cache-dir, if using setup.py remove the folder build, otherwise you may be installing the old compilation again). ## Usage ### Basic Usage #### Reading files Pass the path to a file to any of the functions provided by pyreadstat. It will return a pandas or polars data frame and a metadata object.
The dataframe uses the column names. The metadata object contains the column names, column labels, number_rows, number_columns, file label (if any), file encoding (if applicable), notes and objects about value labels (if present). Be aware that file_label and file_encoding may be None, not all columns may have labels, notes may not be present and there may be no value labels. For example, in order to read a sas7bdat file: ```python import pyreadstat # output format by default is pandas. You can use polars to get a polars dataframe. df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', output_format="pandas") # done! let's see what we got print(df.head()) print(meta.column_names) print(meta.column_labels) print(meta.column_names_to_labels) print(meta.number_rows) print(meta.number_columns) print(meta.file_label) print(meta.file_encoding) # there are other metadata pieces extracted. See the documentation for more details. ``` You can replace the column names by column labels very easily (but check first that all columns have distinct labels!): ```python # replace column names with column labels df.columns = meta.column_labels # to go back to column names df.columns = meta.column_names ``` As mentioned before you can very easily read into a polars dataframe by using the output_format argument: ```python import pyreadstat # this time df will be polars df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', output_format="polars") # done! let's see what we got print(df.head()) ``` #### Writing files Pyreadstat can write STATA (dta), SPSS (sav and zsav, por currently nor supported) and SAS (Xport, sas7bdat and sas7bcat currently not supported) files from pandas or polars dataframes. write functions take as first argument a pandas or polars dataframe (other data structures are not supported), as a second argument the path to the destination file. Optionally you can also pass a file label and a list with column labels. ```python import pandas as pd import pyreadstat # this would work the same for a polars dataframe df = pd.DataFrame([[1,2.0,"a"],[3,4.0,"b"]], columns=["v1", "v2", "v3"]) # column_labels can also be a dictionary with variable name as key and label as value column_labels = ["Variable 1", "Variable 2", "Variable 3"] pyreadstat.write_sav(df, "path/to/destination.sav", file_label="test", column_labels=column_labels) ``` Some special arguments are available depending on the function. write_sav can take also notes as string or list of strings, wheter to compress or not as zsav or apply row compression, variable display widths and variable measures. write_dta can take a stata version. write_xport a name for the dataset. User defined missing values and value labels are also supported. See the [Module documentation](https://ofajardo.github.io/pyreadstat_documentation/_build/html/index.html) for more details. Here there is a relation of all functions available. You can also check the [Module documentation](https://ofajardo.github.io/pyreadstat_documentation/_build/html/index.html). | Function in this package | Purpose | | ------------------- | ----------- | | read_sas7bdat | read SAS sas7bdat files | | read_xport | read SAS Xport (XPT) files | | read_sas7bcat | read SAS catalog files | | read_dta | read STATA dta files | | read_sav | read SPSS sav and zsav files | | read_por | read SPSS por files | | set_catalog_to_sas | enrich sas dataframe with catalog formats | | set_value_labels | replace values by their labels | | read_file_in_chunks | generator to read files in chunks | | write_sav | write SPSS sav and zsav files | | write_por | write SPSS Portable (POR) files | | write_dta | write STATA dta files | | write_xport | write SAS Xport (XPT) files version 8 and 5 | ### More reading options #### Reading only the headers All functions accept a keyword argument "metadataonly" which by default is False. If True, then no data will be read, but still both the metadata and the dataframe will be returned. The metadata will contain all fields as usual, but the dataframe will be emtpy, although with the correct columns names. Sometimes number_rows may be None if it was not possible to determine the number of rows without reading the data. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', metadataonly=True) ``` #### Reading selected columns All functions accept a keyword "usecols" which should be a list of column names. Only the columns which names match those in the list will be imported (case sensitive). This decreases memory consumption and speeds up the process. Usecols must always be a list, even if there is only one member. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', usecols=["variable1", "variable2"]) ``` #### Reading files in parallel processes A challenge when reading large files is the time consumed in the operation. In order to alleviate this pyreadstat provides a function "read\_file\_multiprocessing" to read a file in parallel processes using the python multiprocessing library. As it reads the whole file in one go you need to have enough RAM for the operation. If that is not the case look at Reading rows in chunks (next section). Notice however that you can combine reading in parallel with reading in chunks as described in the next section. Speed ups in the process will depend on a number of factors such as number of processes available, RAM, content of the file etc. ```python import pyreadstat fpath = "path/to/file.sav" df, meta = pyreadstat.read_file_multiprocessing(pyreadstat.read_sav, fpath, num_processes=4) ``` num_processes is the number of workers and it defaults to 4 (or the number of cores if less than 4). You can play with it to see where you get the best performance. You can also get the number of all available workers like this: ``` import multiprocessing num_processes = multiprocessing.cpu_count() ``` **Notes for Xport, Por and some defective SAV files not having the number of rows in the metadata** 1. In all Xport, Por and some defective SAV files, the number of rows cannot be determined from the metadata. In such cases, you can use the parameter num\_rows to be equal or larger to the number of rows in the dataset. This number can be obtained reading the file without multiprocessing, reading in another application, etc. **Notes for windows** 1. For this to work you must include a __name__ == "__main__" section in your script. See [this issue](#85) for more details. ``` import pyreadstat if __name__ == "__main__": df, meta = pyreadstat.read_file_multiprocessing(pyreadstat.read_sav, 'sample.sav') ``` 2. If you include too many workers or you run out of RAM you main get a message about not enough page file size. See [this issue](#87) #### Reading rows in chunks Reading large files with hundred of thouseds of rows can be challenging due to memory restrictions. In such cases, it may be helpful to read the files in chunks. Every reading function has two arguments row_limit and row_offset that help achieving this. row_offset makes to skip a number of rows before start reading. row_limit makes to stop after a number of rows are read. Combining both you can read the file in chunks inside or outside a loop. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat("/path/to/file.sas7bdat", row_offset=1, row_limit=1) # df will contain only the second row of the file ``` Pyreadstat also has a convienence function read_file_in_chunks, which returns a generator that helps you to iterate through the file in chunks. This function takes as first argument a pyreadstat reading function and a second argument a path to a file. Optionally you can change the size of the chunks with chunksize (default to 100000), and also add an offset and limit. You can use any keyword argument you wish to pass to the pyreadstat reading function. ```python import pyreadstat fpath = "path/to/file.sas7bdat" reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sas7bdat, fpath, chunksize= 10, offset=2, limit=100, disable_datetime_conversion=True) for df, meta in reader: print(df) # df will contain 10 rows except for the last one # do some cool calculations here for the chunk ``` For very large files it may be convienient to speed up the process by reading each chunks in parallel. For this purpose you can pass the argument multiprocess=True. This is a combination of read_file_in_chunks and read_file_multiprocessing. Here you can use the arguments row_offset and row_limit to start reading the file from an offest and stop after a row_offset+row_limit. ```python import pyreadstat fpath = "path/to/file.sav" reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sav, fpath, chunksize= 10000, multiprocess=True, num_processes=4) for df, meta in reader: print(df) # df will contain 10000 rows except for the last one # do some cool calculations here for the chunk ``` **If using multiprocessing, please read the notes in the previous section regarding Xport, Por and some defective SAV files not having the number of rows in the metadata** **For Windows, please check the notes on the previous section reading files in parallel processes** #### Reading value labels For sas7bdat files, value labels are stored in separated sas7bcat files. You can use them in combination with the sas7bdat or read them separately. If you want to read them in combination with the sas7bdat files, pass the path to the sas7bcat files to the read_sas7bdat function. The original values will be replaced by the values in the catalog. ```python import pyreadstat # formats_as_category is by default True, and it means the replaced values will be transformed to a pandas/polars category column. There is also formats_as_ordered_category to get an ordered category, this by default is False. df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', catalog_file='/path/to/a/file.sas7bcat', formats_as_category=True, formats_as_ordered_category=False) ``` If you prefer to read the sas7bcat file separately, you can apply the formats later with the function set_catalog_to_sas. In this way you can have two copies of the dataframe, one with catalog and one without. ```python import pyreadstat # this df will have the original values df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat') # read_sas7bdat returns an emtpy data frame and the catalog df_empty, catalog = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bcat') # enrich the dataframe with the catalog # formats_as_category is by default True, and it means the replaced values will be transformed to a pandas/polars category column. formats_as_ordered_category is by default False meaning by default categories are not ordered. df_enriched, meta_enriched = pyreadstat.set_catalog_to_sas(df, meta, catalog, formats_as_category=True, formats_as_ordered_category=False) ``` For SPSS and STATA files, the value labels are included in the files. You can choose to replace the values by the labels when reading the file using the option apply_value_formats, ... ```python import pyreadstat # apply_value_formats is by default False, so you have to set it to True manually if you want the labels # formats_as_category is by default True, and it means the replaced values will be transformed to a pandas/polars category column. formats_as_ordered_category is by default False meaning by default categories are not ordered. df, meta = pyreadstat.read_sav("/path/to/sav/file.sav", apply_value_formats=True, formats_as_category=True, formats_as_ordered_category=False) ``` ... or to do it later with the function set_value_labels: ```python import pyreadstat # This time no value labels. df, meta = pyreadstat.read_sav("/path/to/sav/file.sav", apply_value_formats=False) # now let's add them to a second copy df_enriched = pyreadstat.set_value_labels(df, meta, formats_as_category=True, formats_as_ordered_category=False) ``` Internally each variable is associated with a label set. This information is stored in meta.variable_to_label. Each label set contains a map of the actual value in the variable to the label, this informtion is stored in meta.variable_value_labels. By combining both you can get a dictionary of variable names to a dictionary of actual values to labels. For SPSS and STATA: ```python import pyreadstat df, meta = pyreadstat.read_sav("test_data/basic/sample.sav") # the variables mylabl and myord are associated to the label sets labels0 and labels1 respectively print(meta.variable_to_label) #{'mylabl': 'labels0', 'myord': 'labels1'} # labels0 and labels1 contain a dictionary of actual value to label print(meta.value_labels) #{'labels0': {1.0: 'Male', 2.0: 'Female'}, 'labels1': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} # both things have been joined by pyreadstat for convienent use print(meta.variable_value_labels) #{'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} ``` SAS is very similar except that meta.variable_to_label comes from the sas7bdat file and meta.value_labels comes from the sas7bcat file. That means if you read a sas7bdat file and a sas7bcat file togheter meta.variable_value_labels will be filled in. If you read only the sas7bdat file only meta.variable_to_label will be available and if you read the sas7bcat file only meta.value_labels will be available. If you read a sas7bdat file and there are no associated label sets, SAS will assign by default the variable format as label sets. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat("test_data/sas_catalog/test_data_linux.sas7bdat") meta.variable_to_label {'SEXA': '$A', 'SEXB': '$B'} df2, meta2 = pyreadstat.read_sas7bcat("test_data/sas_catalog/test_formats_linux.sas7bcat") meta2.value_labels {'$A': {'1': 'Male', '2': 'Female'}, '$B': {'2': 'Female', '1': 'Male'}} ``` #### Missing Values There are two types of missing values: system and user defined. System are assigned by the program by default. User defined are valid values that the user decided to give the meaning of missing in order to differentiate between several situations.For example if one has a categorical variable representing if the person passed a test, you could have 0 for did not pass, 1 for pass, and as user defined missing variables 2 for did not show up for the test, 3 for unable to process the results, etc. **By default both cases are represented by NaN in pandas and null in polars when read with pyreadstat**. Notice that the only possible missing value in pandas is NaN (Not a Number) for both string and numeric variables, date, datetime and time variables have NaT (Not a Time). Polars use null for all datatypes. ##### SPSS In the case of SPSS sav files, the user can assign to a numeric variable either up to three discrete missing values or one range plus one discrete missing value. As mentioned by default all of these possiblities are translated into NaN, but one can get those original values by passing the argument user_missing=True to the read_sav function: ```python # user set with default missing values import pyreadstat df, meta = pyreadstat.read_sav("/path/to/file.sav") print(df) >> test_passed 1 0 NaN NaN ``` Now, reading the user defined missing values: ```python # user set with user defined missing values import pyreadstat df, meta = pyreadstat.read_sav("/path/to/file.sav", user_missing=True) print(df) >> test_passed 1 0 2 3 ``` As you see now instead o NaN the values 2 and 3 appear. In case the dataset had value labels, we could bring those in ```python # user set with user defined missing values and labels import pyreadstat df, meta = pyreadstat.read_sav("/path/to/file.sav", user_missing=True, apply_value_formats=True) print(df) >> test_passed "passed" "not passed" "not shown" "not processed" ``` Finally, the information about what values are user missing is stored in the meta object, in the variable missing_ranges. This is a dicitonary with the key being the name of the variable, and as value a list of dictionaries, each dictionary contains the elements "hi" and "lo" to represent the lower and upper bound of the range, however for discrete values as in the example, both boundaries are also present although the value is the same in both cases. ```python # user set with default missing values import pyreadstat df, meta = pyreadstat.read_sav("/path/to/file.sav", user_missing=True, apply_value_formats=True) print(meta.missing_ranges) >>> {'test_passed':[{'hi':2, 'lo':2}, {'hi':3, 'lo':3}]} ``` SPSS sav files also support up to 3 discrete user defined missing values for non numeric (character) variables. Pyreadstat is able to read those and the behavior is the same as for discrete numerical user defined missing values. That means those values will be translated as NaN by default and to the correspoding string value if user_missing is set to True. meta.missing_ranges will show the string value as well. When writing a dataframe to a sav file, if user defined missing values are not set, NaNs are translated to empty strings, as there is no other possibility to represent those missing values and user defined missing values are not set automatically. When reading a sav into a dataframe, if the value in a character variable is an empty string (''), it will not be translated to NaN/null, but will stay as an empty string. This is because the empty string is a valid character value in SPSS and pyreadstat preserves that property. This behaviour generates an asymetrical situation that has to be managed by the user. You can convert empty strings to nan very easily if you think it is appropiate for your dataset, or you can use defined missing values as described before. ##### SAS and STATA In SAS the user can assign values from .A to .Z and ._ as user defined missing values. In Stata values from .a to .z. As in SPSS, those are normally translated to NaN. However, using user_missing=True with read_sas7bdat or read_dta will produce values from A to Z and _ for SAS and a to z for dta. In addition a variable missing_user_values will appear in the metadata object, being a list with those values that are user defined missing values. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat("/path/to/file.sas7bdat", user_missing=True) df, meta = pyreadstat.read_dta("/path/to/file.dta", user_missing=True) print(meta.missing_user_values) ``` The user may also assign a label to user defined missing values. In such case passing the corresponding sas7bcat file to read_sas7bdat or using the option apply_value_formats to read_dta will show those labels instead of the user defined missing value. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat("/path/to/file.sas7bdat", catalog_file="/path/to/file.sas7bcat", user_missing=True) df, meta = pyreadstat.read_dta("/path/to/file.dta", user_missing=True, apply_value_formats=True) ``` Empty strings are still transtaled as empty strings and not as NaN. The information about what values are user missing is stored in the meta object, in the variable missing_user_values. This is a list listing all user defined missing values. User defined missing values are currently not supported for file types other than sas7bdat, sas7bcat and dta. #### Reading datetime and date columns SAS, SPSS and STATA represent datetime, date and other similar concepts as a numeric column and then applies a display format on top. Roughly speaking, internally there are two possible representations: one for concepts with a day or lower granularity (date, week, quarter, year, etc.) and those with a higher granularity than a day (datetime, time, hour, etc). The first group is suceptible to be converted to a python date object and the second to a python datetime object. Pyreadstat attempts to read columns with datetime, date and time formats that are convertible to python datetime, date and time objects automatically. However there are other formats that are not fully convertible to any of these formats, for example SAS "YEAR" (displaying only the year), "MMYY" (displaying only month and year), etc. Because there are too many of these formats and these keep changing, it is not possible to implement a rule for each of those, therefore these columns are not transformed and the user will obtain a numeric column. In order to cope with this issue, there are two options for each reader function: extra\_datetime\_formats and extra\_date\_formats that allow the user to pass these datetime or date formats, to transform the numeric values into datetime or date python objects. Then, the user can format those columns appropiately; for example extracting the year only to an integer column in the case of 'YEAR' or formatting it to a string 'YYYY-MM' in the case of 'MMYY'. The choice between datetime or date format depends on the granularity of the data as explained above. This arguments are also useful in the case you have a valid datetime, date or time format that is currently not recognized in pyreadstat. In those cases, feel free to file an issue to ask those to be added to the list, in the meantime you can use these arguments to do the conversion. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', extra_date_formats=["YEAR", "MMYY"]) ``` #### Reading from file-like objects pyreadstat can read directly from file-like objects instead of file paths. This is useful for: - Reading from zip archives without extracting to disk - Reading from in-memory buffers (BytesIO) - Streaming from remote sources **Reading from a zip archive:** ```python import zipfile import pyreadstat with zipfile.ZipFile('archive.zip') as zf: with zf.open('data.sav') as f: df, meta = pyreadstat.read_sav(f) ``` **Reading from a remote URL:** ```python import io import requests import pyreadstat response = requests.get('https://example.com/data.sav') df, meta = pyreadstat.read_sav(io.BytesIO(response.content)) ``` This approach avoids downloading large files to disk, which can significantly improve performance and reduce disk space requirements when working with remote data or compressed archives. #### Other options You can set the encoding of the original file manually. The encoding must be a [iconv-compatible encoding](https://gist.github.com/hakre/4188459). This is absolutely necessary if you are handling old xport files with non-ascii characters. Those files do not have stamped the encoding in the file itself, therefore the encoding must be set manually. For SPSS POR files it is not possible to set the encoding and files are assumed to be always encoded in UTF-8. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', encoding="LATIN1") ``` You can preserve the original pandas behavior regarding dates (meaning dates are converted to pandas datetime) with the dates_as_pandas_datetime option. This option is effective for pandas only, not for polars. ```python import pyreadstat df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat', dates_as_pandas_datetime=True) ``` You can get a dictionary of numpy arrays instead of a pandas or polars dataframe when reading any file format. In order to do that, set the parameter output_format='dict' (default is 'pandas', the other option is 'polars'). This is useful if you want to transform the data to some other format different to pandas/polars, as transforming the data to pandas is a costly process both in terms of speed and memory. For more information, please check the [Module documentation](https://ofajardo.github.io/pyreadstat_documentation/_build/html/index.html). ### More writing options #### File specific options Some special arguments are available depending on the function. write_sav can take also notes as string or list of strings, wheter to compress or not as zsav or apply row compression, variable display widths and variable measures. write_dta can take a stata version. write_xport a name for the dataset. See the [Module documentation](https://ofajardo.github.io/pyreadstat_documentation/_build/html/index.html) for more details. #### Writing value labels The argument variable_value_labels can be passed to write_sav and write_dta to write value labels. This argument must be a dictionary where keys are variable names (names must match column names in the dataframe). Values are another dictionary where keys are the value present in the dataframe and values are the labels (strings). ```python import pandas as pd import pyreadstat df = pd.DataFrame([[1,1],[2,2],[1,3]], columns=['mylabl', 'myord']) variable_value_labels = {'mylabl': {1: 'Male', 2: 'Female'}, 'myord': {1: 'low', 2: 'medium', 3: 'high'}} path = "/path/to/somefile.sav" pyreadstat.write_sav(df, path, variable_value_labels=variable_value_labels) ``` #### Writing user defined missing values ##### SPSS The argument missing_ranges can be passed to write_sav to write user defined missing values. This argument be a dictionary with keys as variable names matching variable names in the dataframe. The values must be a list. Each element in that list can either be either a discrete numeric or string value (max 3 per variable) or a dictionary with keys 'hi' and 'lo' to indicate the upper and lower range for numeric values (max 1 range value + 1 discrete value per variable). hi and lo may also be the same value in which case it will be interpreted as a discrete missing value. For this to be effective, values in the dataframe must be the same as reported here and not NaN. ```python import pandas as pd import pyreadstat df = pd.DataFrame([["a",1],["c",2],["c",3]], columns=['mychar', 'myord']) missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} path = "/path/to/somefile.sav" pyreadstat.write_sav(df, path, missing_ranges=missing_ranges) ``` ##### STATA The argument missing_user_values can be passed to write_dta to write user defined missing values only for numeric variables. This argument be a dictionary with keys as variable names matching variable names in the dataframe. The values must be a list of missing values, valid values are single character strings between a and z. Optionally a value label can also be attached to those missing values using variable_value_labels. ```python import pandas as pd import pyreadstat df = pd.DataFrame([["a", 1],[2.2, 2],[3.3, "b"]], columns=['Var1', 'Var2']) variable_value_labels = {'Var1':{'a':'a missing value'} missing_ranges = {'Var1':['a'], 'Var2': ['b']} path = "/path/to/somefile.sav" pyreadstat.write_sav(df, path, missing_ranges=missing_ranges, variable_value_labels=variable_value_labels) ``` #### Setting variable formats Numeric types in SPSS, SAS and STATA can have formats that affect how those values are displayed to the user in the application. Pyreadstat automatically sets the formatting in some cases, as for example when translating dates or datetimes (which in SPSS/SAS/STATA are just numbers with a special format). The user can however specify custom formats for their columns with the argument "variable_format", which is a dictionary with the column name as key and a string with the format as values: ```python import pandas as pd import pyreadstat path = "path/where/to/write/file.sav" df = pd.DataFrame({'restricted':[1023, 10], 'integer':[1,2]}) formats = {'restricted':'N4', 'integer':'F1.0'} pyreadstat.write_sav(df, path, variable_format=formats) ``` The appropiate formats to use are beyond the scope of this documentation. Probably you want to read a file produced in the original application and use meta.original_variable\_types to get the formats. Otherwise look for the documentation of the original application. ##### SPSS In the case of SPSS we have some presets for some formats: * restricted_integer: with leading zeros, equivalent to N + variable width (e.g N4) * integer: Numeric with no decimal places, equivalent to F + variable width + ".0" (0 decimal positions). A column of type integer will also be translated into this format automatically. ```python import pandas as pd import pyreadstat path = "path/where/to/write/file.sav" df = pd.DataFrame({'restricted':[1023, 10], 'integer':[1,2]}) formats = {'restricted':'restricted_integer', 'integer':'integer'} pyreadstat.write_sav(df, path, variable_format=formats) ``` There is some information about the possible formats [here](https://www.gnu.org/software/pspp/pspp-dev/html_node/Variable-Record.html). #### Variable type conversion The following rules are used in order to convert from pandas/polars/numpy/python types to the target file types: | Python Type | Converted Type | | ------------------- | --------- | | np.int32/pl.int32 or lower | integer (stata), numeric (spss, sas) | | int, np.int64, pl.int64, np.float, pl.float64 | double (stata), numeric (spss, sas) | | str | character | | bool | integer (stata), numeric (spss, sas) | | datetime, date, time | numeric with datetime/date/time formatting | | category | depends on the original dtype | | any other object | character | | column all missing | integer (stata), numeric (spss, sas) | | column with mixed types | character | Columns with mixed types are translated to character. This does not apply to column cotaining np.nan, where the missing values are correctly translated. It also does not apply to columns with user defined missing values in stata/sas where characters (a to z, A to Z, \_) will be recorded as numeric. ## Roadmap * Include latest releases from Readstat as they come out. ## CD/CI and Wheels A CD/CI pipeline producing the wheels is available [here](https://github.com/ofajardo/pyreadstat_wheels5). Contributions are welcome. ## Known limitations pyreadstat builds on top of Readstat and therefore inherits its limitations. Currently those include: * Cannot write SAS sas7bdat. Those files can be written but not read in SAS and therefore are not supported in pyreadstat. (see [here](https://github.com/WizardMac/ReadStat/issues/98)) Converting data types from foreign applications into python some times also bring some limitations: * Pyreadstat transforms date, datetime and time like variables which are internally represented in the original application as numbers to python datetime objects. Python datetime objects are however limited in the range of dates they can represent (for example the max year is 10,000), while in other applications it is possible (although probably an error in the data) to have very high or very low dates. In this cases pyreadstat would raise an error: ``` OverflowError: date value out of range ``` The workaround is to deal with this include using the keyword argument disable_datetime_conversion so that you will get numbers instead of datetime objects or skipping reading such columns with the argument usecols. ## Python 2.7 support. As version 1.2.3 Python 2.7 is not supported. In previous versions it was possible to compile it for mac and linux but not for windows, but no wheels were provided. In linux and mac it will fail if the path file contains non-ascii characters. ## Change log A log with the changes for each version can be found [here](https://github.com/Roche/pyreadstat/blob/master/change_log.md) ## License pyreadstat is distributed under Apache 2.0 license. Readstat is distributed under MIT license. See the License file for more information. ## Contributing Contributions are welcome! Those include corrections to the documentation, bugs reporting, testing, and of course code pull requests. For code pull requests please consider opening an issue explaining what you plan to do, so that we can get aligned before you start investing time on it (this also avoids duplicated efforts). The ReadStat code in this repo (under the subfolder src) is coming from the main Readstat trunk and should not be modified in order to keep full compatibility with the original. In that way improvements in ReadStat can be taken here with almost no effort. If you would like to propose new features involving changes in the ReadStat code, please submit a pull request to ReadStat first. ## People [Otto Fajardo](https://github.com/ofajardo) - author, maintainer [Matthew Brett](http://matthew.dynevor.org/) - contributor [python wheels](https://github.com/MacPython/pyreadstat-wheels) [Jonathon Love](https://jona.thon.love/) - contributor: open files with international characters. Function to open files for writing. [Clemens Brunner](https://github.com/cbrnr) - integration with pandas.read_spss [Thomas Grainger](https://github.com/graingert) - corrections and suggestions to source code [benjello](https://github.com/benjello), [maxwell8888](https://github.com/maxwell8888), [drcjar](https://github.com/drcjar), [labenech](https://github.com/labenech): improvements to documentation [alchemyst](https://github.com/alchemyst): improvements to docstrings [bmwiedemann](https://github.com/bmwiedemann), [toddrme2178 ](https://github.com/toddrme2178), [Martin Thorsen Ranang](https://github.com/mtr): improvements to source code ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316780.0 pyreadstat-1.3.3/pyproject.toml0000644000076500000240000000016214646232654015165 0ustar00dialout[build-system] requires = [ "setuptools", "wheel", "cython" ] build-backend = "setuptools.build_meta" ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/pyreadstat/0000755000076500000240000000000015134706453014426 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1767630290.0 pyreadstat-1.3.3/pyreadstat/__init__.py0000644000076500000240000000232015126762722016536 0ustar00dialout# ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# from .pyreadstat import read_sas7bdat, read_xport, read_dta, read_sav, read_por, read_sas7bcat from .pyreadstat import write_sav, write_dta, write_xport, write_por #from .pyreadstat import set_value_labels, set_catalog_to_sas #from .pyreadstat import set_catalog_to_sas from .pyreadstat import read_file_in_chunks, read_file_multiprocessing from ._readstat_parser import ReadstatError, metadata_container from .pyfunctions import set_value_labels, set_catalog_to_sas __version__ = "1.3.3" ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180456.0 pyreadstat-1.3.3/pyreadstat/_readstat_parser.c0000644000076500000240000451661415134706450020132 0ustar00dialout/* 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_parser", "sources": [ "pyreadstat/_readstat_parser.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_parser" } 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 #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 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 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 struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::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 #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_parser #define __PYX_HAVE_API__pyreadstat___readstat_parser /* Early includes */ #include #include #include #include "readstat.h" #include "readstat_io_unistd.h" #include "conditional_includes.h" #include #include #if CYTHON_COMPILING_IN_LIMITED_API #ifdef _MSC_VER #pragma message ("This module uses CPython specific internals of 'datetime.datetime', which are not available in the limited API.") #else #warning This module uses CPython specific internals of 'datetime.datetime', which are not available in the limited API. #endif #endif #include "datetime.h" #define __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, minute, second, microsecond, tz, fold, PyDateTimeAPI->DateTimeType) #define __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, microsecond, tz, fold, PyDateTimeAPI->TimeType) #define __Pyx_TimeZone_UTC PyDateTime_TimeZone_UTC #define __Pyx_TimeZone_FromOffsetAndName(offset, name) PyTimeZone_FromOffsetAndName(offset, name) /* Backport for Python < 3.10 */ #if PY_VERSION_HEX < 0x030a00a1 #ifndef PyDateTime_TIME_GET_TZINFO #define PyDateTime_TIME_GET_TZINFO(o) ((((PyDateTime_Time*)o)->hastzinfo) ? ((PyDateTime_Time*)o)->tzinfo : Py_None) #endif #ifndef PyDateTime_DATE_GET_TZINFO #define PyDateTime_DATE_GET_TZINFO(o) ((((PyDateTime_DateTime*)o)->hastzinfo) ? ((PyDateTime_DateTime*)o)->tzinfo : Py_None) #endif #endif #include #ifdef _OPENMP #include #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 #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 #endif template static void __Pyx_pretend_to_initialize(T* ptr) { #if __cplusplus > 201103L if ((std::is_trivially_default_constructible::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_parser.pyx", "", "cpython/datetime.pxd", "cpython/type.pxd", }; /* #### Code section: utility_code_proto_before_types ### */ /* Atomics.proto */ #include #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 #elif CYTHON_ATOMICS && (defined(__cplusplus) && (\ (__cplusplus >= 201103L) ||\ (defined(_MSC_VER) && _MSC_VER >= 1700))) #include #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 #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 /* IncludeStructmemberH.proto */ #include /* 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; struct __pyx_opt_args_7cpython_8datetime_time_new; struct __pyx_opt_args_7cpython_8datetime_datetime_new; struct __pyx_opt_args_7cpython_8datetime_timezone_new; struct __pyx_opt_args_7cpython_8datetime_datetime_from_timestamp; /* "cpython/datetime.pxd":265 * # Create time object using DateTime CAPI factory function * # Note, there are no range checks for any of the arguments. * cdef inline time time_new(int hour, int minute, int second, int microsecond, object tz, int fold=0): # <<<<<<<<<<<<<< * return __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) * */ struct __pyx_opt_args_7cpython_8datetime_time_new { int __pyx_n; int fold; }; /* "cpython/datetime.pxd":270 * # Create datetime object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline datetime datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz, int fold=0): # <<<<<<<<<<<<<< * return __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) * */ struct __pyx_opt_args_7cpython_8datetime_datetime_new { int __pyx_n; int fold; }; /* "cpython/datetime.pxd":279 * * # Create timedelta object using DateTime CAPI factory function. * cdef inline object timezone_new(object offset, object name=None): # <<<<<<<<<<<<<< * return __Pyx_TimeZone_FromOffsetAndName(offset, name if name is not None else NULL) * */ struct __pyx_opt_args_7cpython_8datetime_timezone_new { int __pyx_n; PyObject *name; }; /* "cpython/datetime.pxd":283 * * # Create datetime object using DB API constructor. * cdef inline datetime datetime_from_timestamp(timestamp, tz=None): # <<<<<<<<<<<<<< * return PyDateTimeAPI.DateTime_FromTimestamp( * PyDateTimeAPI.DateTimeType, (timestamp, tz) if tz is not None else (timestamp,), NULL) */ struct __pyx_opt_args_7cpython_8datetime_datetime_from_timestamp { int __pyx_n; PyObject *tz; }; struct __pyx_opt_args_10pyreadstat_16_readstat_parser_run_readstat_parser; /* "pyreadstat/_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; /* "pyreadstat/_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; /* "pyreadstat/_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; /* "pyreadstat/_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_parser.pyx":929 * * * cdef void run_readstat_parser(char * filename, data_container data, py_file_extension file_extension, long row_limit, long row_offset, object file_obj=None) except *: # <<<<<<<<<<<<<< * """ * Runs the parsing of the file by readstat library. */ struct __pyx_opt_args_10pyreadstat_16_readstat_parser_run_readstat_parser { int __pyx_n; PyObject *file_obj; }; /* "pyreadstat/_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); /* ExtTypeTest.proto */ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /* TupleAndListFromArray.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); #endif #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_METH_FASTCALL static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); #endif /* IncludeStringH.proto */ #include /* 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); /* fastcall.proto */ #if CYTHON_AVOID_BORROWED_REFS #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_PySequence_ITEM(args, i) #elif CYTHON_ASSUME_SAFE_MACROS #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_NewRef(__Pyx_PyTuple_GET_ITEM(args, i)) #else #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_XNewRef(PyTuple_GetItem(args, i)) #endif #define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) #define __Pyx_KwValues_VARARGS(args, nargs) NULL #define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) #define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) #if CYTHON_METH_FASTCALL #define __Pyx_ArgRef_FASTCALL(args, i) __Pyx_NewRef(args[i]) #define __Pyx_NumKwargs_FASTCALL(kwds) __Pyx_PyTuple_GET_SIZE(kwds) #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); #else #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) #endif #else #define __Pyx_ArgRef_FASTCALL __Pyx_ArgRef_VARARGS #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS #endif #define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) #if CYTHON_METH_FASTCALL || (CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) #define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(args + start, stop - start) #else #define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) #endif /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* RejectKeywords.proto */ static void __Pyx_RejectKeywords(const char* function_name, PyObject *kwds); /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static CYTHON_INLINE int __Pyx_ParseKeywords( PyObject *kwds, PyObject *const *kwvalues, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs ); /* 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) /* 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); /* 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 /* 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 /* PyObjectDelAttr.proto */ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 #define __Pyx_PyObject_DelAttr(o, n) PyObject_SetAttr(o, n, NULL) #else #define __Pyx_PyObject_DelAttr(o, n) PyObject_DelAttr(o, n) #endif /* PyObjectSetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); #else #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_DelAttr(o,n) #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) #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)); } /* ModFloat[double].proto */ static CYTHON_INLINE double __Pyx_mod_double(double, double, int b_is_constant); /* 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 /* 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); /* 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 /* RaiseUnboundLocalError.proto */ static void __Pyx_RaiseUnboundLocalError(const char *varname); /* PyUnicode_Unicode.proto */ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj); /* PyObjectFormatAndDecref.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); /* JoinPyUnicode.proto */ static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength, Py_UCS4 max_char); /* 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 /* PyObject_Unicode.proto */ #define __Pyx_PyObject_Unicode(obj)\ (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj)) /* UnicodeConcatInPlace.proto */ # if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_REFNANNY #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right, __pyx_refnanny) #else #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right) #endif static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right #if CYTHON_REFNANNY , void* __pyx_refnanny #endif ); #else #define __Pyx_PyUnicode_ConcatInPlace __Pyx_PyUnicode_Concat #endif #define __Pyx_PyUnicode_ConcatInPlaceSafe(left, right) ((unlikely((left) == Py_None) || unlikely((right) == Py_None)) ?\ PyNumber_InPlaceAdd(left, right) : __Pyx_PyUnicode_ConcatInPlace(left, right)) /* PyUnicodeContains.proto */ static CYTHON_INLINE int __Pyx_PyUnicode_ContainsTF(PyObject* substring, PyObject* text, int eq) { int result = PyUnicode_Contains(text, substring); return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); } /* 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 /* SetItemInt.proto */ #define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck, has_gil)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\ (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\ __Pyx_SetItemInt_Generic(o, to_py_func(i), v))) static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v); static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list, int wraparound, int boundscheck); /* 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 /* SliceObject.proto */ #define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)\ __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) static CYTHON_INLINE int __Pyx_PyObject_SetSlice( PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** py_start, PyObject** py_stop, PyObject** py_slice, int has_cstart, int has_cstop, int wraparound); /* 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 /* RaiseUnexpectedTypeError.proto */ static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj); /* PyObjectCallOneArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* PyObjectGetMethod.proto */ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); /* PyObjectCallMethod1.proto */ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); /* append.proto */ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /* 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 /* SliceObject.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** py_start, PyObject** py_stop, PyObject** py_slice, int has_cstart, int has_cstop, int wraparound); /* py_dict_keys.proto */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d); /* 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 /* 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 /* 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); /* 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 /* py_dict_items.proto */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d); /* 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 /* 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 /* 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); /* 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); /* ListExtend.proto */ static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) { #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00a2 return PyList_Extend(L, v); #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 PyObject* none = _PyList_Extend((PyListObject*)L, v); if (unlikely(!none)) return -1; Py_DECREF(none); return 0; #else return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v); #endif } /* CallTypeTraverse.proto */ #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000) #define __Pyx_call_type_traverse(o, always_call, visit, arg) 0 #else static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg); #endif /* LimitedApiGetTypeDict.proto */ #if CYTHON_COMPILING_IN_LIMITED_API static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp); #endif /* SetItemOnTypeDict.proto */ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v); #define __Pyx_SetItemOnTypeDict(tp, k, v) __Pyx__SetItemOnTypeDict((PyTypeObject*)tp, k, v) /* FixUpExtensionType.proto */ static CYTHON_INLINE int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); /* PyObjectCallMethod0.proto */ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); /* ValidateBasesTuple.proto */ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); #endif /* PyType_Ready.proto */ CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); /* DelItemOnTypeDict.proto */ static int __Pyx__DelItemOnTypeDict(PyTypeObject *tp, PyObject *k); #define __Pyx_DelItemOnTypeDict(tp, k) __Pyx__DelItemOnTypeDict((PyTypeObject*)tp, k) /* SetupReduce.proto */ static int __Pyx_setup_reduce(PyObject* type_obj); /* 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 #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 /* ListPack.proto */ static PyObject *__Pyx_PyList_Pack(Py_ssize_t n, ...); /* ImportFrom.proto */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /* FetchSharedCythonModule.proto */ static PyObject *__Pyx_FetchSharedCythonABIModule(void); /* dict_setdefault.proto */ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type); /* FetchCommonType.proto */ static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases); /* CommonTypesMetaclass.proto */ static int __pyx_CommonTypesMetaclass_init(PyObject *module); #define __Pyx_CommonTypesMetaclass_USED /* PyMethodNew.proto */ static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ); /* PyVectorcallFastCallDict.proto */ #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); #endif /* CythonFunctionShared.proto */ #define __Pyx_CyFunction_USED #define __Pyx_CYFUNCTION_STATICMETHOD 0x01 #define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 #define __Pyx_CYFUNCTION_CCLASS 0x04 #define __Pyx_CYFUNCTION_COROUTINE 0x08 #define __Pyx_CyFunction_GetClosure(f)\ (((__pyx_CyFunctionObject *) (f))->func_closure) #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API #define __Pyx_CyFunction_GetClassObj(f)\ (((__pyx_CyFunctionObject *) (f))->func_classobj) #else #define __Pyx_CyFunction_GetClassObj(f)\ ((PyObject*) ((PyCMethodObject *) (f))->mm_class) #endif #define __Pyx_CyFunction_SetClassObj(f, classobj)\ __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) #define __Pyx_CyFunction_Defaults(type, f)\ ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) #define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) typedef struct { #if CYTHON_COMPILING_IN_LIMITED_API PyObject_HEAD PyObject *func; #elif PY_VERSION_HEX < 0x030900B1 PyCFunctionObject func; #else PyCMethodObject func; #endif #if CYTHON_BACKPORT_VECTORCALL ||\ (CYTHON_COMPILING_IN_LIMITED_API && CYTHON_METH_FASTCALL) __pyx_vectorcallfunc func_vectorcall; #endif #if CYTHON_COMPILING_IN_LIMITED_API PyObject *func_weakreflist; #endif PyObject *func_dict; PyObject *func_name; PyObject *func_qualname; PyObject *func_doc; PyObject *func_globals; PyObject *func_code; PyObject *func_closure; #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API PyObject *func_classobj; #endif PyObject *defaults; int flags; PyObject *defaults_tuple; PyObject *defaults_kwdict; PyObject *(*defaults_getter)(PyObject *); PyObject *func_annotations; PyObject *func_is_coroutine; } __pyx_CyFunctionObject; #undef __Pyx_CyOrPyCFunction_Check #define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_mstate_global->__pyx_CyFunctionType) #define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_mstate_global->__pyx_CyFunctionType, &PyCFunction_Type) #define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_mstate_global->__pyx_CyFunctionType) static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void (*cfunc)(void)); #undef __Pyx_IsSameCFunction #define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject *globals, PyObject* code); static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); static CYTHON_INLINE PyObject *__Pyx_CyFunction_InitDefaults(PyObject *func, PyTypeObject *defaults_type); static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, PyObject *tuple); static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, PyObject *dict); static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, PyObject *dict); static int __pyx_CyFunction_init(PyObject *module); #if CYTHON_METH_FASTCALL static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); #if CYTHON_BACKPORT_VECTORCALL || CYTHON_COMPILING_IN_LIMITED_API #define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) #else #define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) #endif #endif /* CythonFunction.proto */ static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject *globals, PyObject* code); /* SetNameInClass.proto */ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 #define __Pyx_SetNameInClass(ns, name, value)\ (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value)) #elif CYTHON_COMPILING_IN_CPYTHON #define __Pyx_SetNameInClass(ns, name, value)\ (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value)) #else #define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value) #endif /* CalculateMetaclass.proto */ static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases); /* PyObjectLookupSpecial.proto */ #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS #define __Pyx_PyObject_LookupSpecialNoError(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 0) #define __Pyx_PyObject_LookupSpecial(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 1) static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error); #else #define __Pyx_PyObject_LookupSpecialNoError(o,n) __Pyx_PyObject_GetAttrStrNoError(o,n) #define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) #endif /* Py3ClassCreate.proto */ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc); static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /* Py3UpdateBases.proto */ static PyObject* __Pyx_PEP560_update_bases(PyObject *bases); /* 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); /* GCCDiagnostics.proto */ #if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #define __Pyx_HAS_GCC_DIAGNOSTIC #endif /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_readstat_type_t(readstat_type_t value); /* 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 __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(PyObject *); /* 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_char(char value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format value); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyLong_As_long(PyObject *); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_off_t(off_t value); /* CIntFromPy.proto */ static CYTHON_INLINE off_t __Pyx_PyLong_As_off_t(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 /* 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); /* VoidPtrExport.proto */ static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig); /* FunctionExport.proto */ static int __Pyx_ExportFunction(const char *name, 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 "." static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4date_4year_year(PyDateTime_Date *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4date_5month_month(PyDateTime_Date *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4date_3day_day(PyDateTime_Date *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_4hour_hour(PyDateTime_Time *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_6minute_minute(PyDateTime_Time *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_6second_second(PyDateTime_Time *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_11microsecond_microsecond(PyDateTime_Time *__pyx_v_self); /* proto*/ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_4time_6tzinfo_tzinfo(PyDateTime_Time *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_4fold_fold(PyDateTime_Time *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_4year_year(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_5month_month(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_3day_day(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_4hour_hour(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_6minute_minute(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_6second_second(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_11microsecond_microsecond(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_8datetime_6tzinfo_tzinfo(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_4fold_fold(PyDateTime_DateTime *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_9timedelta_3day_day(PyDateTime_Delta *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_9timedelta_6second_second(PyDateTime_Delta *__pyx_v_self); /* proto*/ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_9timedelta_11microsecond_microsecond(PyDateTime_Delta *__pyx_v_self); /* proto*/ /* Module declarations from "libc.stddef" */ /* Module declarations from "pyreadstat.readstat_api" */ /* Module declarations from "libc.string" */ /* Module declarations from "libc.stdio" */ /* Module declarations from "__builtin__" */ /* Module declarations from "cpython.type" */ /* Module declarations from "cpython" */ /* Module declarations from "cpython.object" */ /* Module declarations from "cpython.version" */ /* Module declarations from "datetime" */ /* Module declarations from "cpython.datetime" */ static CYTHON_INLINE void __pyx_f_7cpython_8datetime_import_datetime(void); /*proto*/ static CYTHON_INLINE PyDateTime_DateTime *__pyx_f_7cpython_8datetime_datetime_new(int, int, int, int, int, int, int, PyObject *, struct __pyx_opt_args_7cpython_8datetime_datetime_new *__pyx_optional_args); /*proto*/ static CYTHON_INLINE PyDateTime_Delta *__pyx_f_7cpython_8datetime_timedelta_new(int, int, int); /*proto*/ static CYTHON_INLINE double __pyx_f_7cpython_8datetime_total_seconds(PyDateTime_Delta *); /*proto*/ /* Module declarations from "cpython.exc" */ /* Module declarations from "libc.math" */ /* Module declarations from "pyreadstat._readstat_parser" */ static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_sas_origin = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_spss_origin = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_stata_origin = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_unix_origin = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_sas_secs_from_unix = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_spss_secs_from_unix = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser_stata_secs_from_unix = 0; static PyObject *__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx = 0; static __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_f_10pyreadstat_16_readstat_parser_transform_variable_format(PyObject *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format); /*proto*/ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_transform_datetime(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, double, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format, PyObject *, int, PyObject *, double); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_metadata(readstat_metadata_t *, void *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_variable(int, readstat_variable_t *, char *, void *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_value(int, readstat_variable_t *, readstat_value_t, void *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_value_label(char *, readstat_value_t, char *, void *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_note(int, char *, void *); /*proto*/ static void __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_error_t); /*proto*/ static void __pyx_f_10pyreadstat_16_readstat_parser_run_readstat_parser(char *, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension, long, long, struct __pyx_opt_args_10pyreadstat_16_readstat_parser_run_readstat_parser *__pyx_optional_args); /*proto*/ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_data_container_to_dict(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *); /*proto*/ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_dict_to_dataframe(PyObject *, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *); /*proto*/ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_data_container_extract_metadata(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *); /*proto*/ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_convert_readstat_to_python_value(readstat_value_t, int, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_open(char const *, void *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_pyobject_open_handler(char const *, void *); /*proto*/ static int __pyx_f_10pyreadstat_16_readstat_parser_pyobject_close_handler(void *); /*proto*/ static Py_ssize_t __pyx_f_10pyreadstat_16_readstat_parser_pyobject_read_handler(void *, size_t, void *); /*proto*/ static readstat_off_t __pyx_f_10pyreadstat_16_readstat_parser_pyobject_seek_handler(readstat_off_t, readstat_io_flags_t, void *); /*proto*/ /* #### Code section: typeinfo ### */ /* #### Code section: before_global_var ### */ #define __Pyx_MODULE_NAME "pyreadstat._readstat_parser" extern int __pyx_module_is_main_pyreadstat___readstat_parser; int __pyx_module_is_main_pyreadstat___readstat_parser = 0; /* Implementation of "pyreadstat._readstat_parser" */ /* #### Code section: global_var ### */ static PyObject *__pyx_builtin_object; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_all; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_zip; static PyObject *__pyx_builtin_UnicodeError; /* #### Code section: string_decls ### */ static const char __pyx_k_[] = ""; static const char __pyx_k_Q[] = "\200\001\330\004\n\210+\220Q"; static const char __pyx_k_d[] = "d"; static const char __pyx_k_s[] = "s"; static const char __pyx_k__2[] = "'"; static const char __pyx_k__3[] = "."; static const char __pyx_k__4[] = "?"; static const char __pyx_k_gc[] = "gc"; static const char __pyx_k_hi[] = "hi"; static const char __pyx_k_lo[] = "lo"; static const char __pyx_k_np[] = "np"; static const char __pyx_k_nt[] = "nt"; static const char __pyx_k_nw[] = "nw"; static const char __pyx_k_os[] = "os"; static const char __pyx_k_tC[] = "%tC"; static const char __pyx_k_tc[] = "%tc"; static const char __pyx_k_td[] = "%td"; static const char __pyx_k_v2[] = "v2"; static const char __pyx_k_TOD[] = "TOD"; static const char __pyx_k_all[] = "all"; static const char __pyx_k_col[] = "col"; static const char __pyx_k_d_2[] = "%d"; static const char __pyx_k_doc[] = "__doc__"; static const char __pyx_k_get[] = "get"; static const char __pyx_k_loc[] = "loc"; static const char __pyx_k_nan[] = "nan"; static const char __pyx_k_pop[] = "pop"; static const char __pyx_k_sys[] = "sys"; static const char __pyx_k_zip[] = "zip"; static const char __pyx_k_DATE[] = "DATE"; static const char __pyx_k_HHMM[] = "HHMM"; static const char __pyx_k_None[] = "None"; static const char __pyx_k_TIME[] = "TIME"; static const char __pyx_k_copy[] = "copy"; static const char __pyx_k_date[] = "date"; static const char __pyx_k_dict[] = "dict"; static const char __pyx_k_fill[] = "fill"; static const char __pyx_k_func[] = "__func__"; static const char __pyx_k_init[] = "__init__"; static const char __pyx_k_int8[] = "int8"; 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_read[] = "read"; static const char __pyx_k_seek[] = "seek"; static const char __pyx_k_self[] = "self"; static const char __pyx_k_spec[] = "__spec__"; static const char __pyx_k_tell[] = "tell"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_time[] = "time"; static const char __pyx_k_type[] = "type"; static const char __pyx_k_warn[] = "warn"; static const char __pyx_k_ADATE[] = "ADATE"; static const char __pyx_k_DATE8[] = "DATE8"; static const char __pyx_k_DATE9[] = "DATE9"; static const char __pyx_k_DTIME[] = "DTIME"; static const char __pyx_k_EDATE[] = "EDATE"; static const char __pyx_k_JDATE[] = "JDATE"; static const char __pyx_k_M8_ns[] = " 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_7cpython_4type_type; PyTypeObject *__pyx_ptype_7cpython_8datetime_date; PyTypeObject *__pyx_ptype_7cpython_8datetime_time; PyTypeObject *__pyx_ptype_7cpython_8datetime_datetime; PyTypeObject *__pyx_ptype_7cpython_8datetime_timedelta; PyTypeObject *__pyx_ptype_7cpython_8datetime_tzinfo; PyObject *__pyx_type_10pyreadstat_16_readstat_parser_data_container; 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; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop; PyObject *__pyx_slice[1]; PyObject *__pyx_tuple[2]; PyObject *__pyx_codeobj_tab[3]; PyObject *__pyx_string_tab[298]; PyObject *__pyx_int_0; PyObject *__pyx_int_1; PyObject *__pyx_int_100000; /* #### Code section: module_state_contents ### */ /* CommonTypesMetaclass.module_state_decls */ PyTypeObject *__pyx_CommonTypesMetaclassType; /* CachedMethodType.module_state_decls */ #if CYTHON_COMPILING_IN_LIMITED_API PyObject *__Pyx_CachedMethodType; #endif /* 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_b_ __pyx_string_tab[0] #define __pyx_kp_u_ __pyx_string_tab[1] #define __pyx_n_u_ADATE __pyx_string_tab[2] #define __pyx_n_u_ADATE10 __pyx_string_tab[3] #define __pyx_n_u_ADATE8 __pyx_string_tab[4] #define __pyx_n_u_B8601DA __pyx_string_tab[5] #define __pyx_n_u_B8601DN __pyx_string_tab[6] #define __pyx_n_u_B8601DT __pyx_string_tab[7] #define __pyx_n_u_B8601TM __pyx_string_tab[8] #define __pyx_n_u_DATE __pyx_string_tab[9] #define __pyx_n_u_DATE11 __pyx_string_tab[10] #define __pyx_n_u_DATE12 __pyx_string_tab[11] #define __pyx_n_u_DATE8 __pyx_string_tab[12] #define __pyx_n_u_DATE9 __pyx_string_tab[13] #define __pyx_n_u_DATEAMPM __pyx_string_tab[14] #define __pyx_n_u_DATETIME __pyx_string_tab[15] #define __pyx_n_u_DATETIME17 __pyx_string_tab[16] #define __pyx_n_u_DATETIME18 __pyx_string_tab[17] #define __pyx_n_u_DATETIME19 __pyx_string_tab[18] #define __pyx_n_u_DATETIME20 __pyx_string_tab[19] #define __pyx_n_u_DATETIME21 __pyx_string_tab[20] #define __pyx_n_u_DATETIME22 __pyx_string_tab[21] #define __pyx_kp_u_DATETIME23_2 __pyx_string_tab[22] #define __pyx_n_u_DATETIME8 __pyx_string_tab[23] #define __pyx_n_u_DDMMYY __pyx_string_tab[24] #define __pyx_n_u_DDMMYYB __pyx_string_tab[25] #define __pyx_n_u_DDMMYYB10 __pyx_string_tab[26] #define __pyx_n_u_DDMMYYC __pyx_string_tab[27] #define __pyx_n_u_DDMMYYC10 __pyx_string_tab[28] #define __pyx_n_u_DDMMYYD __pyx_string_tab[29] #define __pyx_n_u_DDMMYYD10 __pyx_string_tab[30] #define __pyx_n_u_DDMMYYN6 __pyx_string_tab[31] #define __pyx_n_u_DDMMYYN8 __pyx_string_tab[32] #define __pyx_n_u_DDMMYYP __pyx_string_tab[33] #define __pyx_n_u_DDMMYYP10 __pyx_string_tab[34] #define __pyx_n_u_DDMMYYS __pyx_string_tab[35] #define __pyx_n_u_DDMMYYS10 __pyx_string_tab[36] #define __pyx_n_u_DTDATE __pyx_string_tab[37] #define __pyx_n_u_DTIME __pyx_string_tab[38] #define __pyx_n_u_E8601DA __pyx_string_tab[39] #define __pyx_n_u_E8601DT __pyx_string_tab[40] #define __pyx_n_u_E8601TM __pyx_string_tab[41] #define __pyx_n_u_EDATE __pyx_string_tab[42] #define __pyx_n_u_EDATE10 __pyx_string_tab[43] #define __pyx_n_u_EDATE8 __pyx_string_tab[44] #define __pyx_kp_u_Failed_convert_C_to_python_value __pyx_string_tab[45] #define __pyx_kp_u_Failed_to_read_number_of_variabl __pyx_string_tab[46] #define __pyx_kp_u_File_0_does_not_exist __pyx_string_tab[47] #define __pyx_n_u_HHMM __pyx_string_tab[48] #define __pyx_n_u_IS8601DA __pyx_string_tab[49] #define __pyx_n_u_IS8601DT __pyx_string_tab[50] #define __pyx_n_u_IS8601TM __pyx_string_tab[51] #define __pyx_n_u_JDATE __pyx_string_tab[52] #define __pyx_n_u_JDATE5 __pyx_string_tab[53] #define __pyx_n_u_JDATE7 __pyx_string_tab[54] #define __pyx_kp_u_Just_defining_a_custom_exceptio __pyx_string_tab[55] #define __pyx_kp_u_Just_defining_a_custom_exceptio_2 __pyx_string_tab[56] #define __pyx_kp_u_M8_ns __pyx_string_tab[57] #define __pyx_n_u_MDYAMPM __pyx_string_tab[58] #define __pyx_n_u_MMDDYY __pyx_string_tab[59] #define __pyx_n_u_MMDDYYB __pyx_string_tab[60] #define __pyx_n_u_MMDDYYB10 __pyx_string_tab[61] #define __pyx_n_u_MMDDYYC __pyx_string_tab[62] #define __pyx_n_u_MMDDYYC10 __pyx_string_tab[63] #define __pyx_n_u_MMDDYYD __pyx_string_tab[64] #define __pyx_n_u_MMDDYYD10 __pyx_string_tab[65] #define __pyx_n_u_MMDDYYN6 __pyx_string_tab[66] #define __pyx_n_u_MMDDYYN8 __pyx_string_tab[67] #define __pyx_n_u_MMDDYYP __pyx_string_tab[68] #define __pyx_n_u_MMDDYYP10 __pyx_string_tab[69] #define __pyx_n_u_MMDDYYS __pyx_string_tab[70] #define __pyx_n_u_MMDDYYS10 __pyx_string_tab[71] #define __pyx_kp_u_None __pyx_string_tab[72] #define __pyx_n_u_Object __pyx_string_tab[73] #define __pyx_n_u_OrderedDict __pyx_string_tab[74] #define __pyx_n_u_PyreadstatError __pyx_string_tab[75] #define __pyx_n_u_ReadstatError __pyx_string_tab[76] #define __pyx_n_u_SDATE __pyx_string_tab[77] #define __pyx_n_u_SDATE10 __pyx_string_tab[78] #define __pyx_n_u_SDATE8 __pyx_string_tab[79] #define __pyx_kp_u_STRING_type_with_value __pyx_string_tab[80] #define __pyx_n_u_TIME __pyx_string_tab[81] #define __pyx_kp_u_TIME11_2 __pyx_string_tab[82] #define __pyx_n_u_TIME20 __pyx_string_tab[83] #define __pyx_kp_u_TIME20_3 __pyx_string_tab[84] #define __pyx_n_u_TIME5 __pyx_string_tab[85] #define __pyx_n_u_TIME8 __pyx_string_tab[86] #define __pyx_n_u_TIMEAMPM __pyx_string_tab[87] #define __pyx_n_u_TOD __pyx_string_tab[88] #define __pyx_kp_u_This_class_holds_metadata_we_wa __pyx_string_tab[89] #define __pyx_n_u_TypeError __pyx_string_tab[90] #define __pyx_n_u_UnicodeError __pyx_string_tab[91] #define __pyx_kp_u_Unknown_file_format __pyx_string_tab[92] #define __pyx_kp_u_Unkown_data_type __pyx_string_tab[93] #define __pyx_n_u_WEEKDATE __pyx_string_tab[94] #define __pyx_n_u_WEEKDATX __pyx_string_tab[95] #define __pyx_n_u_YMDHMS16 __pyx_string_tab[96] #define __pyx_n_u_YMDHMS19 __pyx_string_tab[97] #define __pyx_kp_u_YMDHMS19_2 __pyx_string_tab[98] #define __pyx_n_u_YMDHMS20 __pyx_string_tab[99] #define __pyx_n_u_YYMMDD __pyx_string_tab[100] #define __pyx_n_u_YYMMDD10 __pyx_string_tab[101] #define __pyx_n_u_YYMMDDB __pyx_string_tab[102] #define __pyx_n_u_YYMMDDD __pyx_string_tab[103] #define __pyx_n_u_YYMMDDN __pyx_string_tab[104] #define __pyx_n_u_YYMMDDP __pyx_string_tab[105] #define __pyx_n_u_YYMMDDS __pyx_string_tab[106] #define __pyx_kp_u_You_requested_pandas_as_output_f __pyx_string_tab[107] #define __pyx_kp_u_You_requested_polars_as_output_f __pyx_string_tab[108] #define __pyx_kp_u__2 __pyx_string_tab[109] #define __pyx_kp_u__3 __pyx_string_tab[110] #define __pyx_kp_u__4 __pyx_string_tab[111] #define __pyx_n_u_all __pyx_string_tab[112] #define __pyx_n_u_allowed_formats __pyx_string_tab[113] #define __pyx_n_u_append __pyx_string_tab[114] #define __pyx_n_u_astype __pyx_string_tab[115] #define __pyx_n_u_asyncio_coroutines __pyx_string_tab[116] #define __pyx_n_u_backend __pyx_string_tab[117] #define __pyx_n_u_center __pyx_string_tab[118] #define __pyx_n_u_class_getitem __pyx_string_tab[119] #define __pyx_n_u_cline_in_traceback __pyx_string_tab[120] #define __pyx_n_u_col __pyx_string_tab[121] #define __pyx_n_u_collections __pyx_string_tab[122] #define __pyx_kp_u_column_0_is_duplicated_renamed_t __pyx_string_tab[123] #define __pyx_n_u_column_labels __pyx_string_tab[124] #define __pyx_n_u_column_names __pyx_string_tab[125] #define __pyx_n_u_column_names_to_labels __pyx_string_tab[126] #define __pyx_n_u_columns __pyx_string_tab[127] #define __pyx_n_u_copy __pyx_string_tab[128] #define __pyx_n_u_counted_value __pyx_string_tab[129] #define __pyx_n_u_creation_time __pyx_string_tab[130] #define __pyx_n_u_d __pyx_string_tab[131] #define __pyx_kp_u_d_2 __pyx_string_tab[132] #define __pyx_n_u_data_container __pyx_string_tab[133] #define __pyx_n_u_data_container___reduce_cython __pyx_string_tab[134] #define __pyx_n_u_data_container___setstate_cython __pyx_string_tab[135] #define __pyx_n_u_date __pyx_string_tab[136] #define __pyx_n_u_datetime __pyx_string_tab[137] #define __pyx_n_u_dict __pyx_string_tab[138] #define __pyx_kp_u_disable __pyx_string_tab[139] #define __pyx_n_u_doc __pyx_string_tab[140] #define __pyx_n_u_double __pyx_string_tab[141] #define __pyx_n_u_dtype __pyx_string_tab[142] #define __pyx_n_u_dtypes __pyx_string_tab[143] #define __pyx_n_u_duplicated __pyx_string_tab[144] #define __pyx_n_u_empty __pyx_string_tab[145] #define __pyx_kp_u_enable __pyx_string_tab[146] #define __pyx_n_u_encode __pyx_string_tab[147] #define __pyx_n_u_enumerate __pyx_string_tab[148] #define __pyx_n_u_expanduser __pyx_string_tab[149] #define __pyx_n_u_extend __pyx_string_tab[150] #define __pyx_n_u_file_encoding __pyx_string_tab[151] #define __pyx_n_u_file_label __pyx_string_tab[152] #define __pyx_kp_u_file_path_could_not_be_encoded_w __pyx_string_tab[153] #define __pyx_n_u_fill __pyx_string_tab[154] #define __pyx_n_u_float __pyx_string_tab[155] #define __pyx_n_u_float64 __pyx_string_tab[156] #define __pyx_n_u_format __pyx_string_tab[157] #define __pyx_n_u_from_dict __pyx_string_tab[158] #define __pyx_n_u_from_epoch __pyx_string_tab[159] #define __pyx_n_u_fromtimestamp __pyx_string_tab[160] #define __pyx_n_u_fsdecode __pyx_string_tab[161] #define __pyx_n_u_fsencode __pyx_string_tab[162] #define __pyx_n_u_func __pyx_string_tab[163] #define __pyx_kp_u_gc __pyx_string_tab[164] #define __pyx_n_u_get __pyx_string_tab[165] #define __pyx_n_u_get_native_namespace __pyx_string_tab[166] #define __pyx_n_u_getfilesystemencoding __pyx_string_tab[167] #define __pyx_n_u_getstate __pyx_string_tab[168] #define __pyx_n_u_hi __pyx_string_tab[169] #define __pyx_n_u_init __pyx_string_tab[170] #define __pyx_n_u_initializing __pyx_string_tab[171] #define __pyx_n_u_int16 __pyx_string_tab[172] #define __pyx_n_u_int32 __pyx_string_tab[173] #define __pyx_n_u_int64 __pyx_string_tab[174] #define __pyx_n_u_int8 __pyx_string_tab[175] #define __pyx_n_u_is_coroutine __pyx_string_tab[176] #define __pyx_n_u_is_dichotomy __pyx_string_tab[177] #define __pyx_kp_u_isenabled __pyx_string_tab[178] #define __pyx_n_u_isfile __pyx_string_tab[179] #define __pyx_n_u_items __pyx_string_tab[180] #define __pyx_n_u_keys __pyx_string_tab[181] #define __pyx_n_u_label __pyx_string_tab[182] #define __pyx_n_u_left __pyx_string_tab[183] #define __pyx_n_u_lo __pyx_string_tab[184] #define __pyx_n_u_loc __pyx_string_tab[185] #define __pyx_n_u_main __pyx_string_tab[186] #define __pyx_n_u_metaclass __pyx_string_tab[187] #define __pyx_n_u_metadata_container __pyx_string_tab[188] #define __pyx_n_u_metadata_container___init __pyx_string_tab[189] #define __pyx_n_u_missing_ranges __pyx_string_tab[190] #define __pyx_n_u_missing_user_values __pyx_string_tab[191] #define __pyx_n_u_modification_time __pyx_string_tab[192] #define __pyx_n_u_module __pyx_string_tab[193] #define __pyx_n_u_mr_sets __pyx_string_tab[194] #define __pyx_n_u_mro_entries __pyx_string_tab[195] #define __pyx_n_u_name __pyx_string_tab[196] #define __pyx_n_u_name_2 __pyx_string_tab[197] #define __pyx_n_u_nan __pyx_string_tab[198] #define __pyx_n_u_narwhals __pyx_string_tab[199] #define __pyx_n_u_narwhals_stable_v2 __pyx_string_tab[200] #define __pyx_kp_u_no_default___reduce___due_to_non __pyx_string_tab[201] #define __pyx_n_u_nominal __pyx_string_tab[202] #define __pyx_n_u_notes __pyx_string_tab[203] #define __pyx_n_u_np __pyx_string_tab[204] #define __pyx_n_u_nt __pyx_string_tab[205] #define __pyx_n_u_number_columns __pyx_string_tab[206] #define __pyx_n_u_number_rows __pyx_string_tab[207] #define __pyx_n_u_numpy __pyx_string_tab[208] #define __pyx_n_u_nw __pyx_string_tab[209] #define __pyx_n_u_object __pyx_string_tab[210] #define __pyx_n_u_ordinal __pyx_string_tab[211] #define __pyx_n_u_original_variable_types __pyx_string_tab[212] #define __pyx_n_u_os __pyx_string_tab[213] #define __pyx_n_u_output_format __pyx_string_tab[214] #define __pyx_kp_u_output_format_must_be_one_of_all __pyx_string_tab[215] #define __pyx_n_u_pandas __pyx_string_tab[216] #define __pyx_n_u_path __pyx_string_tab[217] #define __pyx_kp_u_path_must_be_either_str_or_bytes __pyx_string_tab[218] #define __pyx_kp_u_path_must_be_str_bytes_or_unicod __pyx_string_tab[219] #define __pyx_n_u_polars __pyx_string_tab[220] #define __pyx_n_u_pop __pyx_string_tab[221] #define __pyx_n_u_prepare __pyx_string_tab[222] #define __pyx_n_u_pyreadstat__readstat_parser __pyx_string_tab[223] #define __pyx_kp_u_pyreadstat__readstat_parser_pyx __pyx_string_tab[224] #define __pyx_n_u_pyx_capi __pyx_string_tab[225] #define __pyx_n_u_pyx_state __pyx_string_tab[226] #define __pyx_n_u_qualname __pyx_string_tab[227] #define __pyx_n_u_range __pyx_string_tab[228] #define __pyx_n_u_read __pyx_string_tab[229] #define __pyx_n_u_readstat_to_numpy_types __pyx_string_tab[230] #define __pyx_n_u_readstat_variable_types __pyx_string_tab[231] #define __pyx_n_u_reduce __pyx_string_tab[232] #define __pyx_n_u_reduce_cython __pyx_string_tab[233] #define __pyx_n_u_reduce_ex __pyx_string_tab[234] #define __pyx_n_u_right __pyx_string_tab[235] #define __pyx_n_u_s __pyx_string_tab[236] #define __pyx_n_u_sas_all_formats __pyx_string_tab[237] #define __pyx_n_u_sas_date_formats __pyx_string_tab[238] #define __pyx_n_u_sas_datetime_formats __pyx_string_tab[239] #define __pyx_n_u_sas_origin __pyx_string_tab[240] #define __pyx_n_u_sas_time_formats __pyx_string_tab[241] #define __pyx_n_u_scale __pyx_string_tab[242] #define __pyx_n_u_schema __pyx_string_tab[243] #define __pyx_n_u_seek __pyx_string_tab[244] #define __pyx_n_u_self __pyx_string_tab[245] #define __pyx_n_u_set_name __pyx_string_tab[246] #define __pyx_n_u_setstate __pyx_string_tab[247] #define __pyx_n_u_setstate_cython __pyx_string_tab[248] #define __pyx_n_u_spec __pyx_string_tab[249] #define __pyx_n_u_spss_all_formats __pyx_string_tab[250] #define __pyx_n_u_spss_date_formats __pyx_string_tab[251] #define __pyx_n_u_spss_datetime_formats __pyx_string_tab[252] #define __pyx_n_u_spss_origin __pyx_string_tab[253] #define __pyx_n_u_spss_time_formats __pyx_string_tab[254] #define __pyx_n_u_stable __pyx_string_tab[255] #define __pyx_n_u_stata_all_formats __pyx_string_tab[256] #define __pyx_n_u_stata_date_formats __pyx_string_tab[257] #define __pyx_n_u_stata_datetime_formats __pyx_string_tab[258] #define __pyx_n_u_stata_origin __pyx_string_tab[259] #define __pyx_n_u_stata_time_formats __pyx_string_tab[260] #define __pyx_n_u_string __pyx_string_tab[261] #define __pyx_kp_u_stringsource __pyx_string_tab[262] #define __pyx_n_u_surrogateescape __pyx_string_tab[263] #define __pyx_n_u_sys __pyx_string_tab[264] #define __pyx_kp_u_tC __pyx_string_tab[265] #define __pyx_n_u_table_name __pyx_string_tab[266] #define __pyx_kp_u_tc __pyx_string_tab[267] #define __pyx_kp_u_tcHH_MM __pyx_string_tab[268] #define __pyx_kp_u_tcHH_MM_SS __pyx_string_tab[269] #define __pyx_kp_u_td __pyx_string_tab[270] #define __pyx_kp_u_tdCCYY_NN_DD __pyx_string_tab[271] #define __pyx_kp_u_tdD_m_Y __pyx_string_tab[272] #define __pyx_n_u_tell __pyx_string_tab[273] #define __pyx_n_u_test __pyx_string_tab[274] #define __pyx_n_u_time __pyx_string_tab[275] #define __pyx_n_u_time_unit __pyx_string_tab[276] #define __pyx_n_u_to_datetime __pyx_string_tab[277] #define __pyx_n_u_to_native __pyx_string_tab[278] #define __pyx_n_u_tolist __pyx_string_tab[279] #define __pyx_n_u_type __pyx_string_tab[280] #define __pyx_n_u_undetermined __pyx_string_tab[281] #define __pyx_n_u_unknown __pyx_string_tab[282] #define __pyx_kp_u_utf_8 __pyx_string_tab[283] #define __pyx_n_u_v2 __pyx_string_tab[284] #define __pyx_n_u_value_labels __pyx_string_tab[285] #define __pyx_n_u_variable_alignment __pyx_string_tab[286] #define __pyx_n_u_variable_display_width __pyx_string_tab[287] #define __pyx_n_u_variable_list __pyx_string_tab[288] #define __pyx_n_u_variable_measure __pyx_string_tab[289] #define __pyx_n_u_variable_storage_width __pyx_string_tab[290] #define __pyx_n_u_variable_to_label __pyx_string_tab[291] #define __pyx_n_u_variable_value_labels __pyx_string_tab[292] #define __pyx_n_u_warn __pyx_string_tab[293] #define __pyx_n_u_warnings __pyx_string_tab[294] #define __pyx_n_u_with_columns __pyx_string_tab[295] #define __pyx_kp_u_with_date_type_in_column __pyx_string_tab[296] #define __pyx_n_u_zip __pyx_string_tab[297] /* #### 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_7cpython_4type_type); Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_8datetime_date); Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_8datetime_time); Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_8datetime_datetime); Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_8datetime_timedelta); Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_8datetime_tzinfo); Py_CLEAR(clear_module_state->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container); Py_CLEAR(clear_module_state->__pyx_type_10pyreadstat_16_readstat_parser_data_container); for (int i=0; i<1; ++i) { Py_CLEAR(clear_module_state->__pyx_slice[i]); } for (int i=0; i<2; ++i) { Py_CLEAR(clear_module_state->__pyx_tuple[i]); } for (int i=0; i<3; ++i) { Py_CLEAR(clear_module_state->__pyx_codeobj_tab[i]); } for (int i=0; i<298; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); } Py_CLEAR(clear_module_state->__pyx_int_0); Py_CLEAR(clear_module_state->__pyx_int_1); Py_CLEAR(clear_module_state->__pyx_int_100000); 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_7cpython_4type_type); Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_8datetime_date); Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_8datetime_time); Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_8datetime_datetime); Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_8datetime_timedelta); Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_8datetime_tzinfo); Py_VISIT(traverse_module_state->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container); Py_VISIT(traverse_module_state->__pyx_type_10pyreadstat_16_readstat_parser_data_container); for (int i=0; i<1; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_slice[i]); } for (int i=0; i<2; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_tuple[i]); } for (int i=0; i<3; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_codeobj_tab[i]); } for (int i=0; i<298; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); } __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_100000); return 0; } #endif /* #### Code section: module_code ### */ /* "cpython/datetime.pxd":44 * * ctypedef extern class datetime.date[object PyDateTime_Date]: * @property # <<<<<<<<<<<<<< * cdef inline int year(self) noexcept: * return PyDateTime_GET_YEAR(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4date_4year_year(PyDateTime_Date *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":46 * @property * cdef inline int year(self) noexcept: * return PyDateTime_GET_YEAR(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_GET_YEAR(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":44 * * ctypedef extern class datetime.date[object PyDateTime_Date]: * @property # <<<<<<<<<<<<<< * cdef inline int year(self) noexcept: * return PyDateTime_GET_YEAR(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":48 * return PyDateTime_GET_YEAR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int month(self) noexcept: * return PyDateTime_GET_MONTH(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4date_5month_month(PyDateTime_Date *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":50 * @property * cdef inline int month(self) noexcept: * return PyDateTime_GET_MONTH(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_GET_MONTH(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":48 * return PyDateTime_GET_YEAR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int month(self) noexcept: * return PyDateTime_GET_MONTH(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":52 * return PyDateTime_GET_MONTH(self) * * @property # <<<<<<<<<<<<<< * cdef inline int day(self) noexcept: * return PyDateTime_GET_DAY(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4date_3day_day(PyDateTime_Date *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":54 * @property * cdef inline int day(self) noexcept: * return PyDateTime_GET_DAY(self) # <<<<<<<<<<<<<< * * ctypedef extern class datetime.time[object PyDateTime_Time]: */ __pyx_r = PyDateTime_GET_DAY(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":52 * return PyDateTime_GET_MONTH(self) * * @property # <<<<<<<<<<<<<< * cdef inline int day(self) noexcept: * return PyDateTime_GET_DAY(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":57 * * ctypedef extern class datetime.time[object PyDateTime_Time]: * @property # <<<<<<<<<<<<<< * cdef inline int hour(self) noexcept: * return PyDateTime_TIME_GET_HOUR(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_4hour_hour(PyDateTime_Time *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":59 * @property * cdef inline int hour(self) noexcept: * return PyDateTime_TIME_GET_HOUR(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_TIME_GET_HOUR(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":57 * * ctypedef extern class datetime.time[object PyDateTime_Time]: * @property # <<<<<<<<<<<<<< * cdef inline int hour(self) noexcept: * return PyDateTime_TIME_GET_HOUR(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":61 * return PyDateTime_TIME_GET_HOUR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int minute(self) noexcept: * return PyDateTime_TIME_GET_MINUTE(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_6minute_minute(PyDateTime_Time *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":63 * @property * cdef inline int minute(self) noexcept: * return PyDateTime_TIME_GET_MINUTE(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_TIME_GET_MINUTE(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":61 * return PyDateTime_TIME_GET_HOUR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int minute(self) noexcept: * return PyDateTime_TIME_GET_MINUTE(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":65 * return PyDateTime_TIME_GET_MINUTE(self) * * @property # <<<<<<<<<<<<<< * cdef inline int second(self) noexcept: * return PyDateTime_TIME_GET_SECOND(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_6second_second(PyDateTime_Time *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":67 * @property * cdef inline int second(self) noexcept: * return PyDateTime_TIME_GET_SECOND(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_TIME_GET_SECOND(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":65 * return PyDateTime_TIME_GET_MINUTE(self) * * @property # <<<<<<<<<<<<<< * cdef inline int second(self) noexcept: * return PyDateTime_TIME_GET_SECOND(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":69 * return PyDateTime_TIME_GET_SECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline int microsecond(self) noexcept: * return PyDateTime_TIME_GET_MICROSECOND(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_11microsecond_microsecond(PyDateTime_Time *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":71 * @property * cdef inline int microsecond(self) noexcept: * return PyDateTime_TIME_GET_MICROSECOND(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_TIME_GET_MICROSECOND(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":69 * return PyDateTime_TIME_GET_SECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline int microsecond(self) noexcept: * return PyDateTime_TIME_GET_MICROSECOND(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":73 * return PyDateTime_TIME_GET_MICROSECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline object tzinfo(self): * return PyDateTime_TIME_GET_TZINFO(self) */ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_4time_6tzinfo_tzinfo(PyDateTime_Time *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1; __Pyx_RefNannySetupContext("tzinfo", 0); /* "cpython/datetime.pxd":75 * @property * cdef inline object tzinfo(self): * return PyDateTime_TIME_GET_TZINFO(self) # <<<<<<<<<<<<<< * * @property */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyDateTime_TIME_GET_TZINFO(((PyObject *)__pyx_v_self)); __Pyx_INCREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); goto __pyx_L0; /* "cpython/datetime.pxd":73 * return PyDateTime_TIME_GET_MICROSECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline object tzinfo(self): * return PyDateTime_TIME_GET_TZINFO(self) */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":77 * return PyDateTime_TIME_GET_TZINFO(self) * * @property # <<<<<<<<<<<<<< * cdef inline int fold(self) noexcept: * # For Python < 3.6 this returns 0 no matter what */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_4time_4fold_fold(PyDateTime_Time *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":80 * cdef inline int fold(self) noexcept: * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_TIME_GET_FOLD(self) # <<<<<<<<<<<<<< * * ctypedef extern class datetime.datetime[object PyDateTime_DateTime]: */ __pyx_r = PyDateTime_TIME_GET_FOLD(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":77 * return PyDateTime_TIME_GET_TZINFO(self) * * @property # <<<<<<<<<<<<<< * cdef inline int fold(self) noexcept: * # For Python < 3.6 this returns 0 no matter what */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":83 * * ctypedef extern class datetime.datetime[object PyDateTime_DateTime]: * @property # <<<<<<<<<<<<<< * cdef inline int year(self) noexcept: * return PyDateTime_GET_YEAR(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_4year_year(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":85 * @property * cdef inline int year(self) noexcept: * return PyDateTime_GET_YEAR(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_GET_YEAR(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":83 * * ctypedef extern class datetime.datetime[object PyDateTime_DateTime]: * @property # <<<<<<<<<<<<<< * cdef inline int year(self) noexcept: * return PyDateTime_GET_YEAR(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":87 * return PyDateTime_GET_YEAR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int month(self) noexcept: * return PyDateTime_GET_MONTH(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_5month_month(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":89 * @property * cdef inline int month(self) noexcept: * return PyDateTime_GET_MONTH(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_GET_MONTH(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":87 * return PyDateTime_GET_YEAR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int month(self) noexcept: * return PyDateTime_GET_MONTH(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":91 * return PyDateTime_GET_MONTH(self) * * @property # <<<<<<<<<<<<<< * cdef inline int day(self) noexcept: * return PyDateTime_GET_DAY(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_3day_day(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":93 * @property * cdef inline int day(self) noexcept: * return PyDateTime_GET_DAY(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_GET_DAY(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":91 * return PyDateTime_GET_MONTH(self) * * @property # <<<<<<<<<<<<<< * cdef inline int day(self) noexcept: * return PyDateTime_GET_DAY(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":95 * return PyDateTime_GET_DAY(self) * * @property # <<<<<<<<<<<<<< * cdef inline int hour(self) noexcept: * return PyDateTime_DATE_GET_HOUR(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_4hour_hour(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":97 * @property * cdef inline int hour(self) noexcept: * return PyDateTime_DATE_GET_HOUR(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_DATE_GET_HOUR(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":95 * return PyDateTime_GET_DAY(self) * * @property # <<<<<<<<<<<<<< * cdef inline int hour(self) noexcept: * return PyDateTime_DATE_GET_HOUR(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":99 * return PyDateTime_DATE_GET_HOUR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int minute(self) noexcept: * return PyDateTime_DATE_GET_MINUTE(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_6minute_minute(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":101 * @property * cdef inline int minute(self) noexcept: * return PyDateTime_DATE_GET_MINUTE(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_DATE_GET_MINUTE(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":99 * return PyDateTime_DATE_GET_HOUR(self) * * @property # <<<<<<<<<<<<<< * cdef inline int minute(self) noexcept: * return PyDateTime_DATE_GET_MINUTE(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":103 * return PyDateTime_DATE_GET_MINUTE(self) * * @property # <<<<<<<<<<<<<< * cdef inline int second(self) noexcept: * return PyDateTime_DATE_GET_SECOND(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_6second_second(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":105 * @property * cdef inline int second(self) noexcept: * return PyDateTime_DATE_GET_SECOND(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_DATE_GET_SECOND(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":103 * return PyDateTime_DATE_GET_MINUTE(self) * * @property # <<<<<<<<<<<<<< * cdef inline int second(self) noexcept: * return PyDateTime_DATE_GET_SECOND(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":107 * return PyDateTime_DATE_GET_SECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline int microsecond(self) noexcept: * return PyDateTime_DATE_GET_MICROSECOND(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_11microsecond_microsecond(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":109 * @property * cdef inline int microsecond(self) noexcept: * return PyDateTime_DATE_GET_MICROSECOND(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_DATE_GET_MICROSECOND(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":107 * return PyDateTime_DATE_GET_SECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline int microsecond(self) noexcept: * return PyDateTime_DATE_GET_MICROSECOND(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":111 * return PyDateTime_DATE_GET_MICROSECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline object tzinfo(self): * return PyDateTime_DATE_GET_TZINFO(self) */ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_8datetime_6tzinfo_tzinfo(PyDateTime_DateTime *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1; __Pyx_RefNannySetupContext("tzinfo", 0); /* "cpython/datetime.pxd":113 * @property * cdef inline object tzinfo(self): * return PyDateTime_DATE_GET_TZINFO(self) # <<<<<<<<<<<<<< * * @property */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyDateTime_DATE_GET_TZINFO(((PyObject *)__pyx_v_self)); __Pyx_INCREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); goto __pyx_L0; /* "cpython/datetime.pxd":111 * return PyDateTime_DATE_GET_MICROSECOND(self) * * @property # <<<<<<<<<<<<<< * cdef inline object tzinfo(self): * return PyDateTime_DATE_GET_TZINFO(self) */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":115 * return PyDateTime_DATE_GET_TZINFO(self) * * @property # <<<<<<<<<<<<<< * cdef inline int fold(self) noexcept: * # For Python < 3.6 this returns 0 no matter what */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_8datetime_4fold_fold(PyDateTime_DateTime *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":118 * cdef inline int fold(self) noexcept: * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_DATE_GET_FOLD(self) # <<<<<<<<<<<<<< * * ctypedef extern class datetime.timedelta[object PyDateTime_Delta]: */ __pyx_r = PyDateTime_DATE_GET_FOLD(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":115 * return PyDateTime_DATE_GET_TZINFO(self) * * @property # <<<<<<<<<<<<<< * cdef inline int fold(self) noexcept: * # For Python < 3.6 this returns 0 no matter what */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":121 * * ctypedef extern class datetime.timedelta[object PyDateTime_Delta]: * @property # <<<<<<<<<<<<<< * cdef inline int day(self) noexcept: * return PyDateTime_DELTA_GET_DAYS(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_9timedelta_3day_day(PyDateTime_Delta *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":123 * @property * cdef inline int day(self) noexcept: * return PyDateTime_DELTA_GET_DAYS(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_DELTA_GET_DAYS(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":121 * * ctypedef extern class datetime.timedelta[object PyDateTime_Delta]: * @property # <<<<<<<<<<<<<< * cdef inline int day(self) noexcept: * return PyDateTime_DELTA_GET_DAYS(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":125 * return PyDateTime_DELTA_GET_DAYS(self) * * @property # <<<<<<<<<<<<<< * cdef inline int second(self) noexcept: * return PyDateTime_DELTA_GET_SECONDS(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_9timedelta_6second_second(PyDateTime_Delta *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":127 * @property * cdef inline int second(self) noexcept: * return PyDateTime_DELTA_GET_SECONDS(self) # <<<<<<<<<<<<<< * * @property */ __pyx_r = PyDateTime_DELTA_GET_SECONDS(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":125 * return PyDateTime_DELTA_GET_DAYS(self) * * @property # <<<<<<<<<<<<<< * cdef inline int second(self) noexcept: * return PyDateTime_DELTA_GET_SECONDS(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":129 * return PyDateTime_DELTA_GET_SECONDS(self) * * @property # <<<<<<<<<<<<<< * cdef inline int microsecond(self) noexcept: * return PyDateTime_DELTA_GET_MICROSECONDS(self) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_9timedelta_11microsecond_microsecond(PyDateTime_Delta *__pyx_v_self) { int __pyx_r; /* "cpython/datetime.pxd":131 * @property * cdef inline int microsecond(self) noexcept: * return PyDateTime_DELTA_GET_MICROSECONDS(self) # <<<<<<<<<<<<<< * * ctypedef extern class datetime.tzinfo[object PyDateTime_TZInfo]: */ __pyx_r = PyDateTime_DELTA_GET_MICROSECONDS(((PyObject *)__pyx_v_self)); goto __pyx_L0; /* "cpython/datetime.pxd":129 * return PyDateTime_DELTA_GET_SECONDS(self) * * @property # <<<<<<<<<<<<<< * cdef inline int microsecond(self) noexcept: * return PyDateTime_DELTA_GET_MICROSECONDS(self) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":255 * # Datetime C API initialization function. * # You have to call it before any usage of DateTime CAPI functions. * cdef inline void import_datetime() noexcept: # <<<<<<<<<<<<<< * PyDateTime_IMPORT * */ static CYTHON_INLINE void __pyx_f_7cpython_8datetime_import_datetime(void) { /* "cpython/datetime.pxd":256 * # You have to call it before any usage of DateTime CAPI functions. * cdef inline void import_datetime() noexcept: * PyDateTime_IMPORT # <<<<<<<<<<<<<< * * # Create date object using DateTime CAPI factory function. */ (void)(PyDateTime_IMPORT); /* "cpython/datetime.pxd":255 * # Datetime C API initialization function. * # You have to call it before any usage of DateTime CAPI functions. * cdef inline void import_datetime() noexcept: # <<<<<<<<<<<<<< * PyDateTime_IMPORT * */ /* function exit code */ } /* "cpython/datetime.pxd":260 * # Create date object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline date date_new(int year, int month, int day): # <<<<<<<<<<<<<< * return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType) * */ static CYTHON_INLINE PyDateTime_Date *__pyx_f_7cpython_8datetime_date_new(int __pyx_v_year, int __pyx_v_month, int __pyx_v_day) { PyDateTime_Date *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("date_new", 0); /* "cpython/datetime.pxd":261 * # Note, there are no range checks for any of the arguments. * cdef inline date date_new(int year, int month, int day): * return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType) # <<<<<<<<<<<<<< * * # Create time object using DateTime CAPI factory function */ __Pyx_XDECREF((PyObject *)__pyx_r); __pyx_t_1 = ((PyObject *)PyDateTimeAPI->Date_FromDate(__pyx_v_year, __pyx_v_month, __pyx_v_day, PyDateTimeAPI->DateType)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = ((PyDateTime_Date *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":260 * # Create date object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline date date_new(int year, int month, int day): # <<<<<<<<<<<<<< * return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("cpython.datetime.date_new", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":265 * # Create time object using DateTime CAPI factory function * # Note, there are no range checks for any of the arguments. * cdef inline time time_new(int hour, int minute, int second, int microsecond, object tz, int fold=0): # <<<<<<<<<<<<<< * return __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) * */ static CYTHON_INLINE PyDateTime_Time *__pyx_f_7cpython_8datetime_time_new(int __pyx_v_hour, int __pyx_v_minute, int __pyx_v_second, int __pyx_v_microsecond, PyObject *__pyx_v_tz, struct __pyx_opt_args_7cpython_8datetime_time_new *__pyx_optional_args) { int __pyx_v_fold = ((int)0); PyDateTime_Time *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("time_new", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_fold = __pyx_optional_args->fold; } } /* "cpython/datetime.pxd":266 * # Note, there are no range checks for any of the arguments. * cdef inline time time_new(int hour, int minute, int second, int microsecond, object tz, int fold=0): * return __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) # <<<<<<<<<<<<<< * * # Create datetime object using DateTime CAPI factory function. */ __Pyx_XDECREF((PyObject *)__pyx_r); __pyx_t_1 = ((PyObject *)__Pyx_DateTime_TimeWithFold(__pyx_v_hour, __pyx_v_minute, __pyx_v_second, __pyx_v_microsecond, __pyx_v_tz, __pyx_v_fold)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 266, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_7cpython_8datetime_time))))) __PYX_ERR(2, 266, __pyx_L1_error) __pyx_r = ((PyDateTime_Time *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":265 * # Create time object using DateTime CAPI factory function * # Note, there are no range checks for any of the arguments. * cdef inline time time_new(int hour, int minute, int second, int microsecond, object tz, int fold=0): # <<<<<<<<<<<<<< * return __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("cpython.datetime.time_new", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":270 * # Create datetime object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline datetime datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz, int fold=0): # <<<<<<<<<<<<<< * return __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) * */ static CYTHON_INLINE PyDateTime_DateTime *__pyx_f_7cpython_8datetime_datetime_new(int __pyx_v_year, int __pyx_v_month, int __pyx_v_day, int __pyx_v_hour, int __pyx_v_minute, int __pyx_v_second, int __pyx_v_microsecond, PyObject *__pyx_v_tz, struct __pyx_opt_args_7cpython_8datetime_datetime_new *__pyx_optional_args) { int __pyx_v_fold = ((int)0); PyDateTime_DateTime *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("datetime_new", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_fold = __pyx_optional_args->fold; } } /* "cpython/datetime.pxd":271 * # Note, there are no range checks for any of the arguments. * cdef inline datetime datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz, int fold=0): * return __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) # <<<<<<<<<<<<<< * * # Create timedelta object using DateTime CAPI factory function. */ __Pyx_XDECREF((PyObject *)__pyx_r); __pyx_t_1 = ((PyObject *)__Pyx_DateTime_DateTimeWithFold(__pyx_v_year, __pyx_v_month, __pyx_v_day, __pyx_v_hour, __pyx_v_minute, __pyx_v_second, __pyx_v_microsecond, __pyx_v_tz, __pyx_v_fold)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = ((PyDateTime_DateTime *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":270 * # Create datetime object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline datetime datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz, int fold=0): # <<<<<<<<<<<<<< * return __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("cpython.datetime.datetime_new", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":275 * # Create timedelta object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline timedelta timedelta_new(int days, int seconds, int useconds): # <<<<<<<<<<<<<< * return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, PyDateTimeAPI.DeltaType) * */ static CYTHON_INLINE PyDateTime_Delta *__pyx_f_7cpython_8datetime_timedelta_new(int __pyx_v_days, int __pyx_v_seconds, int __pyx_v_useconds) { PyDateTime_Delta *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("timedelta_new", 0); /* "cpython/datetime.pxd":276 * # Note, there are no range checks for any of the arguments. * cdef inline timedelta timedelta_new(int days, int seconds, int useconds): * return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, PyDateTimeAPI.DeltaType) # <<<<<<<<<<<<<< * * # Create timedelta object using DateTime CAPI factory function. */ __Pyx_XDECREF((PyObject *)__pyx_r); __pyx_t_1 = ((PyObject *)PyDateTimeAPI->Delta_FromDelta(__pyx_v_days, __pyx_v_seconds, __pyx_v_useconds, 1, PyDateTimeAPI->DeltaType)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 276, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = ((PyDateTime_Delta *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":275 * # Create timedelta object using DateTime CAPI factory function. * # Note, there are no range checks for any of the arguments. * cdef inline timedelta timedelta_new(int days, int seconds, int useconds): # <<<<<<<<<<<<<< * return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, PyDateTimeAPI.DeltaType) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("cpython.datetime.timedelta_new", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":279 * * # Create timedelta object using DateTime CAPI factory function. * cdef inline object timezone_new(object offset, object name=None): # <<<<<<<<<<<<<< * return __Pyx_TimeZone_FromOffsetAndName(offset, name if name is not None else NULL) * */ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_timezone_new(PyObject *__pyx_v_offset, struct __pyx_opt_args_7cpython_8datetime_timezone_new *__pyx_optional_args) { PyObject *__pyx_v_name = ((PyObject *)Py_None); PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("timezone_new", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_name = __pyx_optional_args->name; } } /* "cpython/datetime.pxd":280 * # Create timedelta object using DateTime CAPI factory function. * cdef inline object timezone_new(object offset, object name=None): * return __Pyx_TimeZone_FromOffsetAndName(offset, name if name is not None else NULL) # <<<<<<<<<<<<<< * * # Create datetime object using DB API constructor. */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = (__pyx_v_name != Py_None); if (__pyx_t_2) { __pyx_t_1 = ((PyObject *)__pyx_v_name); } else { __pyx_t_1 = NULL; } __pyx_t_3 = __Pyx_TimeZone_FromOffsetAndName(__pyx_v_offset, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":279 * * # Create timedelta object using DateTime CAPI factory function. * cdef inline object timezone_new(object offset, object name=None): # <<<<<<<<<<<<<< * return __Pyx_TimeZone_FromOffsetAndName(offset, name if name is not None else NULL) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("cpython.datetime.timezone_new", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":283 * * # Create datetime object using DB API constructor. * cdef inline datetime datetime_from_timestamp(timestamp, tz=None): # <<<<<<<<<<<<<< * return PyDateTimeAPI.DateTime_FromTimestamp( * PyDateTimeAPI.DateTimeType, (timestamp, tz) if tz is not None else (timestamp,), NULL) */ static CYTHON_INLINE PyDateTime_DateTime *__pyx_f_7cpython_8datetime_datetime_from_timestamp(PyObject *__pyx_v_timestamp, struct __pyx_opt_args_7cpython_8datetime_datetime_from_timestamp *__pyx_optional_args) { PyObject *__pyx_v_tz = ((PyObject *)Py_None); PyDateTime_DateTime *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("datetime_from_timestamp", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_tz = __pyx_optional_args->tz; } } /* "cpython/datetime.pxd":284 * # Create datetime object using DB API constructor. * cdef inline datetime datetime_from_timestamp(timestamp, tz=None): * return PyDateTimeAPI.DateTime_FromTimestamp( # <<<<<<<<<<<<<< * PyDateTimeAPI.DateTimeType, (timestamp, tz) if tz is not None else (timestamp,), NULL) * */ __Pyx_XDECREF((PyObject *)__pyx_r); /* "cpython/datetime.pxd":285 * cdef inline datetime datetime_from_timestamp(timestamp, tz=None): * return PyDateTimeAPI.DateTime_FromTimestamp( * PyDateTimeAPI.DateTimeType, (timestamp, tz) if tz is not None else (timestamp,), NULL) # <<<<<<<<<<<<<< * * # Create date object using DB API constructor. */ __pyx_t_2 = (__pyx_v_tz != Py_None); if (__pyx_t_2) { __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 285, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_timestamp); __Pyx_GIVEREF(__pyx_v_timestamp); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_timestamp) != (0)) __PYX_ERR(2, 285, __pyx_L1_error); __Pyx_INCREF(__pyx_v_tz); __Pyx_GIVEREF(__pyx_v_tz); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_tz) != (0)) __PYX_ERR(2, 285, __pyx_L1_error); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; } else { __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 285, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_timestamp); __Pyx_GIVEREF(__pyx_v_timestamp); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_timestamp) != (0)) __PYX_ERR(2, 285, __pyx_L1_error); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; } /* "cpython/datetime.pxd":284 * # Create datetime object using DB API constructor. * cdef inline datetime datetime_from_timestamp(timestamp, tz=None): * return PyDateTimeAPI.DateTime_FromTimestamp( # <<<<<<<<<<<<<< * PyDateTimeAPI.DateTimeType, (timestamp, tz) if tz is not None else (timestamp,), NULL) * */ __pyx_t_3 = ((PyObject *)PyDateTimeAPI->DateTime_FromTimestamp(((PyObject *)PyDateTimeAPI->DateTimeType), __pyx_t_1, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 284, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = ((PyDateTime_DateTime *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":283 * * # Create datetime object using DB API constructor. * cdef inline datetime datetime_from_timestamp(timestamp, tz=None): # <<<<<<<<<<<<<< * return PyDateTimeAPI.DateTime_FromTimestamp( * PyDateTimeAPI.DateTimeType, (timestamp, tz) if tz is not None else (timestamp,), NULL) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("cpython.datetime.datetime_from_timestamp", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":288 * * # Create date object using DB API constructor. * cdef inline date date_from_timestamp(timestamp): # <<<<<<<<<<<<<< * return PyDateTimeAPI.Date_FromTimestamp(PyDateTimeAPI.DateType, (timestamp,)) * */ static CYTHON_INLINE PyDateTime_Date *__pyx_f_7cpython_8datetime_date_from_timestamp(PyObject *__pyx_v_timestamp) { PyDateTime_Date *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("date_from_timestamp", 0); /* "cpython/datetime.pxd":289 * # Create date object using DB API constructor. * cdef inline date date_from_timestamp(timestamp): * return PyDateTimeAPI.Date_FromTimestamp(PyDateTimeAPI.DateType, (timestamp,)) # <<<<<<<<<<<<<< * * # More recognizable getters for date/time/datetime/timedelta. */ __Pyx_XDECREF((PyObject *)__pyx_r); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 289, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_timestamp); __Pyx_GIVEREF(__pyx_v_timestamp); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_timestamp) != (0)) __PYX_ERR(2, 289, __pyx_L1_error); __pyx_t_2 = ((PyObject *)PyDateTimeAPI->Date_FromTimestamp(((PyObject *)PyDateTimeAPI->DateType), __pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 289, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = ((PyDateTime_Date *)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; /* "cpython/datetime.pxd":288 * * # Create date object using DB API constructor. * cdef inline date date_from_timestamp(timestamp): # <<<<<<<<<<<<<< * return PyDateTimeAPI.Date_FromTimestamp(PyDateTimeAPI.DateType, (timestamp,)) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cpython.datetime.date_from_timestamp", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":297 * * # Get UTC singleton * cdef inline object get_utc(): # <<<<<<<<<<<<<< * return __Pyx_TimeZone_UTC * */ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_get_utc(void) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_utc", 0); /* "cpython/datetime.pxd":298 * # Get UTC singleton * cdef inline object get_utc(): * return __Pyx_TimeZone_UTC # <<<<<<<<<<<<<< * * # Get tzinfo of time */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__Pyx_TimeZone_UTC)); __pyx_r = ((PyObject *)__Pyx_TimeZone_UTC); goto __pyx_L0; /* "cpython/datetime.pxd":297 * * # Get UTC singleton * cdef inline object get_utc(): # <<<<<<<<<<<<<< * return __Pyx_TimeZone_UTC * */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":301 * * # Get tzinfo of time * cdef inline object time_tzinfo(object o): # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_TZINFO(o) * */ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_time_tzinfo(PyObject *__pyx_v_o) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1; __Pyx_RefNannySetupContext("time_tzinfo", 0); /* "cpython/datetime.pxd":302 * # Get tzinfo of time * cdef inline object time_tzinfo(object o): * return PyDateTime_TIME_GET_TZINFO(o) # <<<<<<<<<<<<<< * * # Get tzinfo of datetime */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyDateTime_TIME_GET_TZINFO(__pyx_v_o); __Pyx_INCREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); goto __pyx_L0; /* "cpython/datetime.pxd":301 * * # Get tzinfo of time * cdef inline object time_tzinfo(object o): # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_TZINFO(o) * */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":305 * * # Get tzinfo of datetime * cdef inline object datetime_tzinfo(object o): # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_TZINFO(o) * */ static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_datetime_tzinfo(PyObject *__pyx_v_o) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1; __Pyx_RefNannySetupContext("datetime_tzinfo", 0); /* "cpython/datetime.pxd":306 * # Get tzinfo of datetime * cdef inline object datetime_tzinfo(object o): * return PyDateTime_DATE_GET_TZINFO(o) # <<<<<<<<<<<<<< * * # Get year of date */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyDateTime_DATE_GET_TZINFO(__pyx_v_o); __Pyx_INCREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); goto __pyx_L0; /* "cpython/datetime.pxd":305 * * # Get tzinfo of datetime * cdef inline object datetime_tzinfo(object o): # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_TZINFO(o) * */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cpython/datetime.pxd":309 * * # Get year of date * cdef inline int date_year(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_YEAR(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_date_year(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":310 * # Get year of date * cdef inline int date_year(object o) noexcept: * return PyDateTime_GET_YEAR(o) # <<<<<<<<<<<<<< * * # Get month of date */ __pyx_r = PyDateTime_GET_YEAR(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":309 * * # Get year of date * cdef inline int date_year(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_YEAR(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":313 * * # Get month of date * cdef inline int date_month(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_MONTH(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_date_month(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":314 * # Get month of date * cdef inline int date_month(object o) noexcept: * return PyDateTime_GET_MONTH(o) # <<<<<<<<<<<<<< * * # Get day of date */ __pyx_r = PyDateTime_GET_MONTH(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":313 * * # Get month of date * cdef inline int date_month(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_MONTH(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":317 * * # Get day of date * cdef inline int date_day(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_DAY(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_date_day(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":318 * # Get day of date * cdef inline int date_day(object o) noexcept: * return PyDateTime_GET_DAY(o) # <<<<<<<<<<<<<< * * # Get year of datetime */ __pyx_r = PyDateTime_GET_DAY(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":317 * * # Get day of date * cdef inline int date_day(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_DAY(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":321 * * # Get year of datetime * cdef inline int datetime_year(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_YEAR(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_year(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":322 * # Get year of datetime * cdef inline int datetime_year(object o) noexcept: * return PyDateTime_GET_YEAR(o) # <<<<<<<<<<<<<< * * # Get month of datetime */ __pyx_r = PyDateTime_GET_YEAR(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":321 * * # Get year of datetime * cdef inline int datetime_year(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_YEAR(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":325 * * # Get month of datetime * cdef inline int datetime_month(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_MONTH(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_month(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":326 * # Get month of datetime * cdef inline int datetime_month(object o) noexcept: * return PyDateTime_GET_MONTH(o) # <<<<<<<<<<<<<< * * # Get day of datetime */ __pyx_r = PyDateTime_GET_MONTH(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":325 * * # Get month of datetime * cdef inline int datetime_month(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_MONTH(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":329 * * # Get day of datetime * cdef inline int datetime_day(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_DAY(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_day(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":330 * # Get day of datetime * cdef inline int datetime_day(object o) noexcept: * return PyDateTime_GET_DAY(o) # <<<<<<<<<<<<<< * * # Get hour of time */ __pyx_r = PyDateTime_GET_DAY(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":329 * * # Get day of datetime * cdef inline int datetime_day(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_GET_DAY(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":333 * * # Get hour of time * cdef inline int time_hour(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_HOUR(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_hour(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":334 * # Get hour of time * cdef inline int time_hour(object o) noexcept: * return PyDateTime_TIME_GET_HOUR(o) # <<<<<<<<<<<<<< * * # Get minute of time */ __pyx_r = PyDateTime_TIME_GET_HOUR(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":333 * * # Get hour of time * cdef inline int time_hour(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_HOUR(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":337 * * # Get minute of time * cdef inline int time_minute(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_MINUTE(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_minute(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":338 * # Get minute of time * cdef inline int time_minute(object o) noexcept: * return PyDateTime_TIME_GET_MINUTE(o) # <<<<<<<<<<<<<< * * # Get second of time */ __pyx_r = PyDateTime_TIME_GET_MINUTE(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":337 * * # Get minute of time * cdef inline int time_minute(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_MINUTE(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":341 * * # Get second of time * cdef inline int time_second(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_SECOND(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_second(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":342 * # Get second of time * cdef inline int time_second(object o) noexcept: * return PyDateTime_TIME_GET_SECOND(o) # <<<<<<<<<<<<<< * * # Get microsecond of time */ __pyx_r = PyDateTime_TIME_GET_SECOND(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":341 * * # Get second of time * cdef inline int time_second(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_SECOND(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":345 * * # Get microsecond of time * cdef inline int time_microsecond(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_MICROSECOND(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_microsecond(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":346 * # Get microsecond of time * cdef inline int time_microsecond(object o) noexcept: * return PyDateTime_TIME_GET_MICROSECOND(o) # <<<<<<<<<<<<<< * * # Get fold of time */ __pyx_r = PyDateTime_TIME_GET_MICROSECOND(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":345 * * # Get microsecond of time * cdef inline int time_microsecond(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_TIME_GET_MICROSECOND(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":349 * * # Get fold of time * cdef inline int time_fold(object o) noexcept: # <<<<<<<<<<<<<< * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_TIME_GET_FOLD(o) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_fold(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":351 * cdef inline int time_fold(object o) noexcept: * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_TIME_GET_FOLD(o) # <<<<<<<<<<<<<< * * # Get hour of datetime */ __pyx_r = PyDateTime_TIME_GET_FOLD(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":349 * * # Get fold of time * cdef inline int time_fold(object o) noexcept: # <<<<<<<<<<<<<< * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_TIME_GET_FOLD(o) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":354 * * # Get hour of datetime * cdef inline int datetime_hour(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_HOUR(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_hour(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":355 * # Get hour of datetime * cdef inline int datetime_hour(object o) noexcept: * return PyDateTime_DATE_GET_HOUR(o) # <<<<<<<<<<<<<< * * # Get minute of datetime */ __pyx_r = PyDateTime_DATE_GET_HOUR(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":354 * * # Get hour of datetime * cdef inline int datetime_hour(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_HOUR(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":358 * * # Get minute of datetime * cdef inline int datetime_minute(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_MINUTE(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_minute(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":359 * # Get minute of datetime * cdef inline int datetime_minute(object o) noexcept: * return PyDateTime_DATE_GET_MINUTE(o) # <<<<<<<<<<<<<< * * # Get second of datetime */ __pyx_r = PyDateTime_DATE_GET_MINUTE(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":358 * * # Get minute of datetime * cdef inline int datetime_minute(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_MINUTE(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":362 * * # Get second of datetime * cdef inline int datetime_second(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_SECOND(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_second(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":363 * # Get second of datetime * cdef inline int datetime_second(object o) noexcept: * return PyDateTime_DATE_GET_SECOND(o) # <<<<<<<<<<<<<< * * # Get microsecond of datetime */ __pyx_r = PyDateTime_DATE_GET_SECOND(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":362 * * # Get second of datetime * cdef inline int datetime_second(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_SECOND(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":366 * * # Get microsecond of datetime * cdef inline int datetime_microsecond(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_MICROSECOND(o) * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_microsecond(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":367 * # Get microsecond of datetime * cdef inline int datetime_microsecond(object o) noexcept: * return PyDateTime_DATE_GET_MICROSECOND(o) # <<<<<<<<<<<<<< * * # Get fold of datetime */ __pyx_r = PyDateTime_DATE_GET_MICROSECOND(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":366 * * # Get microsecond of datetime * cdef inline int datetime_microsecond(object o) noexcept: # <<<<<<<<<<<<<< * return PyDateTime_DATE_GET_MICROSECOND(o) * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":370 * * # Get fold of datetime * cdef inline int datetime_fold(object o) noexcept: # <<<<<<<<<<<<<< * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_DATE_GET_FOLD(o) */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_fold(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":372 * cdef inline int datetime_fold(object o) noexcept: * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_DATE_GET_FOLD(o) # <<<<<<<<<<<<<< * * # Get days of timedelta */ __pyx_r = PyDateTime_DATE_GET_FOLD(__pyx_v_o); goto __pyx_L0; /* "cpython/datetime.pxd":370 * * # Get fold of datetime * cdef inline int datetime_fold(object o) noexcept: # <<<<<<<<<<<<<< * # For Python < 3.6 this returns 0 no matter what * return PyDateTime_DATE_GET_FOLD(o) */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":375 * * # Get days of timedelta * cdef inline int timedelta_days(object o) noexcept: # <<<<<<<<<<<<<< * return (o).days * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_timedelta_days(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":376 * # Get days of timedelta * cdef inline int timedelta_days(object o) noexcept: * return (o).days # <<<<<<<<<<<<<< * * # Get seconds of timedelta */ __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->days; goto __pyx_L0; /* "cpython/datetime.pxd":375 * * # Get days of timedelta * cdef inline int timedelta_days(object o) noexcept: # <<<<<<<<<<<<<< * return (o).days * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":379 * * # Get seconds of timedelta * cdef inline int timedelta_seconds(object o) noexcept: # <<<<<<<<<<<<<< * return (o).seconds * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_timedelta_seconds(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":380 * # Get seconds of timedelta * cdef inline int timedelta_seconds(object o) noexcept: * return (o).seconds # <<<<<<<<<<<<<< * * # Get microseconds of timedelta */ __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->seconds; goto __pyx_L0; /* "cpython/datetime.pxd":379 * * # Get seconds of timedelta * cdef inline int timedelta_seconds(object o) noexcept: # <<<<<<<<<<<<<< * return (o).seconds * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":383 * * # Get microseconds of timedelta * cdef inline int timedelta_microseconds(object o) noexcept: # <<<<<<<<<<<<<< * return (o).microseconds * */ static CYTHON_INLINE int __pyx_f_7cpython_8datetime_timedelta_microseconds(PyObject *__pyx_v_o) { int __pyx_r; /* "cpython/datetime.pxd":384 * # Get microseconds of timedelta * cdef inline int timedelta_microseconds(object o) noexcept: * return (o).microseconds # <<<<<<<<<<<<<< * * cdef inline double total_seconds(timedelta obj) noexcept: */ __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->microseconds; goto __pyx_L0; /* "cpython/datetime.pxd":383 * * # Get microseconds of timedelta * cdef inline int timedelta_microseconds(object o) noexcept: # <<<<<<<<<<<<<< * return (o).microseconds * */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "cpython/datetime.pxd":386 * return (o).microseconds * * cdef inline double total_seconds(timedelta obj) noexcept: # <<<<<<<<<<<<<< * # Mirrors the "timedelta.total_seconds()" method. * # Note that this implementation is not guaranteed to give *exactly* the same */ static CYTHON_INLINE double __pyx_f_7cpython_8datetime_total_seconds(PyDateTime_Delta *__pyx_v_obj) { double __pyx_v_days; double __pyx_v_seconds; double __pyx_v_micros; double __pyx_r; /* "cpython/datetime.pxd":392 * cdef: * double days, seconds, micros * days = PyDateTime_DELTA_GET_DAYS(obj) # <<<<<<<<<<<<<< * seconds = PyDateTime_DELTA_GET_SECONDS(obj) * micros = PyDateTime_DELTA_GET_MICROSECONDS(obj) */ __pyx_v_days = ((double)PyDateTime_DELTA_GET_DAYS(((PyObject *)__pyx_v_obj))); /* "cpython/datetime.pxd":393 * double days, seconds, micros * days = PyDateTime_DELTA_GET_DAYS(obj) * seconds = PyDateTime_DELTA_GET_SECONDS(obj) # <<<<<<<<<<<<<< * micros = PyDateTime_DELTA_GET_MICROSECONDS(obj) * return days * 24 * 3600 + seconds + micros / 1_000_000 */ __pyx_v_seconds = ((double)PyDateTime_DELTA_GET_SECONDS(((PyObject *)__pyx_v_obj))); /* "cpython/datetime.pxd":394 * days = PyDateTime_DELTA_GET_DAYS(obj) * seconds = PyDateTime_DELTA_GET_SECONDS(obj) * micros = PyDateTime_DELTA_GET_MICROSECONDS(obj) # <<<<<<<<<<<<<< * return days * 24 * 3600 + seconds + micros / 1_000_000 */ __pyx_v_micros = ((double)PyDateTime_DELTA_GET_MICROSECONDS(((PyObject *)__pyx_v_obj))); /* "cpython/datetime.pxd":395 * seconds = PyDateTime_DELTA_GET_SECONDS(obj) * micros = PyDateTime_DELTA_GET_MICROSECONDS(obj) * return days * 24 * 3600 + seconds + micros / 1_000_000 # <<<<<<<<<<<<<< */ __pyx_r = ((((__pyx_v_days * 24.0) * 3600.0) + __pyx_v_seconds) + (__pyx_v_micros / 1000000.0)); goto __pyx_L0; /* "cpython/datetime.pxd":386 * return (o).microseconds * * cdef inline double total_seconds(timedelta obj) noexcept: # <<<<<<<<<<<<<< * # Mirrors the "timedelta.total_seconds()" method. * # Note that this implementation is not guaranteed to give *exactly* the same */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":85 * """ * * def __cinit__(self): # <<<<<<<<<<<<<< * self.n_obs = 0 * self.n_vars = 0 */ /* Python wrapper */ static int __pyx_pw_10pyreadstat_16_readstat_parser_14data_container_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_10pyreadstat_16_readstat_parser_14data_container_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { CYTHON_UNUSED Py_ssize_t __pyx_nargs; CYTHON_UNUSED PyObject *const *__pyx_kwvalues; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1; #endif __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, __pyx_nargs); return -1; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return -1; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__cinit__", __pyx_kwds); return -1;} __pyx_r = __pyx_pf_10pyreadstat_16_readstat_parser_14data_container___cinit__(((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_10pyreadstat_16_readstat_parser_14data_container___cinit__(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); /* "pyreadstat/_readstat_parser.pyx":86 * * def __cinit__(self): * self.n_obs = 0 # <<<<<<<<<<<<<< * self.n_vars = 0 * self.max_n_obs = 0 */ __pyx_v_self->n_obs = 0; /* "pyreadstat/_readstat_parser.pyx":87 * def __cinit__(self): * self.n_obs = 0 * self.n_vars = 0 # <<<<<<<<<<<<<< * self.max_n_obs = 0 * self.col_data = list() */ __pyx_v_self->n_vars = 0; /* "pyreadstat/_readstat_parser.pyx":88 * self.n_obs = 0 * self.n_vars = 0 * self.max_n_obs = 0 # <<<<<<<<<<<<<< * self.col_data = list() * self.col_data_len = list() */ __pyx_v_self->max_n_obs = 0; /* "pyreadstat/_readstat_parser.pyx":89 * self.n_vars = 0 * self.max_n_obs = 0 * self.col_data = list() # <<<<<<<<<<<<<< * self.col_data_len = list() * self.col_names = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_data); __Pyx_DECREF(__pyx_v_self->col_data); __pyx_v_self->col_data = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":90 * self.max_n_obs = 0 * self.col_data = list() * self.col_data_len = list() # <<<<<<<<<<<<<< * self.col_names = list() * self.col_labels = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_data_len); __Pyx_DECREF(__pyx_v_self->col_data_len); __pyx_v_self->col_data_len = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":91 * self.col_data = list() * self.col_data_len = list() * self.col_names = list() # <<<<<<<<<<<<<< * self.col_labels = list() * self.col_dtypes = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_names); __Pyx_DECREF(__pyx_v_self->col_names); __pyx_v_self->col_names = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":92 * self.col_data_len = list() * self.col_names = list() * self.col_labels = list() # <<<<<<<<<<<<<< * self.col_dtypes = list() * self.col_numpy_dtypes = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_labels); __Pyx_DECREF(__pyx_v_self->col_labels); __pyx_v_self->col_labels = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":93 * self.col_names = list() * self.col_labels = list() * self.col_dtypes = list() # <<<<<<<<<<<<<< * self.col_numpy_dtypes = list() * self.col_dtypes_isobject = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_dtypes); __Pyx_DECREF(__pyx_v_self->col_dtypes); __pyx_v_self->col_dtypes = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":94 * self.col_labels = list() * self.col_dtypes = list() * self.col_numpy_dtypes = list() # <<<<<<<<<<<<<< * self.col_dtypes_isobject = list() * self.col_dytpes_isfloat = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_numpy_dtypes); __Pyx_DECREF(__pyx_v_self->col_numpy_dtypes); __pyx_v_self->col_numpy_dtypes = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":95 * self.col_dtypes = list() * self.col_numpy_dtypes = list() * self.col_dtypes_isobject = list() # <<<<<<<<<<<<<< * self.col_dytpes_isfloat = list() * self.col_formats = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_dtypes_isobject); __Pyx_DECREF(__pyx_v_self->col_dtypes_isobject); __pyx_v_self->col_dtypes_isobject = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":96 * self.col_numpy_dtypes = list() * self.col_dtypes_isobject = list() * self.col_dytpes_isfloat = list() # <<<<<<<<<<<<<< * self.col_formats = list() * self.col_formats_original = list() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_dytpes_isfloat); __Pyx_DECREF(__pyx_v_self->col_dytpes_isfloat); __pyx_v_self->col_dytpes_isfloat = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":97 * self.col_dtypes_isobject = list() * self.col_dytpes_isfloat = list() * self.col_formats = list() # <<<<<<<<<<<<<< * self.col_formats_original = list() * self.origin = None */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_formats); __Pyx_DECREF(__pyx_v_self->col_formats); __pyx_v_self->col_formats = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":98 * self.col_dytpes_isfloat = list() * self.col_formats = list() * self.col_formats_original = list() # <<<<<<<<<<<<<< * self.origin = None * self.unix_to_origin_secs = 0 */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->col_formats_original); __Pyx_DECREF(__pyx_v_self->col_formats_original); __pyx_v_self->col_formats_original = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":99 * self.col_formats = list() * self.col_formats_original = list() * self.origin = None # <<<<<<<<<<<<<< * self.unix_to_origin_secs = 0 * self.is_unkown_number_rows = 0 */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->origin); __Pyx_DECREF(__pyx_v_self->origin); __pyx_v_self->origin = Py_None; /* "pyreadstat/_readstat_parser.pyx":100 * self.col_formats_original = list() * self.origin = None * self.unix_to_origin_secs = 0 # <<<<<<<<<<<<<< * self.is_unkown_number_rows = 0 * self.file_encoding = None */ __pyx_v_self->unix_to_origin_secs = 0.0; /* "pyreadstat/_readstat_parser.pyx":101 * self.origin = None * self.unix_to_origin_secs = 0 * self.is_unkown_number_rows = 0 # <<<<<<<<<<<<<< * self.file_encoding = None * self.file_label = None */ __pyx_v_self->is_unkown_number_rows = 0; /* "pyreadstat/_readstat_parser.pyx":102 * self.unix_to_origin_secs = 0 * self.is_unkown_number_rows = 0 * self.file_encoding = None # <<<<<<<<<<<<<< * self.file_label = None * self.metaonly = 0 */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->file_encoding); __Pyx_DECREF(__pyx_v_self->file_encoding); __pyx_v_self->file_encoding = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":103 * self.is_unkown_number_rows = 0 * self.file_encoding = None * self.file_label = None # <<<<<<<<<<<<<< * self.metaonly = 0 * self.dates_as_pandas = 0 */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->file_label); __Pyx_DECREF(__pyx_v_self->file_label); __pyx_v_self->file_label = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":104 * self.file_encoding = None * self.file_label = None * self.metaonly = 0 # <<<<<<<<<<<<<< * self.dates_as_pandas = 0 * self.label_to_var_name = dict() */ __pyx_v_self->metaonly = 0; /* "pyreadstat/_readstat_parser.pyx":105 * self.file_label = None * self.metaonly = 0 * self.dates_as_pandas = 0 # <<<<<<<<<<<<<< * self.label_to_var_name = dict() * self.labels_raw = dict() */ __pyx_v_self->dates_as_pandas = 0; /* "pyreadstat/_readstat_parser.pyx":106 * self.metaonly = 0 * self.dates_as_pandas = 0 * self.label_to_var_name = dict() # <<<<<<<<<<<<<< * self.labels_raw = dict() * self.notes = list() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->label_to_var_name); __Pyx_DECREF(__pyx_v_self->label_to_var_name); __pyx_v_self->label_to_var_name = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":107 * self.dates_as_pandas = 0 * self.label_to_var_name = dict() * self.labels_raw = dict() # <<<<<<<<<<<<<< * self.notes = list() * self.user_encoding = None */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->labels_raw); __Pyx_DECREF(__pyx_v_self->labels_raw); __pyx_v_self->labels_raw = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":108 * self.label_to_var_name = dict() * self.labels_raw = dict() * self.notes = list() # <<<<<<<<<<<<<< * self.user_encoding = None * self.table_name = None */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->notes); __Pyx_DECREF(__pyx_v_self->notes); __pyx_v_self->notes = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":109 * self.labels_raw = dict() * self.notes = list() * self.user_encoding = None # <<<<<<<<<<<<<< * self.table_name = None * self.filter_cols = 0 */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->user_encoding); __Pyx_DECREF(__pyx_v_self->user_encoding); __pyx_v_self->user_encoding = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":110 * self.notes = list() * self.user_encoding = None * self.table_name = None # <<<<<<<<<<<<<< * self.filter_cols = 0 * self.use_cols = list() */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->table_name); __Pyx_DECREF(__pyx_v_self->table_name); __pyx_v_self->table_name = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":111 * self.user_encoding = None * self.table_name = None * self.filter_cols = 0 # <<<<<<<<<<<<<< * self.use_cols = list() * self.usernan = 0 */ __pyx_v_self->filter_cols = 0; /* "pyreadstat/_readstat_parser.pyx":112 * self.table_name = None * self.filter_cols = 0 * self.use_cols = list() # <<<<<<<<<<<<<< * self.usernan = 0 * self.missing_ranges = dict() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->use_cols); __Pyx_DECREF(__pyx_v_self->use_cols); __pyx_v_self->use_cols = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":113 * self.filter_cols = 0 * self.use_cols = list() * self.usernan = 0 # <<<<<<<<<<<<<< * self.missing_ranges = dict() * self.missing_user_values = dict() */ __pyx_v_self->usernan = 0; /* "pyreadstat/_readstat_parser.pyx":114 * self.use_cols = list() * self.usernan = 0 * self.missing_ranges = dict() # <<<<<<<<<<<<<< * self.missing_user_values = dict() * self.variable_storage_width = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->missing_ranges); __Pyx_DECREF(__pyx_v_self->missing_ranges); __pyx_v_self->missing_ranges = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":115 * self.usernan = 0 * self.missing_ranges = dict() * self.missing_user_values = dict() # <<<<<<<<<<<<<< * self.variable_storage_width = dict() * self.variable_display_width = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->missing_user_values); __Pyx_DECREF(__pyx_v_self->missing_user_values); __pyx_v_self->missing_user_values = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":116 * self.missing_ranges = dict() * self.missing_user_values = dict() * self.variable_storage_width = dict() # <<<<<<<<<<<<<< * self.variable_display_width = dict() * self.variable_alignment = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->variable_storage_width); __Pyx_DECREF(__pyx_v_self->variable_storage_width); __pyx_v_self->variable_storage_width = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":117 * self.missing_user_values = dict() * self.variable_storage_width = dict() * self.variable_display_width = dict() # <<<<<<<<<<<<<< * self.variable_alignment = dict() * self.variable_measure = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->variable_display_width); __Pyx_DECREF(__pyx_v_self->variable_display_width); __pyx_v_self->variable_display_width = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":118 * self.variable_storage_width = dict() * self.variable_display_width = dict() * self.variable_alignment = dict() # <<<<<<<<<<<<<< * self.variable_measure = dict() * self.no_datetime_conversion = 0 */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->variable_alignment); __Pyx_DECREF(__pyx_v_self->variable_alignment); __pyx_v_self->variable_alignment = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":119 * self.variable_display_width = dict() * self.variable_alignment = dict() * self.variable_measure = dict() # <<<<<<<<<<<<<< * self.no_datetime_conversion = 0 * self.ctime = 0 */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->variable_measure); __Pyx_DECREF(__pyx_v_self->variable_measure); __pyx_v_self->variable_measure = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":120 * self.variable_alignment = dict() * self.variable_measure = dict() * self.no_datetime_conversion = 0 # <<<<<<<<<<<<<< * self.ctime = 0 * self.mtime = 0 */ __pyx_v_self->no_datetime_conversion = 0; /* "pyreadstat/_readstat_parser.pyx":121 * self.variable_measure = dict() * self.no_datetime_conversion = 0 * self.ctime = 0 # <<<<<<<<<<<<<< * self.mtime = 0 * self.mr_sets = dict() */ __pyx_v_self->ctime = 0; /* "pyreadstat/_readstat_parser.pyx":122 * self.no_datetime_conversion = 0 * self.ctime = 0 * self.mtime = 0 # <<<<<<<<<<<<<< * self.mr_sets = dict() * self.output_format = "" */ __pyx_v_self->mtime = 0; /* "pyreadstat/_readstat_parser.pyx":123 * self.ctime = 0 * self.mtime = 0 * self.mr_sets = dict() # <<<<<<<<<<<<<< * self.output_format = "" * */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->mr_sets); __Pyx_DECREF(__pyx_v_self->mr_sets); __pyx_v_self->mr_sets = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":124 * self.mtime = 0 * self.mr_sets = dict() * self.output_format = "" # <<<<<<<<<<<<<< * * class metadata_container: */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_kp_u_); __Pyx_GOTREF(__pyx_v_self->output_format); __Pyx_DECREF(__pyx_v_self->output_format); __pyx_v_self->output_format = __pyx_mstate_global->__pyx_kp_u_; /* "pyreadstat/_readstat_parser.pyx":85 * """ * * def __cinit__(self): # <<<<<<<<<<<<<< * self.n_obs = 0 * self.n_vars = 0 */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pyreadstat._readstat_parser.data_container.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_3__reduce_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_10pyreadstat_16_readstat_parser_14data_container_3__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_3__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_3__reduce_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__reduce_cython__", __pyx_kwds); return NULL;} __pyx_r = __pyx_pf_10pyreadstat_16_readstat_parser_14data_container_2__reduce_cython__(((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_16_readstat_parser_14data_container_2__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":2 * def __reduce_cython__(self): * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" */ __Pyx_Raise(__pyx_builtin_TypeError, __pyx_mstate_global->__pyx_kp_u_no_default___reduce___due_to_non, 0, 0); __PYX_ERR(1, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("pyreadstat._readstat_parser.data_container.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":3 * def __reduce_cython__(self): * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_5__setstate_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_10pyreadstat_16_readstat_parser_14data_container_5__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_5__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_5__setstate_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[1] = {0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_pyx_state,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(1, 3, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(1, 3, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__setstate_cython__", 0) < 0) __PYX_ERR(1, 3, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, i); __PYX_ERR(1, 3, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(1, 3, __pyx_L3_error) } __pyx_v___pyx_state = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(1, 3, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat._readstat_parser.data_container.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10pyreadstat_16_readstat_parser_14data_container_4__setstate_cython__(((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_v_self), __pyx_v___pyx_state); /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_16_readstat_parser_14data_container_4__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":4 * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" # <<<<<<<<<<<<<< */ __Pyx_Raise(__pyx_builtin_TypeError, __pyx_mstate_global->__pyx_kp_u_no_default___reduce___due_to_non, 0, 0); __PYX_ERR(1, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("pyreadstat._readstat_parser.data_container.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":130 * This class holds metadata we want to give back to python * """ * def __init__(self): # <<<<<<<<<<<<<< * self.column_names = list() * self.column_labels = list() */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_16_readstat_parser_18metadata_container_1__init__(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_10pyreadstat_16_readstat_parser_18metadata_container_1__init__ = {"__init__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_16_readstat_parser_18metadata_container_1__init__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10pyreadstat_16_readstat_parser_18metadata_container_1__init__(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_self = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[1] = {0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_self,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 130, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 130, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__init__", 0) < 0) __PYX_ERR(0, 130, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, i); __PYX_ERR(0, 130, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 130, __pyx_L3_error) } __pyx_v_self = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 130, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat._readstat_parser.metadata_container.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10pyreadstat_16_readstat_parser_18metadata_container___init__(__pyx_self, __pyx_v_self); /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_16_readstat_parser_18metadata_container___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "pyreadstat/_readstat_parser.pyx":131 * """ * def __init__(self): * self.column_names = list() # <<<<<<<<<<<<<< * self.column_labels = list() * self.column_names_to_labels = dict() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_column_names, __pyx_t_1) < 0) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":132 * def __init__(self): * self.column_names = list() * self.column_labels = list() # <<<<<<<<<<<<<< * self.column_names_to_labels = dict() * self.file_encoding = None */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_column_labels, __pyx_t_1) < 0) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":133 * self.column_names = list() * self.column_labels = list() * self.column_names_to_labels = dict() # <<<<<<<<<<<<<< * self.file_encoding = None * self.number_columns = None */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_column_names_to_labels, __pyx_t_1) < 0) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":134 * self.column_labels = list() * self.column_names_to_labels = dict() * self.file_encoding = None # <<<<<<<<<<<<<< * self.number_columns = None * self.number_rows = None */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_file_encoding, Py_None) < 0) __PYX_ERR(0, 134, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":135 * self.column_names_to_labels = dict() * self.file_encoding = None * self.number_columns = None # <<<<<<<<<<<<<< * self.number_rows = None * self.variable_value_labels = dict() */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_number_columns, Py_None) < 0) __PYX_ERR(0, 135, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":136 * self.file_encoding = None * self.number_columns = None * self.number_rows = None # <<<<<<<<<<<<<< * self.variable_value_labels = dict() * self.value_labels = dict() */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_number_rows, Py_None) < 0) __PYX_ERR(0, 136, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":137 * self.number_columns = None * self.number_rows = None * self.variable_value_labels = dict() # <<<<<<<<<<<<<< * self.value_labels = dict() * self.variable_to_label = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_variable_value_labels, __pyx_t_1) < 0) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":138 * self.number_rows = None * self.variable_value_labels = dict() * self.value_labels = dict() # <<<<<<<<<<<<<< * self.variable_to_label = dict() * self.notes = list() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_value_labels, __pyx_t_1) < 0) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":139 * self.variable_value_labels = dict() * self.value_labels = dict() * self.variable_to_label = dict() # <<<<<<<<<<<<<< * self.notes = list() * self.original_variable_types = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_variable_to_label, __pyx_t_1) < 0) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":140 * self.value_labels = dict() * self.variable_to_label = dict() * self.notes = list() # <<<<<<<<<<<<<< * self.original_variable_types = dict() * self.readstat_variable_types = dict() */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_notes, __pyx_t_1) < 0) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":141 * self.variable_to_label = dict() * self.notes = list() * self.original_variable_types = dict() # <<<<<<<<<<<<<< * self.readstat_variable_types = dict() * self.table_name = None */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_original_variable_types, __pyx_t_1) < 0) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":142 * self.notes = list() * self.original_variable_types = dict() * self.readstat_variable_types = dict() # <<<<<<<<<<<<<< * self.table_name = None * self.missing_ranges = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_readstat_variable_types, __pyx_t_1) < 0) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":143 * self.original_variable_types = dict() * self.readstat_variable_types = dict() * self.table_name = None # <<<<<<<<<<<<<< * self.missing_ranges = dict() * self.missing_user_values = dict() */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_table_name, Py_None) < 0) __PYX_ERR(0, 143, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":144 * self.readstat_variable_types = dict() * self.table_name = None * self.missing_ranges = dict() # <<<<<<<<<<<<<< * self.missing_user_values = dict() * self.variable_storage_width = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_missing_ranges, __pyx_t_1) < 0) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":145 * self.table_name = None * self.missing_ranges = dict() * self.missing_user_values = dict() # <<<<<<<<<<<<<< * self.variable_storage_width = dict() * self.variable_display_width = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_missing_user_values, __pyx_t_1) < 0) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":146 * self.missing_ranges = dict() * self.missing_user_values = dict() * self.variable_storage_width = dict() # <<<<<<<<<<<<<< * self.variable_display_width = dict() * self.variable_alignment = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_variable_storage_width, __pyx_t_1) < 0) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":147 * self.missing_user_values = dict() * self.variable_storage_width = dict() * self.variable_display_width = dict() # <<<<<<<<<<<<<< * self.variable_alignment = dict() * self.variable_measure = dict() */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_variable_display_width, __pyx_t_1) < 0) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":148 * self.variable_storage_width = dict() * self.variable_display_width = dict() * self.variable_alignment = dict() # <<<<<<<<<<<<<< * self.variable_measure = dict() * self.creation_time = None */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_variable_alignment, __pyx_t_1) < 0) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":149 * self.variable_display_width = dict() * self.variable_alignment = dict() * self.variable_measure = dict() # <<<<<<<<<<<<<< * self.creation_time = None * self.modification_time = None */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_variable_measure, __pyx_t_1) < 0) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":150 * self.variable_alignment = dict() * self.variable_measure = dict() * self.creation_time = None # <<<<<<<<<<<<<< * self.modification_time = None * self.mr_sets = dict() */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_creation_time, Py_None) < 0) __PYX_ERR(0, 150, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":151 * self.variable_measure = dict() * self.creation_time = None * self.modification_time = None # <<<<<<<<<<<<<< * self.mr_sets = dict() * */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_modification_time, Py_None) < 0) __PYX_ERR(0, 151, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":152 * self.creation_time = None * self.modification_time = None * self.mr_sets = dict() # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_mstate_global->__pyx_n_u_mr_sets, __pyx_t_1) < 0) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":130 * This class holds metadata we want to give back to python * """ * def __init__(self): # <<<<<<<<<<<<<< * self.column_names = list() * self.column_labels = list() */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pyreadstat._readstat_parser.metadata_container.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":168 * * * cdef py_datetime_format transform_variable_format(str var_format, py_file_format file_format): # <<<<<<<<<<<<<< * """ * Transforms a readstat var_format to a date, datetime or time format label */ static __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_f_10pyreadstat_16_readstat_parser_transform_variable_format(PyObject *__pyx_v_var_format, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format) { __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_r; int __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "pyreadstat/_readstat_parser.pyx":172 * Transforms a readstat var_format to a date, datetime or time format label * """ * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * if var_format in sas_all_formats: * if var_format in sas_date_formats: */ switch (__pyx_v_file_format) { case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS: /* "pyreadstat/_readstat_parser.pyx":173 * """ * if file_format == FILE_FORMAT_SAS: * if var_format in sas_all_formats: # <<<<<<<<<<<<<< * if var_format in sas_date_formats: * return DATE_FORMAT_DATE */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 173, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":174 * if file_format == FILE_FORMAT_SAS: * if var_format in sas_all_formats: * if var_format in sas_date_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATE * elif var_format in sas_datetime_formats: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 174, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":175 * if var_format in sas_all_formats: * if var_format in sas_date_formats: * return DATE_FORMAT_DATE # <<<<<<<<<<<<<< * elif var_format in sas_datetime_formats: * return DATE_FORMAT_DATETIME */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":174 * if file_format == FILE_FORMAT_SAS: * if var_format in sas_all_formats: * if var_format in sas_date_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATE * elif var_format in sas_datetime_formats: */ } /* "pyreadstat/_readstat_parser.pyx":176 * if var_format in sas_date_formats: * return DATE_FORMAT_DATE * elif var_format in sas_datetime_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATETIME * elif var_format in sas_time_formats: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 176, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":177 * return DATE_FORMAT_DATE * elif var_format in sas_datetime_formats: * return DATE_FORMAT_DATETIME # <<<<<<<<<<<<<< * elif var_format in sas_time_formats: * return DATE_FORMAT_TIME */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":176 * if var_format in sas_date_formats: * return DATE_FORMAT_DATE * elif var_format in sas_datetime_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATETIME * elif var_format in sas_time_formats: */ } /* "pyreadstat/_readstat_parser.pyx":178 * elif var_format in sas_datetime_formats: * return DATE_FORMAT_DATETIME * elif var_format in sas_time_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_TIME * else: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 178, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":179 * return DATE_FORMAT_DATETIME * elif var_format in sas_time_formats: * return DATE_FORMAT_TIME # <<<<<<<<<<<<<< * else: * return DATE_FORMAT_NOTADATE */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_TIME; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":178 * elif var_format in sas_datetime_formats: * return DATE_FORMAT_DATETIME * elif var_format in sas_time_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_TIME * else: */ } /* "pyreadstat/_readstat_parser.pyx":173 * """ * if file_format == FILE_FORMAT_SAS: * if var_format in sas_all_formats: # <<<<<<<<<<<<<< * if var_format in sas_date_formats: * return DATE_FORMAT_DATE */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":181 * return DATE_FORMAT_TIME * else: * return DATE_FORMAT_NOTADATE # <<<<<<<<<<<<<< * * elif file_format == FILE_FORMAT_SPSS: */ /*else*/ { __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE; goto __pyx_L0; } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":172 * Transforms a readstat var_format to a date, datetime or time format label * """ * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * if var_format in sas_all_formats: * if var_format in sas_date_formats: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS: /* "pyreadstat/_readstat_parser.pyx":184 * * elif file_format == FILE_FORMAT_SPSS: * if var_format in spss_all_formats: # <<<<<<<<<<<<<< * if var_format in spss_date_formats: * return DATE_FORMAT_DATE */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 184, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":185 * elif file_format == FILE_FORMAT_SPSS: * if var_format in spss_all_formats: * if var_format in spss_date_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATE * elif var_format in spss_datetime_formats: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 185, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":186 * if var_format in spss_all_formats: * if var_format in spss_date_formats: * return DATE_FORMAT_DATE # <<<<<<<<<<<<<< * elif var_format in spss_datetime_formats: * return DATE_FORMAT_DATETIME */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":185 * elif file_format == FILE_FORMAT_SPSS: * if var_format in spss_all_formats: * if var_format in spss_date_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATE * elif var_format in spss_datetime_formats: */ } /* "pyreadstat/_readstat_parser.pyx":187 * if var_format in spss_date_formats: * return DATE_FORMAT_DATE * elif var_format in spss_datetime_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATETIME * elif var_format in spss_time_formats: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 187, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":188 * return DATE_FORMAT_DATE * elif var_format in spss_datetime_formats: * return DATE_FORMAT_DATETIME # <<<<<<<<<<<<<< * elif var_format in spss_time_formats: * return DATE_FORMAT_TIME */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":187 * if var_format in spss_date_formats: * return DATE_FORMAT_DATE * elif var_format in spss_datetime_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATETIME * elif var_format in spss_time_formats: */ } /* "pyreadstat/_readstat_parser.pyx":189 * elif var_format in spss_datetime_formats: * return DATE_FORMAT_DATETIME * elif var_format in spss_time_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_TIME * else: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 189, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":190 * return DATE_FORMAT_DATETIME * elif var_format in spss_time_formats: * return DATE_FORMAT_TIME # <<<<<<<<<<<<<< * else: * return DATE_FORMAT_NOTADATE */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_TIME; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":189 * elif var_format in spss_datetime_formats: * return DATE_FORMAT_DATETIME * elif var_format in spss_time_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_TIME * else: */ } /* "pyreadstat/_readstat_parser.pyx":184 * * elif file_format == FILE_FORMAT_SPSS: * if var_format in spss_all_formats: # <<<<<<<<<<<<<< * if var_format in spss_date_formats: * return DATE_FORMAT_DATE */ goto __pyx_L5; } /* "pyreadstat/_readstat_parser.pyx":192 * return DATE_FORMAT_TIME * else: * return DATE_FORMAT_NOTADATE # <<<<<<<<<<<<<< * * elif file_format == FILE_FORMAT_STATA: */ /*else*/ { __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE; goto __pyx_L0; } __pyx_L5:; /* "pyreadstat/_readstat_parser.pyx":183 * return DATE_FORMAT_NOTADATE * * elif file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * if var_format in spss_all_formats: * if var_format in spss_date_formats: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA: /* "pyreadstat/_readstat_parser.pyx":195 * * elif file_format == FILE_FORMAT_STATA: * if var_format in stata_all_formats: # <<<<<<<<<<<<<< * if var_format in stata_date_formats: * return DATE_FORMAT_DATE */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 195, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":196 * elif file_format == FILE_FORMAT_STATA: * if var_format in stata_all_formats: * if var_format in stata_date_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATE * elif var_format in stata_datetime_formats: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 196, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":197 * if var_format in stata_all_formats: * if var_format in stata_date_formats: * return DATE_FORMAT_DATE # <<<<<<<<<<<<<< * elif var_format in stata_datetime_formats: * return DATE_FORMAT_DATETIME */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":196 * elif file_format == FILE_FORMAT_STATA: * if var_format in stata_all_formats: * if var_format in stata_date_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATE * elif var_format in stata_datetime_formats: */ } /* "pyreadstat/_readstat_parser.pyx":198 * if var_format in stata_date_formats: * return DATE_FORMAT_DATE * elif var_format in stata_datetime_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATETIME * elif var_format in stata_time_formats: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 198, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":199 * return DATE_FORMAT_DATE * elif var_format in stata_datetime_formats: * return DATE_FORMAT_DATETIME # <<<<<<<<<<<<<< * elif var_format in stata_time_formats: * return DATE_FORMAT_TIME */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":198 * if var_format in stata_date_formats: * return DATE_FORMAT_DATE * elif var_format in stata_datetime_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_DATETIME * elif var_format in stata_time_formats: */ } /* "pyreadstat/_readstat_parser.pyx":200 * elif var_format in stata_datetime_formats: * return DATE_FORMAT_DATETIME * elif var_format in stata_time_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_TIME * else: */ __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_var_format, __pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 200, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":201 * return DATE_FORMAT_DATETIME * elif var_format in stata_time_formats: * return DATE_FORMAT_TIME # <<<<<<<<<<<<<< * else: * return DATE_FORMAT_NOTADATE */ __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_TIME; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":200 * elif var_format in stata_datetime_formats: * return DATE_FORMAT_DATETIME * elif var_format in stata_time_formats: # <<<<<<<<<<<<<< * return DATE_FORMAT_TIME * else: */ } /* "pyreadstat/_readstat_parser.pyx":195 * * elif file_format == FILE_FORMAT_STATA: * if var_format in stata_all_formats: # <<<<<<<<<<<<<< * if var_format in stata_date_formats: * return DATE_FORMAT_DATE */ goto __pyx_L7; } /* "pyreadstat/_readstat_parser.pyx":203 * return DATE_FORMAT_TIME * else: * return DATE_FORMAT_NOTADATE # <<<<<<<<<<<<<< * * cdef object transform_datetime(py_datetime_format var_format, double tstamp, py_file_format file_format, object origin, */ /*else*/ { __pyx_r = __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE; goto __pyx_L0; } __pyx_L7:; /* "pyreadstat/_readstat_parser.pyx":194 * return DATE_FORMAT_NOTADATE * * elif file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * if var_format in stata_all_formats: * if var_format in stata_date_formats: */ break; default: break; } /* "pyreadstat/_readstat_parser.pyx":168 * * * cdef py_datetime_format transform_variable_format(str var_format, py_file_format file_format): # <<<<<<<<<<<<<< * """ * Transforms a readstat var_format to a date, datetime or time format label */ /* function exit code */ __pyx_r = (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("pyreadstat._readstat_parser.transform_variable_format", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) 0; __pyx_L0:; return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":205 * return DATE_FORMAT_NOTADATE * * cdef object transform_datetime(py_datetime_format var_format, double tstamp, py_file_format file_format, object origin, # <<<<<<<<<<<<<< * bint dates_as_pandas, str output_format, double unix_to_origin_secs): * """ */ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_transform_datetime(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_v_var_format, double __pyx_v_tstamp, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format, PyObject *__pyx_v_origin, int __pyx_v_dates_as_pandas, PyObject *__pyx_v_output_format, double __pyx_v_unix_to_origin_secs) { PyObject *__pyx_v_tdelta = 0; int __pyx_v_days; int __pyx_v_secs; double __pyx_v_msecs; int __pyx_v_usecs; PyObject *__pyx_v_mydat = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; size_t __pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("transform_datetime", 0); /* "pyreadstat/_readstat_parser.pyx":223 * # for any other we return a python datetime, date or time object. * # polars also works with these objects, but it is slower * if var_format == DATE_FORMAT_DATE: # <<<<<<<<<<<<<< * if output_format == "polars": * # we want to return days from unix */ switch (__pyx_v_var_format) { case __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE: /* "pyreadstat/_readstat_parser.pyx":224 * # polars also works with these objects, but it is slower * if var_format == DATE_FORMAT_DATE: * if output_format == "polars": # <<<<<<<<<<<<<< * # we want to return days from unix * if file_format == FILE_FORMAT_SPSS: */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_polars, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 224, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":226 * if output_format == "polars": * # we want to return days from unix * if file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * # tstamp is in seconds * return (tstamp - unix_to_origin_secs)/86400 */ __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":228 * if file_format == FILE_FORMAT_SPSS: * # tstamp is in seconds * return (tstamp - unix_to_origin_secs)/86400 # <<<<<<<<<<<<<< * else: * # tstamp is in days */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_tstamp - __pyx_v_unix_to_origin_secs) / 86400.0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 228, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":226 * if output_format == "polars": * # we want to return days from unix * if file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * # tstamp is in seconds * return (tstamp - unix_to_origin_secs)/86400 */ } /* "pyreadstat/_readstat_parser.pyx":231 * else: * # tstamp is in days * return tstamp - (unix_to_origin_secs/86400) # <<<<<<<<<<<<<< * * if file_format == FILE_FORMAT_SPSS: */ /*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyFloat_FromDouble((__pyx_v_tstamp - (__pyx_v_unix_to_origin_secs / 86400.0))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } /* "pyreadstat/_readstat_parser.pyx":224 * # polars also works with these objects, but it is slower * if var_format == DATE_FORMAT_DATE: * if output_format == "polars": # <<<<<<<<<<<<<< * # we want to return days from unix * if file_format == FILE_FORMAT_SPSS: */ } /* "pyreadstat/_readstat_parser.pyx":233 * return tstamp - (unix_to_origin_secs/86400) * * if file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * # tstamp is in seconds * days = (floor(tstamp / 86400)) */ __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":235 * if file_format == FILE_FORMAT_SPSS: * # tstamp is in seconds * days = (floor(tstamp / 86400)) # <<<<<<<<<<<<<< * secs = (tstamp % 86400) * tdelta = timedelta_new(days, secs, 0) */ __pyx_v_days = ((int)floor((__pyx_v_tstamp / 86400.0))); /* "pyreadstat/_readstat_parser.pyx":236 * # tstamp is in seconds * days = (floor(tstamp / 86400)) * secs = (tstamp % 86400) # <<<<<<<<<<<<<< * tdelta = timedelta_new(days, secs, 0) * #tdelta = timedelta(seconds=tstamp) */ __pyx_v_secs = ((int)__Pyx_mod_double(__pyx_v_tstamp, 86400.0, 1)); /* "pyreadstat/_readstat_parser.pyx":237 * days = (floor(tstamp / 86400)) * secs = (tstamp % 86400) * tdelta = timedelta_new(days, secs, 0) # <<<<<<<<<<<<<< * #tdelta = timedelta(seconds=tstamp) * else: */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_timedelta_new(__pyx_v_days, __pyx_v_secs, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_tdelta = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":233 * return tstamp - (unix_to_origin_secs/86400) * * if file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * # tstamp is in seconds * days = (floor(tstamp / 86400)) */ goto __pyx_L5; } /* "pyreadstat/_readstat_parser.pyx":241 * else: * # tstamp is in days * days = tstamp # <<<<<<<<<<<<<< * tdelta = timedelta_new(days, 0, 0) * #tdelta = timedelta(days=tstamp) */ /*else*/ { __pyx_v_days = ((int)__pyx_v_tstamp); /* "pyreadstat/_readstat_parser.pyx":242 * # tstamp is in days * days = tstamp * tdelta = timedelta_new(days, 0, 0) # <<<<<<<<<<<<<< * #tdelta = timedelta(days=tstamp) * mydat = origin + tdelta */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_timedelta_new(__pyx_v_days, 0, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 242, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_tdelta = __pyx_t_2; __pyx_t_2 = 0; } __pyx_L5:; /* "pyreadstat/_readstat_parser.pyx":244 * tdelta = timedelta_new(days, 0, 0) * #tdelta = timedelta(days=tstamp) * mydat = origin + tdelta # <<<<<<<<<<<<<< * if dates_as_pandas: * return mydat */ __pyx_t_2 = PyNumber_Add(__pyx_v_origin, __pyx_v_tdelta); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_mydat = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":245 * #tdelta = timedelta(days=tstamp) * mydat = origin + tdelta * if dates_as_pandas: # <<<<<<<<<<<<<< * return mydat * else: */ if (__pyx_v_dates_as_pandas) { /* "pyreadstat/_readstat_parser.pyx":246 * mydat = origin + tdelta * if dates_as_pandas: * return mydat # <<<<<<<<<<<<<< * else: * return mydat.date() */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_mydat); __pyx_r = __pyx_v_mydat; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":245 * #tdelta = timedelta(days=tstamp) * mydat = origin + tdelta * if dates_as_pandas: # <<<<<<<<<<<<<< * return mydat * else: */ } /* "pyreadstat/_readstat_parser.pyx":248 * return mydat * else: * return mydat.date() # <<<<<<<<<<<<<< * elif var_format == DATE_FORMAT_DATETIME: * if output_format == "polars": */ /*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_v_mydat; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_date, __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_2)) __PYX_ERR(0, 248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } /* "pyreadstat/_readstat_parser.pyx":223 * # for any other we return a python datetime, date or time object. * # polars also works with these objects, but it is slower * if var_format == DATE_FORMAT_DATE: # <<<<<<<<<<<<<< * if output_format == "polars": * # we want to return days from unix */ break; case __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME: /* "pyreadstat/_readstat_parser.pyx":250 * return mydat.date() * elif var_format == DATE_FORMAT_DATETIME: * if output_format == "polars": # <<<<<<<<<<<<<< * # we want to return seconds from unix * if file_format == FILE_FORMAT_STATA: */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_polars, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 250, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":252 * if output_format == "polars": * # we want to return seconds from unix * if file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * # tstamp is in millisecons * return (tstamp/1000) - unix_to_origin_secs */ __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":254 * if file_format == FILE_FORMAT_STATA: * # tstamp is in millisecons * return (tstamp/1000) - unix_to_origin_secs # <<<<<<<<<<<<<< * else: * # tstamp in seconds */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_tstamp / 1000.0) - __pyx_v_unix_to_origin_secs)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":252 * if output_format == "polars": * # we want to return seconds from unix * if file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * # tstamp is in millisecons * return (tstamp/1000) - unix_to_origin_secs */ } /* "pyreadstat/_readstat_parser.pyx":257 * else: * # tstamp in seconds * return tstamp - unix_to_origin_secs # <<<<<<<<<<<<<< * * if file_format == FILE_FORMAT_STATA: */ /*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyFloat_FromDouble((__pyx_v_tstamp - __pyx_v_unix_to_origin_secs)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 257, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } /* "pyreadstat/_readstat_parser.pyx":250 * return mydat.date() * elif var_format == DATE_FORMAT_DATETIME: * if output_format == "polars": # <<<<<<<<<<<<<< * # we want to return seconds from unix * if file_format == FILE_FORMAT_STATA: */ } /* "pyreadstat/_readstat_parser.pyx":259 * return tstamp - unix_to_origin_secs * * if file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) */ __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":261 * if file_format == FILE_FORMAT_STATA: * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) # <<<<<<<<<<<<<< * msecs = tstamp % 86400000 * secs = (msecs/1000) */ __pyx_v_days = ((int)floor((__pyx_v_tstamp / 86400000.0))); /* "pyreadstat/_readstat_parser.pyx":262 * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) * msecs = tstamp % 86400000 # <<<<<<<<<<<<<< * secs = (msecs/1000) * usecs = ((msecs % 1000) * 1000 ) */ __pyx_v_msecs = __Pyx_mod_double(__pyx_v_tstamp, 86400000.0, 1); /* "pyreadstat/_readstat_parser.pyx":263 * days = (floor(tstamp / 86400000)) * msecs = tstamp % 86400000 * secs = (msecs/1000) # <<<<<<<<<<<<<< * usecs = ((msecs % 1000) * 1000 ) * tdelta = timedelta_new(days, secs, usecs) */ __pyx_v_secs = ((int)(__pyx_v_msecs / 1000.0)); /* "pyreadstat/_readstat_parser.pyx":264 * msecs = tstamp % 86400000 * secs = (msecs/1000) * usecs = ((msecs % 1000) * 1000 ) # <<<<<<<<<<<<<< * tdelta = timedelta_new(days, secs, usecs) * #tdelta = timedelta(milliseconds=tstamp) */ __pyx_v_usecs = ((int)(__Pyx_mod_double(__pyx_v_msecs, 1000.0, 1) * 1000.0)); /* "pyreadstat/_readstat_parser.pyx":265 * secs = (msecs/1000) * usecs = ((msecs % 1000) * 1000 ) * tdelta = timedelta_new(days, secs, usecs) # <<<<<<<<<<<<<< * #tdelta = timedelta(milliseconds=tstamp) * else: */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_timedelta_new(__pyx_v_days, __pyx_v_secs, __pyx_v_usecs)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 265, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_tdelta = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":259 * return tstamp - unix_to_origin_secs * * if file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) */ goto __pyx_L9; } /* "pyreadstat/_readstat_parser.pyx":269 * else: * # tstamp in seconds * days = (floor(tstamp / 86400)) # <<<<<<<<<<<<<< * secs = (tstamp % 86400) * tdelta = timedelta_new(days, secs, 0) */ /*else*/ { __pyx_v_days = ((int)floor((__pyx_v_tstamp / 86400.0))); /* "pyreadstat/_readstat_parser.pyx":270 * # tstamp in seconds * days = (floor(tstamp / 86400)) * secs = (tstamp % 86400) # <<<<<<<<<<<<<< * tdelta = timedelta_new(days, secs, 0) * #tdelta = timedelta(seconds=tstamp) */ __pyx_v_secs = ((int)__Pyx_mod_double(__pyx_v_tstamp, 86400.0, 1)); /* "pyreadstat/_readstat_parser.pyx":271 * days = (floor(tstamp / 86400)) * secs = (tstamp % 86400) * tdelta = timedelta_new(days, secs, 0) # <<<<<<<<<<<<<< * #tdelta = timedelta(seconds=tstamp) * mydat = origin + tdelta */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_timedelta_new(__pyx_v_days, __pyx_v_secs, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_tdelta = __pyx_t_2; __pyx_t_2 = 0; } __pyx_L9:; /* "pyreadstat/_readstat_parser.pyx":273 * tdelta = timedelta_new(days, secs, 0) * #tdelta = timedelta(seconds=tstamp) * mydat = origin + tdelta # <<<<<<<<<<<<<< * return mydat * elif var_format == DATE_FORMAT_TIME: */ __pyx_t_2 = PyNumber_Add(__pyx_v_origin, __pyx_v_tdelta); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_mydat = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":274 * #tdelta = timedelta(seconds=tstamp) * mydat = origin + tdelta * return mydat # <<<<<<<<<<<<<< * elif var_format == DATE_FORMAT_TIME: * if file_format == FILE_FORMAT_STATA: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_mydat); __pyx_r = __pyx_v_mydat; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":249 * else: * return mydat.date() * elif var_format == DATE_FORMAT_DATETIME: # <<<<<<<<<<<<<< * if output_format == "polars": * # we want to return seconds from unix */ break; case __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_TIME: /* "pyreadstat/_readstat_parser.pyx":276 * return mydat * elif var_format == DATE_FORMAT_TIME: * if file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) */ __pyx_t_1 = (__pyx_v_file_format == __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":278 * if file_format == FILE_FORMAT_STATA: * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) # <<<<<<<<<<<<<< * msecs = tstamp % 86400000 * secs = (msecs/1000) */ __pyx_v_days = ((int)floor((__pyx_v_tstamp / 86400000.0))); /* "pyreadstat/_readstat_parser.pyx":279 * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) * msecs = tstamp % 86400000 # <<<<<<<<<<<<<< * secs = (msecs/1000) * usecs = ((msecs % 1000) * 1000 ) */ __pyx_v_msecs = __Pyx_mod_double(__pyx_v_tstamp, 86400000.0, 1); /* "pyreadstat/_readstat_parser.pyx":280 * days = (floor(tstamp / 86400000)) * msecs = tstamp % 86400000 * secs = (msecs/1000) # <<<<<<<<<<<<<< * usecs = ((msecs % 1000) * 1000 ) * tdelta = timedelta_new(days, secs, usecs) */ __pyx_v_secs = ((int)(__pyx_v_msecs / 1000.0)); /* "pyreadstat/_readstat_parser.pyx":281 * msecs = tstamp % 86400000 * secs = (msecs/1000) * usecs = ((msecs % 1000) * 1000 ) # <<<<<<<<<<<<<< * tdelta = timedelta_new(days, secs, usecs) * #tdelta = timedelta(milliseconds=tstamp) */ __pyx_v_usecs = ((int)(__Pyx_mod_double(__pyx_v_msecs, 1000.0, 1) * 1000.0)); /* "pyreadstat/_readstat_parser.pyx":282 * secs = (msecs/1000) * usecs = ((msecs % 1000) * 1000 ) * tdelta = timedelta_new(days, secs, usecs) # <<<<<<<<<<<<<< * #tdelta = timedelta(milliseconds=tstamp) * else: */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_timedelta_new(__pyx_v_days, __pyx_v_secs, __pyx_v_usecs)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_tdelta = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":276 * return mydat * elif var_format == DATE_FORMAT_TIME: * if file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * # tstamp is in millisecons * days = (floor(tstamp / 86400000)) */ goto __pyx_L10; } /* "pyreadstat/_readstat_parser.pyx":286 * else: * # tstamp in seconds * days = (floor(tstamp / 86400)) # <<<<<<<<<<<<<< * secs = (tstamp % 86400) * tdelta = timedelta_new(days, secs, 0) */ /*else*/ { __pyx_v_days = ((int)floor((__pyx_v_tstamp / 86400.0))); /* "pyreadstat/_readstat_parser.pyx":287 * # tstamp in seconds * days = (floor(tstamp / 86400)) * secs = (tstamp % 86400) # <<<<<<<<<<<<<< * tdelta = timedelta_new(days, secs, 0) * #tdelta = timedelta(seconds=tstamp) */ __pyx_v_secs = ((int)__Pyx_mod_double(__pyx_v_tstamp, 86400.0, 1)); /* "pyreadstat/_readstat_parser.pyx":288 * days = (floor(tstamp / 86400)) * secs = (tstamp % 86400) * tdelta = timedelta_new(days, secs, 0) # <<<<<<<<<<<<<< * #tdelta = timedelta(seconds=tstamp) * mydat = origin + tdelta */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_timedelta_new(__pyx_v_days, __pyx_v_secs, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_tdelta = __pyx_t_2; __pyx_t_2 = 0; } __pyx_L10:; /* "pyreadstat/_readstat_parser.pyx":290 * tdelta = timedelta_new(days, secs, 0) * #tdelta = timedelta(seconds=tstamp) * mydat = origin + tdelta # <<<<<<<<<<<<<< * return mydat.time() * */ __pyx_t_2 = PyNumber_Add(__pyx_v_origin, __pyx_v_tdelta); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_mydat = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":291 * #tdelta = timedelta(seconds=tstamp) * mydat = origin + tdelta * return mydat.time() # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_v_mydat; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_time, __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_2)) __PYX_ERR(0, 291, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":275 * mydat = origin + tdelta * return mydat * elif var_format == DATE_FORMAT_TIME: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_STATA: * # tstamp is in millisecons */ break; default: break; } /* "pyreadstat/_readstat_parser.pyx":205 * return DATE_FORMAT_NOTADATE * * cdef object transform_datetime(py_datetime_format var_format, double tstamp, py_file_format file_format, object origin, # <<<<<<<<<<<<<< * bint dates_as_pandas, str output_format, double unix_to_origin_secs): * """ */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pyreadstat._readstat_parser.transform_datetime", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_tdelta); __Pyx_XDECREF(__pyx_v_mydat); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":294 * * * cdef object convert_readstat_to_python_value(readstat_value_t value, int index, data_container dc): # <<<<<<<<<<<<<< * """ * Converts a readstat value to a python value. */ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_convert_readstat_to_python_value(readstat_value_t __pyx_v_value, int __pyx_v_index, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc) { readstat_type_t __pyx_v_var_type; __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_v_var_format; __pyx_t_10pyreadstat_16_readstat_parser_py_variable_format __pyx_v_pyformat; PyObject *__pyx_v_origin = 0; int __pyx_v_dates_as_pandas; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; PyObject *__pyx_v_result = 0; char *__pyx_v_c_str_value; PyObject *__pyx_v_py_str_value = 0; int8_t __pyx_v_c_int8_value; int16_t __pyx_v_c_int16_value; int32_t __pyx_v_c_int32_value; float __pyx_v_c_float_value; double __pyx_v_c_double_value; long __pyx_v_py_long_value; double __pyx_v_py_float_value; double __pyx_v_tstamp; PyObject *__pyx_v_output_format = 0; double __pyx_v_unix_to_origin_secs; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; readstat_type_t __pyx_t_2; __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_t_3; double __pyx_t_4; int __pyx_t_5; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_t_6; 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[5]; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("convert_readstat_to_python_value", 0); /* "pyreadstat/_readstat_parser.pyx":322 * cdef str output_format * * var_type = dc.col_dtypes[index] # <<<<<<<<<<<<<< * var_format = dc.col_formats[index] * origin = dc.origin */ if (unlikely(__pyx_v_dc->col_dtypes == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 322, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_dtypes, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 322, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = ((readstat_type_t)__Pyx_PyLong_As_readstat_type_t(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 322, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_var_type = __pyx_t_2; /* "pyreadstat/_readstat_parser.pyx":323 * * var_type = dc.col_dtypes[index] * var_format = dc.col_formats[index] # <<<<<<<<<<<<<< * origin = dc.origin * unix_to_origin_secs = dc.unix_to_origin_secs */ if (unlikely(__pyx_v_dc->col_formats == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 323, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_formats, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = ((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)__Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 323, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_var_format = __pyx_t_3; /* "pyreadstat/_readstat_parser.pyx":324 * var_type = dc.col_dtypes[index] * var_format = dc.col_formats[index] * origin = dc.origin # <<<<<<<<<<<<<< * unix_to_origin_secs = dc.unix_to_origin_secs * dates_as_pandas = dc.dates_as_pandas */ __pyx_t_1 = __pyx_v_dc->origin; __Pyx_INCREF(__pyx_t_1); __pyx_v_origin = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":325 * var_format = dc.col_formats[index] * origin = dc.origin * unix_to_origin_secs = dc.unix_to_origin_secs # <<<<<<<<<<<<<< * dates_as_pandas = dc.dates_as_pandas * file_format = dc.file_format */ __pyx_t_4 = __pyx_v_dc->unix_to_origin_secs; __pyx_v_unix_to_origin_secs = __pyx_t_4; /* "pyreadstat/_readstat_parser.pyx":326 * origin = dc.origin * unix_to_origin_secs = dc.unix_to_origin_secs * dates_as_pandas = dc.dates_as_pandas # <<<<<<<<<<<<<< * file_format = dc.file_format * output_format = dc.output_format */ __pyx_t_5 = __pyx_v_dc->dates_as_pandas; __pyx_v_dates_as_pandas = __pyx_t_5; /* "pyreadstat/_readstat_parser.pyx":327 * unix_to_origin_secs = dc.unix_to_origin_secs * dates_as_pandas = dc.dates_as_pandas * file_format = dc.file_format # <<<<<<<<<<<<<< * output_format = dc.output_format * */ __pyx_t_6 = __pyx_v_dc->file_format; __pyx_v_file_format = __pyx_t_6; /* "pyreadstat/_readstat_parser.pyx":328 * dates_as_pandas = dc.dates_as_pandas * file_format = dc.file_format * output_format = dc.output_format # <<<<<<<<<<<<<< * * # transform to values cython can deal with */ __pyx_t_1 = __pyx_v_dc->output_format; __Pyx_INCREF(__pyx_t_1); __pyx_v_output_format = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":331 * * # transform to values cython can deal with * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * c_str_value = readstat_string_value(value) * if c_str_value != NULL: */ switch (__pyx_v_var_type) { case READSTAT_TYPE_STRING: case READSTAT_TYPE_STRING_REF: /* "pyreadstat/_readstat_parser.pyx":332 * # transform to values cython can deal with * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: * c_str_value = readstat_string_value(value) # <<<<<<<<<<<<<< * if c_str_value != NULL: * py_str_value = c_str_value */ __pyx_v_c_str_value = readstat_string_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":333 * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: * c_str_value = readstat_string_value(value) * if c_str_value != NULL: # <<<<<<<<<<<<<< * py_str_value = c_str_value * else: */ __pyx_t_5 = (__pyx_v_c_str_value != NULL); if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":334 * c_str_value = readstat_string_value(value) * if c_str_value != NULL: * py_str_value = c_str_value # <<<<<<<<<<<<<< * else: * py_str_value = '' */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_c_str_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_py_str_value = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":333 * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: * c_str_value = readstat_string_value(value) * if c_str_value != NULL: # <<<<<<<<<<<<<< * py_str_value = c_str_value * else: */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":336 * py_str_value = c_str_value * else: * py_str_value = '' # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_STRING * elif var_type == READSTAT_TYPE_INT8: */ /*else*/ { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __pyx_v_py_str_value = __pyx_mstate_global->__pyx_kp_u_; } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":337 * else: * py_str_value = '' * pyformat = VAR_FORMAT_STRING # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_INT8: * c_int8_value = readstat_int8_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_STRING; /* "pyreadstat/_readstat_parser.pyx":331 * * # transform to values cython can deal with * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * c_str_value = readstat_string_value(value) * if c_str_value != NULL: */ break; case READSTAT_TYPE_INT8: /* "pyreadstat/_readstat_parser.pyx":339 * pyformat = VAR_FORMAT_STRING * elif var_type == READSTAT_TYPE_INT8: * c_int8_value = readstat_int8_value(value) # <<<<<<<<<<<<<< * py_long_value = c_int8_value * pyformat = VAR_FORMAT_LONG */ __pyx_v_c_int8_value = readstat_int8_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":340 * elif var_type == READSTAT_TYPE_INT8: * c_int8_value = readstat_int8_value(value) * py_long_value = c_int8_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_INT16: */ __pyx_v_py_long_value = ((long)__pyx_v_c_int8_value); /* "pyreadstat/_readstat_parser.pyx":341 * c_int8_value = readstat_int8_value(value) * py_long_value = c_int8_value * pyformat = VAR_FORMAT_LONG # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_INT16: * c_int16_value = readstat_int16_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG; /* "pyreadstat/_readstat_parser.pyx":338 * py_str_value = '' * pyformat = VAR_FORMAT_STRING * elif var_type == READSTAT_TYPE_INT8: # <<<<<<<<<<<<<< * c_int8_value = readstat_int8_value(value) * py_long_value = c_int8_value */ break; case READSTAT_TYPE_INT16: /* "pyreadstat/_readstat_parser.pyx":343 * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_INT16: * c_int16_value = readstat_int16_value(value) # <<<<<<<<<<<<<< * py_long_value = c_int16_value * pyformat = VAR_FORMAT_LONG */ __pyx_v_c_int16_value = readstat_int16_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":344 * elif var_type == READSTAT_TYPE_INT16: * c_int16_value = readstat_int16_value(value) * py_long_value = c_int16_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_INT32: */ __pyx_v_py_long_value = ((long)__pyx_v_c_int16_value); /* "pyreadstat/_readstat_parser.pyx":345 * c_int16_value = readstat_int16_value(value) * py_long_value = c_int16_value * pyformat = VAR_FORMAT_LONG # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_INT32: * c_int32_value = readstat_int32_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG; /* "pyreadstat/_readstat_parser.pyx":342 * py_long_value = c_int8_value * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_INT16: # <<<<<<<<<<<<<< * c_int16_value = readstat_int16_value(value) * py_long_value = c_int16_value */ break; case READSTAT_TYPE_INT32: /* "pyreadstat/_readstat_parser.pyx":347 * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_INT32: * c_int32_value = readstat_int32_value(value) # <<<<<<<<<<<<<< * py_long_value = c_int32_value * pyformat = VAR_FORMAT_LONG */ __pyx_v_c_int32_value = readstat_int32_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":348 * elif var_type == READSTAT_TYPE_INT32: * c_int32_value = readstat_int32_value(value) * py_long_value = c_int32_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_FLOAT: */ __pyx_v_py_long_value = ((long)__pyx_v_c_int32_value); /* "pyreadstat/_readstat_parser.pyx":349 * c_int32_value = readstat_int32_value(value) * py_long_value = c_int32_value * pyformat = VAR_FORMAT_LONG # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_FLOAT: * c_float_value = readstat_float_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG; /* "pyreadstat/_readstat_parser.pyx":346 * py_long_value = c_int16_value * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_INT32: # <<<<<<<<<<<<<< * c_int32_value = readstat_int32_value(value) * py_long_value = c_int32_value */ break; case READSTAT_TYPE_FLOAT: /* "pyreadstat/_readstat_parser.pyx":351 * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_FLOAT: * c_float_value = readstat_float_value(value) # <<<<<<<<<<<<<< * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT */ __pyx_v_c_float_value = readstat_float_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":352 * elif var_type == READSTAT_TYPE_FLOAT: * c_float_value = readstat_float_value(value) * py_float_value = c_float_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_FLOAT * elif var_type == READSTAT_TYPE_DOUBLE: */ __pyx_v_py_float_value = ((double)__pyx_v_c_float_value); /* "pyreadstat/_readstat_parser.pyx":353 * c_float_value = readstat_float_value(value) * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_DOUBLE: * c_double_value = readstat_double_value(value); */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT; /* "pyreadstat/_readstat_parser.pyx":350 * py_long_value = c_int32_value * pyformat = VAR_FORMAT_LONG * elif var_type == READSTAT_TYPE_FLOAT: # <<<<<<<<<<<<<< * c_float_value = readstat_float_value(value) * py_float_value = c_float_value */ break; case READSTAT_TYPE_DOUBLE: /* "pyreadstat/_readstat_parser.pyx":355 * pyformat = VAR_FORMAT_FLOAT * elif var_type == READSTAT_TYPE_DOUBLE: * c_double_value = readstat_double_value(value); # <<<<<<<<<<<<<< * py_float_value = c_double_value * pyformat = VAR_FORMAT_FLOAT */ __pyx_v_c_double_value = readstat_double_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":356 * elif var_type == READSTAT_TYPE_DOUBLE: * c_double_value = readstat_double_value(value); * py_float_value = c_double_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_FLOAT * else: */ __pyx_v_py_float_value = ((double)__pyx_v_c_double_value); /* "pyreadstat/_readstat_parser.pyx":357 * c_double_value = readstat_double_value(value); * py_float_value = c_double_value * pyformat = VAR_FORMAT_FLOAT # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unkown data type") */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT; /* "pyreadstat/_readstat_parser.pyx":354 * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT * elif var_type == READSTAT_TYPE_DOUBLE: # <<<<<<<<<<<<<< * c_double_value = readstat_double_value(value); * py_float_value = c_double_value */ break; default: /* "pyreadstat/_readstat_parser.pyx":359 * pyformat = VAR_FORMAT_FLOAT * else: * raise PyreadstatError("Unkown data type") # <<<<<<<<<<<<<< * * # final transformation and storage */ __pyx_t_1 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_8, __pyx__function); __pyx_t_9 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_Unkown_data_type}; __pyx_t_7 = __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_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 359, __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, 359, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":363 * # final transformation and storage * * if pyformat == VAR_FORMAT_STRING: # <<<<<<<<<<<<<< * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_str_value */ switch (__pyx_v_pyformat) { case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_STRING: /* "pyreadstat/_readstat_parser.pyx":364 * * if pyformat == VAR_FORMAT_STRING: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: # <<<<<<<<<<<<<< * result = py_str_value * else: */ __pyx_t_10 = (__pyx_v_var_format == __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE); if (!__pyx_t_10) { } else { __pyx_t_5 = __pyx_t_10; goto __pyx_L5_bool_binop_done; } __pyx_t_5 = __pyx_v_dc->no_datetime_conversion; __pyx_L5_bool_binop_done:; if (likely(__pyx_t_5)) { /* "pyreadstat/_readstat_parser.pyx":365 * if pyformat == VAR_FORMAT_STRING: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_str_value # <<<<<<<<<<<<<< * else: * #str_byte_val = py_str_value.encode("UTF-8") */ if (unlikely(!__pyx_v_py_str_value)) { __Pyx_RaiseUnboundLocalError("py_str_value"); __PYX_ERR(0, 365, __pyx_L1_error) } __Pyx_INCREF(__pyx_v_py_str_value); __pyx_v_result = __pyx_v_py_str_value; /* "pyreadstat/_readstat_parser.pyx":364 * * if pyformat == VAR_FORMAT_STRING: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: # <<<<<<<<<<<<<< * result = py_str_value * else: */ goto __pyx_L4; } /* "pyreadstat/_readstat_parser.pyx":368 * else: * #str_byte_val = py_str_value.encode("UTF-8") * raise PyreadstatError("STRING type with value '%s' with date type in column '%s'" % (py_str_value, dc.col_names[index])) # <<<<<<<<<<<<<< * elif pyformat == VAR_FORMAT_LONG: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: */ /*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, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely(!__pyx_v_py_str_value)) { __Pyx_RaiseUnboundLocalError("py_str_value"); __PYX_ERR(0, 368, __pyx_L1_error) } __pyx_t_11 = __Pyx_PyUnicode_Unicode(__pyx_v_py_str_value); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); if (unlikely(__pyx_v_dc->col_names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 368, __pyx_L1_error) } __pyx_t_12 = __Pyx_GetItemInt_List(__pyx_v_dc->col_names, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_13 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_t_12), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_14[0] = __pyx_mstate_global->__pyx_kp_u_STRING_type_with_value; __pyx_t_14[1] = __pyx_t_11; __pyx_t_14[2] = __pyx_mstate_global->__pyx_kp_u_with_date_type_in_column; __pyx_t_14[3] = __pyx_t_13; __pyx_t_14[4] = __pyx_mstate_global->__pyx_kp_u__2; __pyx_t_12 = __Pyx_PyUnicode_Join(__pyx_t_14, 5, 24 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_11) + 28 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_13) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_11) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_13)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __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_t_12}; __pyx_t_7 = __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_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 368, __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, 368, __pyx_L1_error) } __pyx_L4:; /* "pyreadstat/_readstat_parser.pyx":363 * # final transformation and storage * * if pyformat == VAR_FORMAT_STRING: # <<<<<<<<<<<<<< * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_str_value */ break; case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG: /* "pyreadstat/_readstat_parser.pyx":370 * raise PyreadstatError("STRING type with value '%s' with date type in column '%s'" % (py_str_value, dc.col_names[index])) * elif pyformat == VAR_FORMAT_LONG: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: # <<<<<<<<<<<<<< * result = py_long_value * else: */ __pyx_t_10 = (__pyx_v_var_format == __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE); if (!__pyx_t_10) { } else { __pyx_t_5 = __pyx_t_10; goto __pyx_L8_bool_binop_done; } __pyx_t_5 = __pyx_v_dc->no_datetime_conversion; __pyx_L8_bool_binop_done:; if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":371 * elif pyformat == VAR_FORMAT_LONG: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_long_value # <<<<<<<<<<<<<< * else: * tstamp = py_long_value */ __pyx_t_7 = __Pyx_PyLong_From_long(__pyx_v_py_long_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_result = __pyx_t_7; __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":370 * raise PyreadstatError("STRING type with value '%s' with date type in column '%s'" % (py_str_value, dc.col_names[index])) * elif pyformat == VAR_FORMAT_LONG: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: # <<<<<<<<<<<<<< * result = py_long_value * else: */ goto __pyx_L7; } /* "pyreadstat/_readstat_parser.pyx":373 * result = py_long_value * else: * tstamp = py_long_value # <<<<<<<<<<<<<< * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) * elif pyformat == VAR_FORMAT_FLOAT: */ /*else*/ { __pyx_v_tstamp = ((double)__pyx_v_py_long_value); /* "pyreadstat/_readstat_parser.pyx":374 * else: * tstamp = py_long_value * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) # <<<<<<<<<<<<<< * elif pyformat == VAR_FORMAT_FLOAT: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: */ __pyx_t_7 = __pyx_f_10pyreadstat_16_readstat_parser_transform_datetime(__pyx_v_var_format, __pyx_v_tstamp, __pyx_v_file_format, __pyx_v_origin, __pyx_v_dates_as_pandas, __pyx_v_output_format, __pyx_v_unix_to_origin_secs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 374, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_result = __pyx_t_7; __pyx_t_7 = 0; } __pyx_L7:; /* "pyreadstat/_readstat_parser.pyx":369 * #str_byte_val = py_str_value.encode("UTF-8") * raise PyreadstatError("STRING type with value '%s' with date type in column '%s'" % (py_str_value, dc.col_names[index])) * elif pyformat == VAR_FORMAT_LONG: # <<<<<<<<<<<<<< * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_long_value */ break; case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT: /* "pyreadstat/_readstat_parser.pyx":376 * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) * elif pyformat == VAR_FORMAT_FLOAT: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: # <<<<<<<<<<<<<< * result = py_float_value * else: */ __pyx_t_10 = (__pyx_v_var_format == __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE); if (!__pyx_t_10) { } else { __pyx_t_5 = __pyx_t_10; goto __pyx_L11_bool_binop_done; } __pyx_t_5 = __pyx_v_dc->no_datetime_conversion; __pyx_L11_bool_binop_done:; if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":377 * elif pyformat == VAR_FORMAT_FLOAT: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_float_value # <<<<<<<<<<<<<< * else: * #tstamp = py_float_value */ __pyx_t_7 = PyFloat_FromDouble(__pyx_v_py_float_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 377, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_result = __pyx_t_7; __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":376 * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) * elif pyformat == VAR_FORMAT_FLOAT: * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: # <<<<<<<<<<<<<< * result = py_float_value * else: */ goto __pyx_L10; } /* "pyreadstat/_readstat_parser.pyx":380 * else: * #tstamp = py_float_value * tstamp = py_float_value # <<<<<<<<<<<<<< * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) * #elif pyformat == VAR_FORMAT_MISSING: */ /*else*/ { __pyx_v_tstamp = __pyx_v_py_float_value; /* "pyreadstat/_readstat_parser.pyx":381 * #tstamp = py_float_value * tstamp = py_float_value * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) # <<<<<<<<<<<<<< * #elif pyformat == VAR_FORMAT_MISSING: * # pass */ __pyx_t_7 = __pyx_f_10pyreadstat_16_readstat_parser_transform_datetime(__pyx_v_var_format, __pyx_v_tstamp, __pyx_v_file_format, __pyx_v_origin, __pyx_v_dates_as_pandas, __pyx_v_output_format, __pyx_v_unix_to_origin_secs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_result = __pyx_t_7; __pyx_t_7 = 0; } __pyx_L10:; /* "pyreadstat/_readstat_parser.pyx":375 * tstamp = py_long_value * result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) * elif pyformat == VAR_FORMAT_FLOAT: # <<<<<<<<<<<<<< * if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: * result = py_float_value */ break; default: /* "pyreadstat/_readstat_parser.pyx":385 * # pass * else: * raise PyreadstatError("Failed convert C to python value") # <<<<<<<<<<<<<< * * return result */ __pyx_t_1 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_9 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_12))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_12); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_12); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_12, __pyx__function); __pyx_t_9 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_Failed_convert_C_to_python_value}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 385, __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, 385, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":387 * raise PyreadstatError("Failed convert C to python value") * * return result # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":294 * * * cdef object convert_readstat_to_python_value(readstat_value_t value, int index, data_container dc): # <<<<<<<<<<<<<< * """ * Converts a readstat value to a python value. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __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_AddTraceback("pyreadstat._readstat_parser.convert_readstat_to_python_value", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_origin); __Pyx_XDECREF(__pyx_v_result); __Pyx_XDECREF(__pyx_v_py_str_value); __Pyx_XDECREF(__pyx_v_output_format); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":390 * * * cdef int handle_metadata(readstat_metadata_t *metadata, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * This function sets the number of observations(rows), number of variables */ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_metadata(readstat_metadata_t *__pyx_v_metadata, void *__pyx_v_ctx) { int __pyx_v_var_count; int __pyx_v_obs_count; int __pyx_v_mr_len; struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc = 0; char *__pyx_v_flabel_orig; char *__pyx_v_fencoding_orig; PyObject *__pyx_v_flabel = 0; PyObject *__pyx_v_fencoding = 0; CYTHON_UNUSED int __pyx_v_metaonly; char *__pyx_v_table; int __pyx_v_i; mr_set_t *__pyx_v_mr_sets_orig; PyObject *__pyx_v_mr_sets = 0; PyObject *__pyx_v_name = 0; PyObject *__pyx_v_variable_list = 0; int __pyx_v_j; int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; size_t __pyx_t_5; int __pyx_t_6; int __pyx_t_7; int __pyx_t_8; int __pyx_t_9; int __pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("handle_metadata", 0); /* "pyreadstat/_readstat_parser.pyx":399 * * cdef int var_count, obs_count, mr_len * cdef data_container dc = ctx # <<<<<<<<<<<<<< * #cdef object row * cdef char * flabel_orig */ __pyx_t_1 = ((PyObject *)__pyx_v_ctx); __Pyx_INCREF(__pyx_t_1); __pyx_v_dc = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":408 * cdef int ctime * cdef int mtime * cdef int i = 0 # <<<<<<<<<<<<<< * cdef mr_set_t * mr_sets_orig * cdef dict mr_sets = {} */ __pyx_v_i = 0; /* "pyreadstat/_readstat_parser.pyx":410 * cdef int i = 0 * cdef mr_set_t * mr_sets_orig * cdef dict mr_sets = {} # <<<<<<<<<<<<<< * cdef str name * cdef list variable_list = [] */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 410, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_mr_sets = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":412 * cdef dict mr_sets = {} * cdef str name * cdef list variable_list = [] # <<<<<<<<<<<<<< * * metaonly = dc.metaonly */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_variable_list = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":414 * cdef list variable_list = [] * * metaonly = dc.metaonly # <<<<<<<<<<<<<< * * var_count = readstat_get_var_count(metadata) */ __pyx_t_2 = __pyx_v_dc->metaonly; __pyx_v_metaonly = __pyx_t_2; /* "pyreadstat/_readstat_parser.pyx":416 * metaonly = dc.metaonly * * var_count = readstat_get_var_count(metadata) # <<<<<<<<<<<<<< * if var_count<0: * raise PyreadstatError("Failed to read number of variables") */ __pyx_v_var_count = readstat_get_var_count(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":417 * * var_count = readstat_get_var_count(metadata) * if var_count<0: # <<<<<<<<<<<<<< * raise PyreadstatError("Failed to read number of variables") * obs_count = readstat_get_row_count(metadata) */ __pyx_t_2 = (__pyx_v_var_count < 0); if (unlikely(__pyx_t_2)) { /* "pyreadstat/_readstat_parser.pyx":418 * var_count = readstat_get_var_count(metadata) * if var_count<0: * raise PyreadstatError("Failed to read number of variables") # <<<<<<<<<<<<<< * obs_count = readstat_get_row_count(metadata) * if obs_count <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, 418, __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_Failed_to_read_number_of_variabl}; __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, 418, __pyx_L1_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, 418, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":417 * * var_count = readstat_get_var_count(metadata) * if var_count<0: # <<<<<<<<<<<<<< * raise PyreadstatError("Failed to read number of variables") * obs_count = readstat_get_row_count(metadata) */ } /* "pyreadstat/_readstat_parser.pyx":419 * if var_count<0: * raise PyreadstatError("Failed to read number of variables") * obs_count = readstat_get_row_count(metadata) # <<<<<<<<<<<<<< * if obs_count <0: * # if <0 it means the number of rows is not known, allocate 100 000 */ __pyx_v_obs_count = readstat_get_row_count(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":420 * raise PyreadstatError("Failed to read number of variables") * obs_count = readstat_get_row_count(metadata) * if obs_count <0: # <<<<<<<<<<<<<< * # if <0 it means the number of rows is not known, allocate 100 000 * obs_count = 100000 */ __pyx_t_2 = (__pyx_v_obs_count < 0); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":422 * if obs_count <0: * # if <0 it means the number of rows is not known, allocate 100 000 * obs_count = 100000 # <<<<<<<<<<<<<< * dc.is_unkown_number_rows = 1 * */ __pyx_v_obs_count = 0x186A0; /* "pyreadstat/_readstat_parser.pyx":423 * # if <0 it means the number of rows is not known, allocate 100 000 * obs_count = 100000 * dc.is_unkown_number_rows = 1 # <<<<<<<<<<<<<< * * dc.n_obs = obs_count */ __pyx_v_dc->is_unkown_number_rows = 1; /* "pyreadstat/_readstat_parser.pyx":420 * raise PyreadstatError("Failed to read number of variables") * obs_count = readstat_get_row_count(metadata) * if obs_count <0: # <<<<<<<<<<<<<< * # if <0 it means the number of rows is not known, allocate 100 000 * obs_count = 100000 */ } /* "pyreadstat/_readstat_parser.pyx":425 * dc.is_unkown_number_rows = 1 * * dc.n_obs = obs_count # <<<<<<<<<<<<<< * dc.n_vars = var_count * */ __pyx_v_dc->n_obs = __pyx_v_obs_count; /* "pyreadstat/_readstat_parser.pyx":426 * * dc.n_obs = obs_count * dc.n_vars = var_count # <<<<<<<<<<<<<< * * mr_len = readstat_get_multiple_response_sets_length(metadata); */ __pyx_v_dc->n_vars = __pyx_v_var_count; /* "pyreadstat/_readstat_parser.pyx":428 * dc.n_vars = var_count * * mr_len = readstat_get_multiple_response_sets_length(metadata); # <<<<<<<<<<<<<< * mr_sets_orig = readstat_get_multiple_response_sets(metadata); * if mr_sets_orig != NULL: */ __pyx_v_mr_len = ((int)readstat_get_multiple_response_sets_length(__pyx_v_metadata)); /* "pyreadstat/_readstat_parser.pyx":429 * * mr_len = readstat_get_multiple_response_sets_length(metadata); * mr_sets_orig = readstat_get_multiple_response_sets(metadata); # <<<<<<<<<<<<<< * if mr_sets_orig != NULL: * i = 0 */ __pyx_v_mr_sets_orig = readstat_get_multiple_response_sets(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":430 * mr_len = readstat_get_multiple_response_sets_length(metadata); * mr_sets_orig = readstat_get_multiple_response_sets(metadata); * if mr_sets_orig != NULL: # <<<<<<<<<<<<<< * i = 0 * while i < mr_len: */ __pyx_t_2 = (__pyx_v_mr_sets_orig != NULL); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":431 * mr_sets_orig = readstat_get_multiple_response_sets(metadata); * if mr_sets_orig != NULL: * i = 0 # <<<<<<<<<<<<<< * while i < mr_len: * name = mr_sets_orig[i].name */ __pyx_v_i = 0; /* "pyreadstat/_readstat_parser.pyx":432 * if mr_sets_orig != NULL: * i = 0 * while i < mr_len: # <<<<<<<<<<<<<< * name = mr_sets_orig[i].name * variable_list = [] */ while (1) { __pyx_t_2 = (__pyx_v_i < __pyx_v_mr_len); if (!__pyx_t_2) break; /* "pyreadstat/_readstat_parser.pyx":433 * i = 0 * while i < mr_len: * name = mr_sets_orig[i].name # <<<<<<<<<<<<<< * variable_list = [] * for j in range(mr_sets_orig[i].num_subvars): */ __pyx_t_1 = __Pyx_PyUnicode_FromString((__pyx_v_mr_sets_orig[__pyx_v_i]).name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 433, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_4)); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":434 * while i < mr_len: * name = mr_sets_orig[i].name * variable_list = [] # <<<<<<<<<<<<<< * for j in range(mr_sets_orig[i].num_subvars): * variable_list.append(mr_sets_orig[i].subvariables[j]) */ __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 434, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_variable_list, ((PyObject*)__pyx_t_4)); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":435 * name = mr_sets_orig[i].name * variable_list = [] * for j in range(mr_sets_orig[i].num_subvars): # <<<<<<<<<<<<<< * variable_list.append(mr_sets_orig[i].subvariables[j]) * mr_sets[name] = { */ __pyx_t_6 = (__pyx_v_mr_sets_orig[__pyx_v_i]).num_subvars; __pyx_t_7 = __pyx_t_6; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_j = __pyx_t_8; /* "pyreadstat/_readstat_parser.pyx":436 * variable_list = [] * for j in range(mr_sets_orig[i].num_subvars): * variable_list.append(mr_sets_orig[i].subvariables[j]) # <<<<<<<<<<<<<< * mr_sets[name] = { * 'type': chr(mr_sets_orig[i].type), */ __pyx_t_4 = __Pyx_PyUnicode_FromString(((__pyx_v_mr_sets_orig[__pyx_v_i]).subvariables[__pyx_v_j])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_variable_list, __pyx_t_4); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } /* "pyreadstat/_readstat_parser.pyx":438 * variable_list.append(mr_sets_orig[i].subvariables[j]) * mr_sets[name] = { * 'type': chr(mr_sets_orig[i].type), # <<<<<<<<<<<<<< * 'is_dichotomy': bool(mr_sets_orig[i].is_dichotomy), * 'counted_value': mr_sets_orig[i].counted_value if mr_sets_orig[i].counted_value != -1 else None, */ __pyx_t_4 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 438, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyUnicode_FromOrdinal((__pyx_v_mr_sets_orig[__pyx_v_i]).type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 438, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_type, __pyx_t_1) < 0) __PYX_ERR(0, 438, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":439 * mr_sets[name] = { * 'type': chr(mr_sets_orig[i].type), * 'is_dichotomy': bool(mr_sets_orig[i].is_dichotomy), # <<<<<<<<<<<<<< * 'counted_value': mr_sets_orig[i].counted_value if mr_sets_orig[i].counted_value != -1 else None, * 'label': mr_sets_orig[i].label, */ __pyx_t_1 = __Pyx_PyLong_From_int((__pyx_v_mr_sets_orig[__pyx_v_i]).is_dichotomy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 439, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_2))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_is_dichotomy, __pyx_t_1) < 0) __PYX_ERR(0, 438, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":440 * 'type': chr(mr_sets_orig[i].type), * 'is_dichotomy': bool(mr_sets_orig[i].is_dichotomy), * 'counted_value': mr_sets_orig[i].counted_value if mr_sets_orig[i].counted_value != -1 else None, # <<<<<<<<<<<<<< * 'label': mr_sets_orig[i].label, * 'variable_list': variable_list */ __pyx_t_2 = ((__pyx_v_mr_sets_orig[__pyx_v_i]).counted_value != -1L); if (__pyx_t_2) { __pyx_t_3 = __Pyx_PyLong_From_int((__pyx_v_mr_sets_orig[__pyx_v_i]).counted_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; } else { __Pyx_INCREF(Py_None); __pyx_t_1 = Py_None; } if (PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_counted_value, __pyx_t_1) < 0) __PYX_ERR(0, 438, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":441 * 'is_dichotomy': bool(mr_sets_orig[i].is_dichotomy), * 'counted_value': mr_sets_orig[i].counted_value if mr_sets_orig[i].counted_value != -1 else None, * 'label': mr_sets_orig[i].label, # <<<<<<<<<<<<<< * 'variable_list': variable_list * } */ __pyx_t_1 = __Pyx_PyUnicode_FromString((__pyx_v_mr_sets_orig[__pyx_v_i]).label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 441, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_label, __pyx_t_1) < 0) __PYX_ERR(0, 438, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":442 * 'counted_value': mr_sets_orig[i].counted_value if mr_sets_orig[i].counted_value != -1 else None, * 'label': mr_sets_orig[i].label, * 'variable_list': variable_list # <<<<<<<<<<<<<< * } * i += 1 */ if (PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_variable_list, __pyx_v_variable_list) < 0) __PYX_ERR(0, 438, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":437 * for j in range(mr_sets_orig[i].num_subvars): * variable_list.append(mr_sets_orig[i].subvariables[j]) * mr_sets[name] = { # <<<<<<<<<<<<<< * 'type': chr(mr_sets_orig[i].type), * 'is_dichotomy': bool(mr_sets_orig[i].is_dichotomy), */ if (unlikely((PyDict_SetItem(__pyx_v_mr_sets, __pyx_v_name, __pyx_t_4) < 0))) __PYX_ERR(0, 437, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":444 * 'variable_list': variable_list * } * i += 1 # <<<<<<<<<<<<<< * dc.mr_sets = mr_sets * */ __pyx_v_i = (__pyx_v_i + 1); } /* "pyreadstat/_readstat_parser.pyx":445 * } * i += 1 * dc.mr_sets = mr_sets # <<<<<<<<<<<<<< * * dc.col_data_len = [obs_count] * var_count */ __Pyx_INCREF(__pyx_v_mr_sets); __Pyx_GIVEREF(__pyx_v_mr_sets); __Pyx_GOTREF(__pyx_v_dc->mr_sets); __Pyx_DECREF(__pyx_v_dc->mr_sets); __pyx_v_dc->mr_sets = __pyx_v_mr_sets; /* "pyreadstat/_readstat_parser.pyx":430 * mr_len = readstat_get_multiple_response_sets_length(metadata); * mr_sets_orig = readstat_get_multiple_response_sets(metadata); * if mr_sets_orig != NULL: # <<<<<<<<<<<<<< * i = 0 * while i < mr_len: */ } /* "pyreadstat/_readstat_parser.pyx":447 * dc.mr_sets = mr_sets * * dc.col_data_len = [obs_count] * var_count # <<<<<<<<<<<<<< * dc.col_numpy_dtypes = [None] * var_count * dc.col_dytpes_isfloat = [0] * var_count */ __pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_obs_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 447, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyList_New(1 * ((__pyx_v_var_count<0) ? 0:__pyx_v_var_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 447, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_var_count; __pyx_temp++) { __Pyx_INCREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, __pyx_temp, __pyx_t_4) != (0)) __PYX_ERR(0, 447, __pyx_L1_error); } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_dc->col_data_len); __Pyx_DECREF(__pyx_v_dc->col_data_len); __pyx_v_dc->col_data_len = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":448 * * dc.col_data_len = [obs_count] * var_count * dc.col_numpy_dtypes = [None] * var_count # <<<<<<<<<<<<<< * dc.col_dytpes_isfloat = [0] * var_count * dc.col_dtypes_isobject = [0] * var_count */ __pyx_t_1 = PyList_New(1 * ((__pyx_v_var_count<0) ? 0:__pyx_v_var_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_var_count; __pyx_temp++) { __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None) != (0)) __PYX_ERR(0, 448, __pyx_L1_error); } } __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_dc->col_numpy_dtypes); __Pyx_DECREF(__pyx_v_dc->col_numpy_dtypes); __pyx_v_dc->col_numpy_dtypes = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":449 * dc.col_data_len = [obs_count] * var_count * dc.col_numpy_dtypes = [None] * var_count * dc.col_dytpes_isfloat = [0] * var_count # <<<<<<<<<<<<<< * dc.col_dtypes_isobject = [0] * var_count * */ __pyx_t_1 = PyList_New(1 * ((__pyx_v_var_count<0) ? 0:__pyx_v_var_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 449, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_var_count; __pyx_temp++) { __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, __pyx_temp, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 449, __pyx_L1_error); } } __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_dc->col_dytpes_isfloat); __Pyx_DECREF(__pyx_v_dc->col_dytpes_isfloat); __pyx_v_dc->col_dytpes_isfloat = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":450 * dc.col_numpy_dtypes = [None] * var_count * dc.col_dytpes_isfloat = [0] * var_count * dc.col_dtypes_isobject = [0] * var_count # <<<<<<<<<<<<<< * * # read other metadata */ __pyx_t_1 = PyList_New(1 * ((__pyx_v_var_count<0) ? 0:__pyx_v_var_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 450, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_var_count; __pyx_temp++) { __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, __pyx_temp, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 450, __pyx_L1_error); } } __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_dc->col_dtypes_isobject); __Pyx_DECREF(__pyx_v_dc->col_dtypes_isobject); __pyx_v_dc->col_dtypes_isobject = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":453 * * # read other metadata * flabel_orig = readstat_get_file_label(metadata); # <<<<<<<<<<<<<< * fencoding_orig = readstat_get_file_encoding(metadata) * if flabel_orig != NULL and flabel_orig[0]: */ __pyx_v_flabel_orig = readstat_get_file_label(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":454 * # read other metadata * flabel_orig = readstat_get_file_label(metadata); * fencoding_orig = readstat_get_file_encoding(metadata) # <<<<<<<<<<<<<< * if flabel_orig != NULL and flabel_orig[0]: * flabel = flabel_orig */ __pyx_v_fencoding_orig = readstat_get_file_encoding(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":455 * flabel_orig = readstat_get_file_label(metadata); * fencoding_orig = readstat_get_file_encoding(metadata) * if flabel_orig != NULL and flabel_orig[0]: # <<<<<<<<<<<<<< * flabel = flabel_orig * else: */ __pyx_t_10 = (__pyx_v_flabel_orig != NULL); if (__pyx_t_10) { } else { __pyx_t_2 = __pyx_t_10; goto __pyx_L11_bool_binop_done; } __pyx_t_10 = ((__pyx_v_flabel_orig[0]) != 0); __pyx_t_2 = __pyx_t_10; __pyx_L11_bool_binop_done:; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":456 * fencoding_orig = readstat_get_file_encoding(metadata) * if flabel_orig != NULL and flabel_orig[0]: * flabel = flabel_orig # <<<<<<<<<<<<<< * else: * flabel = None */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_flabel_orig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 456, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_flabel = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":455 * flabel_orig = readstat_get_file_label(metadata); * fencoding_orig = readstat_get_file_encoding(metadata) * if flabel_orig != NULL and flabel_orig[0]: # <<<<<<<<<<<<<< * flabel = flabel_orig * else: */ goto __pyx_L10; } /* "pyreadstat/_readstat_parser.pyx":458 * flabel = flabel_orig * else: * flabel = None # <<<<<<<<<<<<<< * if fencoding_orig != NULL and fencoding_orig[0]: * fencoding = fencoding_orig */ /*else*/ { __Pyx_INCREF(Py_None); __pyx_v_flabel = ((PyObject*)Py_None); } __pyx_L10:; /* "pyreadstat/_readstat_parser.pyx":459 * else: * flabel = None * if fencoding_orig != NULL and fencoding_orig[0]: # <<<<<<<<<<<<<< * fencoding = fencoding_orig * else: */ __pyx_t_10 = (__pyx_v_fencoding_orig != NULL); if (__pyx_t_10) { } else { __pyx_t_2 = __pyx_t_10; goto __pyx_L14_bool_binop_done; } __pyx_t_10 = ((__pyx_v_fencoding_orig[0]) != 0); __pyx_t_2 = __pyx_t_10; __pyx_L14_bool_binop_done:; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":460 * flabel = None * if fencoding_orig != NULL and fencoding_orig[0]: * fencoding = fencoding_orig # <<<<<<<<<<<<<< * else: * fencoding = None */ __pyx_t_4 = __Pyx_PyUnicode_FromString(__pyx_v_fencoding_orig); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 460, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_fencoding = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":459 * else: * flabel = None * if fencoding_orig != NULL and fencoding_orig[0]: # <<<<<<<<<<<<<< * fencoding = fencoding_orig * else: */ goto __pyx_L13; } /* "pyreadstat/_readstat_parser.pyx":462 * fencoding = fencoding_orig * else: * fencoding = None # <<<<<<<<<<<<<< * * dc.file_encoding = fencoding */ /*else*/ { __Pyx_INCREF(Py_None); __pyx_v_fencoding = ((PyObject*)Py_None); } __pyx_L13:; /* "pyreadstat/_readstat_parser.pyx":464 * fencoding = None * * dc.file_encoding = fencoding # <<<<<<<<<<<<<< * dc.file_label = flabel * */ __Pyx_INCREF(__pyx_v_fencoding); __Pyx_GIVEREF(__pyx_v_fencoding); __Pyx_GOTREF(__pyx_v_dc->file_encoding); __Pyx_DECREF(__pyx_v_dc->file_encoding); __pyx_v_dc->file_encoding = __pyx_v_fencoding; /* "pyreadstat/_readstat_parser.pyx":465 * * dc.file_encoding = fencoding * dc.file_label = flabel # <<<<<<<<<<<<<< * * table = readstat_get_table_name(metadata) */ __Pyx_INCREF(__pyx_v_flabel); __Pyx_GIVEREF(__pyx_v_flabel); __Pyx_GOTREF(__pyx_v_dc->file_label); __Pyx_DECREF(__pyx_v_dc->file_label); __pyx_v_dc->file_label = __pyx_v_flabel; /* "pyreadstat/_readstat_parser.pyx":467 * dc.file_label = flabel * * table = readstat_get_table_name(metadata) # <<<<<<<<<<<<<< * if table != NULL and table[0]: * dc.table_name = table */ __pyx_v_table = readstat_get_table_name(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":468 * * table = readstat_get_table_name(metadata) * if table != NULL and table[0]: # <<<<<<<<<<<<<< * dc.table_name = table * */ __pyx_t_10 = (__pyx_v_table != NULL); if (__pyx_t_10) { } else { __pyx_t_2 = __pyx_t_10; goto __pyx_L17_bool_binop_done; } __pyx_t_10 = ((__pyx_v_table[0]) != 0); __pyx_t_2 = __pyx_t_10; __pyx_L17_bool_binop_done:; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":469 * table = readstat_get_table_name(metadata) * if table != NULL and table[0]: * dc.table_name = table # <<<<<<<<<<<<<< * * dc.ctime = readstat_get_creation_time(metadata) */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_table); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_t_4); __Pyx_GOTREF(__pyx_v_dc->table_name); __Pyx_DECREF(__pyx_v_dc->table_name); __pyx_v_dc->table_name = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":468 * * table = readstat_get_table_name(metadata) * if table != NULL and table[0]: # <<<<<<<<<<<<<< * dc.table_name = table * */ } /* "pyreadstat/_readstat_parser.pyx":471 * dc.table_name = table * * dc.ctime = readstat_get_creation_time(metadata) # <<<<<<<<<<<<<< * dc.mtime = readstat_get_modified_time(metadata) * */ __pyx_v_dc->ctime = readstat_get_creation_time(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":472 * * dc.ctime = readstat_get_creation_time(metadata) * dc.mtime = readstat_get_modified_time(metadata) # <<<<<<<<<<<<<< * * return READSTAT_HANDLER_OK */ __pyx_v_dc->mtime = readstat_get_modified_time(__pyx_v_metadata); /* "pyreadstat/_readstat_parser.pyx":474 * dc.mtime = readstat_get_modified_time(metadata) * * return READSTAT_HANDLER_OK # <<<<<<<<<<<<<< * * cdef int handle_variable(int index, readstat_variable_t *variable, */ __pyx_r = READSTAT_HANDLER_OK; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":390 * * * cdef int handle_metadata(readstat_metadata_t *metadata, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * This function sets the number of observations(rows), number of variables */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pyreadstat._readstat_parser.handle_metadata", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = READSTAT_HANDLER_ABORT; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_dc); __Pyx_XDECREF(__pyx_v_flabel); __Pyx_XDECREF(__pyx_v_fencoding); __Pyx_XDECREF(__pyx_v_mr_sets); __Pyx_XDECREF(__pyx_v_name); __Pyx_XDECREF(__pyx_v_variable_list); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":476 * return READSTAT_HANDLER_OK * * cdef int handle_variable(int index, readstat_variable_t *variable, # <<<<<<<<<<<<<< * char *val_labels, void *ctx) except READSTAT_HANDLER_ABORT: * """ */ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_variable(int __pyx_v_index, readstat_variable_t *__pyx_v_variable, char *__pyx_v_val_labels, void *__pyx_v_ctx) { char *__pyx_v_var_name; char *__pyx_v_var_label; char *__pyx_v_var_format; PyObject *__pyx_v_col_name = 0; PyObject *__pyx_v_col_label = 0; PyObject *__pyx_v_label_name = 0; PyObject *__pyx_v_col_format_original = 0; PyObject *__pyx_v_output_format = 0; __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_v_col_format_final; readstat_type_t __pyx_v_var_type; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; int __pyx_v_n_ranges; readstat_value_t __pyx_v_loval; readstat_value_t __pyx_v_hival; PyObject *__pyx_v_pyloval = 0; PyObject *__pyx_v_pyhival = 0; PyObject *__pyx_v_missing_ranges = 0; PyObject *__pyx_v_curnptype = 0; PyObject *__pyx_v_row = 0; int __pyx_v_metaonly; int __pyx_v_obs_count; int __pyx_v_iscurnptypefloat; int __pyx_v_iscurnptypeobject; PyObject *__pyx_v_newcolname = 0; int __pyx_v_dupcolcnt; struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc = 0; PyObject *__pyx_v_msg = NULL; long __pyx_v_i; size_t __pyx_v_storage_width; readstat_alignment_t __pyx_v_align; PyObject *__pyx_v_pyalign = 0; readstat_measure_t __pyx_v_measure; PyObject *__pyx_v_pymeasure = 0; int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; size_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; int __pyx_t_8; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_t_9; __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_t_10; int __pyx_t_11; PyObject *__pyx_t_12 = NULL; int __pyx_t_13; long __pyx_t_14; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("handle_variable", 0); /* "pyreadstat/_readstat_parser.pyx":505 * cdef int dupcolcnt * * cdef data_container dc = ctx # <<<<<<<<<<<<<< * output_format = dc.output_format * */ __pyx_t_1 = ((PyObject *)__pyx_v_ctx); __Pyx_INCREF(__pyx_t_1); __pyx_v_dc = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":506 * * cdef data_container dc = ctx * output_format = dc.output_format # <<<<<<<<<<<<<< * * # get variable name, label, format and type and put into our data container */ __pyx_t_1 = __pyx_v_dc->output_format; __Pyx_INCREF(__pyx_t_1); __pyx_v_output_format = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":509 * * # get variable name, label, format and type and put into our data container * var_name = readstat_variable_get_name(variable) # <<<<<<<<<<<<<< * if var_name == NULL: * col_name = None */ __pyx_v_var_name = readstat_variable_get_name(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":510 * # get variable name, label, format and type and put into our data container * var_name = readstat_variable_get_name(variable) * if var_name == NULL: # <<<<<<<<<<<<<< * col_name = None * else: */ __pyx_t_2 = (__pyx_v_var_name == NULL); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":511 * var_name = readstat_variable_get_name(variable) * if var_name == NULL: * col_name = None # <<<<<<<<<<<<<< * else: * col_name = var_name */ __Pyx_INCREF(Py_None); __pyx_v_col_name = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":510 * # get variable name, label, format and type and put into our data container * var_name = readstat_variable_get_name(variable) * if var_name == NULL: # <<<<<<<<<<<<<< * col_name = None * else: */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":513 * col_name = None * else: * col_name = var_name # <<<<<<<<<<<<<< * * # if the user introduced a list of columns to include, continue only if the column is in the list */ /*else*/ { __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_var_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_col_name = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":516 * * # if the user introduced a list of columns to include, continue only if the column is in the list * if dc.filter_cols and not (col_name in dc.use_cols): # <<<<<<<<<<<<<< * dc.n_vars -= 1 * return READSTAT_HANDLER_SKIP_VARIABLE */ if (__pyx_v_dc->filter_cols) { } else { __pyx_t_2 = __pyx_v_dc->filter_cols; goto __pyx_L5_bool_binop_done; } __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_col_name, __pyx_v_dc->use_cols, Py_NE)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 516, __pyx_L1_error) __pyx_t_2 = __pyx_t_4; __pyx_L5_bool_binop_done:; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":517 * # if the user introduced a list of columns to include, continue only if the column is in the list * if dc.filter_cols and not (col_name in dc.use_cols): * dc.n_vars -= 1 # <<<<<<<<<<<<<< * return READSTAT_HANDLER_SKIP_VARIABLE * */ __pyx_v_dc->n_vars = (__pyx_v_dc->n_vars - 1); /* "pyreadstat/_readstat_parser.pyx":518 * if dc.filter_cols and not (col_name in dc.use_cols): * dc.n_vars -= 1 * return READSTAT_HANDLER_SKIP_VARIABLE # <<<<<<<<<<<<<< * * index = readstat_variable_get_index_after_skipping(variable) */ __pyx_r = READSTAT_HANDLER_SKIP_VARIABLE; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":516 * * # if the user introduced a list of columns to include, continue only if the column is in the list * if dc.filter_cols and not (col_name in dc.use_cols): # <<<<<<<<<<<<<< * dc.n_vars -= 1 * return READSTAT_HANDLER_SKIP_VARIABLE */ } /* "pyreadstat/_readstat_parser.pyx":520 * return READSTAT_HANDLER_SKIP_VARIABLE * * index = readstat_variable_get_index_after_skipping(variable) # <<<<<<<<<<<<<< * * if col_name in dc.col_names: */ __pyx_v_index = readstat_variable_get_index_after_skipping(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":522 * index = readstat_variable_get_index_after_skipping(variable) * * if col_name in dc.col_names: # <<<<<<<<<<<<<< * dupcolcnt = 1 * while True: */ __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_col_name, __pyx_v_dc->col_names, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 522, __pyx_L1_error) if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":523 * * if col_name in dc.col_names: * dupcolcnt = 1 # <<<<<<<<<<<<<< * while True: * newcolname = col_name + "_duplicated" + str(dupcolcnt) */ __pyx_v_dupcolcnt = 1; /* "pyreadstat/_readstat_parser.pyx":524 * if col_name in dc.col_names: * dupcolcnt = 1 * while True: # <<<<<<<<<<<<<< * newcolname = col_name + "_duplicated" + str(dupcolcnt) * if newcolname in col_name: */ while (1) { /* "pyreadstat/_readstat_parser.pyx":525 * dupcolcnt = 1 * while True: * newcolname = col_name + "_duplicated" + str(dupcolcnt) # <<<<<<<<<<<<<< * if newcolname in col_name: * dupcolcnt += 1 */ __pyx_t_3 = __Pyx_PyUnicode_ConcatSafe(__pyx_v_col_name, __pyx_mstate_global->__pyx_n_u_duplicated); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __Pyx_PyLong_From_int(__pyx_v_dupcolcnt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_Unicode(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF_SET(__pyx_v_newcolname, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":526 * while True: * newcolname = col_name + "_duplicated" + str(dupcolcnt) * if newcolname in col_name: # <<<<<<<<<<<<<< * dupcolcnt += 1 * continue */ if (unlikely(__pyx_v_col_name == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); __PYX_ERR(0, 526, __pyx_L1_error) } __pyx_t_2 = (__Pyx_PyUnicode_ContainsTF(__pyx_v_newcolname, __pyx_v_col_name, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 526, __pyx_L1_error) if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":527 * newcolname = col_name + "_duplicated" + str(dupcolcnt) * if newcolname in col_name: * dupcolcnt += 1 # <<<<<<<<<<<<<< * continue * else: */ __pyx_v_dupcolcnt = (__pyx_v_dupcolcnt + 1); /* "pyreadstat/_readstat_parser.pyx":528 * if newcolname in col_name: * dupcolcnt += 1 * continue # <<<<<<<<<<<<<< * else: * msg = "column '{0}' is duplicated, renamed to '{1}'".format(col_name, newcolname) */ goto __pyx_L8_continue; /* "pyreadstat/_readstat_parser.pyx":526 * while True: * newcolname = col_name + "_duplicated" + str(dupcolcnt) * if newcolname in col_name: # <<<<<<<<<<<<<< * dupcolcnt += 1 * continue */ } /* "pyreadstat/_readstat_parser.pyx":530 * continue * else: * msg = "column '{0}' is duplicated, renamed to '{1}'".format(col_name, newcolname) # <<<<<<<<<<<<<< * warnings.warn(msg) * col_name = newcolname */ /*else*/ { __pyx_t_5 = __pyx_mstate_global->__pyx_kp_u_column_0_is_duplicated_renamed_t; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; { PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_v_col_name, __pyx_v_newcolname}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_format, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_msg = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":531 * else: * msg = "column '{0}' is duplicated, renamed to '{1}'".format(col_name, newcolname) * warnings.warn(msg) # <<<<<<<<<<<<<< * col_name = newcolname * break */ __pyx_t_5 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_warnings); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 531, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_warn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 531, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_7))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7); assert(__pyx_t_5); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_7, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_msg}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_7, __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_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":532 * msg = "column '{0}' is duplicated, renamed to '{1}'".format(col_name, newcolname) * warnings.warn(msg) * col_name = newcolname # <<<<<<<<<<<<<< * break * */ __Pyx_INCREF(__pyx_v_newcolname); __Pyx_DECREF_SET(__pyx_v_col_name, __pyx_v_newcolname); /* "pyreadstat/_readstat_parser.pyx":533 * warnings.warn(msg) * col_name = newcolname * break # <<<<<<<<<<<<<< * * dc.col_names.append(col_name) */ goto __pyx_L9_break; } __pyx_L8_continue:; } __pyx_L9_break:; /* "pyreadstat/_readstat_parser.pyx":522 * index = readstat_variable_get_index_after_skipping(variable) * * if col_name in dc.col_names: # <<<<<<<<<<<<<< * dupcolcnt = 1 * while True: */ } /* "pyreadstat/_readstat_parser.pyx":535 * break * * dc.col_names.append(col_name) # <<<<<<<<<<<<<< * * # the name of the value label for the variable */ if (unlikely(__pyx_v_dc->col_names == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); __PYX_ERR(0, 535, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_dc->col_names, __pyx_v_col_name); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 535, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":538 * * # the name of the value label for the variable * if val_labels != NULL: # <<<<<<<<<<<<<< * label_name = val_labels * if label_name: */ __pyx_t_2 = (__pyx_v_val_labels != NULL); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":539 * # the name of the value label for the variable * if val_labels != NULL: * label_name = val_labels # <<<<<<<<<<<<<< * if label_name: * dc.label_to_var_name[col_name] = label_name */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_val_labels); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 539, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_label_name = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":540 * if val_labels != NULL: * label_name = val_labels * if label_name: # <<<<<<<<<<<<<< * dc.label_to_var_name[col_name] = label_name * */ __pyx_t_2 = (__pyx_v_label_name != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_label_name) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_2 < 0))) __PYX_ERR(0, 540, __pyx_L1_error) if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":541 * label_name = val_labels * if label_name: * dc.label_to_var_name[col_name] = label_name # <<<<<<<<<<<<<< * * var_label = readstat_variable_get_label(variable) */ if (unlikely((PyObject_SetItem(__pyx_v_dc->label_to_var_name, __pyx_v_col_name, __pyx_v_label_name) < 0))) __PYX_ERR(0, 541, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":540 * if val_labels != NULL: * label_name = val_labels * if label_name: # <<<<<<<<<<<<<< * dc.label_to_var_name[col_name] = label_name * */ } /* "pyreadstat/_readstat_parser.pyx":538 * * # the name of the value label for the variable * if val_labels != NULL: # <<<<<<<<<<<<<< * label_name = val_labels * if label_name: */ } /* "pyreadstat/_readstat_parser.pyx":543 * dc.label_to_var_name[col_name] = label_name * * var_label = readstat_variable_get_label(variable) # <<<<<<<<<<<<<< * if var_label == NULL: * col_label = None */ __pyx_v_var_label = readstat_variable_get_label(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":544 * * var_label = readstat_variable_get_label(variable) * if var_label == NULL: # <<<<<<<<<<<<<< * col_label = None * else: */ __pyx_t_2 = (__pyx_v_var_label == NULL); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":545 * var_label = readstat_variable_get_label(variable) * if var_label == NULL: * col_label = None # <<<<<<<<<<<<<< * else: * col_label = var_label */ __Pyx_INCREF(Py_None); __pyx_v_col_label = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":544 * * var_label = readstat_variable_get_label(variable) * if var_label == NULL: # <<<<<<<<<<<<<< * col_label = None * else: */ goto __pyx_L13; } /* "pyreadstat/_readstat_parser.pyx":547 * col_label = None * else: * col_label = var_label # <<<<<<<<<<<<<< * dc.col_labels.append(col_label) * */ /*else*/ { __pyx_t_7 = __Pyx_PyUnicode_FromString(__pyx_v_var_label); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 547, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_col_label = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; } __pyx_L13:; /* "pyreadstat/_readstat_parser.pyx":548 * else: * col_label = var_label * dc.col_labels.append(col_label) # <<<<<<<<<<<<<< * * # format, we have to transform it in something more usable */ if (unlikely(__pyx_v_dc->col_labels == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); __PYX_ERR(0, 548, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_dc->col_labels, __pyx_v_col_label); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 548, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":551 * * # format, we have to transform it in something more usable * var_format = readstat_variable_get_format(variable) # <<<<<<<<<<<<<< * if var_format == NULL: * #col_format_original = "NULL" */ __pyx_v_var_format = readstat_variable_get_format(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":552 * # format, we have to transform it in something more usable * var_format = readstat_variable_get_format(variable) * if var_format == NULL: # <<<<<<<<<<<<<< * #col_format_original = "NULL" * col_format_original = None */ __pyx_t_2 = (__pyx_v_var_format == NULL); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":554 * if var_format == NULL: * #col_format_original = "NULL" * col_format_original = None # <<<<<<<<<<<<<< * else: * col_format_original = var_format */ __Pyx_INCREF(Py_None); __pyx_v_col_format_original = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":552 * # format, we have to transform it in something more usable * var_format = readstat_variable_get_format(variable) * if var_format == NULL: # <<<<<<<<<<<<<< * #col_format_original = "NULL" * col_format_original = None */ goto __pyx_L14; } /* "pyreadstat/_readstat_parser.pyx":556 * col_format_original = None * else: * col_format_original = var_format # <<<<<<<<<<<<<< * file_format = dc.file_format * dc.col_formats_original.append(col_format_original) */ /*else*/ { __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_var_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_col_format_original = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; } __pyx_L14:; /* "pyreadstat/_readstat_parser.pyx":557 * else: * col_format_original = var_format * file_format = dc.file_format # <<<<<<<<<<<<<< * dc.col_formats_original.append(col_format_original) * col_format_final = transform_variable_format(col_format_original, file_format) */ __pyx_t_9 = __pyx_v_dc->file_format; __pyx_v_file_format = __pyx_t_9; /* "pyreadstat/_readstat_parser.pyx":558 * col_format_original = var_format * file_format = dc.file_format * dc.col_formats_original.append(col_format_original) # <<<<<<<<<<<<<< * col_format_final = transform_variable_format(col_format_original, file_format) * dc.col_formats.append(col_format_final) */ if (unlikely(__pyx_v_dc->col_formats_original == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); __PYX_ERR(0, 558, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_dc->col_formats_original, __pyx_v_col_format_original); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 558, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":559 * file_format = dc.file_format * dc.col_formats_original.append(col_format_original) * col_format_final = transform_variable_format(col_format_original, file_format) # <<<<<<<<<<<<<< * dc.col_formats.append(col_format_final) * # readstat type */ __pyx_t_10 = __pyx_f_10pyreadstat_16_readstat_parser_transform_variable_format(__pyx_v_col_format_original, __pyx_v_file_format); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 559, __pyx_L1_error) __pyx_v_col_format_final = __pyx_t_10; /* "pyreadstat/_readstat_parser.pyx":560 * dc.col_formats_original.append(col_format_original) * col_format_final = transform_variable_format(col_format_original, file_format) * dc.col_formats.append(col_format_final) # <<<<<<<<<<<<<< * # readstat type * var_type = readstat_variable_get_type(variable) */ if (unlikely(__pyx_v_dc->col_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); __PYX_ERR(0, 560, __pyx_L1_error) } __pyx_t_7 = __Pyx_PyLong_From___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(__pyx_v_col_format_final); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_dc->col_formats, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":562 * dc.col_formats.append(col_format_final) * # readstat type * var_type = readstat_variable_get_type(variable) # <<<<<<<<<<<<<< * dc.col_dtypes.append(var_type) * # equivalent numpy type */ __pyx_v_var_type = readstat_variable_get_type(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":563 * # readstat type * var_type = readstat_variable_get_type(variable) * dc.col_dtypes.append(var_type) # <<<<<<<<<<<<<< * # equivalent numpy type * # if it's a date then we need object */ if (unlikely(__pyx_v_dc->col_dtypes == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); __PYX_ERR(0, 563, __pyx_L1_error) } __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(__pyx_v_var_type); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_dc->col_dtypes, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":566 * # equivalent numpy type * # if it's a date then we need object * if col_format_final != DATE_FORMAT_NOTADATE and dc.no_datetime_conversion == 0: # <<<<<<<<<<<<<< * curnptype = object * else: */ __pyx_t_4 = (__pyx_v_col_format_final != __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_NOTADATE); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L16_bool_binop_done; } __pyx_t_4 = (__pyx_v_dc->no_datetime_conversion == 0); __pyx_t_2 = __pyx_t_4; __pyx_L16_bool_binop_done:; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":567 * # if it's a date then we need object * if col_format_final != DATE_FORMAT_NOTADATE and dc.no_datetime_conversion == 0: * curnptype = object # <<<<<<<<<<<<<< * else: * curnptype = readstat_to_numpy_types[var_type] */ __Pyx_INCREF(__pyx_builtin_object); __pyx_v_curnptype = __pyx_builtin_object; /* "pyreadstat/_readstat_parser.pyx":566 * # equivalent numpy type * # if it's a date then we need object * if col_format_final != DATE_FORMAT_NOTADATE and dc.no_datetime_conversion == 0: # <<<<<<<<<<<<<< * curnptype = object * else: */ goto __pyx_L15; } /* "pyreadstat/_readstat_parser.pyx":569 * curnptype = object * else: * curnptype = readstat_to_numpy_types[var_type] # <<<<<<<<<<<<<< * iscurnptypefloat = 0 * iscurnptypeobject = 0 */ /*else*/ { if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 569, __pyx_L1_error) } __pyx_t_7 = __Pyx_PyLong_From_readstat_type_t(__pyx_v_var_type); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_curnptype = __pyx_t_1; __pyx_t_1 = 0; } __pyx_L15:; /* "pyreadstat/_readstat_parser.pyx":570 * else: * curnptype = readstat_to_numpy_types[var_type] * iscurnptypefloat = 0 # <<<<<<<<<<<<<< * iscurnptypeobject = 0 * # book keeping numpy types */ __pyx_v_iscurnptypefloat = 0; /* "pyreadstat/_readstat_parser.pyx":571 * curnptype = readstat_to_numpy_types[var_type] * iscurnptypefloat = 0 * iscurnptypeobject = 0 # <<<<<<<<<<<<<< * # book keeping numpy types * dc.col_numpy_dtypes[index] = curnptype */ __pyx_v_iscurnptypeobject = 0; /* "pyreadstat/_readstat_parser.pyx":573 * iscurnptypeobject = 0 * # book keeping numpy types * dc.col_numpy_dtypes[index] = curnptype # <<<<<<<<<<<<<< * if curnptype == object: * iscurnptypeobject = 1 */ if (unlikely(__pyx_v_dc->col_numpy_dtypes == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 573, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_numpy_dtypes, __pyx_v_index, __pyx_v_curnptype, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 573, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":574 * # book keeping numpy types * dc.col_numpy_dtypes[index] = curnptype * if curnptype == object: # <<<<<<<<<<<<<< * iscurnptypeobject = 1 * if curnptype == np.float64: */ __pyx_t_1 = PyObject_RichCompare(__pyx_v_curnptype, __pyx_builtin_object, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 574, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":575 * dc.col_numpy_dtypes[index] = curnptype * if curnptype == object: * iscurnptypeobject = 1 # <<<<<<<<<<<<<< * if curnptype == np.float64: * iscurnptypefloat = 1 */ __pyx_v_iscurnptypeobject = 1; /* "pyreadstat/_readstat_parser.pyx":574 * # book keeping numpy types * dc.col_numpy_dtypes[index] = curnptype * if curnptype == object: # <<<<<<<<<<<<<< * iscurnptypeobject = 1 * if curnptype == np.float64: */ } /* "pyreadstat/_readstat_parser.pyx":576 * if curnptype == object: * iscurnptypeobject = 1 * if curnptype == np.float64: # <<<<<<<<<<<<<< * iscurnptypefloat = 1 * dc.col_dtypes_isobject[index] = iscurnptypeobject */ __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_RichCompare(__pyx_v_curnptype, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __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, 576, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":577 * iscurnptypeobject = 1 * if curnptype == np.float64: * iscurnptypefloat = 1 # <<<<<<<<<<<<<< * dc.col_dtypes_isobject[index] = iscurnptypeobject * dc.col_dytpes_isfloat[index] = iscurnptypefloat */ __pyx_v_iscurnptypefloat = 1; /* "pyreadstat/_readstat_parser.pyx":576 * if curnptype == object: * iscurnptypeobject = 1 * if curnptype == np.float64: # <<<<<<<<<<<<<< * iscurnptypefloat = 1 * dc.col_dtypes_isobject[index] = iscurnptypeobject */ } /* "pyreadstat/_readstat_parser.pyx":578 * if curnptype == np.float64: * iscurnptypefloat = 1 * dc.col_dtypes_isobject[index] = iscurnptypeobject # <<<<<<<<<<<<<< * dc.col_dytpes_isfloat[index] = iscurnptypefloat * metaonly = dc.metaonly */ __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_iscurnptypeobject); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely(__pyx_v_dc->col_dtypes_isobject == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 578, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_dtypes_isobject, __pyx_v_index, __pyx_t_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":579 * iscurnptypefloat = 1 * dc.col_dtypes_isobject[index] = iscurnptypeobject * dc.col_dytpes_isfloat[index] = iscurnptypefloat # <<<<<<<<<<<<<< * metaonly = dc.metaonly * # pre-allocate data */ __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_iscurnptypefloat); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely(__pyx_v_dc->col_dytpes_isfloat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 579, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_dytpes_isfloat, __pyx_v_index, __pyx_t_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":580 * dc.col_dtypes_isobject[index] = iscurnptypeobject * dc.col_dytpes_isfloat[index] = iscurnptypefloat * metaonly = dc.metaonly # <<<<<<<<<<<<<< * # pre-allocate data * if metaonly: */ __pyx_t_2 = __pyx_v_dc->metaonly; __pyx_v_metaonly = __pyx_t_2; /* "pyreadstat/_readstat_parser.pyx":582 * metaonly = dc.metaonly * # pre-allocate data * if metaonly: # <<<<<<<<<<<<<< * if output_format == "pandas": * row = np.empty(1, dtype=curnptype) */ if (__pyx_v_metaonly) { /* "pyreadstat/_readstat_parser.pyx":583 * # pre-allocate data * if metaonly: * if output_format == "pandas": # <<<<<<<<<<<<<< * row = np.empty(1, dtype=curnptype) * else: */ __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 583, __pyx_L1_error) if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":584 * if metaonly: * if output_format == "pandas": * row = np.empty(1, dtype=curnptype) # <<<<<<<<<<<<<< * else: * row = list() */ __pyx_t_7 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_7); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_7, __pyx_mstate_global->__pyx_int_1}; __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_v_curnptype, __pyx_t_5, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 584, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_row = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":583 * # pre-allocate data * if metaonly: * if output_format == "pandas": # <<<<<<<<<<<<<< * row = np.empty(1, dtype=curnptype) * else: */ goto __pyx_L21; } /* "pyreadstat/_readstat_parser.pyx":586 * row = np.empty(1, dtype=curnptype) * else: * row = list() # <<<<<<<<<<<<<< * else: * obs_count = dc.n_obs */ /*else*/ { __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_row = __pyx_t_1; __pyx_t_1 = 0; } __pyx_L21:; /* "pyreadstat/_readstat_parser.pyx":582 * metaonly = dc.metaonly * # pre-allocate data * if metaonly: # <<<<<<<<<<<<<< * if output_format == "pandas": * row = np.empty(1, dtype=curnptype) */ goto __pyx_L20; } /* "pyreadstat/_readstat_parser.pyx":588 * row = list() * else: * obs_count = dc.n_obs # <<<<<<<<<<<<<< * if output_format == "pandas": * row = np.empty(obs_count, dtype=curnptype) */ /*else*/ { __pyx_t_11 = __pyx_v_dc->n_obs; __pyx_v_obs_count = __pyx_t_11; /* "pyreadstat/_readstat_parser.pyx":589 * else: * obs_count = dc.n_obs * if output_format == "pandas": # <<<<<<<<<<<<<< * row = np.empty(obs_count, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: */ __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 589, __pyx_L1_error) if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":590 * obs_count = dc.n_obs * if output_format == "pandas": * row = np.empty(obs_count, dtype=curnptype) # <<<<<<<<<<<<<< * if iscurnptypeobject or iscurnptypefloat: * row.fill(np.nan) */ __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyLong_From_int(__pyx_v_obs_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_7))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_7, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_3, __pyx_t_5}; __pyx_t_12 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_v_curnptype, __pyx_t_12, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 590, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_7, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_12); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_row = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":591 * if output_format == "pandas": * row = np.empty(obs_count, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: # <<<<<<<<<<<<<< * row.fill(np.nan) * else: */ if (!__pyx_v_iscurnptypeobject) { } else { __pyx_t_2 = __pyx_v_iscurnptypeobject; goto __pyx_L24_bool_binop_done; } __pyx_t_2 = __pyx_v_iscurnptypefloat; __pyx_L24_bool_binop_done:; if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":592 * row = np.empty(obs_count, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: * row.fill(np.nan) # <<<<<<<<<<<<<< * else: * row = [None] * obs_count */ __pyx_t_7 = __pyx_v_row; __Pyx_INCREF(__pyx_t_7); __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nan); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_5}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_fill, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":591 * if output_format == "pandas": * row = np.empty(obs_count, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: # <<<<<<<<<<<<<< * row.fill(np.nan) * else: */ } /* "pyreadstat/_readstat_parser.pyx":589 * else: * obs_count = dc.n_obs * if output_format == "pandas": # <<<<<<<<<<<<<< * row = np.empty(obs_count, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: */ goto __pyx_L22; } /* "pyreadstat/_readstat_parser.pyx":594 * row.fill(np.nan) * else: * row = [None] * obs_count # <<<<<<<<<<<<<< * dc.col_data.append(row) * */ /*else*/ { __pyx_t_1 = PyList_New(1 * ((__pyx_v_obs_count<0) ? 0:__pyx_v_obs_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_obs_count; __pyx_temp++) { __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None) != (0)) __PYX_ERR(0, 594, __pyx_L1_error); } } __pyx_v_row = __pyx_t_1; __pyx_t_1 = 0; } __pyx_L22:; } __pyx_L20:; /* "pyreadstat/_readstat_parser.pyx":595 * else: * row = [None] * obs_count * dc.col_data.append(row) # <<<<<<<<<<<<<< * * # missing values */ if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); __PYX_ERR(0, 595, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_dc->col_data, __pyx_v_row); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 595, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":598 * * # missing values * if dc.usernan: # <<<<<<<<<<<<<< * n_ranges = readstat_variable_get_missing_ranges_count(variable) * if n_ranges>0: */ if (__pyx_v_dc->usernan) { /* "pyreadstat/_readstat_parser.pyx":599 * # missing values * if dc.usernan: * n_ranges = readstat_variable_get_missing_ranges_count(variable) # <<<<<<<<<<<<<< * if n_ranges>0: * missing_ranges = list() */ __pyx_v_n_ranges = readstat_variable_get_missing_ranges_count(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":600 * if dc.usernan: * n_ranges = readstat_variable_get_missing_ranges_count(variable) * if n_ranges>0: # <<<<<<<<<<<<<< * missing_ranges = list() * for i in range(0, n_ranges): */ __pyx_t_2 = (__pyx_v_n_ranges > 0); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":601 * n_ranges = readstat_variable_get_missing_ranges_count(variable) * if n_ranges>0: * missing_ranges = list() # <<<<<<<<<<<<<< * for i in range(0, n_ranges): * loval = readstat_variable_get_missing_range_lo(variable, i) */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_missing_ranges = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":602 * if n_ranges>0: * missing_ranges = list() * for i in range(0, n_ranges): # <<<<<<<<<<<<<< * loval = readstat_variable_get_missing_range_lo(variable, i) * pyloval = convert_readstat_to_python_value(loval, index, dc) */ __pyx_t_11 = __pyx_v_n_ranges; __pyx_t_13 = __pyx_t_11; for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { __pyx_v_i = __pyx_t_14; /* "pyreadstat/_readstat_parser.pyx":603 * missing_ranges = list() * for i in range(0, n_ranges): * loval = readstat_variable_get_missing_range_lo(variable, i) # <<<<<<<<<<<<<< * pyloval = convert_readstat_to_python_value(loval, index, dc) * hival = readstat_variable_get_missing_range_hi(variable, i) */ __pyx_v_loval = readstat_variable_get_missing_range_lo(__pyx_v_variable, __pyx_v_i); /* "pyreadstat/_readstat_parser.pyx":604 * for i in range(0, n_ranges): * loval = readstat_variable_get_missing_range_lo(variable, i) * pyloval = convert_readstat_to_python_value(loval, index, dc) # <<<<<<<<<<<<<< * hival = readstat_variable_get_missing_range_hi(variable, i) * pyhival = convert_readstat_to_python_value(hival, index, dc) */ __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_parser_convert_readstat_to_python_value(__pyx_v_loval, __pyx_v_index, __pyx_v_dc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 604, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_pyloval, __pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":605 * loval = readstat_variable_get_missing_range_lo(variable, i) * pyloval = convert_readstat_to_python_value(loval, index, dc) * hival = readstat_variable_get_missing_range_hi(variable, i) # <<<<<<<<<<<<<< * pyhival = convert_readstat_to_python_value(hival, index, dc) * missing_ranges.append({'lo':pyloval, 'hi':pyhival}) */ __pyx_v_hival = readstat_variable_get_missing_range_hi(__pyx_v_variable, __pyx_v_i); /* "pyreadstat/_readstat_parser.pyx":606 * pyloval = convert_readstat_to_python_value(loval, index, dc) * hival = readstat_variable_get_missing_range_hi(variable, i) * pyhival = convert_readstat_to_python_value(hival, index, dc) # <<<<<<<<<<<<<< * missing_ranges.append({'lo':pyloval, 'hi':pyhival}) * dc.missing_ranges[col_name] = missing_ranges */ __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_parser_convert_readstat_to_python_value(__pyx_v_hival, __pyx_v_index, __pyx_v_dc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_pyhival, __pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":607 * hival = readstat_variable_get_missing_range_hi(variable, i) * pyhival = convert_readstat_to_python_value(hival, index, dc) * missing_ranges.append({'lo':pyloval, 'hi':pyhival}) # <<<<<<<<<<<<<< * dc.missing_ranges[col_name] = missing_ranges * */ __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_lo, __pyx_v_pyloval) < 0) __PYX_ERR(0, 607, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_hi, __pyx_v_pyhival) < 0) __PYX_ERR(0, 607, __pyx_L1_error) __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_missing_ranges, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 607, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } /* "pyreadstat/_readstat_parser.pyx":608 * pyhival = convert_readstat_to_python_value(hival, index, dc) * missing_ranges.append({'lo':pyloval, 'hi':pyhival}) * dc.missing_ranges[col_name] = missing_ranges # <<<<<<<<<<<<<< * * cdef size_t storage_width */ if (unlikely(__pyx_v_dc->missing_ranges == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 608, __pyx_L1_error) } if (unlikely((PyDict_SetItem(__pyx_v_dc->missing_ranges, __pyx_v_col_name, __pyx_v_missing_ranges) < 0))) __PYX_ERR(0, 608, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":600 * if dc.usernan: * n_ranges = readstat_variable_get_missing_ranges_count(variable) * if n_ranges>0: # <<<<<<<<<<<<<< * missing_ranges = list() * for i in range(0, n_ranges): */ } /* "pyreadstat/_readstat_parser.pyx":598 * * # missing values * if dc.usernan: # <<<<<<<<<<<<<< * n_ranges = readstat_variable_get_missing_ranges_count(variable) * if n_ranges>0: */ } /* "pyreadstat/_readstat_parser.pyx":611 * * cdef size_t storage_width * storage_width = readstat_variable_get_storage_width(variable) # <<<<<<<<<<<<<< * dc.variable_storage_width[col_name] = storage_width * */ __pyx_v_storage_width = readstat_variable_get_storage_width(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":612 * cdef size_t storage_width * storage_width = readstat_variable_get_storage_width(variable) * dc.variable_storage_width[col_name] = storage_width # <<<<<<<<<<<<<< * * dc.variable_display_width[col_name] = readstat_variable_get_display_width(variable) */ __pyx_t_1 = __Pyx_PyLong_From_int(((int)__pyx_v_storage_width)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 612, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely(__pyx_v_dc->variable_storage_width == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 612, __pyx_L1_error) } if (unlikely((PyDict_SetItem(__pyx_v_dc->variable_storage_width, __pyx_v_col_name, __pyx_t_1) < 0))) __PYX_ERR(0, 612, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":614 * dc.variable_storage_width[col_name] = storage_width * * dc.variable_display_width[col_name] = readstat_variable_get_display_width(variable) # <<<<<<<<<<<<<< * * cdef readstat_alignment_t align */ __pyx_t_1 = __Pyx_PyLong_From_int(readstat_variable_get_display_width(__pyx_v_variable)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 614, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely((PyObject_SetItem(__pyx_v_dc->variable_display_width, __pyx_v_col_name, __pyx_t_1) < 0))) __PYX_ERR(0, 614, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":618 * cdef readstat_alignment_t align * cdef str pyalign * align = readstat_variable_get_alignment(variable) # <<<<<<<<<<<<<< * if align == READSTAT_ALIGNMENT_UNKNOWN: * pyalign = "unknown" */ __pyx_v_align = readstat_variable_get_alignment(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":619 * cdef str pyalign * align = readstat_variable_get_alignment(variable) * if align == READSTAT_ALIGNMENT_UNKNOWN: # <<<<<<<<<<<<<< * pyalign = "unknown" * elif align == READSTAT_ALIGNMENT_LEFT: */ switch (__pyx_v_align) { case READSTAT_ALIGNMENT_UNKNOWN: /* "pyreadstat/_readstat_parser.pyx":620 * align = readstat_variable_get_alignment(variable) * if align == READSTAT_ALIGNMENT_UNKNOWN: * pyalign = "unknown" # <<<<<<<<<<<<<< * elif align == READSTAT_ALIGNMENT_LEFT: * pyalign = "left" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_unknown); __pyx_v_pyalign = __pyx_mstate_global->__pyx_n_u_unknown; /* "pyreadstat/_readstat_parser.pyx":619 * cdef str pyalign * align = readstat_variable_get_alignment(variable) * if align == READSTAT_ALIGNMENT_UNKNOWN: # <<<<<<<<<<<<<< * pyalign = "unknown" * elif align == READSTAT_ALIGNMENT_LEFT: */ break; case READSTAT_ALIGNMENT_LEFT: /* "pyreadstat/_readstat_parser.pyx":622 * pyalign = "unknown" * elif align == READSTAT_ALIGNMENT_LEFT: * pyalign = "left" # <<<<<<<<<<<<<< * elif align == READSTAT_ALIGNMENT_CENTER: * pyalign = "center" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_left); __pyx_v_pyalign = __pyx_mstate_global->__pyx_n_u_left; /* "pyreadstat/_readstat_parser.pyx":621 * if align == READSTAT_ALIGNMENT_UNKNOWN: * pyalign = "unknown" * elif align == READSTAT_ALIGNMENT_LEFT: # <<<<<<<<<<<<<< * pyalign = "left" * elif align == READSTAT_ALIGNMENT_CENTER: */ break; case READSTAT_ALIGNMENT_CENTER: /* "pyreadstat/_readstat_parser.pyx":624 * pyalign = "left" * elif align == READSTAT_ALIGNMENT_CENTER: * pyalign = "center" # <<<<<<<<<<<<<< * elif align == READSTAT_ALIGNMENT_RIGHT: * pyalign = "right" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_center); __pyx_v_pyalign = __pyx_mstate_global->__pyx_n_u_center; /* "pyreadstat/_readstat_parser.pyx":623 * elif align == READSTAT_ALIGNMENT_LEFT: * pyalign = "left" * elif align == READSTAT_ALIGNMENT_CENTER: # <<<<<<<<<<<<<< * pyalign = "center" * elif align == READSTAT_ALIGNMENT_RIGHT: */ break; case READSTAT_ALIGNMENT_RIGHT: /* "pyreadstat/_readstat_parser.pyx":626 * pyalign = "center" * elif align == READSTAT_ALIGNMENT_RIGHT: * pyalign = "right" # <<<<<<<<<<<<<< * else: * pyalign = "undetermined" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_right); __pyx_v_pyalign = __pyx_mstate_global->__pyx_n_u_right; /* "pyreadstat/_readstat_parser.pyx":625 * elif align == READSTAT_ALIGNMENT_CENTER: * pyalign = "center" * elif align == READSTAT_ALIGNMENT_RIGHT: # <<<<<<<<<<<<<< * pyalign = "right" * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":628 * pyalign = "right" * else: * pyalign = "undetermined" # <<<<<<<<<<<<<< * * dc.variable_alignment[col_name] = pyalign */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_undetermined); __pyx_v_pyalign = __pyx_mstate_global->__pyx_n_u_undetermined; break; } /* "pyreadstat/_readstat_parser.pyx":630 * pyalign = "undetermined" * * dc.variable_alignment[col_name] = pyalign # <<<<<<<<<<<<<< * * cdef readstat_measure_t measure */ if (unlikely((PyObject_SetItem(__pyx_v_dc->variable_alignment, __pyx_v_col_name, __pyx_v_pyalign) < 0))) __PYX_ERR(0, 630, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":634 * cdef readstat_measure_t measure * cdef str pymeasure * measure = readstat_variable_get_measure(variable) # <<<<<<<<<<<<<< * if measure == READSTAT_MEASURE_UNKNOWN: * pymeasure = "unknown" */ __pyx_v_measure = readstat_variable_get_measure(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":635 * cdef str pymeasure * measure = readstat_variable_get_measure(variable) * if measure == READSTAT_MEASURE_UNKNOWN: # <<<<<<<<<<<<<< * pymeasure = "unknown" * elif measure == READSTAT_MEASURE_NOMINAL: */ switch (__pyx_v_measure) { case READSTAT_MEASURE_UNKNOWN: /* "pyreadstat/_readstat_parser.pyx":636 * measure = readstat_variable_get_measure(variable) * if measure == READSTAT_MEASURE_UNKNOWN: * pymeasure = "unknown" # <<<<<<<<<<<<<< * elif measure == READSTAT_MEASURE_NOMINAL: * pymeasure = "nominal" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_unknown); __pyx_v_pymeasure = __pyx_mstate_global->__pyx_n_u_unknown; /* "pyreadstat/_readstat_parser.pyx":635 * cdef str pymeasure * measure = readstat_variable_get_measure(variable) * if measure == READSTAT_MEASURE_UNKNOWN: # <<<<<<<<<<<<<< * pymeasure = "unknown" * elif measure == READSTAT_MEASURE_NOMINAL: */ break; case READSTAT_MEASURE_NOMINAL: /* "pyreadstat/_readstat_parser.pyx":638 * pymeasure = "unknown" * elif measure == READSTAT_MEASURE_NOMINAL: * pymeasure = "nominal" # <<<<<<<<<<<<<< * elif measure == READSTAT_MEASURE_ORDINAL: * pymeasure = "ordinal" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_nominal); __pyx_v_pymeasure = __pyx_mstate_global->__pyx_n_u_nominal; /* "pyreadstat/_readstat_parser.pyx":637 * if measure == READSTAT_MEASURE_UNKNOWN: * pymeasure = "unknown" * elif measure == READSTAT_MEASURE_NOMINAL: # <<<<<<<<<<<<<< * pymeasure = "nominal" * elif measure == READSTAT_MEASURE_ORDINAL: */ break; case READSTAT_MEASURE_ORDINAL: /* "pyreadstat/_readstat_parser.pyx":640 * pymeasure = "nominal" * elif measure == READSTAT_MEASURE_ORDINAL: * pymeasure = "ordinal" # <<<<<<<<<<<<<< * elif measure == READSTAT_MEASURE_SCALE: * pymeasure = "scale" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_ordinal); __pyx_v_pymeasure = __pyx_mstate_global->__pyx_n_u_ordinal; /* "pyreadstat/_readstat_parser.pyx":639 * elif measure == READSTAT_MEASURE_NOMINAL: * pymeasure = "nominal" * elif measure == READSTAT_MEASURE_ORDINAL: # <<<<<<<<<<<<<< * pymeasure = "ordinal" * elif measure == READSTAT_MEASURE_SCALE: */ break; case READSTAT_MEASURE_SCALE: /* "pyreadstat/_readstat_parser.pyx":642 * pymeasure = "ordinal" * elif measure == READSTAT_MEASURE_SCALE: * pymeasure = "scale" # <<<<<<<<<<<<<< * else: * pymeasure = "undetermined" */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_scale); __pyx_v_pymeasure = __pyx_mstate_global->__pyx_n_u_scale; /* "pyreadstat/_readstat_parser.pyx":641 * elif measure == READSTAT_MEASURE_ORDINAL: * pymeasure = "ordinal" * elif measure == READSTAT_MEASURE_SCALE: # <<<<<<<<<<<<<< * pymeasure = "scale" * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":644 * pymeasure = "scale" * else: * pymeasure = "undetermined" # <<<<<<<<<<<<<< * * dc.variable_measure[col_name] = pymeasure */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_undetermined); __pyx_v_pymeasure = __pyx_mstate_global->__pyx_n_u_undetermined; break; } /* "pyreadstat/_readstat_parser.pyx":646 * pymeasure = "undetermined" * * dc.variable_measure[col_name] = pymeasure # <<<<<<<<<<<<<< * * return READSTAT_HANDLER_OK */ if (unlikely((PyObject_SetItem(__pyx_v_dc->variable_measure, __pyx_v_col_name, __pyx_v_pymeasure) < 0))) __PYX_ERR(0, 646, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":648 * dc.variable_measure[col_name] = pymeasure * * return READSTAT_HANDLER_OK # <<<<<<<<<<<<<< * * */ __pyx_r = READSTAT_HANDLER_OK; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":476 * return READSTAT_HANDLER_OK * * cdef int handle_variable(int index, readstat_variable_t *variable, # <<<<<<<<<<<<<< * char *val_labels, void *ctx) except READSTAT_HANDLER_ABORT: * """ */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("pyreadstat._readstat_parser.handle_variable", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = READSTAT_HANDLER_ABORT; __pyx_L0:; __Pyx_XDECREF(__pyx_v_col_name); __Pyx_XDECREF(__pyx_v_col_label); __Pyx_XDECREF(__pyx_v_label_name); __Pyx_XDECREF(__pyx_v_col_format_original); __Pyx_XDECREF(__pyx_v_output_format); __Pyx_XDECREF(__pyx_v_pyloval); __Pyx_XDECREF(__pyx_v_pyhival); __Pyx_XDECREF(__pyx_v_missing_ranges); __Pyx_XDECREF(__pyx_v_curnptype); __Pyx_XDECREF(__pyx_v_row); __Pyx_XDECREF(__pyx_v_newcolname); __Pyx_XDECREF((PyObject *)__pyx_v_dc); __Pyx_XDECREF(__pyx_v_msg); __Pyx_XDECREF(__pyx_v_pyalign); __Pyx_XDECREF(__pyx_v_pymeasure); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":651 * * * cdef int handle_value(int obs_index, readstat_variable_t * variable, readstat_value_t value, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * This function transforms every value to python types, and to datetime if */ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_value(int __pyx_v_obs_index, readstat_variable_t *__pyx_v_variable, readstat_value_t __pyx_v_value, void *__pyx_v_ctx) { struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc = 0; int __pyx_v_index; int __pyx_v_max_n_obs; int __pyx_v_is_unkown_number_rows; int __pyx_v_var_max_rows; PyObject *__pyx_v_buf_list = 0; int __pyx_v_iscurnptypeobject; int __pyx_v_iscurnptypefloat; int __pyx_v_missing_tag; PyObject *__pyx_v_pyvalue = 0; PyObject *__pyx_v_curset = 0; PyObject *__pyx_v_curnptype = 0; PyObject *__pyx_v_output_format = 0; int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; size_t __pyx_t_7; int __pyx_t_8; int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("handle_value", 0); /* "pyreadstat/_readstat_parser.pyx":672 * * # extract variables we need from data container * dc = ctx # <<<<<<<<<<<<<< * output_format = dc.output_format * index = readstat_variable_get_index_after_skipping(variable) */ __pyx_t_1 = ((PyObject *)__pyx_v_ctx); __Pyx_INCREF(__pyx_t_1); __pyx_v_dc = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":673 * # extract variables we need from data container * dc = ctx * output_format = dc.output_format # <<<<<<<<<<<<<< * index = readstat_variable_get_index_after_skipping(variable) * max_n_obs = dc.max_n_obs */ __pyx_t_1 = __pyx_v_dc->output_format; __Pyx_INCREF(__pyx_t_1); __pyx_v_output_format = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":674 * dc = ctx * output_format = dc.output_format * index = readstat_variable_get_index_after_skipping(variable) # <<<<<<<<<<<<<< * max_n_obs = dc.max_n_obs * is_unkown_number_rows = dc.is_unkown_number_rows */ __pyx_v_index = readstat_variable_get_index_after_skipping(__pyx_v_variable); /* "pyreadstat/_readstat_parser.pyx":675 * output_format = dc.output_format * index = readstat_variable_get_index_after_skipping(variable) * max_n_obs = dc.max_n_obs # <<<<<<<<<<<<<< * is_unkown_number_rows = dc.is_unkown_number_rows * */ __pyx_t_2 = __pyx_v_dc->max_n_obs; __pyx_v_max_n_obs = __pyx_t_2; /* "pyreadstat/_readstat_parser.pyx":676 * index = readstat_variable_get_index_after_skipping(variable) * max_n_obs = dc.max_n_obs * is_unkown_number_rows = dc.is_unkown_number_rows # <<<<<<<<<<<<<< * * # check that we still have enough room in our pre-allocated lists */ __pyx_t_3 = __pyx_v_dc->is_unkown_number_rows; __pyx_v_is_unkown_number_rows = __pyx_t_3; /* "pyreadstat/_readstat_parser.pyx":680 * # check that we still have enough room in our pre-allocated lists * # if not, add more room * iscurnptypeobject = dc.col_dtypes_isobject[index] # <<<<<<<<<<<<<< * iscurnptypefloat = dc.col_dytpes_isfloat[index] * if is_unkown_number_rows: */ if (unlikely(__pyx_v_dc->col_dtypes_isobject == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 680, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_dtypes_isobject, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 680, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 680, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_iscurnptypeobject = __pyx_t_3; /* "pyreadstat/_readstat_parser.pyx":681 * # if not, add more room * iscurnptypeobject = dc.col_dtypes_isobject[index] * iscurnptypefloat = dc.col_dytpes_isfloat[index] # <<<<<<<<<<<<<< * if is_unkown_number_rows: * if max_n_obs <= obs_index: */ if (unlikely(__pyx_v_dc->col_dytpes_isfloat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 681, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_dytpes_isfloat, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 681, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_iscurnptypefloat = __pyx_t_3; /* "pyreadstat/_readstat_parser.pyx":682 * iscurnptypeobject = dc.col_dtypes_isobject[index] * iscurnptypefloat = dc.col_dytpes_isfloat[index] * if is_unkown_number_rows: # <<<<<<<<<<<<<< * if max_n_obs <= obs_index: * dc.max_n_obs = obs_index + 1 */ if (__pyx_v_is_unkown_number_rows) { /* "pyreadstat/_readstat_parser.pyx":683 * iscurnptypefloat = dc.col_dytpes_isfloat[index] * if is_unkown_number_rows: * if max_n_obs <= obs_index: # <<<<<<<<<<<<<< * dc.max_n_obs = obs_index + 1 * var_max_rows = dc.col_data_len[index] */ __pyx_t_3 = (__pyx_v_max_n_obs <= __pyx_v_obs_index); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":684 * if is_unkown_number_rows: * if max_n_obs <= obs_index: * dc.max_n_obs = obs_index + 1 # <<<<<<<<<<<<<< * var_max_rows = dc.col_data_len[index] * if var_max_rows <= obs_index: */ __pyx_v_dc->max_n_obs = (__pyx_v_obs_index + 1); /* "pyreadstat/_readstat_parser.pyx":683 * iscurnptypefloat = dc.col_dytpes_isfloat[index] * if is_unkown_number_rows: * if max_n_obs <= obs_index: # <<<<<<<<<<<<<< * dc.max_n_obs = obs_index + 1 * var_max_rows = dc.col_data_len[index] */ } /* "pyreadstat/_readstat_parser.pyx":685 * if max_n_obs <= obs_index: * dc.max_n_obs = obs_index + 1 * var_max_rows = dc.col_data_len[index] # <<<<<<<<<<<<<< * if var_max_rows <= obs_index: * if output_format == "pandas": */ if (unlikely(__pyx_v_dc->col_data_len == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 685, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data_len, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __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, 685, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_var_max_rows = __pyx_t_2; /* "pyreadstat/_readstat_parser.pyx":686 * dc.max_n_obs = obs_index + 1 * var_max_rows = dc.col_data_len[index] * if var_max_rows <= obs_index: # <<<<<<<<<<<<<< * if output_format == "pandas": * curnptype = dc.col_numpy_dtypes[index] */ __pyx_t_3 = (__pyx_v_var_max_rows <= __pyx_v_obs_index); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":687 * var_max_rows = dc.col_data_len[index] * if var_max_rows <= obs_index: * if output_format == "pandas": # <<<<<<<<<<<<<< * curnptype = dc.col_numpy_dtypes[index] * buf_list = np.empty(100000, dtype=curnptype) */ __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 687, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":688 * if var_max_rows <= obs_index: * if output_format == "pandas": * curnptype = dc.col_numpy_dtypes[index] # <<<<<<<<<<<<<< * buf_list = np.empty(100000, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: */ if (unlikely(__pyx_v_dc->col_numpy_dtypes == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 688, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_numpy_dtypes, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 688, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_curnptype = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":689 * if output_format == "pandas": * curnptype = dc.col_numpy_dtypes[index] * buf_list = np.empty(100000, dtype=curnptype) # <<<<<<<<<<<<<< * if iscurnptypeobject or iscurnptypefloat: * buf_list.fill(np.nan) */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_4); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_mstate_global->__pyx_int_100000}; __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_v_curnptype, __pyx_t_5, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 689, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_6, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_buf_list = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":690 * curnptype = dc.col_numpy_dtypes[index] * buf_list = np.empty(100000, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: # <<<<<<<<<<<<<< * buf_list.fill(np.nan) * dc.col_data[index] = np.append(dc.col_data[index], buf_list) */ if (!__pyx_v_iscurnptypeobject) { } else { __pyx_t_3 = __pyx_v_iscurnptypeobject; goto __pyx_L8_bool_binop_done; } __pyx_t_3 = __pyx_v_iscurnptypefloat; __pyx_L8_bool_binop_done:; if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":691 * buf_list = np.empty(100000, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: * buf_list.fill(np.nan) # <<<<<<<<<<<<<< * dc.col_data[index] = np.append(dc.col_data[index], buf_list) * else: */ __pyx_t_6 = __pyx_v_buf_list; __Pyx_INCREF(__pyx_t_6); __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_nan); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_4}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_fill, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":690 * curnptype = dc.col_numpy_dtypes[index] * buf_list = np.empty(100000, dtype=curnptype) * if iscurnptypeobject or iscurnptypefloat: # <<<<<<<<<<<<<< * buf_list.fill(np.nan) * dc.col_data[index] = np.append(dc.col_data[index], buf_list) */ } /* "pyreadstat/_readstat_parser.pyx":692 * if iscurnptypeobject or iscurnptypefloat: * buf_list.fill(np.nan) * dc.col_data[index] = np.append(dc.col_data[index], buf_list) # <<<<<<<<<<<<<< * else: * buf_list = [None] * 100000 */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_append); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 692, __pyx_L1_error) } __pyx_t_6 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = 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_7 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_t_6, __pyx_v_buf_list}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 692, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_data, __pyx_v_index, __pyx_t_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":687 * var_max_rows = dc.col_data_len[index] * if var_max_rows <= obs_index: * if output_format == "pandas": # <<<<<<<<<<<<<< * curnptype = dc.col_numpy_dtypes[index] * buf_list = np.empty(100000, dtype=curnptype) */ goto __pyx_L6; } /* "pyreadstat/_readstat_parser.pyx":694 * dc.col_data[index] = np.append(dc.col_data[index], buf_list) * else: * buf_list = [None] * 100000 # <<<<<<<<<<<<<< * dc.col_data[index].extend(buf_list) * var_max_rows += 100000 */ /*else*/ { __pyx_t_1 = PyList_New(1 * 100000); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < 0x186A0; __pyx_temp++) { __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None) != (0)) __PYX_ERR(0, 694, __pyx_L1_error); } } __pyx_v_buf_list = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":695 * else: * buf_list = [None] * 100000 * dc.col_data[index].extend(buf_list) # <<<<<<<<<<<<<< * var_max_rows += 100000 * dc.col_data_len[index] = var_max_rows */ if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 695, __pyx_L1_error) } __pyx_t_6 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __pyx_t_6; __Pyx_INCREF(__pyx_t_5); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_buf_list}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_extend, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L6:; /* "pyreadstat/_readstat_parser.pyx":696 * buf_list = [None] * 100000 * dc.col_data[index].extend(buf_list) * var_max_rows += 100000 # <<<<<<<<<<<<<< * dc.col_data_len[index] = var_max_rows * */ __pyx_v_var_max_rows = (__pyx_v_var_max_rows + 0x186A0); /* "pyreadstat/_readstat_parser.pyx":697 * dc.col_data[index].extend(buf_list) * var_max_rows += 100000 * dc.col_data_len[index] = var_max_rows # <<<<<<<<<<<<<< * * # transform to python value types */ __pyx_t_1 = __Pyx_PyLong_From_int(__pyx_v_var_max_rows); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 697, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely(__pyx_v_dc->col_data_len == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 697, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_data_len, __pyx_v_index, __pyx_t_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 697, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":686 * dc.max_n_obs = obs_index + 1 * var_max_rows = dc.col_data_len[index] * if var_max_rows <= obs_index: # <<<<<<<<<<<<<< * if output_format == "pandas": * curnptype = dc.col_numpy_dtypes[index] */ } /* "pyreadstat/_readstat_parser.pyx":682 * iscurnptypeobject = dc.col_dtypes_isobject[index] * iscurnptypefloat = dc.col_dytpes_isfloat[index] * if is_unkown_number_rows: # <<<<<<<<<<<<<< * if max_n_obs <= obs_index: * dc.max_n_obs = obs_index + 1 */ } /* "pyreadstat/_readstat_parser.pyx":700 * * # transform to python value types * if readstat_value_is_missing(value, variable): # <<<<<<<<<<<<<< * # The user does not want to retrieve missing values * if not dc.usernan or readstat_value_is_system_missing(value): */ __pyx_t_3 = (readstat_value_is_missing(__pyx_v_value, __pyx_v_variable) != 0); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":702 * if readstat_value_is_missing(value, variable): * # The user does not want to retrieve missing values * if not dc.usernan or readstat_value_is_system_missing(value): # <<<<<<<<<<<<<< * if output_format == "pandas": * if iscurnptypefloat == 1 or iscurnptypeobject == 1: */ __pyx_t_8 = (!__pyx_v_dc->usernan); if (!__pyx_t_8) { } else { __pyx_t_3 = __pyx_t_8; goto __pyx_L12_bool_binop_done; } __pyx_t_8 = (readstat_value_is_system_missing(__pyx_v_value) != 0); __pyx_t_3 = __pyx_t_8; __pyx_L12_bool_binop_done:; if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":703 * # The user does not want to retrieve missing values * if not dc.usernan or readstat_value_is_system_missing(value): * if output_format == "pandas": # <<<<<<<<<<<<<< * if iscurnptypefloat == 1 or iscurnptypeobject == 1: * # already allocated */ __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 703, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":704 * if not dc.usernan or readstat_value_is_system_missing(value): * if output_format == "pandas": * if iscurnptypefloat == 1 or iscurnptypeobject == 1: # <<<<<<<<<<<<<< * # already allocated * pass */ __pyx_t_8 = (__pyx_v_iscurnptypefloat == 1); if (!__pyx_t_8) { } else { __pyx_t_3 = __pyx_t_8; goto __pyx_L16_bool_binop_done; } __pyx_t_8 = (__pyx_v_iscurnptypeobject == 1); __pyx_t_3 = __pyx_t_8; __pyx_L16_bool_binop_done:; if (__pyx_t_3) { goto __pyx_L15; } /* "pyreadstat/_readstat_parser.pyx":710 * # for any type except float, the numpy type will be object as now we have nans * else: * dc.col_numpy_dtypes[index] = object # <<<<<<<<<<<<<< * dc.col_dtypes_isobject[index] = 1 * iscurnptypeobject = 1 */ /*else*/ { if (unlikely(__pyx_v_dc->col_numpy_dtypes == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 710, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_numpy_dtypes, __pyx_v_index, __pyx_builtin_object, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 710, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":711 * else: * dc.col_numpy_dtypes[index] = object * dc.col_dtypes_isobject[index] = 1 # <<<<<<<<<<<<<< * iscurnptypeobject = 1 * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) */ if (unlikely(__pyx_v_dc->col_dtypes_isobject == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 711, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_dtypes_isobject, __pyx_v_index, __pyx_mstate_global->__pyx_int_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 711, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":712 * dc.col_numpy_dtypes[index] = object * dc.col_dtypes_isobject[index] = 1 * iscurnptypeobject = 1 # <<<<<<<<<<<<<< * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) * dc.col_data[index][obs_index:] = np.nan */ __pyx_v_iscurnptypeobject = 1; /* "pyreadstat/_readstat_parser.pyx":713 * dc.col_dtypes_isobject[index] = 1 * iscurnptypeobject = 1 * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) # <<<<<<<<<<<<<< * dc.col_data[index][obs_index:] = np.nan * #dc.col_data[index][obs_index] = NAN */ if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 713, __pyx_L1_error) } __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __pyx_t_5; __Pyx_INCREF(__pyx_t_6); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_builtin_object}; __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_copy, Py_False, __pyx_t_4, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 713, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_astype, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 713, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_data, __pyx_v_index, __pyx_t_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":714 * iscurnptypeobject = 1 * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) * dc.col_data[index][obs_index:] = np.nan # <<<<<<<<<<<<<< * #dc.col_data[index][obs_index] = NAN * elif readstat_value_is_defined_missing(value, variable): */ __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 714, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_nan); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 714, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 714, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 714, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_PyObject_SetSlice(__pyx_t_1, __pyx_t_5, __pyx_v_obs_index, 0, NULL, NULL, NULL, 1, 0, 1) < 0) __PYX_ERR(0, 714, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_L15:; /* "pyreadstat/_readstat_parser.pyx":703 * # The user does not want to retrieve missing values * if not dc.usernan or readstat_value_is_system_missing(value): * if output_format == "pandas": # <<<<<<<<<<<<<< * if iscurnptypefloat == 1 or iscurnptypeobject == 1: * # already allocated */ } /* "pyreadstat/_readstat_parser.pyx":702 * if readstat_value_is_missing(value, variable): * # The user does not want to retrieve missing values * if not dc.usernan or readstat_value_is_system_missing(value): # <<<<<<<<<<<<<< * if output_format == "pandas": * if iscurnptypefloat == 1 or iscurnptypeobject == 1: */ goto __pyx_L11; } /* "pyreadstat/_readstat_parser.pyx":716 * dc.col_data[index][obs_index:] = np.nan * #dc.col_data[index][obs_index] = NAN * elif readstat_value_is_defined_missing(value, variable): # <<<<<<<<<<<<<< * # SPSS missing values * pyvalue = convert_readstat_to_python_value(value, index, dc) */ __pyx_t_3 = (readstat_value_is_defined_missing(__pyx_v_value, __pyx_v_variable) != 0); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":718 * elif readstat_value_is_defined_missing(value, variable): * # SPSS missing values * pyvalue = convert_readstat_to_python_value(value, index, dc) # <<<<<<<<<<<<<< * dc.col_data[index][obs_index] = pyvalue * elif readstat_value_is_tagged_missing(value): */ __pyx_t_5 = __pyx_f_10pyreadstat_16_readstat_parser_convert_readstat_to_python_value(__pyx_v_value, __pyx_v_index, __pyx_v_dc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 718, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_v_pyvalue = __pyx_t_5; __pyx_t_5 = 0; /* "pyreadstat/_readstat_parser.pyx":719 * # SPSS missing values * pyvalue = convert_readstat_to_python_value(value, index, dc) * dc.col_data[index][obs_index] = pyvalue # <<<<<<<<<<<<<< * elif readstat_value_is_tagged_missing(value): * iscurnptypeobject = dc.col_dtypes_isobject[index] */ if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 719, __pyx_L1_error) } __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (unlikely((__Pyx_SetItemInt(__pyx_t_5, __pyx_v_obs_index, __pyx_v_pyvalue, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1) < 0))) __PYX_ERR(0, 719, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "pyreadstat/_readstat_parser.pyx":716 * dc.col_data[index][obs_index:] = np.nan * #dc.col_data[index][obs_index] = NAN * elif readstat_value_is_defined_missing(value, variable): # <<<<<<<<<<<<<< * # SPSS missing values * pyvalue = convert_readstat_to_python_value(value, index, dc) */ goto __pyx_L11; } /* "pyreadstat/_readstat_parser.pyx":720 * pyvalue = convert_readstat_to_python_value(value, index, dc) * dc.col_data[index][obs_index] = pyvalue * elif readstat_value_is_tagged_missing(value): # <<<<<<<<<<<<<< * iscurnptypeobject = dc.col_dtypes_isobject[index] * # SAS and Stata missing values */ __pyx_t_3 = (readstat_value_is_tagged_missing(__pyx_v_value) != 0); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":721 * dc.col_data[index][obs_index] = pyvalue * elif readstat_value_is_tagged_missing(value): * iscurnptypeobject = dc.col_dtypes_isobject[index] # <<<<<<<<<<<<<< * # SAS and Stata missing values * missing_tag = readstat_value_tag(value) */ if (unlikely(__pyx_v_dc->col_dtypes_isobject == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 721, __pyx_L1_error) } __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_dc->col_dtypes_isobject, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_iscurnptypeobject = __pyx_t_3; /* "pyreadstat/_readstat_parser.pyx":723 * iscurnptypeobject = dc.col_dtypes_isobject[index] * # SAS and Stata missing values * missing_tag = readstat_value_tag(value) # <<<<<<<<<<<<<< * # In SAS missing values are A to Z or _ in stata a to z * # if (missing_tag >=65 and missing_tag <= 90) or missing_tag == 95 or (missing_tag >=61 and missing_tag <= 122): */ __pyx_v_missing_tag = ((int)readstat_value_tag(__pyx_v_value)); /* "pyreadstat/_readstat_parser.pyx":726 * # In SAS missing values are A to Z or _ in stata a to z * # if (missing_tag >=65 and missing_tag <= 90) or missing_tag == 95 or (missing_tag >=61 and missing_tag <= 122): * if output_format == "pandas": # <<<<<<<<<<<<<< * if iscurnptypeobject == 1: * dc.col_data[index][obs_index] = chr(missing_tag) */ __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 726, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":727 * # if (missing_tag >=65 and missing_tag <= 90) or missing_tag == 95 or (missing_tag >=61 and missing_tag <= 122): * if output_format == "pandas": * if iscurnptypeobject == 1: # <<<<<<<<<<<<<< * dc.col_data[index][obs_index] = chr(missing_tag) * else: */ __pyx_t_3 = (__pyx_v_iscurnptypeobject == 1); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":728 * if output_format == "pandas": * if iscurnptypeobject == 1: * dc.col_data[index][obs_index] = chr(missing_tag) # <<<<<<<<<<<<<< * else: * dc.col_numpy_dtypes[index] = object */ __pyx_t_5 = PyUnicode_FromOrdinal(__pyx_v_missing_tag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 728, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 728, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely((__Pyx_SetItemInt(__pyx_t_1, __pyx_v_obs_index, __pyx_t_5, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1) < 0))) __PYX_ERR(0, 728, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "pyreadstat/_readstat_parser.pyx":727 * # if (missing_tag >=65 and missing_tag <= 90) or missing_tag == 95 or (missing_tag >=61 and missing_tag <= 122): * if output_format == "pandas": * if iscurnptypeobject == 1: # <<<<<<<<<<<<<< * dc.col_data[index][obs_index] = chr(missing_tag) * else: */ goto __pyx_L19; } /* "pyreadstat/_readstat_parser.pyx":730 * dc.col_data[index][obs_index] = chr(missing_tag) * else: * dc.col_numpy_dtypes[index] = object # <<<<<<<<<<<<<< * dc.col_dtypes_isobject[index] = 1 * dc.col_dytpes_isfloat[index] = 0 */ /*else*/ { if (unlikely(__pyx_v_dc->col_numpy_dtypes == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 730, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_numpy_dtypes, __pyx_v_index, __pyx_builtin_object, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 730, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":731 * else: * dc.col_numpy_dtypes[index] = object * dc.col_dtypes_isobject[index] = 1 # <<<<<<<<<<<<<< * dc.col_dytpes_isfloat[index] = 0 * iscurnptypeobject = 1 */ if (unlikely(__pyx_v_dc->col_dtypes_isobject == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 731, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_dtypes_isobject, __pyx_v_index, __pyx_mstate_global->__pyx_int_1, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 731, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":732 * dc.col_numpy_dtypes[index] = object * dc.col_dtypes_isobject[index] = 1 * dc.col_dytpes_isfloat[index] = 0 # <<<<<<<<<<<<<< * iscurnptypeobject = 1 * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) */ if (unlikely(__pyx_v_dc->col_dytpes_isfloat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 732, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_dytpes_isfloat, __pyx_v_index, __pyx_mstate_global->__pyx_int_0, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 732, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":733 * dc.col_dtypes_isobject[index] = 1 * dc.col_dytpes_isfloat[index] = 0 * iscurnptypeobject = 1 # <<<<<<<<<<<<<< * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) * dc.col_data[index][obs_index] = chr(missing_tag) */ __pyx_v_iscurnptypeobject = 1; /* "pyreadstat/_readstat_parser.pyx":734 * dc.col_dytpes_isfloat[index] = 0 * iscurnptypeobject = 1 * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) # <<<<<<<<<<<<<< * dc.col_data[index][obs_index] = chr(missing_tag) * else: */ if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 734, __pyx_L1_error) } __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_1, __pyx_builtin_object}; __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_copy, Py_False, __pyx_t_6, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 734, __pyx_L1_error) __pyx_t_5 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_astype, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 734, __pyx_L1_error) } if (unlikely((__Pyx_SetItemInt(__pyx_v_dc->col_data, __pyx_v_index, __pyx_t_5, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1) < 0))) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "pyreadstat/_readstat_parser.pyx":735 * iscurnptypeobject = 1 * dc.col_data[index] = dc.col_data[index].astype(object, copy=False) * dc.col_data[index][obs_index] = chr(missing_tag) # <<<<<<<<<<<<<< * else: * dc.col_data[index][obs_index] = chr(missing_tag) */ __pyx_t_5 = PyUnicode_FromOrdinal(__pyx_v_missing_tag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 735, __pyx_L1_error) } __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (unlikely((__Pyx_SetItemInt(__pyx_t_4, __pyx_v_obs_index, __pyx_t_5, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1) < 0))) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_L19:; /* "pyreadstat/_readstat_parser.pyx":726 * # In SAS missing values are A to Z or _ in stata a to z * # if (missing_tag >=65 and missing_tag <= 90) or missing_tag == 95 or (missing_tag >=61 and missing_tag <= 122): * if output_format == "pandas": # <<<<<<<<<<<<<< * if iscurnptypeobject == 1: * dc.col_data[index][obs_index] = chr(missing_tag) */ goto __pyx_L18; } /* "pyreadstat/_readstat_parser.pyx":737 * dc.col_data[index][obs_index] = chr(missing_tag) * else: * dc.col_data[index][obs_index] = chr(missing_tag) # <<<<<<<<<<<<<< * curset = dc.missing_user_values.get(index) * if curset is None: */ /*else*/ { __pyx_t_5 = PyUnicode_FromOrdinal(__pyx_v_missing_tag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 737, __pyx_L1_error) } __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (unlikely((__Pyx_SetItemInt(__pyx_t_4, __pyx_v_obs_index, __pyx_t_5, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1) < 0))) __PYX_ERR(0, 737, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_L18:; /* "pyreadstat/_readstat_parser.pyx":738 * else: * dc.col_data[index][obs_index] = chr(missing_tag) * curset = dc.missing_user_values.get(index) # <<<<<<<<<<<<<< * if curset is None: * curset = set() */ if (unlikely(__pyx_v_dc->missing_user_values == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get"); __PYX_ERR(0, 738, __pyx_L1_error) } __pyx_t_5 = __Pyx_PyLong_From_int(__pyx_v_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 738, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_dc->missing_user_values, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 738, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (!(likely(PySet_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None) || __Pyx_RaiseUnexpectedTypeError("set", __pyx_t_4))) __PYX_ERR(0, 738, __pyx_L1_error) __pyx_v_curset = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":739 * dc.col_data[index][obs_index] = chr(missing_tag) * curset = dc.missing_user_values.get(index) * if curset is None: # <<<<<<<<<<<<<< * curset = set() * curset.add(chr(missing_tag)) */ __pyx_t_3 = (__pyx_v_curset == ((PyObject*)Py_None)); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":740 * curset = dc.missing_user_values.get(index) * if curset is None: * curset = set() # <<<<<<<<<<<<<< * curset.add(chr(missing_tag)) * dc.missing_user_values[index] = curset */ __pyx_t_4 = PySet_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 740, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_curset, ((PyObject*)__pyx_t_4)); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":739 * dc.col_data[index][obs_index] = chr(missing_tag) * curset = dc.missing_user_values.get(index) * if curset is None: # <<<<<<<<<<<<<< * curset = set() * curset.add(chr(missing_tag)) */ } /* "pyreadstat/_readstat_parser.pyx":741 * if curset is None: * curset = set() * curset.add(chr(missing_tag)) # <<<<<<<<<<<<<< * dc.missing_user_values[index] = curset * else: */ if (unlikely(__pyx_v_curset == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "add"); __PYX_ERR(0, 741, __pyx_L1_error) } __pyx_t_4 = PyUnicode_FromOrdinal(__pyx_v_missing_tag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 741, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = PySet_Add(__pyx_v_curset, __pyx_t_4); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 741, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":742 * curset = set() * curset.add(chr(missing_tag)) * dc.missing_user_values[index] = curset # <<<<<<<<<<<<<< * else: * pyvalue = convert_readstat_to_python_value(value, index, dc) */ if (unlikely(__pyx_v_dc->missing_user_values == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 742, __pyx_L1_error) } __pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 742, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (unlikely((PyDict_SetItem(__pyx_v_dc->missing_user_values, __pyx_t_4, __pyx_v_curset) < 0))) __PYX_ERR(0, 742, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":720 * pyvalue = convert_readstat_to_python_value(value, index, dc) * dc.col_data[index][obs_index] = pyvalue * elif readstat_value_is_tagged_missing(value): # <<<<<<<<<<<<<< * iscurnptypeobject = dc.col_dtypes_isobject[index] * # SAS and Stata missing values */ } __pyx_L11:; /* "pyreadstat/_readstat_parser.pyx":700 * * # transform to python value types * if readstat_value_is_missing(value, variable): # <<<<<<<<<<<<<< * # The user does not want to retrieve missing values * if not dc.usernan or readstat_value_is_system_missing(value): */ goto __pyx_L10; } /* "pyreadstat/_readstat_parser.pyx":744 * dc.missing_user_values[index] = curset * else: * pyvalue = convert_readstat_to_python_value(value, index, dc) # <<<<<<<<<<<<<< * dc.col_data[index][obs_index] = pyvalue * */ /*else*/ { __pyx_t_4 = __pyx_f_10pyreadstat_16_readstat_parser_convert_readstat_to_python_value(__pyx_v_value, __pyx_v_index, __pyx_v_dc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_pyvalue = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":745 * else: * pyvalue = convert_readstat_to_python_value(value, index, dc) * dc.col_data[index][obs_index] = pyvalue # <<<<<<<<<<<<<< * * return READSTAT_HANDLER_OK */ if (unlikely(__pyx_v_dc->col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 745, __pyx_L1_error) } __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_dc->col_data, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 745, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (unlikely((__Pyx_SetItemInt(__pyx_t_4, __pyx_v_obs_index, __pyx_v_pyvalue, int, 1, __Pyx_PyLong_From_int, 0, 1, 1, 1) < 0))) __PYX_ERR(0, 745, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_L10:; /* "pyreadstat/_readstat_parser.pyx":747 * dc.col_data[index][obs_index] = pyvalue * * return READSTAT_HANDLER_OK # <<<<<<<<<<<<<< * * */ __pyx_r = READSTAT_HANDLER_OK; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":651 * * * cdef int handle_value(int obs_index, readstat_variable_t * variable, readstat_value_t value, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * This function transforms every value to python types, and to datetime if */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pyreadstat._readstat_parser.handle_value", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = READSTAT_HANDLER_ABORT; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_dc); __Pyx_XDECREF(__pyx_v_buf_list); __Pyx_XDECREF(__pyx_v_pyvalue); __Pyx_XDECREF(__pyx_v_curset); __Pyx_XDECREF(__pyx_v_curnptype); __Pyx_XDECREF(__pyx_v_output_format); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":750 * * * cdef int handle_value_label(char *val_labels, readstat_value_t value, char *label, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * Reads the label for the value that belongs to the label set val_labels. In Handle variable we need to do a map */ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_value_label(char *__pyx_v_val_labels, readstat_value_t __pyx_v_value, char *__pyx_v_label, void *__pyx_v_ctx) { struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc = 0; char *__pyx_v_c_str_value; PyObject *__pyx_v_py_str_value = 0; int8_t __pyx_v_c_int8_value; int16_t __pyx_v_c_int16_value; int32_t __pyx_v_c_int32_value; float __pyx_v_c_float_value; double __pyx_v_c_double_value; long __pyx_v_py_long_value; double __pyx_v_py_float_value; __pyx_t_10pyreadstat_16_readstat_parser_py_variable_format __pyx_v_pyformat; PyObject *__pyx_v_labels_raw = 0; PyObject *__pyx_v_var_label = 0; PyObject *__pyx_v_value_label_name = 0; readstat_type_t __pyx_v_value_type; PyObject *__pyx_v_cur_dict = NULL; int __pyx_v_missing_tag; int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; size_t __pyx_t_3; int __pyx_t_4; int __pyx_t_5; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("handle_value_label", 0); /* "pyreadstat/_readstat_parser.pyx":756 * """ * * cdef data_container dc = ctx # <<<<<<<<<<<<<< * * cdef char * c_str_value */ __pyx_t_1 = ((PyObject *)__pyx_v_ctx); __Pyx_INCREF(__pyx_t_1); __pyx_v_dc = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":774 * cdef str value_label_name * * var_label = val_labels # <<<<<<<<<<<<<< * value_label_name = label * */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_val_labels); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_var_label = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":775 * * var_label = val_labels * value_label_name = label # <<<<<<<<<<<<<< * * cdef readstat_type_t value_type */ __pyx_t_2 = __Pyx_PyUnicode_FromString(__pyx_v_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 775, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_value_label_name = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":778 * * cdef readstat_type_t value_type * value_type = readstat_value_type(value) # <<<<<<<<<<<<<< * * labels_raw = dc.labels_raw */ __pyx_v_value_type = readstat_value_type(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":780 * value_type = readstat_value_type(value) * * labels_raw = dc.labels_raw # <<<<<<<<<<<<<< * cur_dict = labels_raw.get(var_label) * if not cur_dict: */ __pyx_t_1 = __pyx_v_dc->labels_raw; __Pyx_INCREF(__pyx_t_1); __pyx_v_labels_raw = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":781 * * labels_raw = dc.labels_raw * cur_dict = labels_raw.get(var_label) # <<<<<<<<<<<<<< * if not cur_dict: * cur_dict = dict() */ __pyx_t_2 = __pyx_v_labels_raw; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_var_label}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_get, __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_cur_dict = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":782 * labels_raw = dc.labels_raw * cur_dict = labels_raw.get(var_label) * if not cur_dict: # <<<<<<<<<<<<<< * cur_dict = dict() * */ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_cur_dict); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 782, __pyx_L1_error) __pyx_t_5 = (!__pyx_t_4); if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":783 * cur_dict = labels_raw.get(var_label) * if not cur_dict: * cur_dict = dict() # <<<<<<<<<<<<<< * * if readstat_value_is_tagged_missing(value): */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_cur_dict, __pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":782 * labels_raw = dc.labels_raw * cur_dict = labels_raw.get(var_label) * if not cur_dict: # <<<<<<<<<<<<<< * cur_dict = dict() * */ } /* "pyreadstat/_readstat_parser.pyx":785 * cur_dict = dict() * * if readstat_value_is_tagged_missing(value): # <<<<<<<<<<<<<< * # SAS and Stata missing values * missing_tag = readstat_value_tag(value) */ __pyx_t_5 = (readstat_value_is_tagged_missing(__pyx_v_value) != 0); if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":787 * if readstat_value_is_tagged_missing(value): * # SAS and Stata missing values * missing_tag = readstat_value_tag(value) # <<<<<<<<<<<<<< * # In SAS missing values are A to Z or _ in stata a to z * cur_dict[chr(missing_tag)] = value_label_name */ __pyx_v_missing_tag = ((int)readstat_value_tag(__pyx_v_value)); /* "pyreadstat/_readstat_parser.pyx":789 * missing_tag = readstat_value_tag(value) * # In SAS missing values are A to Z or _ in stata a to z * cur_dict[chr(missing_tag)] = value_label_name # <<<<<<<<<<<<<< * else: * */ __pyx_t_1 = PyUnicode_FromOrdinal(__pyx_v_missing_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 789, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely((PyObject_SetItem(__pyx_v_cur_dict, __pyx_t_1, __pyx_v_value_label_name) < 0))) __PYX_ERR(0, 789, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":785 * cur_dict = dict() * * if readstat_value_is_tagged_missing(value): # <<<<<<<<<<<<<< * # SAS and Stata missing values * missing_tag = readstat_value_tag(value) */ goto __pyx_L4; } /* "pyreadstat/_readstat_parser.pyx":792 * else: * * if value_type == READSTAT_TYPE_STRING or value_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * c_str_value = readstat_string_value(value) * py_str_value = c_str_value */ /*else*/ { /* "pyreadstat/_readstat_parser.pyx":812 * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT * elif value_type == READSTAT_TYPE_DOUBLE: # <<<<<<<<<<<<<< * c_double_value = readstat_double_value(value); * py_float_value = c_double_value */ switch (__pyx_v_value_type) { case READSTAT_TYPE_STRING: /* "pyreadstat/_readstat_parser.pyx":792 * else: * * if value_type == READSTAT_TYPE_STRING or value_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * c_str_value = readstat_string_value(value) * py_str_value = c_str_value */ case READSTAT_TYPE_STRING_REF: /* "pyreadstat/_readstat_parser.pyx":793 * * if value_type == READSTAT_TYPE_STRING or value_type == READSTAT_TYPE_STRING_REF: * c_str_value = readstat_string_value(value) # <<<<<<<<<<<<<< * py_str_value = c_str_value * pyformat = VAR_FORMAT_STRING */ __pyx_v_c_str_value = readstat_string_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":794 * if value_type == READSTAT_TYPE_STRING or value_type == READSTAT_TYPE_STRING_REF: * c_str_value = readstat_string_value(value) * py_str_value = c_str_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_STRING * elif value_type == READSTAT_TYPE_INT8: */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_c_str_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 794, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_py_str_value = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":795 * c_str_value = readstat_string_value(value) * py_str_value = c_str_value * pyformat = VAR_FORMAT_STRING # <<<<<<<<<<<<<< * elif value_type == READSTAT_TYPE_INT8: * c_int8_value = readstat_int8_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_STRING; /* "pyreadstat/_readstat_parser.pyx":792 * else: * * if value_type == READSTAT_TYPE_STRING or value_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * c_str_value = readstat_string_value(value) * py_str_value = c_str_value */ break; case READSTAT_TYPE_INT8: /* "pyreadstat/_readstat_parser.pyx":797 * pyformat = VAR_FORMAT_STRING * elif value_type == READSTAT_TYPE_INT8: * c_int8_value = readstat_int8_value(value) # <<<<<<<<<<<<<< * py_long_value = c_int8_value * pyformat = VAR_FORMAT_LONG */ __pyx_v_c_int8_value = readstat_int8_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":798 * elif value_type == READSTAT_TYPE_INT8: * c_int8_value = readstat_int8_value(value) * py_long_value = c_int8_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_INT16: */ __pyx_v_py_long_value = ((long)__pyx_v_c_int8_value); /* "pyreadstat/_readstat_parser.pyx":799 * c_int8_value = readstat_int8_value(value) * py_long_value = c_int8_value * pyformat = VAR_FORMAT_LONG # <<<<<<<<<<<<<< * elif value_type == READSTAT_TYPE_INT16: * c_int16_value = readstat_int16_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG; /* "pyreadstat/_readstat_parser.pyx":796 * py_str_value = c_str_value * pyformat = VAR_FORMAT_STRING * elif value_type == READSTAT_TYPE_INT8: # <<<<<<<<<<<<<< * c_int8_value = readstat_int8_value(value) * py_long_value = c_int8_value */ break; case READSTAT_TYPE_INT16: /* "pyreadstat/_readstat_parser.pyx":801 * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_INT16: * c_int16_value = readstat_int16_value(value) # <<<<<<<<<<<<<< * py_long_value = c_int16_value * pyformat = VAR_FORMAT_LONG */ __pyx_v_c_int16_value = readstat_int16_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":802 * elif value_type == READSTAT_TYPE_INT16: * c_int16_value = readstat_int16_value(value) * py_long_value = c_int16_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_INT32: */ __pyx_v_py_long_value = ((long)__pyx_v_c_int16_value); /* "pyreadstat/_readstat_parser.pyx":803 * c_int16_value = readstat_int16_value(value) * py_long_value = c_int16_value * pyformat = VAR_FORMAT_LONG # <<<<<<<<<<<<<< * elif value_type == READSTAT_TYPE_INT32: * c_int32_value = readstat_int32_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG; /* "pyreadstat/_readstat_parser.pyx":800 * py_long_value = c_int8_value * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_INT16: # <<<<<<<<<<<<<< * c_int16_value = readstat_int16_value(value) * py_long_value = c_int16_value */ break; case READSTAT_TYPE_INT32: /* "pyreadstat/_readstat_parser.pyx":805 * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_INT32: * c_int32_value = readstat_int32_value(value) # <<<<<<<<<<<<<< * py_long_value = c_int32_value * pyformat = VAR_FORMAT_LONG */ __pyx_v_c_int32_value = readstat_int32_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":806 * elif value_type == READSTAT_TYPE_INT32: * c_int32_value = readstat_int32_value(value) * py_long_value = c_int32_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_FLOAT: */ __pyx_v_py_long_value = ((long)__pyx_v_c_int32_value); /* "pyreadstat/_readstat_parser.pyx":807 * c_int32_value = readstat_int32_value(value) * py_long_value = c_int32_value * pyformat = VAR_FORMAT_LONG # <<<<<<<<<<<<<< * elif value_type == READSTAT_TYPE_FLOAT: * c_float_value = readstat_float_value(value) */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG; /* "pyreadstat/_readstat_parser.pyx":804 * py_long_value = c_int16_value * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_INT32: # <<<<<<<<<<<<<< * c_int32_value = readstat_int32_value(value) * py_long_value = c_int32_value */ break; case READSTAT_TYPE_FLOAT: /* "pyreadstat/_readstat_parser.pyx":809 * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_FLOAT: * c_float_value = readstat_float_value(value) # <<<<<<<<<<<<<< * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT */ __pyx_v_c_float_value = readstat_float_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":810 * elif value_type == READSTAT_TYPE_FLOAT: * c_float_value = readstat_float_value(value) * py_float_value = c_float_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_FLOAT * elif value_type == READSTAT_TYPE_DOUBLE: */ __pyx_v_py_float_value = ((double)__pyx_v_c_float_value); /* "pyreadstat/_readstat_parser.pyx":811 * c_float_value = readstat_float_value(value) * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT # <<<<<<<<<<<<<< * elif value_type == READSTAT_TYPE_DOUBLE: * c_double_value = readstat_double_value(value); */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT; /* "pyreadstat/_readstat_parser.pyx":808 * py_long_value = c_int32_value * pyformat = VAR_FORMAT_LONG * elif value_type == READSTAT_TYPE_FLOAT: # <<<<<<<<<<<<<< * c_float_value = readstat_float_value(value) * py_float_value = c_float_value */ break; case READSTAT_TYPE_DOUBLE: /* "pyreadstat/_readstat_parser.pyx":813 * pyformat = VAR_FORMAT_FLOAT * elif value_type == READSTAT_TYPE_DOUBLE: * c_double_value = readstat_double_value(value); # <<<<<<<<<<<<<< * py_float_value = c_double_value * pyformat = VAR_FORMAT_FLOAT */ __pyx_v_c_double_value = readstat_double_value(__pyx_v_value); /* "pyreadstat/_readstat_parser.pyx":814 * elif value_type == READSTAT_TYPE_DOUBLE: * c_double_value = readstat_double_value(value); * py_float_value = c_double_value # <<<<<<<<<<<<<< * pyformat = VAR_FORMAT_FLOAT * else: */ __pyx_v_py_float_value = ((double)__pyx_v_c_double_value); /* "pyreadstat/_readstat_parser.pyx":815 * c_double_value = readstat_double_value(value); * py_float_value = c_double_value * pyformat = VAR_FORMAT_FLOAT # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unkown data type") */ __pyx_v_pyformat = __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT; /* "pyreadstat/_readstat_parser.pyx":812 * py_float_value = c_float_value * pyformat = VAR_FORMAT_FLOAT * elif value_type == READSTAT_TYPE_DOUBLE: # <<<<<<<<<<<<<< * c_double_value = readstat_double_value(value); * py_float_value = c_double_value */ break; default: /* "pyreadstat/_readstat_parser.pyx":817 * pyformat = VAR_FORMAT_FLOAT * else: * raise PyreadstatError("Unkown data type") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 817, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_3 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_Unkown_data_type}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 817, __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, 817, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":820 * * * if pyformat == VAR_FORMAT_STRING: # <<<<<<<<<<<<<< * cur_dict[py_str_value] = value_label_name * elif pyformat == VAR_FORMAT_LONG: */ switch (__pyx_v_pyformat) { case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_STRING: /* "pyreadstat/_readstat_parser.pyx":821 * * if pyformat == VAR_FORMAT_STRING: * cur_dict[py_str_value] = value_label_name # <<<<<<<<<<<<<< * elif pyformat == VAR_FORMAT_LONG: * cur_dict[py_long_value] = value_label_name */ if (unlikely(!__pyx_v_py_str_value)) { __Pyx_RaiseUnboundLocalError("py_str_value"); __PYX_ERR(0, 821, __pyx_L1_error) } if (unlikely((PyObject_SetItem(__pyx_v_cur_dict, __pyx_v_py_str_value, __pyx_v_value_label_name) < 0))) __PYX_ERR(0, 821, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":820 * * * if pyformat == VAR_FORMAT_STRING: # <<<<<<<<<<<<<< * cur_dict[py_str_value] = value_label_name * elif pyformat == VAR_FORMAT_LONG: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_LONG: /* "pyreadstat/_readstat_parser.pyx":823 * cur_dict[py_str_value] = value_label_name * elif pyformat == VAR_FORMAT_LONG: * cur_dict[py_long_value] = value_label_name # <<<<<<<<<<<<<< * elif pyformat == VAR_FORMAT_FLOAT: * cur_dict[py_float_value] = value_label_name */ if (unlikely((__Pyx_SetItemInt(__pyx_v_cur_dict, __pyx_v_py_long_value, __pyx_v_value_label_name, long, 1, __Pyx_PyLong_From_long, 0, 1, 1, 1) < 0))) __PYX_ERR(0, 823, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":822 * if pyformat == VAR_FORMAT_STRING: * cur_dict[py_str_value] = value_label_name * elif pyformat == VAR_FORMAT_LONG: # <<<<<<<<<<<<<< * cur_dict[py_long_value] = value_label_name * elif pyformat == VAR_FORMAT_FLOAT: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_FLOAT: /* "pyreadstat/_readstat_parser.pyx":825 * cur_dict[py_long_value] = value_label_name * elif pyformat == VAR_FORMAT_FLOAT: * cur_dict[py_float_value] = value_label_name # <<<<<<<<<<<<<< * elif pyformat == VAR_FORMAT_MISSING: * pass */ __pyx_t_2 = PyFloat_FromDouble(__pyx_v_py_float_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 825, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (unlikely((PyObject_SetItem(__pyx_v_cur_dict, __pyx_t_2, __pyx_v_value_label_name) < 0))) __PYX_ERR(0, 825, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":824 * elif pyformat == VAR_FORMAT_LONG: * cur_dict[py_long_value] = value_label_name * elif pyformat == VAR_FORMAT_FLOAT: # <<<<<<<<<<<<<< * cur_dict[py_float_value] = value_label_name * elif pyformat == VAR_FORMAT_MISSING: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_VAR_FORMAT_MISSING: /* "pyreadstat/_readstat_parser.pyx":826 * elif pyformat == VAR_FORMAT_FLOAT: * cur_dict[py_float_value] = value_label_name * elif pyformat == VAR_FORMAT_MISSING: # <<<<<<<<<<<<<< * pass * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":829 * pass * else: * raise PyreadstatError("Failed convert C to python value") # <<<<<<<<<<<<<< * * dc.labels_raw[var_label] = cur_dict */ __pyx_t_6 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 829, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); assert(__pyx_t_6); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_1, __pyx__function); __pyx_t_3 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_mstate_global->__pyx_kp_u_Failed_convert_C_to_python_value}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 829, __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, 829, __pyx_L1_error) break; } } __pyx_L4:; /* "pyreadstat/_readstat_parser.pyx":831 * raise PyreadstatError("Failed convert C to python value") * * dc.labels_raw[var_label] = cur_dict # <<<<<<<<<<<<<< * * return READSTAT_HANDLER_OK */ if (unlikely((PyObject_SetItem(__pyx_v_dc->labels_raw, __pyx_v_var_label, __pyx_v_cur_dict) < 0))) __PYX_ERR(0, 831, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":833 * dc.labels_raw[var_label] = cur_dict * * return READSTAT_HANDLER_OK # <<<<<<<<<<<<<< * * cdef int handle_note (int note_index, char *note, void *ctx) except READSTAT_HANDLER_ABORT: */ __pyx_r = READSTAT_HANDLER_OK; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":750 * * * cdef int handle_value_label(char *val_labels, readstat_value_t value, char *label, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * Reads the label for the value that belongs to the label set val_labels. In Handle variable we need to do a map */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pyreadstat._readstat_parser.handle_value_label", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = READSTAT_HANDLER_ABORT; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_dc); __Pyx_XDECREF(__pyx_v_py_str_value); __Pyx_XDECREF(__pyx_v_labels_raw); __Pyx_XDECREF(__pyx_v_var_label); __Pyx_XDECREF(__pyx_v_value_label_name); __Pyx_XDECREF(__pyx_v_cur_dict); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":835 * return READSTAT_HANDLER_OK * * cdef int handle_note (int note_index, char *note, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * Collects notes (text annotations) attached to the documents. It happens for spss and stata */ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_note(CYTHON_UNUSED int __pyx_v_note_index, char *__pyx_v_note, void *__pyx_v_ctx) { PyObject *__pyx_v_pynote = 0; struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc = 0; 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("handle_note", 0); /* "pyreadstat/_readstat_parser.pyx":841 * * cdef str pynote * cdef data_container dc = ctx # <<<<<<<<<<<<<< * * pynote = note */ __pyx_t_1 = ((PyObject *)__pyx_v_ctx); __Pyx_INCREF(__pyx_t_1); __pyx_v_dc = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":843 * cdef data_container dc = ctx * * pynote = note # <<<<<<<<<<<<<< * dc.notes.append(pynote) * */ __pyx_t_1 = __Pyx_PyUnicode_FromString(__pyx_v_note); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 843, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_pynote = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":844 * * pynote = note * dc.notes.append(pynote) # <<<<<<<<<<<<<< * * return READSTAT_HANDLER_OK */ __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_dc->notes, __pyx_v_pynote); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 844, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":846 * dc.notes.append(pynote) * * return READSTAT_HANDLER_OK # <<<<<<<<<<<<<< * * cdef int handle_open(const char *u8_path, void *io_ctx) except READSTAT_HANDLER_ABORT: */ __pyx_r = READSTAT_HANDLER_OK; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":835 * return READSTAT_HANDLER_OK * * cdef int handle_note (int note_index, char *note, void *ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * Collects notes (text annotations) attached to the documents. It happens for spss and stata */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("pyreadstat._readstat_parser.handle_note", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = READSTAT_HANDLER_ABORT; __pyx_L0:; __Pyx_XDECREF(__pyx_v_pynote); __Pyx_XDECREF((PyObject *)__pyx_v_dc); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":848 * return READSTAT_HANDLER_OK * * cdef int handle_open(const char *u8_path, void *io_ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * Special open handler for windows in order to be able to handle paths with international characters */ static int __pyx_f_10pyreadstat_16_readstat_parser_handle_open(char const *__pyx_v_u8_path, void *__pyx_v_io_ctx) { int __pyx_v_fd; Py_ssize_t __pyx_v_length; wchar_t *__pyx_v_u16_path; 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; int __pyx_t_7; wchar_t *__pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("handle_open", 0); /* "pyreadstat/_readstat_parser.pyx":856 * cdef Py_ssize_t length * * if not os.path.isfile(u8_path): # <<<<<<<<<<<<<< * return -1 * */ __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __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, 856, __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_3 = __Pyx_PyUnicode_FromString(__pyx_v_u8_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_3}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isfile, __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_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = (!__pyx_t_6); if (__pyx_t_7) { /* "pyreadstat/_readstat_parser.pyx":857 * * if not os.path.isfile(u8_path): * return -1 # <<<<<<<<<<<<<< * * if os.name == "nt": */ __pyx_r = -1; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":856 * cdef Py_ssize_t length * * if not os.path.isfile(u8_path): # <<<<<<<<<<<<<< * return -1 * */ } /* "pyreadstat/_readstat_parser.pyx":859 * return -1 * * if os.name == "nt": # <<<<<<<<<<<<<< * u16_path = PyUnicode_AsWideCharString(u8_path, &length) * fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) */ __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 859, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_nt, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 859, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_7) { /* "pyreadstat/_readstat_parser.pyx":860 * * if os.name == "nt": * u16_path = PyUnicode_AsWideCharString(u8_path, &length) # <<<<<<<<<<<<<< * fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) * assign_fd(io_ctx, fd) */ __pyx_t_4 = __Pyx_PyUnicode_FromString(__pyx_v_u8_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 860, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_8 = PyUnicode_AsWideCharString(__pyx_t_4, (&__pyx_v_length)); if (unlikely(__pyx_t_8 == ((wchar_t *)0))) __PYX_ERR(0, 860, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_u16_path = __pyx_t_8; /* "pyreadstat/_readstat_parser.pyx":861 * if os.name == "nt": * u16_path = PyUnicode_AsWideCharString(u8_path, &length) * fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) # <<<<<<<<<<<<<< * assign_fd(io_ctx, fd) * return fd */ __pyx_v_fd = _wsopen(__pyx_v_u16_path, (_O_RDONLY | _O_BINARY), _SH_DENYWR, 0); /* "pyreadstat/_readstat_parser.pyx":862 * u16_path = PyUnicode_AsWideCharString(u8_path, &length) * fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) * assign_fd(io_ctx, fd) # <<<<<<<<<<<<<< * return fd * else: */ assign_fd(__pyx_v_io_ctx, __pyx_v_fd); /* "pyreadstat/_readstat_parser.pyx":863 * fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) * assign_fd(io_ctx, fd) * return fd # <<<<<<<<<<<<<< * else: * return -1 */ __pyx_r = __pyx_v_fd; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":859 * return -1 * * if os.name == "nt": # <<<<<<<<<<<<<< * u16_path = PyUnicode_AsWideCharString(u8_path, &length) * fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) */ } /* "pyreadstat/_readstat_parser.pyx":865 * return fd * else: * return -1 # <<<<<<<<<<<<<< * * */ /*else*/ { __pyx_r = -1; goto __pyx_L0; } /* "pyreadstat/_readstat_parser.pyx":848 * return READSTAT_HANDLER_OK * * cdef int handle_open(const char *u8_path, void *io_ctx) except READSTAT_HANDLER_ABORT: # <<<<<<<<<<<<<< * """ * Special open handler for windows in order to be able to handle paths with international characters */ /* 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_AddTraceback("pyreadstat._readstat_parser.handle_open", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = READSTAT_HANDLER_ABORT; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":870 * cdef object _file_object_ctx = None * * cdef int pyobject_open_handler(const char *path, void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """File is already open - this is a no-op""" * return 0 */ static int __pyx_f_10pyreadstat_16_readstat_parser_pyobject_open_handler(CYTHON_UNUSED char const *__pyx_v_path, CYTHON_UNUSED void *__pyx_v_io_ctx) { int __pyx_r; /* "pyreadstat/_readstat_parser.pyx":872 * cdef int pyobject_open_handler(const char *path, void *io_ctx) noexcept: * """File is already open - this is a no-op""" * return 0 # <<<<<<<<<<<<<< * * cdef int pyobject_close_handler(void *io_ctx) noexcept: */ __pyx_r = 0; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":870 * cdef object _file_object_ctx = None * * cdef int pyobject_open_handler(const char *path, void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """File is already open - this is a no-op""" * return 0 */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":874 * return 0 * * cdef int pyobject_close_handler(void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """User manages file lifetime - this is a no-op""" * return 0 */ static int __pyx_f_10pyreadstat_16_readstat_parser_pyobject_close_handler(CYTHON_UNUSED void *__pyx_v_io_ctx) { int __pyx_r; /* "pyreadstat/_readstat_parser.pyx":876 * cdef int pyobject_close_handler(void *io_ctx) noexcept: * """User manages file lifetime - this is a no-op""" * return 0 # <<<<<<<<<<<<<< * * cdef ssize_t pyobject_read_handler(void *buf, size_t nbyte, void *io_ctx) noexcept: */ __pyx_r = 0; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":874 * return 0 * * cdef int pyobject_close_handler(void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """User manages file lifetime - this is a no-op""" * return 0 */ /* function exit code */ __pyx_L0:; return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":878 * return 0 * * cdef ssize_t pyobject_read_handler(void *buf, size_t nbyte, void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """Bridge Python file.read() to C read operation""" * global _file_object_ctx */ static Py_ssize_t __pyx_f_10pyreadstat_16_readstat_parser_pyobject_read_handler(void *__pyx_v_buf, size_t __pyx_v_nbyte, CYTHON_UNUSED void *__pyx_v_io_ctx) { PyObject *__pyx_v_data = 0; Py_ssize_t __pyx_v_bytes_read; char *__pyx_v_data_ptr; PyObject *__pyx_v_file_obj = NULL; Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations 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; size_t __pyx_t_7; Py_ssize_t __pyx_t_8; int __pyx_t_9; char *__pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("pyobject_read_handler", 0); /* "pyreadstat/_readstat_parser.pyx":885 * cdef char *data_ptr * * try: # <<<<<<<<<<<<<< * file_obj = _file_object_ctx * data = file_obj.read(nbyte) */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); __Pyx_XGOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { /* "pyreadstat/_readstat_parser.pyx":886 * * try: * file_obj = _file_object_ctx # <<<<<<<<<<<<<< * data = file_obj.read(nbyte) * bytes_read = len(data) */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx); __pyx_v_file_obj = __pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx; /* "pyreadstat/_readstat_parser.pyx":887 * try: * file_obj = _file_object_ctx * data = file_obj.read(nbyte) # <<<<<<<<<<<<<< * bytes_read = len(data) * if bytes_read > 0: */ __pyx_t_5 = __pyx_v_file_obj; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyLong_FromSize_t(__pyx_v_nbyte); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 887, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_6}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_read, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 887, __pyx_L3_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, 887, __pyx_L3_error) __pyx_v_data = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":888 * file_obj = _file_object_ctx * data = file_obj.read(nbyte) * bytes_read = len(data) # <<<<<<<<<<<<<< * if bytes_read > 0: * data_ptr = data */ if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 888, __pyx_L3_error) } __pyx_t_8 = __Pyx_PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 888, __pyx_L3_error) __pyx_v_bytes_read = __pyx_t_8; /* "pyreadstat/_readstat_parser.pyx":889 * data = file_obj.read(nbyte) * bytes_read = len(data) * if bytes_read > 0: # <<<<<<<<<<<<<< * data_ptr = data * memcpy(buf, data_ptr, bytes_read) */ __pyx_t_9 = (__pyx_v_bytes_read > 0); if (__pyx_t_9) { /* "pyreadstat/_readstat_parser.pyx":890 * bytes_read = len(data) * if bytes_read > 0: * data_ptr = data # <<<<<<<<<<<<<< * memcpy(buf, data_ptr, bytes_read) * return bytes_read */ if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); __PYX_ERR(0, 890, __pyx_L3_error) } __pyx_t_10 = __Pyx_PyBytes_AsWritableString(__pyx_v_data); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 890, __pyx_L3_error) __pyx_v_data_ptr = ((char *)__pyx_t_10); /* "pyreadstat/_readstat_parser.pyx":891 * if bytes_read > 0: * data_ptr = data * memcpy(buf, data_ptr, bytes_read) # <<<<<<<<<<<<<< * return bytes_read * except: */ (void)(memcpy(__pyx_v_buf, __pyx_v_data_ptr, __pyx_v_bytes_read)); /* "pyreadstat/_readstat_parser.pyx":889 * data = file_obj.read(nbyte) * bytes_read = len(data) * if bytes_read > 0: # <<<<<<<<<<<<<< * data_ptr = data * memcpy(buf, data_ptr, bytes_read) */ } /* "pyreadstat/_readstat_parser.pyx":892 * data_ptr = data * memcpy(buf, data_ptr, bytes_read) * return bytes_read # <<<<<<<<<<<<<< * except: * return -1 */ __pyx_r = __pyx_v_bytes_read; goto __pyx_L7_try_return; /* "pyreadstat/_readstat_parser.pyx":885 * cdef char *data_ptr * * try: # <<<<<<<<<<<<<< * file_obj = _file_object_ctx * data = file_obj.read(nbyte) */ } __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; /* "pyreadstat/_readstat_parser.pyx":893 * memcpy(buf, data_ptr, bytes_read) * return bytes_read * except: # <<<<<<<<<<<<<< * return -1 * */ /*except:*/ { __Pyx_ErrRestore(0,0,0); /* "pyreadstat/_readstat_parser.pyx":894 * return bytes_read * except: * return -1 # <<<<<<<<<<<<<< * * cdef readstat_off_t pyobject_seek_handler(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx) noexcept: */ __pyx_r = -1L; goto __pyx_L6_except_return; } /* "pyreadstat/_readstat_parser.pyx":885 * cdef char *data_ptr * * try: # <<<<<<<<<<<<<< * file_obj = _file_object_ctx * data = file_obj.read(nbyte) */ __pyx_L7_try_return:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L0; __pyx_L6_except_return:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L0; } /* "pyreadstat/_readstat_parser.pyx":878 * return 0 * * cdef ssize_t pyobject_read_handler(void *buf, size_t nbyte, void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """Bridge Python file.read() to C read operation""" * global _file_object_ctx */ /* function exit code */ __pyx_L0:; __Pyx_XDECREF(__pyx_v_data); __Pyx_XDECREF(__pyx_v_file_obj); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":896 * return -1 * * cdef readstat_off_t pyobject_seek_handler(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """Bridge Python file.seek() to C seek operation""" * global _file_object_ctx */ static readstat_off_t __pyx_f_10pyreadstat_16_readstat_parser_pyobject_seek_handler(readstat_off_t __pyx_v_offset, readstat_io_flags_t __pyx_v_whence, CYTHON_UNUSED void *__pyx_v_io_ctx) { int __pyx_v_py_whence; PyObject *__pyx_v_file_obj = NULL; readstat_off_t __pyx_r; __Pyx_RefNannyDeclarations 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; size_t __pyx_t_8; readstat_off_t __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("pyobject_seek_handler", 0); /* "pyreadstat/_readstat_parser.pyx":901 * cdef int py_whence * * try: # <<<<<<<<<<<<<< * file_obj = _file_object_ctx * if whence == READSTAT_SEEK_SET: */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); __Pyx_XGOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { /* "pyreadstat/_readstat_parser.pyx":902 * * try: * file_obj = _file_object_ctx # <<<<<<<<<<<<<< * if whence == READSTAT_SEEK_SET: * py_whence = 0 */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx); __pyx_v_file_obj = __pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx; /* "pyreadstat/_readstat_parser.pyx":903 * try: * file_obj = _file_object_ctx * if whence == READSTAT_SEEK_SET: # <<<<<<<<<<<<<< * py_whence = 0 * elif whence == READSTAT_SEEK_CUR: */ switch (__pyx_v_whence) { case READSTAT_SEEK_SET: /* "pyreadstat/_readstat_parser.pyx":904 * file_obj = _file_object_ctx * if whence == READSTAT_SEEK_SET: * py_whence = 0 # <<<<<<<<<<<<<< * elif whence == READSTAT_SEEK_CUR: * py_whence = 1 */ __pyx_v_py_whence = 0; /* "pyreadstat/_readstat_parser.pyx":903 * try: * file_obj = _file_object_ctx * if whence == READSTAT_SEEK_SET: # <<<<<<<<<<<<<< * py_whence = 0 * elif whence == READSTAT_SEEK_CUR: */ break; case READSTAT_SEEK_CUR: /* "pyreadstat/_readstat_parser.pyx":906 * py_whence = 0 * elif whence == READSTAT_SEEK_CUR: * py_whence = 1 # <<<<<<<<<<<<<< * else: # READSTAT_SEEK_END * py_whence = 2 */ __pyx_v_py_whence = 1; /* "pyreadstat/_readstat_parser.pyx":905 * if whence == READSTAT_SEEK_SET: * py_whence = 0 * elif whence == READSTAT_SEEK_CUR: # <<<<<<<<<<<<<< * py_whence = 1 * else: # READSTAT_SEEK_END */ break; default: /* "pyreadstat/_readstat_parser.pyx":908 * py_whence = 1 * else: # READSTAT_SEEK_END * py_whence = 2 # <<<<<<<<<<<<<< * * file_obj.seek(offset, py_whence) */ __pyx_v_py_whence = 2; break; } /* "pyreadstat/_readstat_parser.pyx":910 * py_whence = 2 * * file_obj.seek(offset, py_whence) # <<<<<<<<<<<<<< * return file_obj.tell() * except: */ __pyx_t_5 = __pyx_v_file_obj; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyLong_From_off_t(__pyx_v_offset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 910, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_py_whence); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 910, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = 0; { PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_7}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_seek, __pyx_callargs+__pyx_t_8, (3-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":911 * * file_obj.seek(offset, py_whence) * return file_obj.tell() # <<<<<<<<<<<<<< * except: * return -1 */ __pyx_t_7 = __pyx_v_file_obj; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_tell, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 911, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_t_9 = __Pyx_PyLong_As_off_t(__pyx_t_4); if (unlikely((__pyx_t_9 == ((readstat_off_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 911, __pyx_L3_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_9; goto __pyx_L7_try_return; /* "pyreadstat/_readstat_parser.pyx":901 * cdef int py_whence * * try: # <<<<<<<<<<<<<< * file_obj = _file_object_ctx * if whence == READSTAT_SEEK_SET: */ } __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":912 * file_obj.seek(offset, py_whence) * return file_obj.tell() * except: # <<<<<<<<<<<<<< * return -1 * */ /*except:*/ { __Pyx_ErrRestore(0,0,0); /* "pyreadstat/_readstat_parser.pyx":913 * return file_obj.tell() * except: * return -1 # <<<<<<<<<<<<<< * * */ __pyx_r = -1L; goto __pyx_L6_except_return; } /* "pyreadstat/_readstat_parser.pyx":901 * cdef int py_whence * * try: # <<<<<<<<<<<<<< * file_obj = _file_object_ctx * if whence == READSTAT_SEEK_SET: */ __pyx_L7_try_return:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L0; __pyx_L6_except_return:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L0; } /* "pyreadstat/_readstat_parser.pyx":896 * return -1 * * cdef readstat_off_t pyobject_seek_handler(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx) noexcept: # <<<<<<<<<<<<<< * """Bridge Python file.seek() to C seek operation""" * global _file_object_ctx */ /* function exit code */ __pyx_L0:; __Pyx_XDECREF(__pyx_v_file_obj); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":916 * * * 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_parser_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_parser.pyx":923 * cdef char * err_readstat * cdef str err_message * if retcode != READSTAT_OK: # <<<<<<<<<<<<<< * err_readstat = readstat_error_message(retcode) * err_message = err_readstat */ __pyx_t_1 = (__pyx_v_retcode != READSTAT_OK); if (unlikely(__pyx_t_1)) { /* "pyreadstat/_readstat_parser.pyx":924 * cdef str err_message * if retcode != READSTAT_OK: * err_readstat = readstat_error_message(retcode) # <<<<<<<<<<<<<< * err_message = err_readstat * raise ReadstatError(err_message) */ __pyx_v_err_readstat = readstat_error_message(__pyx_v_retcode); /* "pyreadstat/_readstat_parser.pyx":925 * if retcode != READSTAT_OK: * err_readstat = readstat_error_message(retcode) * err_message = err_readstat # <<<<<<<<<<<<<< * raise ReadstatError(err_message) * */ __pyx_t_2 = __Pyx_PyUnicode_FromString(__pyx_v_err_readstat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 925, __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_parser.pyx":926 * err_readstat = readstat_error_message(retcode) * err_message = err_readstat * raise ReadstatError(err_message) # <<<<<<<<<<<<<< * * */ __pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_ReadstatError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 926, __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, 926, __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, 926, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":923 * cdef char * err_readstat * cdef str err_message * if retcode != READSTAT_OK: # <<<<<<<<<<<<<< * err_readstat = readstat_error_message(retcode) * err_message = err_readstat */ } /* "pyreadstat/_readstat_parser.pyx":916 * * * 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_parser.check_exit_status", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_v_err_message); __Pyx_RefNannyFinishContext(); } /* "pyreadstat/_readstat_parser.pyx":929 * * * cdef void run_readstat_parser(char * filename, data_container data, py_file_extension file_extension, long row_limit, long row_offset, object file_obj=None) except *: # <<<<<<<<<<<<<< * """ * Runs the parsing of the file by readstat library. */ static void __pyx_f_10pyreadstat_16_readstat_parser_run_readstat_parser(char *__pyx_v_filename, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_data, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension, long __pyx_v_row_limit, long __pyx_v_row_offset, struct __pyx_opt_args_10pyreadstat_16_readstat_parser_run_readstat_parser *__pyx_optional_args) { PyObject *__pyx_v_file_obj = ((PyObject *)Py_None); readstat_parser_t *__pyx_v_parser; readstat_error_t __pyx_v_error; readstat_metadata_handler __pyx_v_metadata_handler; readstat_variable_handler __pyx_v_variable_handler; readstat_value_handler __pyx_v_value_handler; readstat_value_label_handler __pyx_v_value_label_handler; readstat_note_handler __pyx_v_note_handler; readstat_open_handler __pyx_v_open_handler; readstat_close_handler __pyx_v_close_handler; readstat_read_handler __pyx_v_read_handler; readstat_seek_handler __pyx_v_seek_handler; void *__pyx_v_ctx; PyObject *__pyx_v_pyerr; int __pyx_v_metaonly; PyObject *__pyx_v_encoding_bytes = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("run_readstat_parser", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_file_obj = __pyx_optional_args->file_obj; } } /* "pyreadstat/_readstat_parser.pyx":956 * cdef bytes encoding_byte * * metaonly = data.metaonly # <<<<<<<<<<<<<< * ctx = data * */ __pyx_t_1 = __pyx_v_data->metaonly; __pyx_v_metaonly = __pyx_t_1; /* "pyreadstat/_readstat_parser.pyx":957 * * metaonly = data.metaonly * ctx = data # <<<<<<<<<<<<<< * * #readstat_error_t error = READSTAT_OK; */ __pyx_v_ctx = ((void *)__pyx_v_data); /* "pyreadstat/_readstat_parser.pyx":960 * * #readstat_error_t error = READSTAT_OK; * parser = readstat_parser_init() # <<<<<<<<<<<<<< * metadata_handler = handle_metadata * variable_handler = handle_variable */ __pyx_v_parser = readstat_parser_init(); /* "pyreadstat/_readstat_parser.pyx":961 * #readstat_error_t error = READSTAT_OK; * parser = readstat_parser_init() * metadata_handler = handle_metadata # <<<<<<<<<<<<<< * variable_handler = handle_variable * value_handler = handle_value */ __pyx_v_metadata_handler = ((readstat_metadata_handler)__pyx_f_10pyreadstat_16_readstat_parser_handle_metadata); /* "pyreadstat/_readstat_parser.pyx":962 * parser = readstat_parser_init() * metadata_handler = handle_metadata * variable_handler = handle_variable # <<<<<<<<<<<<<< * value_handler = handle_value * value_label_handler = handle_value_label */ __pyx_v_variable_handler = ((readstat_variable_handler)__pyx_f_10pyreadstat_16_readstat_parser_handle_variable); /* "pyreadstat/_readstat_parser.pyx":963 * metadata_handler = handle_metadata * variable_handler = handle_variable * value_handler = handle_value # <<<<<<<<<<<<<< * value_label_handler = handle_value_label * note_handler = handle_note */ __pyx_v_value_handler = ((readstat_value_handler)__pyx_f_10pyreadstat_16_readstat_parser_handle_value); /* "pyreadstat/_readstat_parser.pyx":964 * variable_handler = handle_variable * value_handler = handle_value * value_label_handler = handle_value_label # <<<<<<<<<<<<<< * note_handler = handle_note * */ __pyx_v_value_label_handler = ((readstat_value_label_handler)__pyx_f_10pyreadstat_16_readstat_parser_handle_value_label); /* "pyreadstat/_readstat_parser.pyx":965 * value_handler = handle_value * value_label_handler = handle_value_label * note_handler = handle_note # <<<<<<<<<<<<<< * * */ __pyx_v_note_handler = ((readstat_note_handler)__pyx_f_10pyreadstat_16_readstat_parser_handle_note); /* "pyreadstat/_readstat_parser.pyx":968 * * * check_exit_status(readstat_set_metadata_handler(parser, metadata_handler)) # <<<<<<<<<<<<<< * check_exit_status(readstat_set_variable_handler(parser, variable_handler)) * check_exit_status(readstat_set_value_label_handler(parser, value_label_handler)) */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_metadata_handler(__pyx_v_parser, __pyx_v_metadata_handler)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 968, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":969 * * check_exit_status(readstat_set_metadata_handler(parser, metadata_handler)) * check_exit_status(readstat_set_variable_handler(parser, variable_handler)) # <<<<<<<<<<<<<< * check_exit_status(readstat_set_value_label_handler(parser, value_label_handler)) * check_exit_status(readstat_set_note_handler(parser, note_handler)) */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_variable_handler(__pyx_v_parser, __pyx_v_variable_handler)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 969, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":970 * check_exit_status(readstat_set_metadata_handler(parser, metadata_handler)) * check_exit_status(readstat_set_variable_handler(parser, variable_handler)) * check_exit_status(readstat_set_value_label_handler(parser, value_label_handler)) # <<<<<<<<<<<<<< * check_exit_status(readstat_set_note_handler(parser, note_handler)) * */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_value_label_handler(__pyx_v_parser, __pyx_v_value_label_handler)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 970, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":971 * check_exit_status(readstat_set_variable_handler(parser, variable_handler)) * check_exit_status(readstat_set_value_label_handler(parser, value_label_handler)) * check_exit_status(readstat_set_note_handler(parser, note_handler)) # <<<<<<<<<<<<<< * * # Set up custom I/O handlers for file objects */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_note_handler(__pyx_v_parser, __pyx_v_note_handler)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 971, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":974 * * # Set up custom I/O handlers for file objects * if file_obj is not None: # <<<<<<<<<<<<<< * _file_object_ctx = file_obj * open_handler = pyobject_open_handler */ __pyx_t_1 = (__pyx_v_file_obj != Py_None); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":975 * # Set up custom I/O handlers for file objects * if file_obj is not None: * _file_object_ctx = file_obj # <<<<<<<<<<<<<< * open_handler = pyobject_open_handler * close_handler = pyobject_close_handler */ __Pyx_INCREF(__pyx_v_file_obj); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx, __pyx_v_file_obj); __Pyx_GIVEREF(__pyx_v_file_obj); /* "pyreadstat/_readstat_parser.pyx":976 * if file_obj is not None: * _file_object_ctx = file_obj * open_handler = pyobject_open_handler # <<<<<<<<<<<<<< * close_handler = pyobject_close_handler * read_handler = pyobject_read_handler */ __pyx_v_open_handler = ((readstat_open_handler)__pyx_f_10pyreadstat_16_readstat_parser_pyobject_open_handler); /* "pyreadstat/_readstat_parser.pyx":977 * _file_object_ctx = file_obj * open_handler = pyobject_open_handler * close_handler = pyobject_close_handler # <<<<<<<<<<<<<< * read_handler = pyobject_read_handler * seek_handler = pyobject_seek_handler */ __pyx_v_close_handler = ((readstat_close_handler)__pyx_f_10pyreadstat_16_readstat_parser_pyobject_close_handler); /* "pyreadstat/_readstat_parser.pyx":978 * open_handler = pyobject_open_handler * close_handler = pyobject_close_handler * read_handler = pyobject_read_handler # <<<<<<<<<<<<<< * seek_handler = pyobject_seek_handler * readstat_set_open_handler(parser, open_handler) */ __pyx_v_read_handler = ((readstat_read_handler)__pyx_f_10pyreadstat_16_readstat_parser_pyobject_read_handler); /* "pyreadstat/_readstat_parser.pyx":979 * close_handler = pyobject_close_handler * read_handler = pyobject_read_handler * seek_handler = pyobject_seek_handler # <<<<<<<<<<<<<< * readstat_set_open_handler(parser, open_handler) * readstat_set_close_handler(parser, close_handler) */ __pyx_v_seek_handler = ((readstat_seek_handler)__pyx_f_10pyreadstat_16_readstat_parser_pyobject_seek_handler); /* "pyreadstat/_readstat_parser.pyx":980 * read_handler = pyobject_read_handler * seek_handler = pyobject_seek_handler * readstat_set_open_handler(parser, open_handler) # <<<<<<<<<<<<<< * readstat_set_close_handler(parser, close_handler) * readstat_set_read_handler(parser, read_handler) */ (void)(readstat_set_open_handler(__pyx_v_parser, __pyx_v_open_handler)); /* "pyreadstat/_readstat_parser.pyx":981 * seek_handler = pyobject_seek_handler * readstat_set_open_handler(parser, open_handler) * readstat_set_close_handler(parser, close_handler) # <<<<<<<<<<<<<< * readstat_set_read_handler(parser, read_handler) * readstat_set_seek_handler(parser, seek_handler) */ (void)(readstat_set_close_handler(__pyx_v_parser, __pyx_v_close_handler)); /* "pyreadstat/_readstat_parser.pyx":982 * readstat_set_open_handler(parser, open_handler) * readstat_set_close_handler(parser, close_handler) * readstat_set_read_handler(parser, read_handler) # <<<<<<<<<<<<<< * readstat_set_seek_handler(parser, seek_handler) * elif os.name == "nt": */ (void)(readstat_set_read_handler(__pyx_v_parser, __pyx_v_read_handler)); /* "pyreadstat/_readstat_parser.pyx":983 * readstat_set_close_handler(parser, close_handler) * readstat_set_read_handler(parser, read_handler) * readstat_set_seek_handler(parser, seek_handler) # <<<<<<<<<<<<<< * elif os.name == "nt": * # on windows we need a custom open handler in order to deal with internation characters in the path. */ (void)(readstat_set_seek_handler(__pyx_v_parser, __pyx_v_seek_handler)); /* "pyreadstat/_readstat_parser.pyx":974 * * # Set up custom I/O handlers for file objects * if file_obj is not None: # <<<<<<<<<<<<<< * _file_object_ctx = file_obj * open_handler = pyobject_open_handler */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":984 * readstat_set_read_handler(parser, read_handler) * readstat_set_seek_handler(parser, seek_handler) * elif os.name == "nt": # <<<<<<<<<<<<<< * # on windows we need a custom open handler in order to deal with internation characters in the path. * open_handler = handle_open */ __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 984, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 984, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_nt, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 984, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":986 * elif os.name == "nt": * # on windows we need a custom open handler in order to deal with internation characters in the path. * open_handler = handle_open # <<<<<<<<<<<<<< * readstat_set_open_handler(parser, open_handler) * */ __pyx_v_open_handler = ((readstat_open_handler)__pyx_f_10pyreadstat_16_readstat_parser_handle_open); /* "pyreadstat/_readstat_parser.pyx":987 * # on windows we need a custom open handler in order to deal with internation characters in the path. * open_handler = handle_open * readstat_set_open_handler(parser, open_handler) # <<<<<<<<<<<<<< * * if not metaonly: */ (void)(readstat_set_open_handler(__pyx_v_parser, __pyx_v_open_handler)); /* "pyreadstat/_readstat_parser.pyx":984 * readstat_set_read_handler(parser, read_handler) * readstat_set_seek_handler(parser, seek_handler) * elif os.name == "nt": # <<<<<<<<<<<<<< * # on windows we need a custom open handler in order to deal with internation characters in the path. * open_handler = handle_open */ } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":989 * readstat_set_open_handler(parser, open_handler) * * if not metaonly: # <<<<<<<<<<<<<< * check_exit_status(readstat_set_value_handler(parser, value_handler)) * */ __pyx_t_1 = (!__pyx_v_metaonly); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":990 * * if not metaonly: * check_exit_status(readstat_set_value_handler(parser, value_handler)) # <<<<<<<<<<<<<< * * # if the user set the encoding manually */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_value_handler(__pyx_v_parser, __pyx_v_value_handler)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 990, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":989 * readstat_set_open_handler(parser, open_handler) * * if not metaonly: # <<<<<<<<<<<<<< * check_exit_status(readstat_set_value_handler(parser, value_handler)) * */ } /* "pyreadstat/_readstat_parser.pyx":993 * * # if the user set the encoding manually * if data.user_encoding: # <<<<<<<<<<<<<< * encoding_bytes = data.user_encoding.encode("utf-8") * readstat_set_file_character_encoding(parser, encoding_bytes) */ __pyx_t_1 = (__pyx_v_data->user_encoding != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_data->user_encoding) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_1 < 0))) __PYX_ERR(0, 993, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":994 * # if the user set the encoding manually * if data.user_encoding: * encoding_bytes = data.user_encoding.encode("utf-8") # <<<<<<<<<<<<<< * readstat_set_file_character_encoding(parser, encoding_bytes) * */ if (unlikely(__pyx_v_data->user_encoding == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode"); __PYX_ERR(0, 994, __pyx_L1_error) } __pyx_t_3 = PyUnicode_AsUTF8String(__pyx_v_data->user_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 994, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_encoding_bytes = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":995 * if data.user_encoding: * encoding_bytes = data.user_encoding.encode("utf-8") * readstat_set_file_character_encoding(parser, encoding_bytes) # <<<<<<<<<<<<<< * * if row_limit: */ __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_encoding_bytes); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 995, __pyx_L1_error) (void)(readstat_set_file_character_encoding(__pyx_v_parser, ((char *)__pyx_t_4))); /* "pyreadstat/_readstat_parser.pyx":993 * * # if the user set the encoding manually * if data.user_encoding: # <<<<<<<<<<<<<< * encoding_bytes = data.user_encoding.encode("utf-8") * readstat_set_file_character_encoding(parser, encoding_bytes) */ } /* "pyreadstat/_readstat_parser.pyx":997 * readstat_set_file_character_encoding(parser, encoding_bytes) * * if row_limit: # <<<<<<<<<<<<<< * check_exit_status(readstat_set_row_limit(parser, row_limit)) * */ __pyx_t_1 = (__pyx_v_row_limit != 0); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":998 * * if row_limit: * check_exit_status(readstat_set_row_limit(parser, row_limit)) # <<<<<<<<<<<<<< * * if row_offset: */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_row_limit(__pyx_v_parser, __pyx_v_row_limit)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 998, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":997 * readstat_set_file_character_encoding(parser, encoding_bytes) * * if row_limit: # <<<<<<<<<<<<<< * check_exit_status(readstat_set_row_limit(parser, row_limit)) * */ } /* "pyreadstat/_readstat_parser.pyx":1000 * check_exit_status(readstat_set_row_limit(parser, row_limit)) * * if row_offset: # <<<<<<<<<<<<<< * check_exit_status(readstat_set_row_offset(parser, row_offset)) * */ __pyx_t_1 = (__pyx_v_row_offset != 0); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1001 * * if row_offset: * check_exit_status(readstat_set_row_offset(parser, row_offset)) # <<<<<<<<<<<<<< * * # parse! */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(readstat_set_row_offset(__pyx_v_parser, __pyx_v_row_offset)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1001, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1000 * check_exit_status(readstat_set_row_limit(parser, row_limit)) * * if row_offset: # <<<<<<<<<<<<<< * check_exit_status(readstat_set_row_offset(parser, row_offset)) * */ } /* "pyreadstat/_readstat_parser.pyx":1004 * * # parse! * if file_extension == FILE_EXT_SAV: # <<<<<<<<<<<<<< * error = readstat_parse_sav(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BDAT: */ switch (__pyx_v_file_extension) { case __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAV: /* "pyreadstat/_readstat_parser.pyx":1005 * # parse! * if file_extension == FILE_EXT_SAV: * error = readstat_parse_sav(parser, filename, ctx); # <<<<<<<<<<<<<< * elif file_extension == FILE_EXT_SAS7BDAT: * error = readstat_parse_sas7bdat(parser, filename, ctx); */ __pyx_v_error = readstat_parse_sav(__pyx_v_parser, __pyx_v_filename, __pyx_v_ctx); /* "pyreadstat/_readstat_parser.pyx":1004 * * # parse! * if file_extension == FILE_EXT_SAV: # <<<<<<<<<<<<<< * error = readstat_parse_sav(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BDAT: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAS7BDAT: /* "pyreadstat/_readstat_parser.pyx":1007 * error = readstat_parse_sav(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BDAT: * error = readstat_parse_sas7bdat(parser, filename, ctx); # <<<<<<<<<<<<<< * elif file_extension == FILE_EXT_DTA: * error = readstat_parse_dta(parser, filename, ctx); */ __pyx_v_error = readstat_parse_sas7bdat(__pyx_v_parser, __pyx_v_filename, __pyx_v_ctx); /* "pyreadstat/_readstat_parser.pyx":1006 * if file_extension == FILE_EXT_SAV: * error = readstat_parse_sav(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BDAT: # <<<<<<<<<<<<<< * error = readstat_parse_sas7bdat(parser, filename, ctx); * elif file_extension == FILE_EXT_DTA: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_DTA: /* "pyreadstat/_readstat_parser.pyx":1009 * error = readstat_parse_sas7bdat(parser, filename, ctx); * elif file_extension == FILE_EXT_DTA: * error = readstat_parse_dta(parser, filename, ctx); # <<<<<<<<<<<<<< * elif file_extension == FILE_EXT_XPORT: * error = readstat_parse_xport(parser, filename, ctx); */ __pyx_v_error = readstat_parse_dta(__pyx_v_parser, __pyx_v_filename, __pyx_v_ctx); /* "pyreadstat/_readstat_parser.pyx":1008 * elif file_extension == FILE_EXT_SAS7BDAT: * error = readstat_parse_sas7bdat(parser, filename, ctx); * elif file_extension == FILE_EXT_DTA: # <<<<<<<<<<<<<< * error = readstat_parse_dta(parser, filename, ctx); * elif file_extension == FILE_EXT_XPORT: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_XPORT: /* "pyreadstat/_readstat_parser.pyx":1011 * error = readstat_parse_dta(parser, filename, ctx); * elif file_extension == FILE_EXT_XPORT: * error = readstat_parse_xport(parser, filename, ctx); # <<<<<<<<<<<<<< * elif file_extension == FILE_EXT_POR: * error = readstat_parse_por(parser, filename, ctx); */ __pyx_v_error = readstat_parse_xport(__pyx_v_parser, __pyx_v_filename, __pyx_v_ctx); /* "pyreadstat/_readstat_parser.pyx":1010 * elif file_extension == FILE_EXT_DTA: * error = readstat_parse_dta(parser, filename, ctx); * elif file_extension == FILE_EXT_XPORT: # <<<<<<<<<<<<<< * error = readstat_parse_xport(parser, filename, ctx); * elif file_extension == FILE_EXT_POR: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_POR: /* "pyreadstat/_readstat_parser.pyx":1013 * error = readstat_parse_xport(parser, filename, ctx); * elif file_extension == FILE_EXT_POR: * error = readstat_parse_por(parser, filename, ctx); # <<<<<<<<<<<<<< * elif file_extension == FILE_EXT_SAS7BCAT: * error = readstat_parse_sas7bcat(parser, filename, ctx); */ __pyx_v_error = readstat_parse_por(__pyx_v_parser, __pyx_v_filename, __pyx_v_ctx); /* "pyreadstat/_readstat_parser.pyx":1012 * elif file_extension == FILE_EXT_XPORT: * error = readstat_parse_xport(parser, filename, ctx); * elif file_extension == FILE_EXT_POR: # <<<<<<<<<<<<<< * error = readstat_parse_por(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BCAT: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAS7BCAT: /* "pyreadstat/_readstat_parser.pyx":1015 * error = readstat_parse_por(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BCAT: * error = readstat_parse_sas7bcat(parser, filename, ctx); # <<<<<<<<<<<<<< * #error = parse_func(parser, filename, ctx); * readstat_parser_free(parser) */ __pyx_v_error = readstat_parse_sas7bcat(__pyx_v_parser, __pyx_v_filename, __pyx_v_ctx); /* "pyreadstat/_readstat_parser.pyx":1014 * elif file_extension == FILE_EXT_POR: * error = readstat_parse_por(parser, filename, ctx); * elif file_extension == FILE_EXT_SAS7BCAT: # <<<<<<<<<<<<<< * error = readstat_parse_sas7bcat(parser, filename, ctx); * #error = parse_func(parser, filename, ctx); */ break; default: break; } /* "pyreadstat/_readstat_parser.pyx":1017 * error = readstat_parse_sas7bcat(parser, filename, ctx); * #error = parse_func(parser, filename, ctx); * readstat_parser_free(parser) # <<<<<<<<<<<<<< * # check if a python error ocurred, if yes, it will be printed by the interpreter, * # if not, make sure that the return from parse_func is OK, if not print */ readstat_parser_free(__pyx_v_parser); /* "pyreadstat/_readstat_parser.pyx":1020 * # check if a python error ocurred, if yes, it will be printed by the interpreter, * # if not, make sure that the return from parse_func is OK, if not print * pyerr = PyErr_Occurred() # <<<<<<<<<<<<<< * if pyerr == NULL: * check_exit_status(error) */ __pyx_v_pyerr = PyErr_Occurred(); /* "pyreadstat/_readstat_parser.pyx":1021 * # if not, make sure that the return from parse_func is OK, if not print * pyerr = PyErr_Occurred() * if pyerr == NULL: # <<<<<<<<<<<<<< * check_exit_status(error) * */ __pyx_t_1 = (((void *)__pyx_v_pyerr) == NULL); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1022 * pyerr = PyErr_Occurred() * if pyerr == NULL: * check_exit_status(error) # <<<<<<<<<<<<<< * * */ __pyx_f_10pyreadstat_16_readstat_parser_check_exit_status(__pyx_v_error); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1022, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1021 * # if not, make sure that the return from parse_func is OK, if not print * pyerr = PyErr_Occurred() * if pyerr == NULL: # <<<<<<<<<<<<<< * check_exit_status(error) * */ } /* "pyreadstat/_readstat_parser.pyx":929 * * * cdef void run_readstat_parser(char * filename, data_container data, py_file_extension file_extension, long row_limit, long row_offset, object file_obj=None) except *: # <<<<<<<<<<<<<< * """ * Runs the parsing of the file by readstat library. */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pyreadstat._readstat_parser.run_readstat_parser", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_v_encoding_bytes); __Pyx_RefNannyFinishContext(); } /* "pyreadstat/_readstat_parser.pyx":1025 * * * cdef object data_container_to_dict(data_container data): # <<<<<<<<<<<<<< * """ * Transforms a data container object to a pandas data frame */ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_data_container_to_dict(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_data) { PyObject *__pyx_v_final_container = 0; PyObject *__pyx_v_col_data = 0; PyObject *__pyx_v_col_names = 0; PyObject *__pyx_v_cur_name_str = 0; int __pyx_v_fc_cnt; int __pyx_v_is_unkown_number_rows; int __pyx_v_max_n_obs; int __pyx_v_metaonly; PyObject *__pyx_v_cur_data = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; size_t __pyx_t_4; int __pyx_t_5; int __pyx_t_6; Py_ssize_t __pyx_t_7; Py_ssize_t __pyx_t_8; int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("data_container_to_dict", 0); /* "pyreadstat/_readstat_parser.pyx":1039 * cdef bint metaonly * * final_container = OrderedDict() # <<<<<<<<<<<<<< * col_data = data.col_data * col_names = data.col_names */ __pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1039, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1039, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_final_container = __pyx_t_1; __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":1040 * * final_container = OrderedDict() * col_data = data.col_data # <<<<<<<<<<<<<< * col_names = data.col_names * is_unkown_number_rows = data.is_unkown_number_rows */ __pyx_t_1 = __pyx_v_data->col_data; __Pyx_INCREF(__pyx_t_1); __pyx_v_col_data = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":1041 * final_container = OrderedDict() * col_data = data.col_data * col_names = data.col_names # <<<<<<<<<<<<<< * is_unkown_number_rows = data.is_unkown_number_rows * max_n_obs = data.max_n_obs */ __pyx_t_1 = __pyx_v_data->col_names; __Pyx_INCREF(__pyx_t_1); __pyx_v_col_names = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":1042 * col_data = data.col_data * col_names = data.col_names * is_unkown_number_rows = data.is_unkown_number_rows # <<<<<<<<<<<<<< * max_n_obs = data.max_n_obs * metaonly = data.metaonly */ __pyx_t_5 = __pyx_v_data->is_unkown_number_rows; __pyx_v_is_unkown_number_rows = __pyx_t_5; /* "pyreadstat/_readstat_parser.pyx":1043 * col_names = data.col_names * is_unkown_number_rows = data.is_unkown_number_rows * max_n_obs = data.max_n_obs # <<<<<<<<<<<<<< * metaonly = data.metaonly * */ __pyx_t_6 = __pyx_v_data->max_n_obs; __pyx_v_max_n_obs = __pyx_t_6; /* "pyreadstat/_readstat_parser.pyx":1044 * is_unkown_number_rows = data.is_unkown_number_rows * max_n_obs = data.max_n_obs * metaonly = data.metaonly # <<<<<<<<<<<<<< * * for fc_cnt in range(0, len(col_names)): */ __pyx_t_5 = __pyx_v_data->metaonly; __pyx_v_metaonly = __pyx_t_5; /* "pyreadstat/_readstat_parser.pyx":1046 * metaonly = data.metaonly * * for fc_cnt in range(0, len(col_names)): # <<<<<<<<<<<<<< * cur_name_str = col_names[fc_cnt] * cur_data = col_data[fc_cnt] */ if (unlikely(__pyx_v_col_names == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 1046, __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, 1046, __pyx_L1_error) __pyx_t_8 = __pyx_t_7; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_8; __pyx_t_6+=1) { __pyx_v_fc_cnt = __pyx_t_6; /* "pyreadstat/_readstat_parser.pyx":1047 * * for fc_cnt in range(0, len(col_names)): * cur_name_str = col_names[fc_cnt] # <<<<<<<<<<<<<< * cur_data = col_data[fc_cnt] * if is_unkown_number_rows and not metaonly: */ if (unlikely(__pyx_v_col_names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1047, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_names, __pyx_v_fc_cnt, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1047, __pyx_L1_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, 1047, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_cur_name_str, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":1048 * for fc_cnt in range(0, len(col_names)): * cur_name_str = col_names[fc_cnt] * cur_data = col_data[fc_cnt] # <<<<<<<<<<<<<< * if is_unkown_number_rows and not metaonly: * cur_data = cur_data[0:max_n_obs] */ if (unlikely(__pyx_v_col_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1048, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_col_data, __pyx_v_fc_cnt, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1048, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_cur_data, __pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":1049 * cur_name_str = col_names[fc_cnt] * cur_data = col_data[fc_cnt] * if is_unkown_number_rows and not metaonly: # <<<<<<<<<<<<<< * cur_data = cur_data[0:max_n_obs] * if not metaonly: */ if (__pyx_v_is_unkown_number_rows) { } else { __pyx_t_5 = __pyx_v_is_unkown_number_rows; goto __pyx_L6_bool_binop_done; } __pyx_t_9 = (!__pyx_v_metaonly); __pyx_t_5 = __pyx_t_9; __pyx_L6_bool_binop_done:; if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":1050 * cur_data = col_data[fc_cnt] * if is_unkown_number_rows and not metaonly: * cur_data = cur_data[0:max_n_obs] # <<<<<<<<<<<<<< * if not metaonly: * final_container[cur_name_str] = cur_data */ __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_cur_data, 0, __pyx_v_max_n_obs, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1050, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_cur_data, __pyx_t_1); __pyx_t_1 = 0; /* "pyreadstat/_readstat_parser.pyx":1049 * cur_name_str = col_names[fc_cnt] * cur_data = col_data[fc_cnt] * if is_unkown_number_rows and not metaonly: # <<<<<<<<<<<<<< * cur_data = cur_data[0:max_n_obs] * if not metaonly: */ } /* "pyreadstat/_readstat_parser.pyx":1051 * if is_unkown_number_rows and not metaonly: * cur_data = cur_data[0:max_n_obs] * if not metaonly: # <<<<<<<<<<<<<< * final_container[cur_name_str] = cur_data * else: */ __pyx_t_5 = (!__pyx_v_metaonly); if (__pyx_t_5) { /* "pyreadstat/_readstat_parser.pyx":1052 * cur_data = cur_data[0:max_n_obs] * if not metaonly: * final_container[cur_name_str] = cur_data # <<<<<<<<<<<<<< * else: * final_container[cur_name_str] = list() */ if (unlikely((PyObject_SetItem(__pyx_v_final_container, __pyx_v_cur_name_str, __pyx_v_cur_data) < 0))) __PYX_ERR(0, 1052, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1051 * if is_unkown_number_rows and not metaonly: * cur_data = cur_data[0:max_n_obs] * if not metaonly: # <<<<<<<<<<<<<< * final_container[cur_name_str] = cur_data * else: */ goto __pyx_L8; } /* "pyreadstat/_readstat_parser.pyx":1054 * final_container[cur_name_str] = cur_data * else: * final_container[cur_name_str] = list() # <<<<<<<<<<<<<< * * return final_container */ /*else*/ { __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1054, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely((PyObject_SetItem(__pyx_v_final_container, __pyx_v_cur_name_str, __pyx_t_1) < 0))) __PYX_ERR(0, 1054, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L8:; } /* "pyreadstat/_readstat_parser.pyx":1056 * final_container[cur_name_str] = list() * * return final_container # <<<<<<<<<<<<<< * * cdef object dict_to_dataframe(object dict_data, data_container dc): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_final_container); __pyx_r = __pyx_v_final_container; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":1025 * * * cdef object data_container_to_dict(data_container data): # <<<<<<<<<<<<<< * """ * Transforms a data container object to a pandas data frame */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pyreadstat._readstat_parser.data_container_to_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_final_container); __Pyx_XDECREF(__pyx_v_col_data); __Pyx_XDECREF(__pyx_v_col_names); __Pyx_XDECREF(__pyx_v_cur_name_str); __Pyx_XDECREF(__pyx_v_cur_data); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":1058 * return final_container * * cdef object dict_to_dataframe(object dict_data, data_container dc): # <<<<<<<<<<<<<< * """ * Transforms a dict of numpy arrays to a pandas data frame */ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_dict_to_dataframe(PyObject *__pyx_v_dict_data, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_dc) { int __pyx_v_dates_as_pandas; int __pyx_v_allsame; int __pyx_v_index; PyObject *__pyx_v_column = 0; PyObject *__pyx_v_output_format = 0; PyObject *__pyx_v_col_name = 0; __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_v_var_format; PyObject *__pyx_v_dtypes = 0; PyObject *__pyx_v_sertypes = 0; PyObject *__pyx_v_datetime_cols = 0; PyObject *__pyx_v_date_cols = 0; PyObject *__pyx_v_schema = 0; Py_ssize_t __pyx_v_indx; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_natnamespace = NULL; PyObject *__pyx_v_pd = NULL; PyObject *__pyx_v_pl = NULL; PyObject *__pyx_v_x = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; Py_ssize_t __pyx_t_4; Py_ssize_t __pyx_t_5; Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; Py_ssize_t __pyx_t_9; PyObject *(*__pyx_t_10)(PyObject *); PyObject *__pyx_t_11 = NULL; PyObject *__pyx_t_12 = NULL; PyObject *__pyx_t_13 = NULL; PyObject *__pyx_t_14 = NULL; size_t __pyx_t_15; int __pyx_t_16; __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __pyx_t_17; int __pyx_t_18; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dict_to_dataframe", 0); /* "pyreadstat/_readstat_parser.pyx":1068 * cdef py_datetime_format var_format * cdef list dtypes, sertypes, datetime_cols, date_cols * cdef dict schema = None # <<<<<<<<<<<<<< * * dates_as_pandas = dc.dates_as_pandas */ __Pyx_INCREF(Py_None); __pyx_v_schema = ((PyObject*)Py_None); /* "pyreadstat/_readstat_parser.pyx":1070 * cdef dict schema = None * * dates_as_pandas = dc.dates_as_pandas # <<<<<<<<<<<<<< * output_format = dc.output_format * */ __pyx_t_1 = __pyx_v_dc->dates_as_pandas; __pyx_v_dates_as_pandas = __pyx_t_1; /* "pyreadstat/_readstat_parser.pyx":1071 * * dates_as_pandas = dc.dates_as_pandas * output_format = dc.output_format # <<<<<<<<<<<<<< * * if dict_data: */ __pyx_t_2 = __pyx_v_dc->output_format; __Pyx_INCREF(__pyx_t_2); __pyx_v_output_format = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1073 * output_format = dc.output_format * * if dict_data: # <<<<<<<<<<<<<< * #schema = None * # in polars if missing user values we need to explicitly set the type */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dict_data); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1073, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1077 * # in polars if missing user values we need to explicitly set the type * # of that column to Object if not all the elements are of the same type * if output_format != "pandas" and dc.missing_user_values: # <<<<<<<<<<<<<< * schema = dict() * for indx in range(0, len(dc.col_names)): */ __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_NE)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1077, __pyx_L1_error) if (__pyx_t_3) { } else { __pyx_t_1 = __pyx_t_3; goto __pyx_L5_bool_binop_done; } __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_dc->missing_user_values); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1077, __pyx_L1_error) __pyx_t_1 = __pyx_t_3; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1078 * # of that column to Object if not all the elements are of the same type * if output_format != "pandas" and dc.missing_user_values: * schema = dict() # <<<<<<<<<<<<<< * for indx in range(0, len(dc.col_names)): * col_name = dc.col_names[indx] */ __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1078, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_schema, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1079 * if output_format != "pandas" and dc.missing_user_values: * schema = dict() * for indx in range(0, len(dc.col_names)): # <<<<<<<<<<<<<< * col_name = dc.col_names[indx] * if indx in dc.missing_user_values.keys(): */ __pyx_t_2 = __pyx_v_dc->col_names; __Pyx_INCREF(__pyx_t_2); if (unlikely(__pyx_t_2 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 1079, __pyx_L1_error) } __pyx_t_4 = __Pyx_PyList_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1079, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_5 = __pyx_t_4; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_indx = __pyx_t_6; /* "pyreadstat/_readstat_parser.pyx":1080 * schema = dict() * for indx in range(0, len(dc.col_names)): * col_name = dc.col_names[indx] # <<<<<<<<<<<<<< * if indx in dc.missing_user_values.keys(): * sertypes = [type(x) for x in dict_data[col_name] if x is not None] */ if (unlikely(__pyx_v_dc->col_names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1080, __pyx_L1_error) } __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_dc->col_names, __pyx_v_indx, Py_ssize_t, 1, PyLong_FromSsize_t, 1, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1080, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_2))) __PYX_ERR(0, 1080, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_col_name, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1081 * for indx in range(0, len(dc.col_names)): * col_name = dc.col_names[indx] * if indx in dc.missing_user_values.keys(): # <<<<<<<<<<<<<< * sertypes = [type(x) for x in dict_data[col_name] if x is not None] * # all missing, let polars decide */ __pyx_t_2 = PyLong_FromSsize_t(__pyx_v_indx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (unlikely(__pyx_v_dc->missing_user_values == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "keys"); __PYX_ERR(0, 1081, __pyx_L1_error) } __pyx_t_7 = __Pyx_PyDict_Keys(__pyx_v_dc->missing_user_values); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_t_7, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1081, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1082 * col_name = dc.col_names[indx] * if indx in dc.missing_user_values.keys(): * sertypes = [type(x) for x in dict_data[col_name] if x is not None] # <<<<<<<<<<<<<< * # all missing, let polars decide * if not sertypes: */ __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1082, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dict_data, __pyx_v_col_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1082, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_8 = __pyx_t_2; __Pyx_INCREF(__pyx_t_8); __pyx_t_9 = 0; __pyx_t_10 = NULL; } else { __pyx_t_9 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1082, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1082, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_10)) { if (likely(PyList_CheckExact(__pyx_t_8))) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1082, __pyx_L1_error) #endif if (__pyx_t_9 >= __pyx_temp) break; } __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_8, __pyx_t_9); ++__pyx_t_9; } else { { Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1082, __pyx_L1_error) #endif if (__pyx_t_9 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_9)); #else __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_8, __pyx_t_9); #endif ++__pyx_t_9; } if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1082, __pyx_L1_error) } else { __pyx_t_2 = __pyx_t_10(__pyx_t_8); 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, 1082, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_2); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)((PyObject *)Py_TYPE(__pyx_v_x))))) __PYX_ERR(0, 1082, __pyx_L1_error) } } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_v_sertypes, ((PyObject*)__pyx_t_7)); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1084 * sertypes = [type(x) for x in dict_data[col_name] if x is not None] * # all missing, let polars decide * if not sertypes: # <<<<<<<<<<<<<< * schema[col_name] = None * continue */ __pyx_t_1 = (__Pyx_PyList_GET_SIZE(__pyx_v_sertypes) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_1 < 0))) __PYX_ERR(0, 1084, __pyx_L1_error) __pyx_t_3 = (!__pyx_t_1); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1085 * # all missing, let polars decide * if not sertypes: * schema[col_name] = None # <<<<<<<<<<<<<< * continue * allsame = all([x==sertypes[0] for x in sertypes]) */ if (unlikely((PyDict_SetItem(__pyx_v_schema, __pyx_v_col_name, Py_None) < 0))) __PYX_ERR(0, 1085, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1086 * if not sertypes: * schema[col_name] = None * continue # <<<<<<<<<<<<<< * allsame = all([x==sertypes[0] for x in sertypes]) * # all the same: let polars decide */ goto __pyx_L7_continue; /* "pyreadstat/_readstat_parser.pyx":1084 * sertypes = [type(x) for x in dict_data[col_name] if x is not None] * # all missing, let polars decide * if not sertypes: # <<<<<<<<<<<<<< * schema[col_name] = None * continue */ } /* "pyreadstat/_readstat_parser.pyx":1087 * schema[col_name] = None * continue * allsame = all([x==sertypes[0] for x in sertypes]) # <<<<<<<<<<<<<< * # all the same: let polars decide * if allsame: */ __pyx_t_8 = NULL; __Pyx_INCREF(__pyx_builtin_all); __pyx_t_2 = __pyx_builtin_all; __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_12 = __pyx_v_sertypes; __Pyx_INCREF(__pyx_t_12); __pyx_t_9 = 0; for (;;) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_12); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1087, __pyx_L1_error) #endif if (__pyx_t_9 >= __pyx_temp) break; } __pyx_t_13 = __Pyx_PyList_GetItemRef(__pyx_t_12, __pyx_t_9); ++__pyx_t_9; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_13); __pyx_t_13 = 0; __pyx_t_13 = __Pyx_GetItemInt_List(__pyx_v_sertypes, 0, long, 1, __Pyx_PyLong_From_long, 1, 0, 1, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_14 = PyObject_RichCompare(__pyx_v_x, __pyx_t_13, Py_EQ); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; if (unlikely(__Pyx_ListComp_Append(__pyx_t_11, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_15 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_11}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (__pyx_t_15*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_allsame = __pyx_t_3; /* "pyreadstat/_readstat_parser.pyx":1089 * allsame = all([x==sertypes[0] for x in sertypes]) * # all the same: let polars decide * if allsame: # <<<<<<<<<<<<<< * schema[col_name] = None * # not all the same type, has to be Object */ if (__pyx_v_allsame) { /* "pyreadstat/_readstat_parser.pyx":1090 * # all the same: let polars decide * if allsame: * schema[col_name] = None # <<<<<<<<<<<<<< * # not all the same type, has to be Object * else: */ if (unlikely((PyDict_SetItem(__pyx_v_schema, __pyx_v_col_name, Py_None) < 0))) __PYX_ERR(0, 1090, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1089 * allsame = all([x==sertypes[0] for x in sertypes]) * # all the same: let polars decide * if allsame: # <<<<<<<<<<<<<< * schema[col_name] = None * # not all the same type, has to be Object */ goto __pyx_L18; } /* "pyreadstat/_readstat_parser.pyx":1093 * # not all the same type, has to be Object * else: * schema[col_name] = nw.Object # <<<<<<<<<<<<<< * else: * schema[col_name] = None */ /*else*/ { __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1093, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_Object); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1093, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely((PyDict_SetItem(__pyx_v_schema, __pyx_v_col_name, __pyx_t_2) < 0))) __PYX_ERR(0, 1093, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __pyx_L18:; /* "pyreadstat/_readstat_parser.pyx":1081 * for indx in range(0, len(dc.col_names)): * col_name = dc.col_names[indx] * if indx in dc.missing_user_values.keys(): # <<<<<<<<<<<<<< * sertypes = [type(x) for x in dict_data[col_name] if x is not None] * # all missing, let polars decide */ goto __pyx_L9; } /* "pyreadstat/_readstat_parser.pyx":1095 * schema[col_name] = nw.Object * else: * schema[col_name] = None # <<<<<<<<<<<<<< * * data_frame = nw.from_dict(dict_data, backend=output_format, schema=schema) */ /*else*/ { if (unlikely((PyDict_SetItem(__pyx_v_schema, __pyx_v_col_name, Py_None) < 0))) __PYX_ERR(0, 1095, __pyx_L1_error) } __pyx_L9:; __pyx_L7_continue:; } /* "pyreadstat/_readstat_parser.pyx":1077 * # in polars if missing user values we need to explicitly set the type * # of that column to Object if not all the elements are of the same type * if output_format != "pandas" and dc.missing_user_values: # <<<<<<<<<<<<<< * schema = dict() * for indx in range(0, len(dc.col_names)): */ } /* "pyreadstat/_readstat_parser.pyx":1097 * schema[col_name] = None * * data_frame = nw.from_dict(dict_data, backend=output_format, schema=schema) # <<<<<<<<<<<<<< * natnamespace = nw.get_native_namespace(data_frame) * data_frame = data_frame.to_native() */ __pyx_t_7 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_mstate_global->__pyx_n_u_from_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_15 = 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_15 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_7, __pyx_v_dict_data}; __pyx_t_11 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_backend, __pyx_v_output_format, __pyx_t_11, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 1097, __pyx_L1_error) if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_schema, __pyx_v_schema, __pyx_t_11, __pyx_callargs+2, 1) < 0) __PYX_ERR(0, 1097, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (__pyx_t_15*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_11); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_data_frame = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1098 * * data_frame = nw.from_dict(dict_data, backend=output_format, schema=schema) * natnamespace = nw.get_native_namespace(data_frame) # <<<<<<<<<<<<<< * data_frame = data_frame.to_native() * */ __pyx_t_8 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1098, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_mstate_global->__pyx_n_u_get_native_namespace); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1098, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_15 = 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_15 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_data_frame}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (__pyx_t_15*__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, 1098, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_natnamespace = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1099 * data_frame = nw.from_dict(dict_data, backend=output_format, schema=schema) * natnamespace = nw.get_native_namespace(data_frame) * data_frame = data_frame.to_native() # <<<<<<<<<<<<<< * * if dates_as_pandas and output_format=="pandas": */ __pyx_t_7 = __pyx_v_data_frame; __Pyx_INCREF(__pyx_t_7); __pyx_t_15 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_to_native, __pyx_callargs+__pyx_t_15, (1-__pyx_t_15) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1099, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1101 * data_frame = data_frame.to_native() * * if dates_as_pandas and output_format=="pandas": # <<<<<<<<<<<<<< * pd = natnamespace * dtypes = data_frame.dtypes.tolist() */ if (__pyx_v_dates_as_pandas) { } else { __pyx_t_3 = __pyx_v_dates_as_pandas; goto __pyx_L20_bool_binop_done; } __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1101, __pyx_L1_error) __pyx_t_3 = __pyx_t_1; __pyx_L20_bool_binop_done:; if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1102 * * if dates_as_pandas and output_format=="pandas": * pd = natnamespace # <<<<<<<<<<<<<< * dtypes = data_frame.dtypes.tolist() * # check that datetime columns are datetime type */ __Pyx_INCREF(__pyx_v_natnamespace); __pyx_v_pd = __pyx_v_natnamespace; /* "pyreadstat/_readstat_parser.pyx":1103 * if dates_as_pandas and output_format=="pandas": * pd = natnamespace * dtypes = data_frame.dtypes.tolist() # <<<<<<<<<<<<<< * # check that datetime columns are datetime type * # this is needed in case all date values are nan */ __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_data_frame, __pyx_mstate_global->__pyx_n_u_dtypes); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7); __pyx_t_15 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_tolist, __pyx_callargs+__pyx_t_15, (1-__pyx_t_15) | (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_2)) __PYX_ERR(0, 1103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_t_2))) __PYX_ERR(0, 1103, __pyx_L1_error) __pyx_v_dtypes = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1106 * # check that datetime columns are datetime type * # this is needed in case all date values are nan * for index, column in enumerate(data_frame.columns): # <<<<<<<<<<<<<< * var_format = dc.col_formats[index] * if dtypes[index] != '__pyx_n_u_columns); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_8 = __pyx_t_2; __Pyx_INCREF(__pyx_t_8); __pyx_t_4 = 0; __pyx_t_10 = NULL; } else { __pyx_t_4 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1106, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_10)) { if (likely(PyList_CheckExact(__pyx_t_8))) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1106, __pyx_L1_error) #endif if (__pyx_t_4 >= __pyx_temp) break; } __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_8, __pyx_t_4); ++__pyx_t_4; } else { { Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1106, __pyx_L1_error) #endif if (__pyx_t_4 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_4)); #else __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_8, __pyx_t_4); #endif ++__pyx_t_4; } if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1106, __pyx_L1_error) } else { __pyx_t_2 = __pyx_t_10(__pyx_t_8); 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, 1106, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_2); if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_2))) __PYX_ERR(0, 1106, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_column, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; __pyx_v_index = __pyx_t_16; __pyx_t_16 = (__pyx_t_16 + 1); /* "pyreadstat/_readstat_parser.pyx":1107 * # this is needed in case all date values are nan * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] # <<<<<<<<<<<<<< * if dtypes[index] != 'col_formats == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1107, __pyx_L1_error) } __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_dc->col_formats, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_17 = ((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)__Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(__pyx_t_2)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1107, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_var_format = __pyx_t_17; /* "pyreadstat/_readstat_parser.pyx":1108 * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] * if dtypes[index] != '__pyx_kp_u_M8_ns, Py_NE)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1108, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { } else { __pyx_t_3 = __pyx_t_1; goto __pyx_L25_bool_binop_done; } switch (__pyx_v_var_format) { case __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE: case __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME: __pyx_t_1 = 1; break; default: __pyx_t_1 = 0; break; } __pyx_t_3 = __pyx_t_1; __pyx_L25_bool_binop_done:; if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1109 * var_format = dc.col_formats[index] * if dtypes[index] != '__pyx_n_u_to_datetime, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_data_frame, __pyx_mstate_global->__pyx_n_u_loc); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_INCREF(__pyx_mstate_global->__pyx_slice[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[0]); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_mstate_global->__pyx_slice[0]) != (0)) __PYX_ERR(0, 1109, __pyx_L1_error); __Pyx_INCREF(__pyx_v_column); __Pyx_GIVEREF(__pyx_v_column); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_column) != (0)) __PYX_ERR(0, 1109, __pyx_L1_error); if (unlikely((PyObject_SetItem(__pyx_t_11, __pyx_t_7, __pyx_t_2) < 0))) __PYX_ERR(0, 1109, __pyx_L1_error) __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1108 * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] * if dtypes[index] != '__pyx_n_u_polars, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1111, __pyx_L1_error) if (__pyx_t_1) { } else { __pyx_t_3 = __pyx_t_1; goto __pyx_L29_bool_binop_done; } __pyx_t_1 = (!__pyx_v_dc->no_datetime_conversion); __pyx_t_3 = __pyx_t_1; __pyx_L29_bool_binop_done:; if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1113 * if output_format == "polars" and not dc.no_datetime_conversion: * # datetime and date vectorized conversion * pl = natnamespace # <<<<<<<<<<<<<< * datetime_cols = list() * date_cols = list() */ __Pyx_INCREF(__pyx_v_natnamespace); __pyx_v_pl = __pyx_v_natnamespace; /* "pyreadstat/_readstat_parser.pyx":1114 * # datetime and date vectorized conversion * pl = natnamespace * datetime_cols = list() # <<<<<<<<<<<<<< * date_cols = list() * for index, column in enumerate(data_frame.columns): */ __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1114, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_datetime_cols = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/_readstat_parser.pyx":1115 * pl = natnamespace * datetime_cols = list() * date_cols = list() # <<<<<<<<<<<<<< * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] */ __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_date_cols = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/_readstat_parser.pyx":1116 * datetime_cols = list() * date_cols = list() * for index, column in enumerate(data_frame.columns): # <<<<<<<<<<<<<< * var_format = dc.col_formats[index] * if var_format == DATE_FORMAT_DATETIME: */ __pyx_t_16 = 0; __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_data_frame, __pyx_mstate_global->__pyx_n_u_columns); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { __pyx_t_2 = __pyx_t_8; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; __pyx_t_10 = NULL; } else { __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1116, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; for (;;) { if (likely(!__pyx_t_10)) { 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, 1116, __pyx_L1_error) #endif if (__pyx_t_4 >= __pyx_temp) break; } __pyx_t_8 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_4); ++__pyx_t_4; } 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, 1116, __pyx_L1_error) #endif if (__pyx_t_4 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_8 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4)); #else __pyx_t_8 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_4); #endif ++__pyx_t_4; } if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1116, __pyx_L1_error) } else { __pyx_t_8 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_8)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 1116, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_8); if (!(likely(PyUnicode_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_8))) __PYX_ERR(0, 1116, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_column, ((PyObject*)__pyx_t_8)); __pyx_t_8 = 0; __pyx_v_index = __pyx_t_16; __pyx_t_16 = (__pyx_t_16 + 1); /* "pyreadstat/_readstat_parser.pyx":1117 * date_cols = list() * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] # <<<<<<<<<<<<<< * if var_format == DATE_FORMAT_DATETIME: * datetime_cols.append(column) */ if (unlikely(__pyx_v_dc->col_formats == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1117, __pyx_L1_error) } __pyx_t_8 = __Pyx_GetItemInt_List(__pyx_v_dc->col_formats, __pyx_v_index, int, 1, __Pyx_PyLong_From_int, 1, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1117, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_17 = ((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)__Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(__pyx_t_8)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1117, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_var_format = __pyx_t_17; /* "pyreadstat/_readstat_parser.pyx":1118 * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] * if var_format == DATE_FORMAT_DATETIME: # <<<<<<<<<<<<<< * datetime_cols.append(column) * if var_format == DATE_FORMAT_DATE: */ __pyx_t_3 = (__pyx_v_var_format == __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATETIME); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1119 * var_format = dc.col_formats[index] * if var_format == DATE_FORMAT_DATETIME: * datetime_cols.append(column) # <<<<<<<<<<<<<< * if var_format == DATE_FORMAT_DATE: * date_cols.append(column) */ __pyx_t_18 = __Pyx_PyList_Append(__pyx_v_datetime_cols, __pyx_v_column); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1119, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1118 * for index, column in enumerate(data_frame.columns): * var_format = dc.col_formats[index] * if var_format == DATE_FORMAT_DATETIME: # <<<<<<<<<<<<<< * datetime_cols.append(column) * if var_format == DATE_FORMAT_DATE: */ } /* "pyreadstat/_readstat_parser.pyx":1120 * if var_format == DATE_FORMAT_DATETIME: * datetime_cols.append(column) * if var_format == DATE_FORMAT_DATE: # <<<<<<<<<<<<<< * date_cols.append(column) * if datetime_cols: */ __pyx_t_3 = (__pyx_v_var_format == __pyx_e_10pyreadstat_16_readstat_parser_DATE_FORMAT_DATE); if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1121 * datetime_cols.append(column) * if var_format == DATE_FORMAT_DATE: * date_cols.append(column) # <<<<<<<<<<<<<< * if datetime_cols: * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) */ __pyx_t_18 = __Pyx_PyList_Append(__pyx_v_date_cols, __pyx_v_column); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1121, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1120 * if var_format == DATE_FORMAT_DATETIME: * datetime_cols.append(column) * if var_format == DATE_FORMAT_DATE: # <<<<<<<<<<<<<< * date_cols.append(column) * if datetime_cols: */ } /* "pyreadstat/_readstat_parser.pyx":1116 * datetime_cols = list() * date_cols = list() * for index, column in enumerate(data_frame.columns): # <<<<<<<<<<<<<< * var_format = dc.col_formats[index] * if var_format == DATE_FORMAT_DATETIME: */ } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1122 * if var_format == DATE_FORMAT_DATE: * date_cols.append(column) * if datetime_cols: # <<<<<<<<<<<<<< * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) * if date_cols: */ __pyx_t_3 = (__Pyx_PyList_GET_SIZE(__pyx_v_datetime_cols) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_3 < 0))) __PYX_ERR(0, 1122, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1123 * date_cols.append(column) * if datetime_cols: * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) # <<<<<<<<<<<<<< * if date_cols: * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*date_cols), time_unit='d')) */ __pyx_t_8 = __pyx_v_data_frame; __Pyx_INCREF(__pyx_t_8); __pyx_t_11 = __pyx_v_pl; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_pl, __pyx_mstate_global->__pyx_n_u_col); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_14 = PySequence_Tuple(__pyx_v_datetime_cols); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_14, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_15 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_11, __pyx_t_13}; __pyx_t_14 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_time_unit, __pyx_mstate_global->__pyx_n_u_s, __pyx_t_14, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 1123, __pyx_L1_error) __pyx_t_7 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_from_epoch, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_14); __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } __pyx_t_15 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_7}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (1*__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, 1123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1122 * if var_format == DATE_FORMAT_DATE: * date_cols.append(column) * if datetime_cols: # <<<<<<<<<<<<<< * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) * if date_cols: */ } /* "pyreadstat/_readstat_parser.pyx":1124 * if datetime_cols: * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) * if date_cols: # <<<<<<<<<<<<<< * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*date_cols), time_unit='d')) * */ __pyx_t_3 = (__Pyx_PyList_GET_SIZE(__pyx_v_date_cols) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_3 < 0))) __PYX_ERR(0, 1124, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/_readstat_parser.pyx":1125 * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) * if date_cols: * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*date_cols), time_unit='d')) # <<<<<<<<<<<<<< * * else: */ __pyx_t_7 = __pyx_v_data_frame; __Pyx_INCREF(__pyx_t_7); __pyx_t_14 = __pyx_v_pl; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_pl, __pyx_mstate_global->__pyx_n_u_col); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_11 = PySequence_Tuple(__pyx_v_date_cols); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_11, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_15 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_14, __pyx_t_12}; __pyx_t_11 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_time_unit, __pyx_mstate_global->__pyx_n_u_d, __pyx_t_11, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 1125, __pyx_L1_error) __pyx_t_8 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_from_epoch, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_11); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } __pyx_t_15 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_8}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_with_columns, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (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_2)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1124 * if datetime_cols: * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*datetime_cols), time_unit='s')) * if date_cols: # <<<<<<<<<<<<<< * data_frame = data_frame.with_columns(pl.from_epoch(pl.col(*date_cols), time_unit='d')) * */ } /* "pyreadstat/_readstat_parser.pyx":1111 * data_frame.loc[:, column] = pd.to_datetime(data_frame[column]) * * if output_format == "polars" and not dc.no_datetime_conversion: # <<<<<<<<<<<<<< * # datetime and date vectorized conversion * pl = natnamespace */ } /* "pyreadstat/_readstat_parser.pyx":1073 * output_format = dc.output_format * * if dict_data: # <<<<<<<<<<<<<< * #schema = None * # in polars if missing user values we need to explicitly set the type */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":1128 * * else: * data_frame = nw.from_dict(dict_data, backend=output_format).to_native() # <<<<<<<<<<<<<< * * return data_frame */ /*else*/ { __pyx_t_11 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_from_dict); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_15 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_14))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_14); assert(__pyx_t_11); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_14); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_14, __pyx__function); __pyx_t_15 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_11, __pyx_v_dict_data}; __pyx_t_12 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_backend, __pyx_v_output_format, __pyx_t_12, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 1128, __pyx_L1_error) __pyx_t_7 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_14, __pyx_callargs+__pyx_t_15, (2-__pyx_t_15) | (__pyx_t_15*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_12); __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); __pyx_t_15 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_to_native, __pyx_callargs+__pyx_t_15, (1-__pyx_t_15) | (1*__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, 1128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_data_frame = __pyx_t_2; __pyx_t_2 = 0; } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":1130 * data_frame = nw.from_dict(dict_data, backend=output_format).to_native() * * return data_frame # <<<<<<<<<<<<<< * * cdef object data_container_extract_metadata(data_container data): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_data_frame); __pyx_r = __pyx_v_data_frame; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":1058 * return final_container * * cdef object dict_to_dataframe(object dict_data, data_container dc): # <<<<<<<<<<<<<< * """ * Transforms a dict of numpy arrays to a pandas data frame */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __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_AddTraceback("pyreadstat._readstat_parser.dict_to_dataframe", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_column); __Pyx_XDECREF(__pyx_v_output_format); __Pyx_XDECREF(__pyx_v_col_name); __Pyx_XDECREF(__pyx_v_dtypes); __Pyx_XDECREF(__pyx_v_sertypes); __Pyx_XDECREF(__pyx_v_datetime_cols); __Pyx_XDECREF(__pyx_v_date_cols); __Pyx_XDECREF(__pyx_v_schema); __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_natnamespace); __Pyx_XDECREF(__pyx_v_pd); __Pyx_XDECREF(__pyx_v_pl); __Pyx_XDECREF(__pyx_v_x); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":1132 * return data_frame * * cdef object data_container_extract_metadata(data_container data): # <<<<<<<<<<<<<< * """ * Extracts metadata from a data container and puts it into a metadata */ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_data_container_extract_metadata(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_data) { int __pyx_v_metaonly; int __pyx_v_is_unkown_number_rows; PyObject *__pyx_v_label_to_var_name = 0; PyObject *__pyx_v_labels_raw = 0; PyObject *__pyx_v_var_name = 0; PyObject *__pyx_v_var_label = 0; PyObject *__pyx_v_current_labels = 0; PyObject *__pyx_v_original_types = 0; readstat_type_t __pyx_v_var_type; PyObject *__pyx_v_metadata = 0; PyObject *__pyx_v_variable_value_labels = NULL; PyObject *__pyx_v_readstat_types = NULL; PyObject *__pyx_v_indx = NULL; PyObject *__pyx_v_cur_col = NULL; PyObject *__pyx_v_cur_type = NULL; PyObject *__pyx_v_curset = NULL; PyObject *__pyx_7genexpr__pyx_v_k = NULL; PyObject *__pyx_7genexpr__pyx_v_v = NULL; PyObject *__pyx_r = NULL; __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; Py_ssize_t __pyx_t_6; PyObject *(*__pyx_t_7)(PyObject *); PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; PyObject *(*__pyx_t_10)(PyObject *); readstat_type_t __pyx_t_11; PyObject *__pyx_t_12 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("data_container_extract_metadata", 0); /* "pyreadstat/_readstat_parser.pyx":1149 * cdef readstat_type_t var_type * * metaonly = data.metaonly # <<<<<<<<<<<<<< * is_unkown_number_rows = data.is_unkown_number_rows * */ __pyx_t_1 = __pyx_v_data->metaonly; __pyx_v_metaonly = __pyx_t_1; /* "pyreadstat/_readstat_parser.pyx":1150 * * metaonly = data.metaonly * is_unkown_number_rows = data.is_unkown_number_rows # <<<<<<<<<<<<<< * * cdef object metadata = metadata_container() */ __pyx_t_1 = __pyx_v_data->is_unkown_number_rows; __pyx_v_is_unkown_number_rows = __pyx_t_1; /* "pyreadstat/_readstat_parser.pyx":1152 * is_unkown_number_rows = data.is_unkown_number_rows * * cdef object metadata = metadata_container() # <<<<<<<<<<<<<< * * # mr sets */ __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_metadata_container); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1152, __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, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__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, 1152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_metadata = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1155 * * # mr sets * metadata.mr_sets = data.mr_sets # <<<<<<<<<<<<<< * * # number of rows */ __pyx_t_2 = __pyx_v_data->mr_sets; __Pyx_INCREF(__pyx_t_2); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_mr_sets, __pyx_t_2) < 0) __PYX_ERR(0, 1155, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1158 * * # number of rows * metadata.number_columns = data.n_vars # <<<<<<<<<<<<<< * if is_unkown_number_rows: * if not metaonly: */ __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_data->n_vars); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_number_columns, __pyx_t_2) < 0) __PYX_ERR(0, 1158, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1159 * # number of rows * metadata.number_columns = data.n_vars * if is_unkown_number_rows: # <<<<<<<<<<<<<< * if not metaonly: * metadata.number_rows = data.max_n_obs */ if (__pyx_v_is_unkown_number_rows) { /* "pyreadstat/_readstat_parser.pyx":1160 * metadata.number_columns = data.n_vars * if is_unkown_number_rows: * if not metaonly: # <<<<<<<<<<<<<< * metadata.number_rows = data.max_n_obs * else: */ __pyx_t_1 = (!__pyx_v_metaonly); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1161 * if is_unkown_number_rows: * if not metaonly: * metadata.number_rows = data.max_n_obs # <<<<<<<<<<<<<< * else: * metadata.number_rows = data.n_obs */ __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_data->max_n_obs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_number_rows, __pyx_t_2) < 0) __PYX_ERR(0, 1161, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1160 * metadata.number_columns = data.n_vars * if is_unkown_number_rows: * if not metaonly: # <<<<<<<<<<<<<< * metadata.number_rows = data.max_n_obs * else: */ } /* "pyreadstat/_readstat_parser.pyx":1159 * # number of rows * metadata.number_columns = data.n_vars * if is_unkown_number_rows: # <<<<<<<<<<<<<< * if not metaonly: * metadata.number_rows = data.max_n_obs */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":1163 * metadata.number_rows = data.max_n_obs * else: * metadata.number_rows = data.n_obs # <<<<<<<<<<<<<< * * # value labels */ /*else*/ { __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_data->n_obs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_number_rows, __pyx_t_2) < 0) __PYX_ERR(0, 1163, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":1166 * * # value labels * labels_raw = data.labels_raw # <<<<<<<<<<<<<< * label_to_var_name = data.label_to_var_name * variable_value_labels = dict() */ __pyx_t_2 = __pyx_v_data->labels_raw; __Pyx_INCREF(__pyx_t_2); __pyx_v_labels_raw = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1167 * # value labels * labels_raw = data.labels_raw * label_to_var_name = data.label_to_var_name # <<<<<<<<<<<<<< * variable_value_labels = dict() * */ __pyx_t_2 = __pyx_v_data->label_to_var_name; __Pyx_INCREF(__pyx_t_2); __pyx_v_label_to_var_name = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1168 * labels_raw = data.labels_raw * label_to_var_name = data.label_to_var_name * variable_value_labels = dict() # <<<<<<<<<<<<<< * * if labels_raw: */ __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_variable_value_labels = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1170 * variable_value_labels = dict() * * if labels_raw: # <<<<<<<<<<<<<< * for var_name, var_label in label_to_var_name.items(): * current_labels = labels_raw.get(var_label) */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_labels_raw); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1170, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1171 * * if labels_raw: * for var_name, var_label in label_to_var_name.items(): # <<<<<<<<<<<<<< * current_labels = labels_raw.get(var_label) * if current_labels: */ __pyx_t_4 = __pyx_v_label_to_var_name; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_items, __pyx_callargs+__pyx_t_5, (1-__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, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_4 = __pyx_t_2; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1171, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_7)) { 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, 1171, __pyx_L1_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_4, __pyx_t_6); ++__pyx_t_6; } 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, 1171, __pyx_L1_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6)); #else __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_6); #endif ++__pyx_t_6; } if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1171, __pyx_L1_error) } else { __pyx_t_2 = __pyx_t_7(__pyx_t_4); 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, 1171, __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, 1171, __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_8 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_8); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_8 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_8); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1171, __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, 1171, __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_3 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_8); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 1171, __pyx_L1_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L9_unpacking_done; __pyx_L8_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, 1171, __pyx_L1_error) __pyx_L9_unpacking_done:; } if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_3))) __PYX_ERR(0, 1171, __pyx_L1_error) if (!(likely(PyUnicode_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_8))) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_var_name, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_XDECREF_SET(__pyx_v_var_label, ((PyObject*)__pyx_t_8)); __pyx_t_8 = 0; /* "pyreadstat/_readstat_parser.pyx":1172 * if labels_raw: * for var_name, var_label in label_to_var_name.items(): * current_labels = labels_raw.get(var_label) # <<<<<<<<<<<<<< * if current_labels: * variable_value_labels[var_name] = current_labels */ __pyx_t_8 = __pyx_v_labels_raw; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_var_label}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_get, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_XDECREF_SET(__pyx_v_current_labels, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":1173 * for var_name, var_label in label_to_var_name.items(): * current_labels = labels_raw.get(var_label) * if current_labels: # <<<<<<<<<<<<<< * variable_value_labels[var_name] = current_labels * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_current_labels); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1173, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1174 * current_labels = labels_raw.get(var_label) * if current_labels: * variable_value_labels[var_name] = current_labels # <<<<<<<<<<<<<< * * original_types = dict() */ if (unlikely((PyDict_SetItem(__pyx_v_variable_value_labels, __pyx_v_var_name, __pyx_v_current_labels) < 0))) __PYX_ERR(0, 1174, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1173 * for var_name, var_label in label_to_var_name.items(): * current_labels = labels_raw.get(var_label) * if current_labels: # <<<<<<<<<<<<<< * variable_value_labels[var_name] = current_labels * */ } /* "pyreadstat/_readstat_parser.pyx":1171 * * if labels_raw: * for var_name, var_label in label_to_var_name.items(): # <<<<<<<<<<<<<< * current_labels = labels_raw.get(var_label) * if current_labels: */ } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1170 * variable_value_labels = dict() * * if labels_raw: # <<<<<<<<<<<<<< * for var_name, var_label in label_to_var_name.items(): * current_labels = labels_raw.get(var_label) */ } /* "pyreadstat/_readstat_parser.pyx":1176 * variable_value_labels[var_name] = current_labels * * original_types = dict() # <<<<<<<<<<<<<< * readstat_types = dict() * for indx in range(metadata.number_columns): */ __pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_original_types = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1177 * * original_types = dict() * readstat_types = dict() # <<<<<<<<<<<<<< * for indx in range(metadata.number_columns): * cur_col = data.col_names[indx] */ __pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_readstat_types = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1178 * original_types = dict() * readstat_types = dict() * for indx in range(metadata.number_columns): # <<<<<<<<<<<<<< * cur_col = data.col_names[indx] * cur_type = data.col_formats_original[indx] */ __pyx_t_2 = NULL; __Pyx_INCREF(__pyx_builtin_range); __pyx_t_8 = __pyx_builtin_range; __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_number_columns); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_3}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_8, __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_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { __pyx_t_8 = __pyx_t_4; __Pyx_INCREF(__pyx_t_8); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1178, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; for (;;) { if (likely(!__pyx_t_7)) { if (likely(PyList_CheckExact(__pyx_t_8))) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1178, __pyx_L1_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } __pyx_t_4 = __Pyx_PyList_GetItemRef(__pyx_t_8, __pyx_t_6); ++__pyx_t_6; } else { { Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1178, __pyx_L1_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6)); #else __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_8, __pyx_t_6); #endif ++__pyx_t_6; } if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1178, __pyx_L1_error) } else { __pyx_t_4 = __pyx_t_7(__pyx_t_8); 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, 1178, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_indx, __pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1179 * readstat_types = dict() * for indx in range(metadata.number_columns): * cur_col = data.col_names[indx] # <<<<<<<<<<<<<< * cur_type = data.col_formats_original[indx] * original_types[cur_col] = cur_type */ if (unlikely(__pyx_v_data->col_names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1179, __pyx_L1_error) } __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_data->col_names, __pyx_v_indx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1179, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_cur_col, __pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1180 * for indx in range(metadata.number_columns): * cur_col = data.col_names[indx] * cur_type = data.col_formats_original[indx] # <<<<<<<<<<<<<< * original_types[cur_col] = cur_type * var_type = data.col_dtypes[indx] */ if (unlikely(__pyx_v_data->col_formats_original == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1180, __pyx_L1_error) } __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_data->col_formats_original, __pyx_v_indx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_cur_type, __pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1181 * cur_col = data.col_names[indx] * cur_type = data.col_formats_original[indx] * original_types[cur_col] = cur_type # <<<<<<<<<<<<<< * var_type = data.col_dtypes[indx] * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: */ if (unlikely((PyObject_SetItem(__pyx_v_original_types, __pyx_v_cur_col, __pyx_v_cur_type) < 0))) __PYX_ERR(0, 1181, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1182 * cur_type = data.col_formats_original[indx] * original_types[cur_col] = cur_type * var_type = data.col_dtypes[indx] # <<<<<<<<<<<<<< * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: * readstat_types[cur_col] = "string" */ if (unlikely(__pyx_v_data->col_dtypes == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1182, __pyx_L1_error) } __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_data->col_dtypes, __pyx_v_indx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_11 = ((readstat_type_t)__Pyx_PyLong_As_readstat_type_t(__pyx_t_4)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_var_type = __pyx_t_11; /* "pyreadstat/_readstat_parser.pyx":1183 * original_types[cur_col] = cur_type * var_type = data.col_dtypes[indx] * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "string" * elif var_type == READSTAT_TYPE_INT8: */ switch (__pyx_v_var_type) { case READSTAT_TYPE_STRING: case READSTAT_TYPE_STRING_REF: /* "pyreadstat/_readstat_parser.pyx":1184 * var_type = data.col_dtypes[indx] * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: * readstat_types[cur_col] = "string" # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_INT8: * readstat_types[cur_col] = "int8" */ if (unlikely((PyDict_SetItem(__pyx_v_readstat_types, __pyx_v_cur_col, __pyx_mstate_global->__pyx_n_u_string) < 0))) __PYX_ERR(0, 1184, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1183 * original_types[cur_col] = cur_type * var_type = data.col_dtypes[indx] * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "string" * elif var_type == READSTAT_TYPE_INT8: */ break; case READSTAT_TYPE_INT8: /* "pyreadstat/_readstat_parser.pyx":1186 * readstat_types[cur_col] = "string" * elif var_type == READSTAT_TYPE_INT8: * readstat_types[cur_col] = "int8" # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_INT16: * readstat_types[cur_col] = "int16" */ if (unlikely((PyDict_SetItem(__pyx_v_readstat_types, __pyx_v_cur_col, __pyx_mstate_global->__pyx_n_u_int8) < 0))) __PYX_ERR(0, 1186, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1185 * if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: * readstat_types[cur_col] = "string" * elif var_type == READSTAT_TYPE_INT8: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "int8" * elif var_type == READSTAT_TYPE_INT16: */ break; case READSTAT_TYPE_INT16: /* "pyreadstat/_readstat_parser.pyx":1188 * readstat_types[cur_col] = "int8" * elif var_type == READSTAT_TYPE_INT16: * readstat_types[cur_col] = "int16" # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_INT32: * readstat_types[cur_col] = "int32" */ if (unlikely((PyDict_SetItem(__pyx_v_readstat_types, __pyx_v_cur_col, __pyx_mstate_global->__pyx_n_u_int16) < 0))) __PYX_ERR(0, 1188, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1187 * elif var_type == READSTAT_TYPE_INT8: * readstat_types[cur_col] = "int8" * elif var_type == READSTAT_TYPE_INT16: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "int16" * elif var_type == READSTAT_TYPE_INT32: */ break; case READSTAT_TYPE_INT32: /* "pyreadstat/_readstat_parser.pyx":1190 * readstat_types[cur_col] = "int16" * elif var_type == READSTAT_TYPE_INT32: * readstat_types[cur_col] = "int32" # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_FLOAT: * readstat_types[cur_col] = "float" */ if (unlikely((PyDict_SetItem(__pyx_v_readstat_types, __pyx_v_cur_col, __pyx_mstate_global->__pyx_n_u_int32) < 0))) __PYX_ERR(0, 1190, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1189 * elif var_type == READSTAT_TYPE_INT16: * readstat_types[cur_col] = "int16" * elif var_type == READSTAT_TYPE_INT32: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "int32" * elif var_type == READSTAT_TYPE_FLOAT: */ break; case READSTAT_TYPE_FLOAT: /* "pyreadstat/_readstat_parser.pyx":1192 * readstat_types[cur_col] = "int32" * elif var_type == READSTAT_TYPE_FLOAT: * readstat_types[cur_col] = "float" # <<<<<<<<<<<<<< * elif var_type == READSTAT_TYPE_DOUBLE: * readstat_types[cur_col] = "double" */ if (unlikely((PyDict_SetItem(__pyx_v_readstat_types, __pyx_v_cur_col, __pyx_mstate_global->__pyx_n_u_float) < 0))) __PYX_ERR(0, 1192, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1191 * elif var_type == READSTAT_TYPE_INT32: * readstat_types[cur_col] = "int32" * elif var_type == READSTAT_TYPE_FLOAT: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "float" * elif var_type == READSTAT_TYPE_DOUBLE: */ break; case READSTAT_TYPE_DOUBLE: /* "pyreadstat/_readstat_parser.pyx":1194 * readstat_types[cur_col] = "float" * elif var_type == READSTAT_TYPE_DOUBLE: * readstat_types[cur_col] = "double" # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unkown data type") */ if (unlikely((PyDict_SetItem(__pyx_v_readstat_types, __pyx_v_cur_col, __pyx_mstate_global->__pyx_n_u_double) < 0))) __PYX_ERR(0, 1194, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1193 * elif var_type == READSTAT_TYPE_FLOAT: * readstat_types[cur_col] = "float" * elif var_type == READSTAT_TYPE_DOUBLE: # <<<<<<<<<<<<<< * readstat_types[cur_col] = "double" * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":1196 * readstat_types[cur_col] = "double" * else: * raise PyreadstatError("Unkown data type") # <<<<<<<<<<<<<< * * for indx, curset in data.missing_user_values.items(): */ __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = 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_5 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_Unkown_data_type}; __pyx_t_4 = __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_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1196, __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, 1196, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":1178 * original_types = dict() * readstat_types = dict() * for indx in range(metadata.number_columns): # <<<<<<<<<<<<<< * cur_col = data.col_names[indx] * cur_type = data.col_formats_original[indx] */ } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/_readstat_parser.pyx":1198 * raise PyreadstatError("Unkown data type") * * for indx, curset in data.missing_user_values.items(): # <<<<<<<<<<<<<< * cur_col = data.col_names[indx] * metadata.missing_user_values[cur_col] = sorted(list(curset)) */ if (unlikely(__pyx_v_data->missing_user_values == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); __PYX_ERR(0, 1198, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyDict_Items(__pyx_v_data->missing_user_values); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { __pyx_t_4 = __pyx_t_8; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1198, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; for (;;) { if (likely(!__pyx_t_7)) { 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, 1198, __pyx_L1_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } __pyx_t_8 = __Pyx_PyList_GetItemRef(__pyx_t_4, __pyx_t_6); ++__pyx_t_6; } 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, 1198, __pyx_L1_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_8 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6)); #else __pyx_t_8 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_6); #endif ++__pyx_t_6; } if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1198, __pyx_L1_error) } else { __pyx_t_8 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_8)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 1198, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_8); if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { PyObject* sequence = __pyx_t_8; 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, 1198, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { Py_ssize_t index = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_9); index = 0; __pyx_t_2 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L17_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_3 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L17_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 1198, __pyx_L1_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L18_unpacking_done; __pyx_L17_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, 1198, __pyx_L1_error) __pyx_L18_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_indx, __pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF_SET(__pyx_v_curset, __pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1199 * * for indx, curset in data.missing_user_values.items(): * cur_col = data.col_names[indx] # <<<<<<<<<<<<<< * metadata.missing_user_values[cur_col] = sorted(list(curset)) * */ if (unlikely(__pyx_v_data->col_names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 1199, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_data->col_names, __pyx_v_indx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1199, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF_SET(__pyx_v_cur_col, __pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/_readstat_parser.pyx":1200 * for indx, curset in data.missing_user_values.items(): * cur_col = data.col_names[indx] * metadata.missing_user_values[cur_col] = sorted(list(curset)) # <<<<<<<<<<<<<< * * metadata.notes = data.notes */ __pyx_t_8 = PySequence_List(__pyx_v_curset); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_3 = PySequence_List(__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely((PyList_Sort(__pyx_t_3) < 0))) __PYX_ERR(0, 1200, __pyx_L1_error) __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_missing_user_values); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (unlikely((PyObject_SetItem(__pyx_t_8, __pyx_v_cur_col, __pyx_t_3) < 0))) __PYX_ERR(0, 1200, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1198 * raise PyreadstatError("Unkown data type") * * for indx, curset in data.missing_user_values.items(): # <<<<<<<<<<<<<< * cur_col = data.col_names[indx] * metadata.missing_user_values[cur_col] = sorted(list(curset)) */ } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1202 * metadata.missing_user_values[cur_col] = sorted(list(curset)) * * metadata.notes = data.notes # <<<<<<<<<<<<<< * metadata.column_names = data.col_names * metadata.column_labels = data.col_labels */ __pyx_t_4 = __pyx_v_data->notes; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_notes, __pyx_t_4) < 0) __PYX_ERR(0, 1202, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1203 * * metadata.notes = data.notes * metadata.column_names = data.col_names # <<<<<<<<<<<<<< * metadata.column_labels = data.col_labels * metadata.column_names_to_labels = {k:v for k,v in zip(data.col_names, data.col_labels)} */ __pyx_t_4 = __pyx_v_data->col_names; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_column_names, __pyx_t_4) < 0) __PYX_ERR(0, 1203, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1204 * metadata.notes = data.notes * metadata.column_names = data.col_names * metadata.column_labels = data.col_labels # <<<<<<<<<<<<<< * metadata.column_names_to_labels = {k:v for k,v in zip(data.col_names, data.col_labels)} * metadata.file_encoding = data.file_encoding */ __pyx_t_4 = __pyx_v_data->col_labels; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_column_labels, __pyx_t_4) < 0) __PYX_ERR(0, 1204, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1205 * metadata.column_names = data.col_names * metadata.column_labels = data.col_labels * metadata.column_names_to_labels = {k:v for k,v in zip(data.col_names, data.col_labels)} # <<<<<<<<<<<<<< * metadata.file_encoding = data.file_encoding * metadata.file_label = data.file_label */ { /* enter inner scope */ __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_8 = NULL; __Pyx_INCREF(__pyx_builtin_zip); __pyx_t_2 = __pyx_builtin_zip; __pyx_t_5 = 1; { PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_v_data->col_names, __pyx_v_data->col_labels}; __pyx_t_3 = __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_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_GOTREF(__pyx_t_3); } if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1205, __pyx_L22_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; for (;;) { if (likely(!__pyx_t_7)) { 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, 1205, __pyx_L22_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } __pyx_t_3 = __Pyx_PyList_GetItemRef(__pyx_t_2, __pyx_t_6); ++__pyx_t_6; } 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, 1205, __pyx_L22_error) #endif if (__pyx_t_6 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_3 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6)); #else __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_6); #endif ++__pyx_t_6; } if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1205, __pyx_L22_error) } else { __pyx_t_3 = __pyx_t_7(__pyx_t_2); 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, 1205, __pyx_L22_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, 1205, __pyx_L22_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_8); __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_9); } else { __pyx_t_8 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_XGOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_XGOTREF(__pyx_t_9); } #else __pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_GOTREF(__pyx_t_9); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_12 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1205, __pyx_L22_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_12); index = 0; __pyx_t_8 = __pyx_t_10(__pyx_t_12); if (unlikely(!__pyx_t_8)) goto __pyx_L25_unpacking_failed; __Pyx_GOTREF(__pyx_t_8); index = 1; __pyx_t_9 = __pyx_t_10(__pyx_t_12); if (unlikely(!__pyx_t_9)) goto __pyx_L25_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_12), 2) < 0) __PYX_ERR(0, 1205, __pyx_L22_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; goto __pyx_L26_unpacking_done; __pyx_L25_unpacking_failed:; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_10 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 1205, __pyx_L22_error) __pyx_L26_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_k, __pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_v, __pyx_t_9); __pyx_t_9 = 0; if (unlikely(PyDict_SetItem(__pyx_t_4, (PyObject*)__pyx_7genexpr__pyx_v_k, (PyObject*)__pyx_7genexpr__pyx_v_v))) __PYX_ERR(0, 1205, __pyx_L22_error) } __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_L28_exit_scope; __pyx_L22_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_L28_exit_scope:; } /* exit inner scope */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_column_names_to_labels, __pyx_t_4) < 0) __PYX_ERR(0, 1205, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1206 * metadata.column_labels = data.col_labels * metadata.column_names_to_labels = {k:v for k,v in zip(data.col_names, data.col_labels)} * metadata.file_encoding = data.file_encoding # <<<<<<<<<<<<<< * metadata.file_label = data.file_label * metadata.variable_value_labels = variable_value_labels */ __pyx_t_4 = __pyx_v_data->file_encoding; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_encoding, __pyx_t_4) < 0) __PYX_ERR(0, 1206, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1207 * metadata.column_names_to_labels = {k:v for k,v in zip(data.col_names, data.col_labels)} * metadata.file_encoding = data.file_encoding * metadata.file_label = data.file_label # <<<<<<<<<<<<<< * metadata.variable_value_labels = variable_value_labels * metadata.value_labels = labels_raw */ __pyx_t_4 = __pyx_v_data->file_label; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_label, __pyx_t_4) < 0) __PYX_ERR(0, 1207, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1208 * metadata.file_encoding = data.file_encoding * metadata.file_label = data.file_label * metadata.variable_value_labels = variable_value_labels # <<<<<<<<<<<<<< * metadata.value_labels = labels_raw * metadata.variable_to_label = label_to_var_name */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_variable_value_labels, __pyx_v_variable_value_labels) < 0) __PYX_ERR(0, 1208, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1209 * metadata.file_label = data.file_label * metadata.variable_value_labels = variable_value_labels * metadata.value_labels = labels_raw # <<<<<<<<<<<<<< * metadata.variable_to_label = label_to_var_name * metadata.original_variable_types = original_types */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_value_labels, __pyx_v_labels_raw) < 0) __PYX_ERR(0, 1209, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1210 * metadata.variable_value_labels = variable_value_labels * metadata.value_labels = labels_raw * metadata.variable_to_label = label_to_var_name # <<<<<<<<<<<<<< * metadata.original_variable_types = original_types * metadata.readstat_variable_types = readstat_types */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_variable_to_label, __pyx_v_label_to_var_name) < 0) __PYX_ERR(0, 1210, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1211 * metadata.value_labels = labels_raw * metadata.variable_to_label = label_to_var_name * metadata.original_variable_types = original_types # <<<<<<<<<<<<<< * metadata.readstat_variable_types = readstat_types * metadata.table_name = data.table_name */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_original_variable_types, __pyx_v_original_types) < 0) __PYX_ERR(0, 1211, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1212 * metadata.variable_to_label = label_to_var_name * metadata.original_variable_types = original_types * metadata.readstat_variable_types = readstat_types # <<<<<<<<<<<<<< * metadata.table_name = data.table_name * metadata.missing_ranges = data.missing_ranges */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_readstat_variable_types, __pyx_v_readstat_types) < 0) __PYX_ERR(0, 1212, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1213 * metadata.original_variable_types = original_types * metadata.readstat_variable_types = readstat_types * metadata.table_name = data.table_name # <<<<<<<<<<<<<< * metadata.missing_ranges = data.missing_ranges * metadata.variable_storage_width = data.variable_storage_width */ __pyx_t_4 = __pyx_v_data->table_name; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_table_name, __pyx_t_4) < 0) __PYX_ERR(0, 1213, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1214 * metadata.readstat_variable_types = readstat_types * metadata.table_name = data.table_name * metadata.missing_ranges = data.missing_ranges # <<<<<<<<<<<<<< * metadata.variable_storage_width = data.variable_storage_width * metadata.variable_display_width = data.variable_display_width */ __pyx_t_4 = __pyx_v_data->missing_ranges; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_missing_ranges, __pyx_t_4) < 0) __PYX_ERR(0, 1214, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1215 * metadata.table_name = data.table_name * metadata.missing_ranges = data.missing_ranges * metadata.variable_storage_width = data.variable_storage_width # <<<<<<<<<<<<<< * metadata.variable_display_width = data.variable_display_width * metadata.variable_alignment = data.variable_alignment */ __pyx_t_4 = __pyx_v_data->variable_storage_width; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_variable_storage_width, __pyx_t_4) < 0) __PYX_ERR(0, 1215, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1216 * metadata.missing_ranges = data.missing_ranges * metadata.variable_storage_width = data.variable_storage_width * metadata.variable_display_width = data.variable_display_width # <<<<<<<<<<<<<< * metadata.variable_alignment = data.variable_alignment * metadata.variable_measure = data.variable_measure */ __pyx_t_4 = __pyx_v_data->variable_display_width; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_variable_display_width, __pyx_t_4) < 0) __PYX_ERR(0, 1216, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1217 * metadata.variable_storage_width = data.variable_storage_width * metadata.variable_display_width = data.variable_display_width * metadata.variable_alignment = data.variable_alignment # <<<<<<<<<<<<<< * metadata.variable_measure = data.variable_measure * metadata.creation_time = datetime.datetime.fromtimestamp(data.ctime) */ __pyx_t_4 = __pyx_v_data->variable_alignment; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_variable_alignment, __pyx_t_4) < 0) __PYX_ERR(0, 1217, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1218 * metadata.variable_display_width = data.variable_display_width * metadata.variable_alignment = data.variable_alignment * metadata.variable_measure = data.variable_measure # <<<<<<<<<<<<<< * metadata.creation_time = datetime.datetime.fromtimestamp(data.ctime) * metadata.modification_time = datetime.datetime.fromtimestamp(data.mtime) */ __pyx_t_4 = __pyx_v_data->variable_measure; __Pyx_INCREF(__pyx_t_4); if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_variable_measure, __pyx_t_4) < 0) __PYX_ERR(0, 1218, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1219 * metadata.variable_alignment = data.variable_alignment * metadata.variable_measure = data.variable_measure * metadata.creation_time = datetime.datetime.fromtimestamp(data.ctime) # <<<<<<<<<<<<<< * metadata.modification_time = datetime.datetime.fromtimestamp(data.mtime) * */ __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_9; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyLong_From_int(__pyx_v_data->ctime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_3}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_fromtimestamp, __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_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_creation_time, __pyx_t_4) < 0) __PYX_ERR(0, 1219, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1220 * metadata.variable_measure = data.variable_measure * metadata.creation_time = datetime.datetime.fromtimestamp(data.ctime) * metadata.modification_time = datetime.datetime.fromtimestamp(data.mtime) # <<<<<<<<<<<<<< * * return metadata */ __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = __pyx_t_2; __Pyx_INCREF(__pyx_t_9); __pyx_t_3 = __Pyx_PyLong_From_int(__pyx_v_data->mtime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_3}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_fromtimestamp, __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_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_modification_time, __pyx_t_4) < 0) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":1222 * metadata.modification_time = datetime.datetime.fromtimestamp(data.mtime) * * return metadata # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_metadata); __pyx_r = __pyx_v_metadata; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":1132 * return data_frame * * cdef object data_container_extract_metadata(data_container data): # <<<<<<<<<<<<<< * """ * Extracts metadata from a data container and puts it into a metadata */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("pyreadstat._readstat_parser.data_container_extract_metadata", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_label_to_var_name); __Pyx_XDECREF(__pyx_v_labels_raw); __Pyx_XDECREF(__pyx_v_var_name); __Pyx_XDECREF(__pyx_v_var_label); __Pyx_XDECREF(__pyx_v_current_labels); __Pyx_XDECREF(__pyx_v_original_types); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XDECREF(__pyx_v_variable_value_labels); __Pyx_XDECREF(__pyx_v_readstat_types); __Pyx_XDECREF(__pyx_v_indx); __Pyx_XDECREF(__pyx_v_cur_col); __Pyx_XDECREF(__pyx_v_cur_type); __Pyx_XDECREF(__pyx_v_curset); __Pyx_XDECREF(__pyx_7genexpr__pyx_v_k); __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/_readstat_parser.pyx":1225 * * * cdef object run_conversion(object filename_path, py_file_format file_format, py_file_extension file_extension, # <<<<<<<<<<<<<< * str encoding, bint metaonly, bint dates_as_pandas, list usecols, bint usernan, * bint no_datetime_conversion, long row_limit, long row_offset, str output_format, */ static PyObject *__pyx_f_10pyreadstat_16_readstat_parser_run_conversion(PyObject *__pyx_v_filename_path, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension, PyObject *__pyx_v_encoding, int __pyx_v_metaonly, int __pyx_v_dates_as_pandas, PyObject *__pyx_v_usecols, int __pyx_v_usernan, int __pyx_v_no_datetime_conversion, long __pyx_v_row_limit, long __pyx_v_row_offset, PyObject *__pyx_v_output_format, PyObject *__pyx_v_extra_datetime_formats, PyObject *__pyx_v_extra_date_formats, PyObject *__pyx_v_extra_time_formats) { PyObject *__pyx_v_filename_bytes = 0; char *__pyx_v_filename; struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *__pyx_v_data = 0; PyObject *__pyx_v_origin = 0; PyObject *__pyx_v_allowed_formats = 0; PyObject *__pyx_v_data_dict = 0; PyObject *__pyx_v_data_frame = 0; PyObject *__pyx_v_file_obj = 0; CYTHON_UNUSED PyObject *__pyx_v_pandas = NULL; CYTHON_UNUSED PyObject *__pyx_v_polars = NULL; CYTHON_UNUSED void *__pyx_v_ctx; PyObject *__pyx_v_unix_to_origin_secs = NULL; PyObject *__pyx_v_metadata = NULL; PyObject *__pyx_r = 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; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; size_t __pyx_t_10; int __pyx_t_11; 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; PyObject *__pyx_t_17 = NULL; int __pyx_t_18; char *__pyx_t_19; double __pyx_t_20; struct __pyx_opt_args_10pyreadstat_16_readstat_parser_run_readstat_parser __pyx_t_21; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("run_conversion", 0); __Pyx_INCREF(__pyx_v_output_format); /* "pyreadstat/_readstat_parser.pyx":1244 * cdef object data_dict * cdef object data_frame * cdef object file_obj = None # <<<<<<<<<<<<<< * * # Check if filename_path is a file-like object */ __Pyx_INCREF(Py_None); __pyx_v_file_obj = Py_None; /* "pyreadstat/_readstat_parser.pyx":1247 * * # Check if filename_path is a file-like object * if hasattr(filename_path, 'read') and hasattr(filename_path, 'seek'): # <<<<<<<<<<<<<< * file_obj = filename_path * filename_bytes = b"" # Empty path - will be ignored when file_obj is used */ __pyx_t_2 = __Pyx_HasAttr(__pyx_v_filename_path, __pyx_mstate_global->__pyx_n_u_read); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 1247, __pyx_L1_error) if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = __Pyx_HasAttr(__pyx_v_filename_path, __pyx_mstate_global->__pyx_n_u_seek); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 1247, __pyx_L1_error) __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1248 * # Check if filename_path is a file-like object * if hasattr(filename_path, 'read') and hasattr(filename_path, 'seek'): * file_obj = filename_path # <<<<<<<<<<<<<< * filename_bytes = b"" # Empty path - will be ignored when file_obj is used * elif hasattr(os, 'fsencode'): */ __Pyx_INCREF(__pyx_v_filename_path); __Pyx_DECREF_SET(__pyx_v_file_obj, __pyx_v_filename_path); /* "pyreadstat/_readstat_parser.pyx":1249 * if hasattr(filename_path, 'read') and hasattr(filename_path, 'seek'): * file_obj = filename_path * filename_bytes = b"" # Empty path - will be ignored when file_obj is used # <<<<<<<<<<<<<< * elif hasattr(os, 'fsencode'): * try: */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_b_); __pyx_v_filename_bytes = __pyx_mstate_global->__pyx_kp_b_; /* "pyreadstat/_readstat_parser.pyx":1247 * * # Check if filename_path is a file-like object * if hasattr(filename_path, 'read') and hasattr(filename_path, 'seek'): # <<<<<<<<<<<<<< * file_obj = filename_path * filename_bytes = b"" # Empty path - will be ignored when file_obj is used */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":1250 * file_obj = filename_path * filename_bytes = b"" # Empty path - will be ignored when file_obj is used * elif hasattr(os, 'fsencode'): # <<<<<<<<<<<<<< * try: * filename_bytes = os.fsencode(filename_path) */ __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1250, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __Pyx_HasAttr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_fsencode); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1250, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1251 * filename_bytes = b"" # Empty path - will be ignored when file_obj is used * elif hasattr(os, 'fsencode'): * try: # <<<<<<<<<<<<<< * filename_bytes = os.fsencode(filename_path) * except UnicodeError: */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6); __Pyx_XGOTREF(__pyx_t_4); __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); /*try:*/ { /* "pyreadstat/_readstat_parser.pyx":1252 * elif 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_7 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1252, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_fsencode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1252, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_9))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9); assert(__pyx_t_7); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_9, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_filename_path}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1252, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_3); } if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_3))) __PYX_ERR(0, 1252, __pyx_L6_error) __pyx_v_filename_bytes = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1251 * filename_bytes = b"" # Empty path - will be ignored when file_obj is used * elif hasattr(os, 'fsencode'): * try: # <<<<<<<<<<<<<< * filename_bytes = os.fsencode(filename_path) * except UnicodeError: */ } __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L11_try_end; __pyx_L6_error:; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; /* "pyreadstat/_readstat_parser.pyx":1253 * 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_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeError); if (__pyx_t_11) { __Pyx_AddTraceback("pyreadstat._readstat_parser.run_conversion", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_9, &__pyx_t_7) < 0) __PYX_ERR(0, 1253, __pyx_L8_except_error) __Pyx_XGOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_7); /* "pyreadstat/_readstat_parser.pyx":1254 * 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_12 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_warnings); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_mstate_global->__pyx_n_u_warn); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_15 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_mstate_global->__pyx_n_u_sys); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_16); __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_mstate_global->__pyx_n_u_getfilesystemencoding); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_17); __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_17))) { __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_17); assert(__pyx_t_15); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_17); __Pyx_INCREF(__pyx_t_15); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_17, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_15, NULL}; __pyx_t_13 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+__pyx_t_10, (1-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_13); } __pyx_t_17 = __Pyx_PyUnicode_FormatSafe(__pyx_mstate_global->__pyx_kp_u_file_path_could_not_be_encoded_w, __pyx_t_13); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_17); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_14))) { __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_14); assert(__pyx_t_12); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_14); __Pyx_INCREF(__pyx_t_12); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_14, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_t_17}; __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_14, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1254, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_8); } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/_readstat_parser.pyx":1255 * 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_14 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1255, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_17); __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_mstate_global->__pyx_n_u_fsdecode); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1255, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_12))) { __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12); assert(__pyx_t_14); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_12); __Pyx_INCREF(__pyx_t_14); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_12, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_v_filename_path}; __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1255, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_8); } __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_encode); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1255, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1255, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; if (!(likely(PyBytes_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_8))) __PYX_ERR(0, 1255, __pyx_L8_except_error) __Pyx_XDECREF_SET(__pyx_v_filename_bytes, ((PyObject*)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L7_exception_handled; } goto __pyx_L8_except_error; /* "pyreadstat/_readstat_parser.pyx":1251 * filename_bytes = b"" # Empty path - will be ignored when file_obj is used * elif hasattr(os, 'fsencode'): * try: # <<<<<<<<<<<<<< * filename_bytes = os.fsencode(filename_path) * except UnicodeError: */ __pyx_L8_except_error:; __Pyx_XGIVEREF(__pyx_t_4); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); goto __pyx_L1_error; __pyx_L7_exception_handled:; __Pyx_XGIVEREF(__pyx_t_4); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); __pyx_L11_try_end:; } /* "pyreadstat/_readstat_parser.pyx":1250 * file_obj = filename_path * filename_bytes = b"" # Empty path - will be ignored when file_obj is used * elif hasattr(os, 'fsencode'): # <<<<<<<<<<<<<< * try: * filename_bytes = os.fsencode(filename_path) */ goto __pyx_L3; } /* "pyreadstat/_readstat_parser.pyx":1257 * 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_7 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_filename_path)), ((PyObject *)(&PyUnicode_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1257, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1257, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1258 * else: * if type(filename_path) == str: * filename_bytes = filename_path.encode('utf-8') # <<<<<<<<<<<<<< * elif type(filename_path) == bytes: * filename_bytes = filename_path */ __pyx_t_9 = __pyx_v_filename_path; __Pyx_INCREF(__pyx_t_9); __pyx_t_10 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __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_10, (2-__pyx_t_10) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_7))) __PYX_ERR(0, 1258, __pyx_L1_error) __pyx_v_filename_bytes = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1257 * 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_L14; } /* "pyreadstat/_readstat_parser.pyx":1259 * if type(filename_path) == str: * filename_bytes = filename_path.encode('utf-8') * elif type(filename_path) == bytes: # <<<<<<<<<<<<<< * filename_bytes = filename_path * else: */ __pyx_t_7 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_filename_path)), ((PyObject *)(&PyBytes_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1259, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1259, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (likely(__pyx_t_1)) { /* "pyreadstat/_readstat_parser.pyx":1260 * 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_t_7 = __pyx_v_filename_path; __Pyx_INCREF(__pyx_t_7); if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_7))) __PYX_ERR(0, 1260, __pyx_L1_error) __pyx_v_filename_bytes = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1259 * if type(filename_path) == str: * filename_bytes = filename_path.encode('utf-8') * elif type(filename_path) == bytes: # <<<<<<<<<<<<<< * filename_bytes = filename_path * else: */ goto __pyx_L14; } /* "pyreadstat/_readstat_parser.pyx":1262 * filename_bytes = filename_path * else: * raise PyreadstatError("path must be either str or bytes") # <<<<<<<<<<<<<< * if type(filename_path) not in (str, bytes, unicode): * raise PyreadstatError("path must be str, bytes or unicode") */ /*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, 1262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_10 = 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_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_path_must_be_either_str_or_bytes}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__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_7)) __PYX_ERR(0, 1262, __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, 1262, __pyx_L1_error) } __pyx_L14:; /* "pyreadstat/_readstat_parser.pyx":1263 * else: * raise PyreadstatError("path must be either str or bytes") * if type(filename_path) not in (str, bytes, unicode): # <<<<<<<<<<<<<< * raise PyreadstatError("path must be str, bytes or unicode") * filename_bytes = filename_path.encode('utf-8') */ __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_filename_path))); __pyx_t_7 = ((PyObject *)Py_TYPE(__pyx_v_filename_path)); __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_t_7), ((PyObject *)(&PyUnicode_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1263, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1263, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L16_bool_binop_done; } __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_t_7), ((PyObject *)(&PyBytes_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1263, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1263, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L16_bool_binop_done; } __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_t_7), ((PyObject *)(&PyUnicode_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1263, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1263, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L16_bool_binop_done:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_2 = __pyx_t_1; if (unlikely(__pyx_t_2)) { /* "pyreadstat/_readstat_parser.pyx":1264 * raise PyreadstatError("path must be either str or bytes") * if type(filename_path) not in (str, bytes, unicode): * raise PyreadstatError("path must be str, bytes or unicode") # <<<<<<<<<<<<<< * filename_bytes = filename_path.encode('utf-8') * */ __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1264, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_9))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_9, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_path_must_be_str_bytes_or_unicod}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1264, __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, 1264, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1263 * else: * raise PyreadstatError("path must be either str or bytes") * if type(filename_path) not in (str, bytes, unicode): # <<<<<<<<<<<<<< * raise PyreadstatError("path must be str, bytes or unicode") * filename_bytes = filename_path.encode('utf-8') */ } /* "pyreadstat/_readstat_parser.pyx":1265 * if type(filename_path) not in (str, bytes, unicode): * raise PyreadstatError("path must be str, bytes or unicode") * filename_bytes = filename_path.encode('utf-8') # <<<<<<<<<<<<<< * * # Only check file existence for path-based reads */ __pyx_t_9 = __pyx_v_filename_path; __Pyx_INCREF(__pyx_t_9); __pyx_t_10 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __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_10, (2-__pyx_t_10) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1265, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_7))) __PYX_ERR(0, 1265, __pyx_L1_error) __Pyx_DECREF_SET(__pyx_v_filename_bytes, ((PyObject*)__pyx_t_7)); __pyx_t_7 = 0; } __pyx_L3:; /* "pyreadstat/_readstat_parser.pyx":1268 * * # Only check file existence for path-based reads * if file_obj is None: # <<<<<<<<<<<<<< * filename_bytes = os.path.expanduser(filename_bytes) * if not os.path.isfile(filename_bytes): */ __pyx_t_2 = (__pyx_v_file_obj == Py_None); if (__pyx_t_2) { /* "pyreadstat/_readstat_parser.pyx":1269 * # Only check file existence for path-based reads * if file_obj is None: * filename_bytes = os.path.expanduser(filename_bytes) # <<<<<<<<<<<<<< * if not os.path.isfile(filename_bytes): * raise PyreadstatError("File {0} does not exist!".format(filename_path)) */ __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_path); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = __pyx_t_8; __Pyx_INCREF(__pyx_t_9); __pyx_t_10 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_filename_bytes}; __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_expanduser, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_t_7))) __PYX_ERR(0, 1269, __pyx_L1_error) __Pyx_DECREF_SET(__pyx_v_filename_bytes, ((PyObject*)__pyx_t_7)); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1270 * if file_obj is None: * filename_bytes = os.path.expanduser(filename_bytes) * if not os.path.isfile(filename_bytes): # <<<<<<<<<<<<<< * raise PyreadstatError("File {0} does not exist!".format(filename_path)) * */ __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_os); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_8 = __pyx_t_3; __Pyx_INCREF(__pyx_t_8); __pyx_t_10 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_filename_bytes}; __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isfile, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1270, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_1 = (!__pyx_t_2); if (unlikely(__pyx_t_1)) { /* "pyreadstat/_readstat_parser.pyx":1271 * filename_bytes = os.path.expanduser(filename_bytes) * if not os.path.isfile(filename_bytes): * raise PyreadstatError("File {0} does not exist!".format(filename_path)) # <<<<<<<<<<<<<< * * if output_format is None: */ __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_12 = __pyx_mstate_global->__pyx_kp_u_File_0_does_not_exist; __Pyx_INCREF(__pyx_t_12); __pyx_t_10 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_v_filename_path}; __pyx_t_9 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_format, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); } __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_8, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_9}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1271, __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, 1271, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1270 * if file_obj is None: * filename_bytes = os.path.expanduser(filename_bytes) * if not os.path.isfile(filename_bytes): # <<<<<<<<<<<<<< * raise PyreadstatError("File {0} does not exist!".format(filename_path)) * */ } /* "pyreadstat/_readstat_parser.pyx":1268 * * # Only check file existence for path-based reads * if file_obj is None: # <<<<<<<<<<<<<< * filename_bytes = os.path.expanduser(filename_bytes) * if not os.path.isfile(filename_bytes): */ } /* "pyreadstat/_readstat_parser.pyx":1273 * raise PyreadstatError("File {0} does not exist!".format(filename_path)) * * if output_format is None: # <<<<<<<<<<<<<< * output_format = 'pandas' * allowed_formats = {'pandas', 'dict', 'polars'} */ __pyx_t_1 = (__pyx_v_output_format == ((PyObject*)Py_None)); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1274 * * if output_format is None: * output_format = 'pandas' # <<<<<<<<<<<<<< * allowed_formats = {'pandas', 'dict', 'polars'} * if output_format not in allowed_formats: */ __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_pandas); __Pyx_DECREF_SET(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas); /* "pyreadstat/_readstat_parser.pyx":1273 * raise PyreadstatError("File {0} does not exist!".format(filename_path)) * * if output_format is None: # <<<<<<<<<<<<<< * output_format = 'pandas' * allowed_formats = {'pandas', 'dict', 'polars'} */ } /* "pyreadstat/_readstat_parser.pyx":1275 * if output_format is None: * output_format = 'pandas' * allowed_formats = {'pandas', 'dict', 'polars'} # <<<<<<<<<<<<<< * if output_format not in allowed_formats: * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) */ __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (PySet_Add(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_pandas) < 0) __PYX_ERR(0, 1275, __pyx_L1_error) if (PySet_Add(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_dict) < 0) __PYX_ERR(0, 1275, __pyx_L1_error) if (PySet_Add(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_polars) < 0) __PYX_ERR(0, 1275, __pyx_L1_error) __pyx_v_allowed_formats = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1276 * output_format = 'pandas' * allowed_formats = {'pandas', 'dict', 'polars'} * if output_format not in allowed_formats: # <<<<<<<<<<<<<< * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": */ __pyx_t_1 = (__Pyx_PySet_ContainsTF(__pyx_v_output_format, __pyx_v_allowed_formats, Py_NE)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1276, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* "pyreadstat/_readstat_parser.pyx":1277 * allowed_formats = {'pandas', 'dict', 'polars'} * if output_format not in allowed_formats: * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) # <<<<<<<<<<<<<< * if output_format == "pandas": * try: */ __pyx_t_8 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1277, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_12 = __pyx_mstate_global->__pyx_kp_u_output_format_must_be_one_of_all; __Pyx_INCREF(__pyx_t_12); __pyx_t_10 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_12, NULL}; __pyx_t_14 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1277, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_allowed_formats, __pyx_v_allowed_formats, __pyx_t_14, __pyx_callargs+1, 0) < 0) __PYX_ERR(0, 1277, __pyx_L1_error) if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_output_format, __pyx_v_output_format, __pyx_t_14, __pyx_callargs+1, 1) < 0) __PYX_ERR(0, 1277, __pyx_L1_error) __pyx_t_3 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_format, __pyx_callargs+__pyx_t_10, (1-__pyx_t_10) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_14); __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1277, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_9))) { __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); assert(__pyx_t_8); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_9, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_3}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1277, __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, 1277, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1276 * output_format = 'pandas' * allowed_formats = {'pandas', 'dict', 'polars'} * if output_format not in allowed_formats: # <<<<<<<<<<<<<< * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": */ } /* "pyreadstat/_readstat_parser.pyx":1278 * if output_format not in allowed_formats: * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": # <<<<<<<<<<<<<< * try: * import pandas */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_pandas, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1278, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1279 * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": * try: # <<<<<<<<<<<<<< * import pandas * except: */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_4); /*try:*/ { /* "pyreadstat/_readstat_parser.pyx":1280 * if output_format == "pandas": * try: * import pandas # <<<<<<<<<<<<<< * except: * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") */ __pyx_t_7 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_pandas, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1280, __pyx_L24_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_pandas = __pyx_t_7; __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1279 * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": * try: # <<<<<<<<<<<<<< * import pandas * except: */ } __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L29_try_end; __pyx_L24_error:; __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __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; __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; /* "pyreadstat/_readstat_parser.pyx":1281 * try: * import pandas * except: # <<<<<<<<<<<<<< * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") * if output_format == "polars": */ /*except:*/ { __Pyx_AddTraceback("pyreadstat._readstat_parser.run_conversion", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_9, &__pyx_t_3) < 0) __PYX_ERR(0, 1281, __pyx_L26_except_error) __Pyx_XGOTREF(__pyx_t_7); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_3); /* "pyreadstat/_readstat_parser.pyx":1282 * import pandas * except: * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") # <<<<<<<<<<<<<< * if output_format == "polars": * try: */ __pyx_t_14 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1282, __pyx_L26_except_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_12))) { __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12); assert(__pyx_t_14); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_12); __Pyx_INCREF(__pyx_t_14); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_12, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_mstate_global->__pyx_kp_u_You_requested_pandas_as_output_f}; __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1282, __pyx_L26_except_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, 1282, __pyx_L26_except_error) } /* "pyreadstat/_readstat_parser.pyx":1279 * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": * try: # <<<<<<<<<<<<<< * import pandas * except: */ __pyx_L26_except_error:; __Pyx_XGIVEREF(__pyx_t_6); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_4); __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_5, __pyx_t_4); goto __pyx_L1_error; __pyx_L29_try_end:; } /* "pyreadstat/_readstat_parser.pyx":1278 * if output_format not in allowed_formats: * raise PyreadstatError("output format must be one of {allowed_formats}, '{output_format}' was given".format(allowed_formats=allowed_formats, output_format=output_format)) * if output_format == "pandas": # <<<<<<<<<<<<<< * try: * import pandas */ } /* "pyreadstat/_readstat_parser.pyx":1283 * except: * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") * if output_format == "polars": # <<<<<<<<<<<<<< * try: * import polars */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_polars, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1283, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1284 * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") * if output_format == "polars": * try: # <<<<<<<<<<<<<< * import polars * except: */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6); __Pyx_XGOTREF(__pyx_t_4); __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); /*try:*/ { /* "pyreadstat/_readstat_parser.pyx":1285 * if output_format == "polars": * try: * import polars # <<<<<<<<<<<<<< * except: * raise PyreadstatError("You requested polars as output_format but cannot import polars") */ __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_polars, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1285, __pyx_L33_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_polars = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1284 * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") * if output_format == "polars": * try: # <<<<<<<<<<<<<< * import polars * except: */ } __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L38_try_end; __pyx_L33_error:; __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __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; __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; /* "pyreadstat/_readstat_parser.pyx":1286 * try: * import polars * except: # <<<<<<<<<<<<<< * raise PyreadstatError("You requested polars as output_format but cannot import polars") * */ /*except:*/ { __Pyx_AddTraceback("pyreadstat._readstat_parser.run_conversion", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_9, &__pyx_t_7) < 0) __PYX_ERR(0, 1286, __pyx_L35_except_error) __Pyx_XGOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_7); /* "pyreadstat/_readstat_parser.pyx":1287 * import polars * except: * raise PyreadstatError("You requested polars as output_format but cannot import polars") # <<<<<<<<<<<<<< * * */ __pyx_t_12 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1287, __pyx_L35_except_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_14))) { __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_14); assert(__pyx_t_12); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_14); __Pyx_INCREF(__pyx_t_12); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_14, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_mstate_global->__pyx_kp_u_You_requested_polars_as_output_f}; __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_14, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1287, __pyx_L35_except_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, 1287, __pyx_L35_except_error) } /* "pyreadstat/_readstat_parser.pyx":1284 * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") * if output_format == "polars": * try: # <<<<<<<<<<<<<< * import polars * except: */ __pyx_L35_except_error:; __Pyx_XGIVEREF(__pyx_t_4); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); goto __pyx_L1_error; __pyx_L38_try_end:; } /* "pyreadstat/_readstat_parser.pyx":1283 * except: * raise PyreadstatError("You requested pandas as output_format but cannot import pandas") * if output_format == "polars": # <<<<<<<<<<<<<< * try: * import polars */ } /* "pyreadstat/_readstat_parser.pyx":1290 * * * if extra_date_formats is not None: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_SAS: * sas_date_formats.extend(extra_date_formats) */ __pyx_t_1 = (__pyx_v_extra_date_formats != ((PyObject*)Py_None)); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1291 * * if extra_date_formats is not None: * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * sas_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_SPSS: */ switch (__pyx_v_file_format) { case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS: /* "pyreadstat/_readstat_parser.pyx":1292 * if extra_date_formats is not None: * if file_format == FILE_FORMAT_SAS: * sas_date_formats.extend(extra_date_formats) # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_SPSS: * spss_date_formats.extend(extra_date_formats) */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1292, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats, __pyx_v_extra_date_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1292, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1291 * * if extra_date_formats is not None: * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * sas_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_SPSS: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS: /* "pyreadstat/_readstat_parser.pyx":1294 * sas_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_SPSS: * spss_date_formats.extend(extra_date_formats) # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_STATA: * stata_date_formats.extend(extra_date_formats) */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1294, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats, __pyx_v_extra_date_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1294, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1293 * if file_format == FILE_FORMAT_SAS: * sas_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * spss_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_STATA: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA: /* "pyreadstat/_readstat_parser.pyx":1296 * spss_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_STATA: * stata_date_formats.extend(extra_date_formats) # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unknown file format") */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1296, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats, __pyx_v_extra_date_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1296, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1295 * elif file_format == FILE_FORMAT_SPSS: * spss_date_formats.extend(extra_date_formats) * elif file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * stata_date_formats.extend(extra_date_formats) * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":1298 * stata_date_formats.extend(extra_date_formats) * else: * raise PyreadstatError("Unknown file format") # <<<<<<<<<<<<<< * if extra_datetime_formats is not None: * if file_format == FILE_FORMAT_SAS: */ __pyx_t_9 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_10 = 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_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_Unknown_file_format}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__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_7)) __PYX_ERR(0, 1298, __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, 1298, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":1290 * * * if extra_date_formats is not None: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_SAS: * sas_date_formats.extend(extra_date_formats) */ } /* "pyreadstat/_readstat_parser.pyx":1299 * else: * raise PyreadstatError("Unknown file format") * if extra_datetime_formats is not None: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_SAS: * sas_datetime_formats.extend(extra_datetime_formats) */ __pyx_t_1 = (__pyx_v_extra_datetime_formats != ((PyObject*)Py_None)); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1300 * raise PyreadstatError("Unknown file format") * if extra_datetime_formats is not None: * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * sas_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_SPSS: */ switch (__pyx_v_file_format) { case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS: /* "pyreadstat/_readstat_parser.pyx":1301 * if extra_datetime_formats is not None: * if file_format == FILE_FORMAT_SAS: * sas_datetime_formats.extend(extra_datetime_formats) # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_SPSS: * spss_datetime_formats.extend(extra_datetime_formats) */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1301, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats, __pyx_v_extra_datetime_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1301, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1300 * raise PyreadstatError("Unknown file format") * if extra_datetime_formats is not None: * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * sas_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_SPSS: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS: /* "pyreadstat/_readstat_parser.pyx":1303 * sas_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_SPSS: * spss_datetime_formats.extend(extra_datetime_formats) # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_STATA: * stata_datetime_formats.extend(extra_datetime_formats) */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1303, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats, __pyx_v_extra_datetime_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1303, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1302 * if file_format == FILE_FORMAT_SAS: * sas_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * spss_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_STATA: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA: /* "pyreadstat/_readstat_parser.pyx":1305 * spss_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_STATA: * stata_datetime_formats.extend(extra_datetime_formats) # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unknown file format") */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1305, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats, __pyx_v_extra_datetime_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1305, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1304 * elif file_format == FILE_FORMAT_SPSS: * spss_datetime_formats.extend(extra_datetime_formats) * elif file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * stata_datetime_formats.extend(extra_datetime_formats) * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":1307 * stata_datetime_formats.extend(extra_datetime_formats) * else: * raise PyreadstatError("Unknown file format") # <<<<<<<<<<<<<< * if extra_time_formats is not None: * if file_format == FILE_FORMAT_SAS: */ __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_9))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_9, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_Unknown_file_format}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1307, __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, 1307, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":1299 * else: * raise PyreadstatError("Unknown file format") * if extra_datetime_formats is not None: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_SAS: * sas_datetime_formats.extend(extra_datetime_formats) */ } /* "pyreadstat/_readstat_parser.pyx":1308 * else: * raise PyreadstatError("Unknown file format") * if extra_time_formats is not None: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_SAS: * sas_time_formats.extend(extra_time_formats) */ __pyx_t_1 = (__pyx_v_extra_time_formats != ((PyObject*)Py_None)); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1309 * raise PyreadstatError("Unknown file format") * if extra_time_formats is not None: * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * sas_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_SPSS: */ switch (__pyx_v_file_format) { case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS: /* "pyreadstat/_readstat_parser.pyx":1310 * if extra_time_formats is not None: * if file_format == FILE_FORMAT_SAS: * sas_time_formats.extend(extra_time_formats) # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_SPSS: * spss_time_formats.extend(extra_time_formats) */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1310, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats, __pyx_v_extra_time_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1310, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1309 * raise PyreadstatError("Unknown file format") * if extra_time_formats is not None: * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * sas_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_SPSS: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS: /* "pyreadstat/_readstat_parser.pyx":1312 * sas_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_SPSS: * spss_time_formats.extend(extra_time_formats) # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_STATA: * stata_time_formats.extend(extra_time_formats) */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1312, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats, __pyx_v_extra_time_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1312, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1311 * if file_format == FILE_FORMAT_SAS: * sas_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * spss_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_STATA: */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA: /* "pyreadstat/_readstat_parser.pyx":1314 * spss_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_STATA: * stata_time_formats.extend(extra_time_formats) # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unknown file format") */ if (unlikely(__pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend"); __PYX_ERR(0, 1314, __pyx_L1_error) } __pyx_t_18 = __Pyx_PyList_Extend(__pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats, __pyx_v_extra_time_formats); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 1314, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1313 * elif file_format == FILE_FORMAT_SPSS: * spss_time_formats.extend(extra_time_formats) * elif file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * stata_time_formats.extend(extra_time_formats) * else: */ break; default: /* "pyreadstat/_readstat_parser.pyx":1316 * stata_time_formats.extend(extra_time_formats) * else: * raise PyreadstatError("Unknown file format") # <<<<<<<<<<<<<< * global sas_all_formats, spss_all_formats, stata_all_formats * sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats */ __pyx_t_9 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1316, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_10 = 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_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_Unknown_file_format}; __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__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_7)) __PYX_ERR(0, 1316, __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, 1316, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":1308 * else: * raise PyreadstatError("Unknown file format") * if extra_time_formats is not None: # <<<<<<<<<<<<<< * if file_format == FILE_FORMAT_SAS: * sas_time_formats.extend(extra_time_formats) */ } /* "pyreadstat/_readstat_parser.pyx":1318 * raise PyreadstatError("Unknown file format") * global sas_all_formats, spss_all_formats, stata_all_formats * sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats # <<<<<<<<<<<<<< * stata_all_formats = stata_date_formats + stata_datetime_formats + stata_time_formats * spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats */ __pyx_t_7 = PyNumber_Add(__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats, __pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_3 = PyNumber_Add(__pyx_t_7, __pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1319 * global sas_all_formats, spss_all_formats, stata_all_formats * sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats * stata_all_formats = stata_date_formats + stata_datetime_formats + stata_time_formats # <<<<<<<<<<<<<< * spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats * */ __pyx_t_3 = PyNumber_Add(__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats, __pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = PyNumber_Add(__pyx_t_3, __pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats, ((PyObject*)__pyx_t_7)); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = 0; /* "pyreadstat/_readstat_parser.pyx":1320 * sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats * stata_all_formats = stata_date_formats + stata_datetime_formats + stata_time_formats * spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats # <<<<<<<<<<<<<< * * filename = filename_bytes */ __pyx_t_7 = PyNumber_Add(__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats, __pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_3 = PyNumber_Add(__pyx_t_7, __pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1322 * spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats * * filename = filename_bytes # <<<<<<<<<<<<<< * * data = data_container() */ if (unlikely(__pyx_v_filename_bytes == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); __PYX_ERR(0, 1322, __pyx_L1_error) } __pyx_t_19 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename_bytes); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 1322, __pyx_L1_error) __pyx_v_filename = ((char *)__pyx_t_19); /* "pyreadstat/_readstat_parser.pyx":1324 * filename = filename_bytes * * data = data_container() # <<<<<<<<<<<<<< * ctx = data * */ __pyx_t_7 = NULL; __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container); __pyx_t_9 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container); __pyx_t_10 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_10, (1-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1324, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_3); } __pyx_v_data = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1325 * * data = data_container() * ctx = data # <<<<<<<<<<<<<< * * data.file_format = file_format */ __pyx_v_ctx = ((void *)__pyx_v_data); /* "pyreadstat/_readstat_parser.pyx":1327 * ctx = data * * data.file_format = file_format # <<<<<<<<<<<<<< * data.metaonly = metaonly * data.dates_as_pandas = dates_as_pandas */ __pyx_v_data->file_format = __pyx_v_file_format; /* "pyreadstat/_readstat_parser.pyx":1328 * * data.file_format = file_format * data.metaonly = metaonly # <<<<<<<<<<<<<< * data.dates_as_pandas = dates_as_pandas * data.output_format = output_format */ __pyx_v_data->metaonly = __pyx_v_metaonly; /* "pyreadstat/_readstat_parser.pyx":1329 * data.file_format = file_format * data.metaonly = metaonly * data.dates_as_pandas = dates_as_pandas # <<<<<<<<<<<<<< * data.output_format = output_format * */ __pyx_v_data->dates_as_pandas = __pyx_v_dates_as_pandas; /* "pyreadstat/_readstat_parser.pyx":1330 * data.metaonly = metaonly * data.dates_as_pandas = dates_as_pandas * data.output_format = output_format # <<<<<<<<<<<<<< * * if encoding: */ __Pyx_INCREF(__pyx_v_output_format); __Pyx_GIVEREF(__pyx_v_output_format); __Pyx_GOTREF(__pyx_v_data->output_format); __Pyx_DECREF(__pyx_v_data->output_format); __pyx_v_data->output_format = __pyx_v_output_format; /* "pyreadstat/_readstat_parser.pyx":1332 * data.output_format = output_format * * if encoding: # <<<<<<<<<<<<<< * data.user_encoding = encoding * */ __pyx_t_1 = (__pyx_v_encoding != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_encoding) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_1 < 0))) __PYX_ERR(0, 1332, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1333 * * if encoding: * data.user_encoding = encoding # <<<<<<<<<<<<<< * * if file_format == FILE_FORMAT_SAS: */ __Pyx_INCREF(__pyx_v_encoding); __Pyx_GIVEREF(__pyx_v_encoding); __Pyx_GOTREF(__pyx_v_data->user_encoding); __Pyx_DECREF(__pyx_v_data->user_encoding); __pyx_v_data->user_encoding = __pyx_v_encoding; /* "pyreadstat/_readstat_parser.pyx":1332 * data.output_format = output_format * * if encoding: # <<<<<<<<<<<<<< * data.user_encoding = encoding * */ } /* "pyreadstat/_readstat_parser.pyx":1335 * data.user_encoding = encoding * * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * origin = sas_origin * unix_to_origin_secs = sas_secs_from_unix */ switch (__pyx_v_file_format) { case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS: /* "pyreadstat/_readstat_parser.pyx":1336 * * if file_format == FILE_FORMAT_SAS: * origin = sas_origin # <<<<<<<<<<<<<< * unix_to_origin_secs = sas_secs_from_unix * elif file_format == FILE_FORMAT_SPSS: */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_origin); __pyx_v_origin = __pyx_v_10pyreadstat_16_readstat_parser_sas_origin; /* "pyreadstat/_readstat_parser.pyx":1337 * if file_format == FILE_FORMAT_SAS: * origin = sas_origin * unix_to_origin_secs = sas_secs_from_unix # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_SPSS: * origin = spss_origin */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_secs_from_unix); __pyx_v_unix_to_origin_secs = __pyx_v_10pyreadstat_16_readstat_parser_sas_secs_from_unix; /* "pyreadstat/_readstat_parser.pyx":1335 * data.user_encoding = encoding * * if file_format == FILE_FORMAT_SAS: # <<<<<<<<<<<<<< * origin = sas_origin * unix_to_origin_secs = sas_secs_from_unix */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS: /* "pyreadstat/_readstat_parser.pyx":1339 * unix_to_origin_secs = sas_secs_from_unix * elif file_format == FILE_FORMAT_SPSS: * origin = spss_origin # <<<<<<<<<<<<<< * unix_to_origin_secs = spss_secs_from_unix * elif file_format == FILE_FORMAT_STATA: */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_origin); __pyx_v_origin = __pyx_v_10pyreadstat_16_readstat_parser_spss_origin; /* "pyreadstat/_readstat_parser.pyx":1340 * elif file_format == FILE_FORMAT_SPSS: * origin = spss_origin * unix_to_origin_secs = spss_secs_from_unix # <<<<<<<<<<<<<< * elif file_format == FILE_FORMAT_STATA: * origin = stata_origin */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_secs_from_unix); __pyx_v_unix_to_origin_secs = __pyx_v_10pyreadstat_16_readstat_parser_spss_secs_from_unix; /* "pyreadstat/_readstat_parser.pyx":1338 * origin = sas_origin * unix_to_origin_secs = sas_secs_from_unix * elif file_format == FILE_FORMAT_SPSS: # <<<<<<<<<<<<<< * origin = spss_origin * unix_to_origin_secs = spss_secs_from_unix */ break; case __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA: /* "pyreadstat/_readstat_parser.pyx":1342 * unix_to_origin_secs = spss_secs_from_unix * elif file_format == FILE_FORMAT_STATA: * origin = stata_origin # <<<<<<<<<<<<<< * unix_to_origin_secs = stata_secs_from_unix * else: */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_origin); __pyx_v_origin = __pyx_v_10pyreadstat_16_readstat_parser_stata_origin; /* "pyreadstat/_readstat_parser.pyx":1343 * elif file_format == FILE_FORMAT_STATA: * origin = stata_origin * unix_to_origin_secs = stata_secs_from_unix # <<<<<<<<<<<<<< * else: * raise PyreadstatError("Unknown file format") */ __Pyx_INCREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_secs_from_unix); __pyx_v_unix_to_origin_secs = __pyx_v_10pyreadstat_16_readstat_parser_stata_secs_from_unix; /* "pyreadstat/_readstat_parser.pyx":1341 * origin = spss_origin * unix_to_origin_secs = spss_secs_from_unix * elif file_format == FILE_FORMAT_STATA: # <<<<<<<<<<<<<< * origin = stata_origin * unix_to_origin_secs = stata_secs_from_unix */ break; default: /* "pyreadstat/_readstat_parser.pyx":1345 * unix_to_origin_secs = stata_secs_from_unix * else: * raise PyreadstatError("Unknown file format") # <<<<<<<<<<<<<< * * data.origin = origin */ __pyx_t_9 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_10 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_7))) { __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); assert(__pyx_t_9); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_7, __pyx__function); __pyx_t_10 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_mstate_global->__pyx_kp_u_Unknown_file_format}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+__pyx_t_10, (2-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1345, __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, 1345, __pyx_L1_error) break; } /* "pyreadstat/_readstat_parser.pyx":1347 * raise PyreadstatError("Unknown file format") * * data.origin = origin # <<<<<<<<<<<<<< * data.unix_to_origin_secs = unix_to_origin_secs * */ __Pyx_INCREF(__pyx_v_origin); __Pyx_GIVEREF(__pyx_v_origin); __Pyx_GOTREF(__pyx_v_data->origin); __Pyx_DECREF(__pyx_v_data->origin); __pyx_v_data->origin = __pyx_v_origin; /* "pyreadstat/_readstat_parser.pyx":1348 * * data.origin = origin * data.unix_to_origin_secs = unix_to_origin_secs # <<<<<<<<<<<<<< * * if usecols is not None: */ __pyx_t_20 = __Pyx_PyFloat_AsDouble(__pyx_v_unix_to_origin_secs); if (unlikely((__pyx_t_20 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1348, __pyx_L1_error) __pyx_v_data->unix_to_origin_secs = __pyx_t_20; /* "pyreadstat/_readstat_parser.pyx":1350 * data.unix_to_origin_secs = unix_to_origin_secs * * if usecols is not None: # <<<<<<<<<<<<<< * data.filter_cols = 1 * data.use_cols = usecols */ __pyx_t_1 = (__pyx_v_usecols != ((PyObject*)Py_None)); if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1351 * * if usecols is not None: * data.filter_cols = 1 # <<<<<<<<<<<<<< * data.use_cols = usecols * */ __pyx_v_data->filter_cols = 1; /* "pyreadstat/_readstat_parser.pyx":1352 * if usecols is not None: * data.filter_cols = 1 * data.use_cols = usecols # <<<<<<<<<<<<<< * * data.usernan = usernan */ __Pyx_INCREF(__pyx_v_usecols); __Pyx_GIVEREF(__pyx_v_usecols); __Pyx_GOTREF(__pyx_v_data->use_cols); __Pyx_DECREF(__pyx_v_data->use_cols); __pyx_v_data->use_cols = __pyx_v_usecols; /* "pyreadstat/_readstat_parser.pyx":1350 * data.unix_to_origin_secs = unix_to_origin_secs * * if usecols is not None: # <<<<<<<<<<<<<< * data.filter_cols = 1 * data.use_cols = usecols */ } /* "pyreadstat/_readstat_parser.pyx":1354 * data.use_cols = usecols * * data.usernan = usernan # <<<<<<<<<<<<<< * data.no_datetime_conversion = no_datetime_conversion * */ __pyx_v_data->usernan = __pyx_v_usernan; /* "pyreadstat/_readstat_parser.pyx":1355 * * data.usernan = usernan * data.no_datetime_conversion = no_datetime_conversion # <<<<<<<<<<<<<< * * # go! */ __pyx_v_data->no_datetime_conversion = __pyx_v_no_datetime_conversion; /* "pyreadstat/_readstat_parser.pyx":1358 * * # go! * run_readstat_parser(filename, data, file_extension, row_limit, row_offset, file_obj) # <<<<<<<<<<<<<< * data_dict = data_container_to_dict(data) * if output_format == 'dict': */ __pyx_t_21.__pyx_n = 1; __pyx_t_21.file_obj = __pyx_v_file_obj; __pyx_f_10pyreadstat_16_readstat_parser_run_readstat_parser(__pyx_v_filename, __pyx_v_data, __pyx_v_file_extension, __pyx_v_row_limit, __pyx_v_row_offset, &__pyx_t_21); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1358, __pyx_L1_error) /* "pyreadstat/_readstat_parser.pyx":1359 * # go! * run_readstat_parser(filename, data, file_extension, row_limit, row_offset, file_obj) * data_dict = data_container_to_dict(data) # <<<<<<<<<<<<<< * if output_format == 'dict': * data_frame = data_dict */ __pyx_t_3 = __pyx_f_10pyreadstat_16_readstat_parser_data_container_to_dict(__pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_data_dict = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1360 * run_readstat_parser(filename, data, file_extension, row_limit, row_offset, file_obj) * data_dict = data_container_to_dict(data) * if output_format == 'dict': # <<<<<<<<<<<<<< * data_frame = data_dict * else: */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_dict, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1360, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/_readstat_parser.pyx":1361 * data_dict = data_container_to_dict(data) * if output_format == 'dict': * data_frame = data_dict # <<<<<<<<<<<<<< * else: * data_frame = dict_to_dataframe(data_dict, data) */ __Pyx_INCREF(__pyx_v_data_dict); __pyx_v_data_frame = __pyx_v_data_dict; /* "pyreadstat/_readstat_parser.pyx":1360 * run_readstat_parser(filename, data, file_extension, row_limit, row_offset, file_obj) * data_dict = data_container_to_dict(data) * if output_format == 'dict': # <<<<<<<<<<<<<< * data_frame = data_dict * else: */ goto __pyx_L46; } /* "pyreadstat/_readstat_parser.pyx":1363 * data_frame = data_dict * else: * data_frame = dict_to_dataframe(data_dict, data) # <<<<<<<<<<<<<< * metadata = data_container_extract_metadata(data) * */ /*else*/ { __pyx_t_3 = __pyx_f_10pyreadstat_16_readstat_parser_dict_to_dataframe(__pyx_v_data_dict, __pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_data_frame = __pyx_t_3; __pyx_t_3 = 0; } __pyx_L46:; /* "pyreadstat/_readstat_parser.pyx":1364 * else: * data_frame = dict_to_dataframe(data_dict, data) * metadata = data_container_extract_metadata(data) # <<<<<<<<<<<<<< * * return data_frame, metadata */ __pyx_t_3 = __pyx_f_10pyreadstat_16_readstat_parser_data_container_extract_metadata(__pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1364, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_metadata = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":1366 * metadata = data_container_extract_metadata(data) * * return data_frame, metadata # <<<<<<<<<<<<<< * */ __Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 1366, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 1366, __pyx_L1_error); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; /* "pyreadstat/_readstat_parser.pyx":1225 * * * cdef object run_conversion(object filename_path, py_file_format file_format, py_file_extension file_extension, # <<<<<<<<<<<<<< * str encoding, bint metaonly, bint dates_as_pandas, list usecols, bint usernan, * bint no_datetime_conversion, long row_limit, long row_offset, str output_format, */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __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_XDECREF(__pyx_t_17); __Pyx_AddTraceback("pyreadstat._readstat_parser.run_conversion", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_filename_bytes); __Pyx_XDECREF((PyObject *)__pyx_v_data); __Pyx_XDECREF(__pyx_v_origin); __Pyx_XDECREF(__pyx_v_allowed_formats); __Pyx_XDECREF(__pyx_v_data_dict); __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_file_obj); __Pyx_XDECREF(__pyx_v_pandas); __Pyx_XDECREF(__pyx_v_polars); __Pyx_XDECREF(__pyx_v_unix_to_origin_secs); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XDECREF(__pyx_v_output_format); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* #### Code section: module_exttypes ### */ static PyObject *__pyx_tp_new_10pyreadstat_16_readstat_parser_data_container(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *p; PyObject *o; #if CYTHON_COMPILING_IN_LIMITED_API allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); o = alloc_func(t, 0); #else if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) { o = (*t->tp_alloc)(t, 0); } else { o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_mstate_global->__pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; #endif p = ((struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)o); p->col_data = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_data_len = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_names = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_labels = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_dtypes = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_numpy_dtypes = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_dtypes_isobject = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_dytpes_isfloat = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); p->col_formats_original = ((PyObject*)Py_None); Py_INCREF(Py_None); p->origin = Py_None; Py_INCREF(Py_None); p->file_label = ((PyObject*)Py_None); Py_INCREF(Py_None); p->file_encoding = ((PyObject*)Py_None); Py_INCREF(Py_None); p->label_to_var_name = Py_None; Py_INCREF(Py_None); p->labels_raw = Py_None; Py_INCREF(Py_None); p->notes = Py_None; Py_INCREF(Py_None); p->user_encoding = ((PyObject*)Py_None); Py_INCREF(Py_None); p->table_name = ((PyObject*)Py_None); Py_INCREF(Py_None); p->use_cols = ((PyObject*)Py_None); Py_INCREF(Py_None); p->missing_ranges = ((PyObject*)Py_None); Py_INCREF(Py_None); p->missing_user_values = ((PyObject*)Py_None); Py_INCREF(Py_None); p->variable_storage_width = ((PyObject*)Py_None); Py_INCREF(Py_None); p->variable_display_width = Py_None; Py_INCREF(Py_None); p->variable_alignment = Py_None; Py_INCREF(Py_None); p->variable_measure = Py_None; Py_INCREF(Py_None); p->mr_sets = ((PyObject*)Py_None); Py_INCREF(Py_None); p->output_format = ((PyObject*)Py_None); Py_INCREF(Py_None); if (unlikely(__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_1__cinit__(o, __pyx_mstate_global->__pyx_empty_tuple, NULL) < 0)) goto bad; return o; bad: Py_DECREF(o); o = 0; return NULL; } static void __pyx_tp_dealloc_10pyreadstat_16_readstat_parser_data_container(PyObject *o) { struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *p = (struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_10pyreadstat_16_readstat_parser_data_container) { if (PyObject_CallFinalizerFromDealloc(o)) return; } } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->col_data); Py_CLEAR(p->col_data_len); Py_CLEAR(p->col_names); Py_CLEAR(p->col_labels); Py_CLEAR(p->col_dtypes); Py_CLEAR(p->col_numpy_dtypes); Py_CLEAR(p->col_dtypes_isobject); Py_CLEAR(p->col_dytpes_isfloat); Py_CLEAR(p->col_formats); Py_CLEAR(p->col_formats_original); Py_CLEAR(p->origin); Py_CLEAR(p->file_label); Py_CLEAR(p->file_encoding); Py_CLEAR(p->label_to_var_name); Py_CLEAR(p->labels_raw); Py_CLEAR(p->notes); Py_CLEAR(p->user_encoding); Py_CLEAR(p->table_name); Py_CLEAR(p->use_cols); Py_CLEAR(p->missing_ranges); Py_CLEAR(p->missing_user_values); Py_CLEAR(p->variable_storage_width); Py_CLEAR(p->variable_display_width); Py_CLEAR(p->variable_alignment); Py_CLEAR(p->variable_measure); Py_CLEAR(p->mr_sets); Py_CLEAR(p->output_format); #if CYTHON_USE_TYPE_SLOTS (*Py_TYPE(o)->tp_free)(o); #else { freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); if (tp_free) tp_free(o); } #endif } static int __pyx_tp_traverse_10pyreadstat_16_readstat_parser_data_container(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *p = (struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)o; { e = __Pyx_call_type_traverse(o, 1, v, a); if (e) return e; } if (p->col_data) { e = (*v)(p->col_data, a); if (e) return e; } if (p->col_data_len) { e = (*v)(p->col_data_len, a); if (e) return e; } if (p->col_names) { e = (*v)(p->col_names, a); if (e) return e; } if (p->col_labels) { e = (*v)(p->col_labels, a); if (e) return e; } if (p->col_dtypes) { e = (*v)(p->col_dtypes, a); if (e) return e; } if (p->col_numpy_dtypes) { e = (*v)(p->col_numpy_dtypes, a); if (e) return e; } if (p->col_dtypes_isobject) { e = (*v)(p->col_dtypes_isobject, a); if (e) return e; } if (p->col_dytpes_isfloat) { e = (*v)(p->col_dytpes_isfloat, a); if (e) return e; } if (p->col_formats) { e = (*v)(p->col_formats, a); if (e) return e; } if (p->col_formats_original) { e = (*v)(p->col_formats_original, a); if (e) return e; } if (p->origin) { e = (*v)(p->origin, a); if (e) return e; } if (p->label_to_var_name) { e = (*v)(p->label_to_var_name, a); if (e) return e; } if (p->labels_raw) { e = (*v)(p->labels_raw, a); if (e) return e; } if (p->notes) { e = (*v)(p->notes, a); if (e) return e; } if (p->use_cols) { e = (*v)(p->use_cols, a); if (e) return e; } if (p->missing_ranges) { e = (*v)(p->missing_ranges, a); if (e) return e; } if (p->missing_user_values) { e = (*v)(p->missing_user_values, a); if (e) return e; } if (p->variable_storage_width) { e = (*v)(p->variable_storage_width, a); if (e) return e; } if (p->variable_display_width) { e = (*v)(p->variable_display_width, a); if (e) return e; } if (p->variable_alignment) { e = (*v)(p->variable_alignment, a); if (e) return e; } if (p->variable_measure) { e = (*v)(p->variable_measure, a); if (e) return e; } if (p->mr_sets) { e = (*v)(p->mr_sets, a); if (e) return e; } return 0; } static int __pyx_tp_clear_10pyreadstat_16_readstat_parser_data_container(PyObject *o) { PyObject* tmp; struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *p = (struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)o; tmp = ((PyObject*)p->col_data); p->col_data = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_data_len); p->col_data_len = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_names); p->col_names = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_labels); p->col_labels = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_dtypes); p->col_dtypes = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_numpy_dtypes); p->col_numpy_dtypes = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_dtypes_isobject); p->col_dtypes_isobject = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_dytpes_isfloat); p->col_dytpes_isfloat = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_formats); p->col_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->col_formats_original); p->col_formats_original = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->origin); p->origin = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->label_to_var_name); p->label_to_var_name = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->labels_raw); p->labels_raw = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->notes); p->notes = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->use_cols); p->use_cols = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->missing_ranges); p->missing_ranges = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->missing_user_values); p->missing_user_values = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->variable_storage_width); p->variable_storage_width = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->variable_display_width); p->variable_display_width = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->variable_alignment); p->variable_alignment = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->variable_measure); p->variable_measure = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->mr_sets); p->mr_sets = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_10pyreadstat_16_readstat_parser_data_container[] = { {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_3__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_16_readstat_parser_14data_container_5__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; #if CYTHON_USE_TYPE_SPECS static PyType_Slot __pyx_type_10pyreadstat_16_readstat_parser_data_container_slots[] = { {Py_tp_dealloc, (void *)__pyx_tp_dealloc_10pyreadstat_16_readstat_parser_data_container}, {Py_tp_doc, (void *)PyDoc_STR("\n This extension type holds all the data we need to get from our file from \n the readstat parser and will be used later to compose our pandas data frame\n ")}, {Py_tp_traverse, (void *)__pyx_tp_traverse_10pyreadstat_16_readstat_parser_data_container}, {Py_tp_clear, (void *)__pyx_tp_clear_10pyreadstat_16_readstat_parser_data_container}, {Py_tp_methods, (void *)__pyx_methods_10pyreadstat_16_readstat_parser_data_container}, {Py_tp_new, (void *)__pyx_tp_new_10pyreadstat_16_readstat_parser_data_container}, {0, 0}, }; static PyType_Spec __pyx_type_10pyreadstat_16_readstat_parser_data_container_spec = { "pyreadstat._readstat_parser.data_container", sizeof(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container), 0, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, __pyx_type_10pyreadstat_16_readstat_parser_data_container_slots, }; #else static PyTypeObject __pyx_type_10pyreadstat_16_readstat_parser_data_container = { PyVarObject_HEAD_INIT(0, 0) "pyreadstat._readstat_parser.""data_container", /*tp_name*/ sizeof(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_10pyreadstat_16_readstat_parser_data_container, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_as_async*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ PyDoc_STR("\n This extension type holds all the data we need to get from our file from \n the readstat parser and will be used later to compose our pandas data frame\n "), /*tp_doc*/ __pyx_tp_traverse_10pyreadstat_16_readstat_parser_data_container, /*tp_traverse*/ __pyx_tp_clear_10pyreadstat_16_readstat_parser_data_container, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_10pyreadstat_16_readstat_parser_data_container, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ #if !CYTHON_USE_TYPE_SPECS 0, /*tp_dictoffset*/ #endif 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_10pyreadstat_16_readstat_parser_data_container, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if CYTHON_USE_TP_FINALIZE 0, /*tp_finalize*/ #else NULL, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) 0, /*tp_vectorcall*/ #endif #if __PYX_NEED_TP_PRINT_SLOT == 1 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /*tp_watched*/ #endif #if PY_VERSION_HEX >= 0x030d00A4 0, /*tp_versions_used*/ #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 0, /*tp_pypy_flags*/ #endif }; #endif 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_parser_readstat_to_numpy_types = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_sas_origin = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_spss_origin = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_stata_origin = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_unix_origin = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_sas_secs_from_unix = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_spss_secs_from_unix = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser_stata_secs_from_unix = Py_None; Py_INCREF(Py_None); __pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx = 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); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); /*--- Variable export code ---*/ if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_readstat_to_numpy_types, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_sas_date_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_sas_datetime_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_sas_time_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_sas_all_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_sas_all_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_sas_origin, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_sas_origin, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_spss_datetime_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_spss_date_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_spss_time_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_spss_all_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_spss_all_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_spss_origin, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_spss_origin, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_stata_datetime_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_stata_date_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_stata_time_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_stata_all_formats, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_stata_all_formats, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportVoidPtr(__pyx_mstate_global->__pyx_n_u_stata_origin, (void *)&__pyx_v_10pyreadstat_16_readstat_parser_stata_origin, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } 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("transform_variable_format", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_transform_variable_format, "__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format (PyObject *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("transform_datetime", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_transform_datetime, "PyObject *(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, double, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format, PyObject *, int, PyObject *, double)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("handle_metadata", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_handle_metadata, "int (readstat_metadata_t *, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("handle_variable", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_handle_variable, "int (int, readstat_variable_t *, char *, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("handle_value", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_handle_value, "int (int, readstat_variable_t *, readstat_value_t, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("handle_value_label", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_handle_value_label, "int (char *, readstat_value_t, char *, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("handle_note", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_handle_note, "int (int, char *, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("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) if (__Pyx_ExportFunction("run_readstat_parser", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_run_readstat_parser, "void (char *, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension, long, long, struct __pyx_opt_args_10pyreadstat_16_readstat_parser_run_readstat_parser *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("data_container_to_dict", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_data_container_to_dict, "PyObject *(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("dict_to_dataframe", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_dict_to_dataframe, "PyObject *(PyObject *, struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("data_container_extract_metadata", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_data_container_extract_metadata, "PyObject *(struct __pyx_obj_10pyreadstat_16_readstat_parser_data_container *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ExportFunction("run_conversion", (void (*)(void))__pyx_f_10pyreadstat_16_readstat_parser_run_conversion, "PyObject *(PyObject *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension, PyObject *, int, int, PyObject *, int, int, long, long, PyObject *, PyObject *, PyObject *, PyObject *)") < 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); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ #if CYTHON_USE_TYPE_SPECS __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_10pyreadstat_16_readstat_parser_data_container_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container)) __PYX_ERR(0, 79, __pyx_L1_error) if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_10pyreadstat_16_readstat_parser_data_container_spec, __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container) < 0) __PYX_ERR(0, 79, __pyx_L1_error) #else __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container = &__pyx_type_10pyreadstat_16_readstat_parser_data_container; #endif #if !CYTHON_COMPILING_IN_LIMITED_API #endif #if !CYTHON_USE_TYPE_SPECS if (__Pyx_PyType_Ready(__pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container) < 0) __PYX_ERR(0, 79, __pyx_L1_error) #endif #if !CYTHON_COMPILING_IN_LIMITED_API if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container->tp_dictoffset && __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container->tp_getattro == PyObject_GenericGetAttr)) { __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container->tp_getattro = PyObject_GenericGetAttr; } #endif if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_data_container, (PyObject *) __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container) < 0) __PYX_ERR(0, 79, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject *) __pyx_mstate->__pyx_ptype_10pyreadstat_16_readstat_parser_data_container) < 0) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } 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(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_mstate->__pyx_ptype_7cpython_4type_type = __Pyx_ImportType_3_1_2(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyTypeObject), #elif CYTHON_COMPILING_IN_LIMITED_API 0, 0, #else sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule("datetime"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 43, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_mstate->__pyx_ptype_7cpython_8datetime_date = __Pyx_ImportType_3_1_2(__pyx_t_1, "datetime", "date", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyDateTime_Date), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Date), #elif CYTHON_COMPILING_IN_LIMITED_API sizeof(PyDateTime_Date), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Date), #else sizeof(PyDateTime_Date), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Date), #endif __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__pyx_ptype_7cpython_8datetime_date) __PYX_ERR(2, 43, __pyx_L1_error) __pyx_mstate->__pyx_ptype_7cpython_8datetime_time = __Pyx_ImportType_3_1_2(__pyx_t_1, "datetime", "time", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyDateTime_Time), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Time), #elif CYTHON_COMPILING_IN_LIMITED_API sizeof(PyDateTime_Time), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Time), #else sizeof(PyDateTime_Time), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Time), #endif __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__pyx_ptype_7cpython_8datetime_time) __PYX_ERR(2, 56, __pyx_L1_error) __pyx_mstate->__pyx_ptype_7cpython_8datetime_datetime = __Pyx_ImportType_3_1_2(__pyx_t_1, "datetime", "datetime", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyDateTime_DateTime), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_DateTime), #elif CYTHON_COMPILING_IN_LIMITED_API sizeof(PyDateTime_DateTime), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_DateTime), #else sizeof(PyDateTime_DateTime), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_DateTime), #endif __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__pyx_ptype_7cpython_8datetime_datetime) __PYX_ERR(2, 82, __pyx_L1_error) __pyx_mstate->__pyx_ptype_7cpython_8datetime_timedelta = __Pyx_ImportType_3_1_2(__pyx_t_1, "datetime", "timedelta", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyDateTime_Delta), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Delta), #elif CYTHON_COMPILING_IN_LIMITED_API sizeof(PyDateTime_Delta), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Delta), #else sizeof(PyDateTime_Delta), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_Delta), #endif __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__pyx_ptype_7cpython_8datetime_timedelta) __PYX_ERR(2, 120, __pyx_L1_error) __pyx_mstate->__pyx_ptype_7cpython_8datetime_tzinfo = __Pyx_ImportType_3_1_2(__pyx_t_1, "datetime", "tzinfo", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyDateTime_TZInfo), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_TZInfo), #elif CYTHON_COMPILING_IN_LIMITED_API sizeof(PyDateTime_TZInfo), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_TZInfo), #else sizeof(PyDateTime_TZInfo), __PYX_GET_STRUCT_ALIGNMENT_3_1_2(PyDateTime_TZInfo), #endif __Pyx_ImportType_CheckSize_Warn_3_1_2); if (!__pyx_mstate->__pyx_ptype_7cpython_8datetime_tzinfo) __PYX_ERR(2, 133, __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); __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); /*--- Variable import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_import_code(__pyx_mstatetype *__pyx_mstate) { __Pyx_RefNannyDeclarations CYTHON_UNUSED_VAR(__pyx_mstate); __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } #if CYTHON_PEP489_MULTI_PHASE_INIT static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ static int __pyx_pymod_exec__readstat_parser(PyObject* module); /*proto*/ static PyModuleDef_Slot __pyx_moduledef_slots[] = { {Py_mod_create, (void*)__pyx_pymod_create}, {Py_mod_exec, (void*)__pyx_pymod_exec__readstat_parser}, #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_parser", 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_parser(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC PyInit__readstat_parser(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_parser(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; 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_parser' 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_parser" 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_parser", 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_parser) { 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_parser")) { if (unlikely((PyDict_SetItemString(modules, "pyreadstat._readstat_parser", __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); if (unlikely((__Pyx_modinit_variable_export_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) if (unlikely((__Pyx_modinit_function_export_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) if (unlikely((__Pyx_modinit_type_init_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) if (unlikely((__Pyx_modinit_type_import_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) (void)__Pyx_modinit_variable_import_code(__pyx_mstate); (void)__Pyx_modinit_function_import_code(__pyx_mstate); /*--- Execution code ---*/ /* "pyreadstat/_readstat_parser.pyx":25 * from libc.string cimport memcpy * * from collections import OrderedDict # <<<<<<<<<<<<<< * import datetime * import os */ __pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_OrderedDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_collections, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_OrderedDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_OrderedDict, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":26 * * from collections import OrderedDict * import datetime # <<<<<<<<<<<<<< * import os * import warnings */ __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_datetime, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_datetime, __pyx_t_3) < 0) __PYX_ERR(0, 26, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":27 * from collections import OrderedDict * import datetime * import os # <<<<<<<<<<<<<< * import warnings * import sys */ __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_os, 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_os, __pyx_t_3) < 0) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":28 * import datetime * import os * import warnings # <<<<<<<<<<<<<< * import sys * */ __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_warnings, NULL); 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_warnings, __pyx_t_3) < 0) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":29 * import os * import warnings * import sys # <<<<<<<<<<<<<< * * import narwhals.stable.v2 as nw */ __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_sys, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 29, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_sys, __pyx_t_3) < 0) __PYX_ERR(0, 29, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":31 * import sys * * import narwhals.stable.v2 as nw # <<<<<<<<<<<<<< * import numpy as np * */ __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, 31, __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, 31, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":32 * * import narwhals.stable.v2 as nw * import numpy as np # <<<<<<<<<<<<<< * * from readstat_api cimport * */ __pyx_t_3 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_numpy, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __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, 32, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":37 * * # necessary to work with the datetime C API * import_datetime() # <<<<<<<<<<<<<< * * cdef object unix_origin = datetime_new(1970, 1, 1, 0, 0, 0, 0, None) */ __pyx_f_7cpython_8datetime_import_datetime(); /* "pyreadstat/_readstat_parser.pyx":39 * import_datetime() * * cdef object unix_origin = datetime_new(1970, 1, 1, 0, 0, 0, 0, None) # <<<<<<<<<<<<<< * * cdef list sas_date_formats = ["WEEKDATE", "MMDDYY", "DDMMYY", "YYMMDD", "DATE", "DATE9", "YYMMDD10", */ __pyx_t_3 = ((PyObject *)__pyx_f_7cpython_8datetime_datetime_new(0x7B2, 1, 1, 0, 0, 0, 0, Py_None, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_unix_origin); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_unix_origin, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":41 * cdef object unix_origin = datetime_new(1970, 1, 1, 0, 0, 0, 0, None) * * cdef list sas_date_formats = ["WEEKDATE", "MMDDYY", "DDMMYY", "YYMMDD", "DATE", "DATE9", "YYMMDD10", # <<<<<<<<<<<<<< * "DDMMYYB", "DDMMYYB10", "DDMMYYC", "DDMMYYC10", "DDMMYYD", "DDMMYYD10", * "DDMMYYN6", "DDMMYYN8", "DDMMYYP", "DDMMYYP10", "DDMMYYS", "DDMMYYS10", */ __pyx_t_3 = __Pyx_PyList_Pack(41, __pyx_mstate_global->__pyx_n_u_WEEKDATE, __pyx_mstate_global->__pyx_n_u_MMDDYY, __pyx_mstate_global->__pyx_n_u_DDMMYY, __pyx_mstate_global->__pyx_n_u_YYMMDD, __pyx_mstate_global->__pyx_n_u_DATE, __pyx_mstate_global->__pyx_n_u_DATE9, __pyx_mstate_global->__pyx_n_u_YYMMDD10, __pyx_mstate_global->__pyx_n_u_DDMMYYB, __pyx_mstate_global->__pyx_n_u_DDMMYYB10, __pyx_mstate_global->__pyx_n_u_DDMMYYC, __pyx_mstate_global->__pyx_n_u_DDMMYYC10, __pyx_mstate_global->__pyx_n_u_DDMMYYD, __pyx_mstate_global->__pyx_n_u_DDMMYYD10, __pyx_mstate_global->__pyx_n_u_DDMMYYN6, __pyx_mstate_global->__pyx_n_u_DDMMYYN8, __pyx_mstate_global->__pyx_n_u_DDMMYYP, __pyx_mstate_global->__pyx_n_u_DDMMYYP10, __pyx_mstate_global->__pyx_n_u_DDMMYYS, __pyx_mstate_global->__pyx_n_u_DDMMYYS10, __pyx_mstate_global->__pyx_n_u_MMDDYYB, __pyx_mstate_global->__pyx_n_u_MMDDYYB10, __pyx_mstate_global->__pyx_n_u_MMDDYYC, __pyx_mstate_global->__pyx_n_u_MMDDYYC10, __pyx_mstate_global->__pyx_n_u_MMDDYYD, __pyx_mstate_global->__pyx_n_u_MMDDYYD10, __pyx_mstate_global->__pyx_n_u_MMDDYYN6, __pyx_mstate_global->__pyx_n_u_MMDDYYN8, __pyx_mstate_global->__pyx_n_u_MMDDYYP, __pyx_mstate_global->__pyx_n_u_MMDDYYP10, __pyx_mstate_global->__pyx_n_u_MMDDYYS, __pyx_mstate_global->__pyx_n_u_MMDDYYS10, __pyx_mstate_global->__pyx_n_u_WEEKDATX, __pyx_mstate_global->__pyx_n_u_DTDATE, __pyx_mstate_global->__pyx_n_u_IS8601DA, __pyx_mstate_global->__pyx_n_u_E8601DA, __pyx_mstate_global->__pyx_n_u_B8601DA, __pyx_mstate_global->__pyx_n_u_YYMMDDB, __pyx_mstate_global->__pyx_n_u_YYMMDDD, __pyx_mstate_global->__pyx_n_u_YYMMDDN, __pyx_mstate_global->__pyx_n_u_YYMMDDP, __pyx_mstate_global->__pyx_n_u_YYMMDDS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_sas_date_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":50 * "IS8601DA", "E8601DA", "B8601DA", * "YYMMDDB", "YYMMDDD", "YYMMDDN", "YYMMDDP", "YYMMDDS",] * cdef list sas_datetime_formats = ["DATETIME", "DATETIME18", "DATETIME19", "DATETIME20", "DATETIME21", "DATETIME22", # <<<<<<<<<<<<<< * "E8601DT", "DATEAMPM", "MDYAMPM", "IS8601DT", "B8601DT", "B8601DN"] * cdef list sas_time_formats = ["TIME", "HHMM", "TIME20.3", "TIME20", "TIME5", "TOD", "TIMEAMPM", "IS8601TM", "E8601TM", "B8601TM", ] */ __pyx_t_3 = __Pyx_PyList_Pack(12, __pyx_mstate_global->__pyx_n_u_DATETIME, __pyx_mstate_global->__pyx_n_u_DATETIME18, __pyx_mstate_global->__pyx_n_u_DATETIME19, __pyx_mstate_global->__pyx_n_u_DATETIME20, __pyx_mstate_global->__pyx_n_u_DATETIME21, __pyx_mstate_global->__pyx_n_u_DATETIME22, __pyx_mstate_global->__pyx_n_u_E8601DT, __pyx_mstate_global->__pyx_n_u_DATEAMPM, __pyx_mstate_global->__pyx_n_u_MDYAMPM, __pyx_mstate_global->__pyx_n_u_IS8601DT, __pyx_mstate_global->__pyx_n_u_B8601DT, __pyx_mstate_global->__pyx_n_u_B8601DN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_sas_datetime_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":52 * cdef list sas_datetime_formats = ["DATETIME", "DATETIME18", "DATETIME19", "DATETIME20", "DATETIME21", "DATETIME22", * "E8601DT", "DATEAMPM", "MDYAMPM", "IS8601DT", "B8601DT", "B8601DN"] * cdef list sas_time_formats = ["TIME", "HHMM", "TIME20.3", "TIME20", "TIME5", "TOD", "TIMEAMPM", "IS8601TM", "E8601TM", "B8601TM", ] # <<<<<<<<<<<<<< * # "HOUR" # these do not print as full time formats in sas * #cdef list sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats */ __pyx_t_3 = __Pyx_PyList_Pack(10, __pyx_mstate_global->__pyx_n_u_TIME, __pyx_mstate_global->__pyx_n_u_HHMM, __pyx_mstate_global->__pyx_kp_u_TIME20_3, __pyx_mstate_global->__pyx_n_u_TIME20, __pyx_mstate_global->__pyx_n_u_TIME5, __pyx_mstate_global->__pyx_n_u_TOD, __pyx_mstate_global->__pyx_n_u_TIMEAMPM, __pyx_mstate_global->__pyx_n_u_IS8601TM, __pyx_mstate_global->__pyx_n_u_E8601TM, __pyx_mstate_global->__pyx_n_u_B8601TM); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_sas_time_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":56 * #cdef list sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats * cdef list sas_all_formats * cdef object sas_origin = datetime_new(1960, 1, 1, 0, 0, 0, 0, None) # <<<<<<<<<<<<<< * cdef object sas_secs_from_unix = total_seconds(unix_origin - sas_origin) * */ __pyx_t_3 = ((PyObject *)__pyx_f_7cpython_8datetime_datetime_new(0x7A8, 1, 1, 0, 0, 0, 0, Py_None, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_origin); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_sas_origin, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":57 * cdef list sas_all_formats * cdef object sas_origin = datetime_new(1960, 1, 1, 0, 0, 0, 0, None) * cdef object sas_secs_from_unix = total_seconds(unix_origin - sas_origin) # <<<<<<<<<<<<<< * * cdef list spss_datetime_formats = ["DATETIME", "DATETIME8", 'DATETIME17', 'DATETIME20', 'DATETIME23.2',"YMDHMS16","YMDHMS19","YMDHMS19.2", "YMDHMS20"] */ __pyx_t_3 = PyNumber_Subtract(__pyx_v_10pyreadstat_16_readstat_parser_unix_origin, __pyx_v_10pyreadstat_16_readstat_parser_sas_origin); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 57, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_mstate_global->__pyx_ptype_7cpython_8datetime_timedelta))))) __PYX_ERR(0, 57, __pyx_L1_error) __pyx_t_2 = PyFloat_FromDouble(__pyx_f_7cpython_8datetime_total_seconds(((PyDateTime_Delta *)__pyx_t_3))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 57, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_sas_secs_from_unix); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_sas_secs_from_unix, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":59 * cdef object sas_secs_from_unix = total_seconds(unix_origin - sas_origin) * * cdef list spss_datetime_formats = ["DATETIME", "DATETIME8", 'DATETIME17', 'DATETIME20', 'DATETIME23.2',"YMDHMS16","YMDHMS19","YMDHMS19.2", "YMDHMS20"] # <<<<<<<<<<<<<< * cdef list spss_date_formats = ["DATE",'DATE8','DATE11', 'DATE12', "ADATE","ADATE8", "ADATE10", "EDATE", 'EDATE8','EDATE10', "JDATE", "JDATE5", "JDATE7", "SDATE", "SDATE8", "SDATE10",] * cdef list spss_time_formats = ["TIME", "DTIME", 'TIME8', 'TIME5', 'TIME11.2'] */ __pyx_t_2 = __Pyx_PyList_Pack(9, __pyx_mstate_global->__pyx_n_u_DATETIME, __pyx_mstate_global->__pyx_n_u_DATETIME8, __pyx_mstate_global->__pyx_n_u_DATETIME17, __pyx_mstate_global->__pyx_n_u_DATETIME20, __pyx_mstate_global->__pyx_kp_u_DATETIME23_2, __pyx_mstate_global->__pyx_n_u_YMDHMS16, __pyx_mstate_global->__pyx_n_u_YMDHMS19, __pyx_mstate_global->__pyx_kp_u_YMDHMS19_2, __pyx_mstate_global->__pyx_n_u_YMDHMS20); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 59, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_spss_datetime_formats, ((PyObject*)__pyx_t_2)); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":60 * * cdef list spss_datetime_formats = ["DATETIME", "DATETIME8", 'DATETIME17', 'DATETIME20', 'DATETIME23.2',"YMDHMS16","YMDHMS19","YMDHMS19.2", "YMDHMS20"] * cdef list spss_date_formats = ["DATE",'DATE8','DATE11', 'DATE12', "ADATE","ADATE8", "ADATE10", "EDATE", 'EDATE8','EDATE10', "JDATE", "JDATE5", "JDATE7", "SDATE", "SDATE8", "SDATE10",] # <<<<<<<<<<<<<< * cdef list spss_time_formats = ["TIME", "DTIME", 'TIME8', 'TIME5', 'TIME11.2'] * #cdef list spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats */ __pyx_t_2 = __Pyx_PyList_Pack(16, __pyx_mstate_global->__pyx_n_u_DATE, __pyx_mstate_global->__pyx_n_u_DATE8, __pyx_mstate_global->__pyx_n_u_DATE11, __pyx_mstate_global->__pyx_n_u_DATE12, __pyx_mstate_global->__pyx_n_u_ADATE, __pyx_mstate_global->__pyx_n_u_ADATE8, __pyx_mstate_global->__pyx_n_u_ADATE10, __pyx_mstate_global->__pyx_n_u_EDATE, __pyx_mstate_global->__pyx_n_u_EDATE8, __pyx_mstate_global->__pyx_n_u_EDATE10, __pyx_mstate_global->__pyx_n_u_JDATE, __pyx_mstate_global->__pyx_n_u_JDATE5, __pyx_mstate_global->__pyx_n_u_JDATE7, __pyx_mstate_global->__pyx_n_u_SDATE, __pyx_mstate_global->__pyx_n_u_SDATE8, __pyx_mstate_global->__pyx_n_u_SDATE10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_spss_date_formats, ((PyObject*)__pyx_t_2)); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":61 * cdef list spss_datetime_formats = ["DATETIME", "DATETIME8", 'DATETIME17', 'DATETIME20', 'DATETIME23.2',"YMDHMS16","YMDHMS19","YMDHMS19.2", "YMDHMS20"] * cdef list spss_date_formats = ["DATE",'DATE8','DATE11', 'DATE12', "ADATE","ADATE8", "ADATE10", "EDATE", 'EDATE8','EDATE10', "JDATE", "JDATE5", "JDATE7", "SDATE", "SDATE8", "SDATE10",] * cdef list spss_time_formats = ["TIME", "DTIME", 'TIME8', 'TIME5', 'TIME11.2'] # <<<<<<<<<<<<<< * #cdef list spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats * cdef list spss_all_formats */ __pyx_t_2 = __Pyx_PyList_Pack(5, __pyx_mstate_global->__pyx_n_u_TIME, __pyx_mstate_global->__pyx_n_u_DTIME, __pyx_mstate_global->__pyx_n_u_TIME8, __pyx_mstate_global->__pyx_n_u_TIME5, __pyx_mstate_global->__pyx_kp_u_TIME11_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_spss_time_formats, ((PyObject*)__pyx_t_2)); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":64 * #cdef list spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats * cdef list spss_all_formats * cdef object spss_origin = datetime_new(1582, 10, 14, 0, 0, 0, 0, None) # <<<<<<<<<<<<<< * cdef object spss_secs_from_unix = total_seconds(unix_origin - spss_origin) * */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_8datetime_datetime_new(0x62E, 10, 14, 0, 0, 0, 0, Py_None, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_origin); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_spss_origin, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":65 * cdef list spss_all_formats * cdef object spss_origin = datetime_new(1582, 10, 14, 0, 0, 0, 0, None) * cdef object spss_secs_from_unix = total_seconds(unix_origin - spss_origin) # <<<<<<<<<<<<<< * * cdef list stata_datetime_formats = ["%tC", "%tc"] */ __pyx_t_2 = PyNumber_Subtract(__pyx_v_10pyreadstat_16_readstat_parser_unix_origin, __pyx_v_10pyreadstat_16_readstat_parser_spss_origin); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_7cpython_8datetime_timedelta))))) __PYX_ERR(0, 65, __pyx_L1_error) __pyx_t_3 = PyFloat_FromDouble(__pyx_f_7cpython_8datetime_total_seconds(((PyDateTime_Delta *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_spss_secs_from_unix); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_spss_secs_from_unix, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":67 * cdef object spss_secs_from_unix = total_seconds(unix_origin - spss_origin) * * cdef list stata_datetime_formats = ["%tC", "%tc"] # <<<<<<<<<<<<<< * cdef list stata_date_formats = ["%td", "%d", "%tdD_m_Y", "%tdCCYY-NN-DD"] * cdef list stata_time_formats = ["%tcHH:MM:SS", "%tcHH:MM"] */ __pyx_t_3 = __Pyx_PyList_Pack(2, __pyx_mstate_global->__pyx_kp_u_tC, __pyx_mstate_global->__pyx_kp_u_tc); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_stata_datetime_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":68 * * cdef list stata_datetime_formats = ["%tC", "%tc"] * cdef list stata_date_formats = ["%td", "%d", "%tdD_m_Y", "%tdCCYY-NN-DD"] # <<<<<<<<<<<<<< * cdef list stata_time_formats = ["%tcHH:MM:SS", "%tcHH:MM"] * #cdef list stata_all_formats = stata_datetime_formats + stata_date_formats + stata_time_formats */ __pyx_t_3 = __Pyx_PyList_Pack(4, __pyx_mstate_global->__pyx_kp_u_td, __pyx_mstate_global->__pyx_kp_u_d_2, __pyx_mstate_global->__pyx_kp_u_tdD_m_Y, __pyx_mstate_global->__pyx_kp_u_tdCCYY_NN_DD); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 68, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_stata_date_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":69 * cdef list stata_datetime_formats = ["%tC", "%tc"] * cdef list stata_date_formats = ["%td", "%d", "%tdD_m_Y", "%tdCCYY-NN-DD"] * cdef list stata_time_formats = ["%tcHH:MM:SS", "%tcHH:MM"] # <<<<<<<<<<<<<< * #cdef list stata_all_formats = stata_datetime_formats + stata_date_formats + stata_time_formats * cdef list stata_all_formats */ __pyx_t_3 = __Pyx_PyList_Pack(2, __pyx_mstate_global->__pyx_kp_u_tcHH_MM_SS, __pyx_mstate_global->__pyx_kp_u_tcHH_MM); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 69, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_stata_time_formats, ((PyObject*)__pyx_t_3)); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":72 * #cdef list stata_all_formats = stata_datetime_formats + stata_date_formats + stata_time_formats * cdef list stata_all_formats * cdef object stata_origin = datetime_new(1960, 1, 1, 0, 0, 0, 0, None) # <<<<<<<<<<<<<< * cdef object stata_secs_from_unix = total_seconds(unix_origin - stata_origin) * */ __pyx_t_3 = ((PyObject *)__pyx_f_7cpython_8datetime_datetime_new(0x7A8, 1, 1, 0, 0, 0, 0, Py_None, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_origin); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_stata_origin, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":73 * cdef list stata_all_formats * cdef object stata_origin = datetime_new(1960, 1, 1, 0, 0, 0, 0, None) * cdef object stata_secs_from_unix = total_seconds(unix_origin - stata_origin) # <<<<<<<<<<<<<< * * cdef dict readstat_to_numpy_types = {READSTAT_TYPE_STRING: object, READSTAT_TYPE_STRING_REF: object, */ __pyx_t_3 = PyNumber_Subtract(__pyx_v_10pyreadstat_16_readstat_parser_unix_origin, __pyx_v_10pyreadstat_16_readstat_parser_stata_origin); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_mstate_global->__pyx_ptype_7cpython_8datetime_timedelta))))) __PYX_ERR(0, 73, __pyx_L1_error) __pyx_t_2 = PyFloat_FromDouble(__pyx_f_7cpython_8datetime_total_seconds(((PyDateTime_Delta *)__pyx_t_3))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_stata_secs_from_unix); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_stata_secs_from_unix, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":75 * cdef object stata_secs_from_unix = total_seconds(unix_origin - stata_origin) * * cdef dict readstat_to_numpy_types = {READSTAT_TYPE_STRING: object, READSTAT_TYPE_STRING_REF: object, # <<<<<<<<<<<<<< * READSTAT_TYPE_INT8: np.int64, READSTAT_TYPE_INT16: np.int64, READSTAT_TYPE_INT32:np.int64, * READSTAT_TYPE_FLOAT: np.float64, READSTAT_TYPE_DOUBLE: np.float64} */ __pyx_t_2 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_STRING); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_builtin_object) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_STRING_REF); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_builtin_object) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":76 * * cdef dict readstat_to_numpy_types = {READSTAT_TYPE_STRING: object, READSTAT_TYPE_STRING_REF: object, * READSTAT_TYPE_INT8: np.int64, READSTAT_TYPE_INT16: np.int64, READSTAT_TYPE_INT32:np.int64, # <<<<<<<<<<<<<< * READSTAT_TYPE_FLOAT: np.float64, READSTAT_TYPE_DOUBLE: np.float64} * */ __pyx_t_3 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_INT8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_t_5) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_INT16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_t_2, __pyx_t_5, __pyx_t_4) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_INT32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (PyDict_SetItem(__pyx_t_2, __pyx_t_4, __pyx_t_3) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/_readstat_parser.pyx":77 * cdef dict readstat_to_numpy_types = {READSTAT_TYPE_STRING: object, READSTAT_TYPE_STRING_REF: object, * READSTAT_TYPE_INT8: np.int64, READSTAT_TYPE_INT16: np.int64, READSTAT_TYPE_INT32:np.int64, * READSTAT_TYPE_FLOAT: np.float64, READSTAT_TYPE_DOUBLE: np.float64} # <<<<<<<<<<<<<< * * cdef class data_container: */ __pyx_t_3 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_FLOAT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_t_5) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyLong_From_readstat_type_t(READSTAT_TYPE_DOUBLE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_t_2, __pyx_t_5, __pyx_t_4) < 0) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser_readstat_to_numpy_types, ((PyObject*)__pyx_t_2)); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_16_readstat_parser_14data_container_3__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_data_container___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat__readstat_parser, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "(tree fragment)":3 * def __reduce_cython__(self): * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_16_readstat_parser_14data_container_5__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_data_container___setstate_cython, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat__readstat_parser, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":126 * self.output_format = "" * * class metadata_container: # <<<<<<<<<<<<<< * """ * This class holds metadata we want to give back to python */ __pyx_t_2 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_mstate_global->__pyx_empty_tuple, __pyx_mstate_global->__pyx_n_u_metadata_container, __pyx_mstate_global->__pyx_n_u_metadata_container, (PyObject *) NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat__readstat_parser, __pyx_mstate_global->__pyx_kp_u_This_class_holds_metadata_we_wa); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* "pyreadstat/_readstat_parser.pyx":130 * This class holds metadata we want to give back to python * """ * def __init__(self): # <<<<<<<<<<<<<< * self.column_names = list() * self.column_labels = list() */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_16_readstat_parser_18metadata_container_1__init__, 0, __pyx_mstate_global->__pyx_n_u_metadata_container___init, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat__readstat_parser, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_init, __pyx_t_4) < 0) __PYX_ERR(0, 130, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":126 * self.output_format = "" * * class metadata_container: # <<<<<<<<<<<<<< * """ * This class holds metadata we want to give back to python */ __pyx_t_4 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_mstate_global->__pyx_n_u_metadata_container, __pyx_mstate_global->__pyx_empty_tuple, __pyx_t_2, NULL, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_metadata_container, __pyx_t_4) < 0) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/_readstat_parser.pyx":155 * * * class ReadstatError(Exception): # <<<<<<<<<<<<<< * """ * Just defining a custom exception to raise when readstat gives an error return code. */ __pyx_t_2 = PyTuple_Pack(1, ((PyObject *)(((PyTypeObject*)PyExc_Exception)))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PEP560_update_bases(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_CalculateMetaclass(NULL, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_5, __pyx_t_4, __pyx_mstate_global->__pyx_n_u_ReadstatError, __pyx_mstate_global->__pyx_n_u_ReadstatError, (PyObject *) NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat__readstat_parser, __pyx_mstate_global->__pyx_kp_u_Just_defining_a_custom_exceptio); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__pyx_t_4 != __pyx_t_2) { if (unlikely((PyDict_SetItemString(__pyx_t_3, "__orig_bases__", __pyx_t_2) < 0))) __PYX_ERR(0, 155, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_Py3ClassCreate(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_ReadstatError, __pyx_t_4, __pyx_t_3, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_ReadstatError, __pyx_t_2) < 0) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/_readstat_parser.pyx":161 * pass * * class PyreadstatError(Exception): # <<<<<<<<<<<<<< * """ * Just defining a custom exception to raise when pyreadstat raises an exception. */ __pyx_t_4 = PyTuple_Pack(1, ((PyObject *)(((PyTypeObject*)PyExc_Exception)))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PEP560_update_bases(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_CalculateMetaclass(NULL, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_Py3MetaclassPrepare(__pyx_t_3, __pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError, __pyx_mstate_global->__pyx_n_u_PyreadstatError, (PyObject *) NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat__readstat_parser, __pyx_mstate_global->__pyx_kp_u_Just_defining_a_custom_exceptio_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__pyx_t_5 != __pyx_t_4) { if (unlikely((PyDict_SetItemString(__pyx_t_2, "__orig_bases__", __pyx_t_4) < 0))) __PYX_ERR(0, 161, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_PyreadstatError, __pyx_t_5, __pyx_t_2, NULL, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_PyreadstatError, __pyx_t_4) < 0) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_DECREF(__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; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "pyreadstat/_readstat_parser.pyx":868 * * * cdef object _file_object_ctx = None # <<<<<<<<<<<<<< * * cdef int pyobject_open_handler(const char *path, void *io_ctx) noexcept: */ __Pyx_INCREF(Py_None); __Pyx_XGOTREF(__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx); __Pyx_DECREF_SET(__pyx_v_10pyreadstat_16_readstat_parser__file_object_ctx, Py_None); __Pyx_GIVEREF(Py_None); /* "pyreadstat/_readstat_parser.pyx":1 * # cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # <<<<<<<<<<<<<< * * # ############################################################################# */ __pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_5) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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); if (__pyx_m) { if (__pyx_mstate->__pyx_d && stringtab_initialized) { __Pyx_AddTraceback("init pyreadstat._readstat_parser", __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_parser"); } __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, 0, 0}, /* PyObject cname: __pyx_kp_b_ */ {__pyx_k_, sizeof(__pyx_k_), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_ */ {__pyx_k_ADATE, sizeof(__pyx_k_ADATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ADATE */ {__pyx_k_ADATE10, sizeof(__pyx_k_ADATE10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ADATE10 */ {__pyx_k_ADATE8, sizeof(__pyx_k_ADATE8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ADATE8 */ {__pyx_k_B8601DA, sizeof(__pyx_k_B8601DA), 0, 1, 1}, /* PyObject cname: __pyx_n_u_B8601DA */ {__pyx_k_B8601DN, sizeof(__pyx_k_B8601DN), 0, 1, 1}, /* PyObject cname: __pyx_n_u_B8601DN */ {__pyx_k_B8601DT, sizeof(__pyx_k_B8601DT), 0, 1, 1}, /* PyObject cname: __pyx_n_u_B8601DT */ {__pyx_k_B8601TM, sizeof(__pyx_k_B8601TM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_B8601TM */ {__pyx_k_DATE, sizeof(__pyx_k_DATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATE */ {__pyx_k_DATE11, sizeof(__pyx_k_DATE11), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATE11 */ {__pyx_k_DATE12, sizeof(__pyx_k_DATE12), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATE12 */ {__pyx_k_DATE8, sizeof(__pyx_k_DATE8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATE8 */ {__pyx_k_DATE9, sizeof(__pyx_k_DATE9), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATE9 */ {__pyx_k_DATEAMPM, sizeof(__pyx_k_DATEAMPM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATEAMPM */ {__pyx_k_DATETIME, sizeof(__pyx_k_DATETIME), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME */ {__pyx_k_DATETIME17, sizeof(__pyx_k_DATETIME17), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME17 */ {__pyx_k_DATETIME18, sizeof(__pyx_k_DATETIME18), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME18 */ {__pyx_k_DATETIME19, sizeof(__pyx_k_DATETIME19), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME19 */ {__pyx_k_DATETIME20, sizeof(__pyx_k_DATETIME20), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME20 */ {__pyx_k_DATETIME21, sizeof(__pyx_k_DATETIME21), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME21 */ {__pyx_k_DATETIME22, sizeof(__pyx_k_DATETIME22), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME22 */ {__pyx_k_DATETIME23_2, sizeof(__pyx_k_DATETIME23_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_DATETIME23_2 */ {__pyx_k_DATETIME8, sizeof(__pyx_k_DATETIME8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DATETIME8 */ {__pyx_k_DDMMYY, sizeof(__pyx_k_DDMMYY), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYY */ {__pyx_k_DDMMYYB, sizeof(__pyx_k_DDMMYYB), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYB */ {__pyx_k_DDMMYYB10, sizeof(__pyx_k_DDMMYYB10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYB10 */ {__pyx_k_DDMMYYC, sizeof(__pyx_k_DDMMYYC), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYC */ {__pyx_k_DDMMYYC10, sizeof(__pyx_k_DDMMYYC10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYC10 */ {__pyx_k_DDMMYYD, sizeof(__pyx_k_DDMMYYD), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYD */ {__pyx_k_DDMMYYD10, sizeof(__pyx_k_DDMMYYD10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYD10 */ {__pyx_k_DDMMYYN6, sizeof(__pyx_k_DDMMYYN6), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYN6 */ {__pyx_k_DDMMYYN8, sizeof(__pyx_k_DDMMYYN8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYN8 */ {__pyx_k_DDMMYYP, sizeof(__pyx_k_DDMMYYP), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYP */ {__pyx_k_DDMMYYP10, sizeof(__pyx_k_DDMMYYP10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYP10 */ {__pyx_k_DDMMYYS, sizeof(__pyx_k_DDMMYYS), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYS */ {__pyx_k_DDMMYYS10, sizeof(__pyx_k_DDMMYYS10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DDMMYYS10 */ {__pyx_k_DTDATE, sizeof(__pyx_k_DTDATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DTDATE */ {__pyx_k_DTIME, sizeof(__pyx_k_DTIME), 0, 1, 1}, /* PyObject cname: __pyx_n_u_DTIME */ {__pyx_k_E8601DA, sizeof(__pyx_k_E8601DA), 0, 1, 1}, /* PyObject cname: __pyx_n_u_E8601DA */ {__pyx_k_E8601DT, sizeof(__pyx_k_E8601DT), 0, 1, 1}, /* PyObject cname: __pyx_n_u_E8601DT */ {__pyx_k_E8601TM, sizeof(__pyx_k_E8601TM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_E8601TM */ {__pyx_k_EDATE, sizeof(__pyx_k_EDATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_EDATE */ {__pyx_k_EDATE10, sizeof(__pyx_k_EDATE10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_EDATE10 */ {__pyx_k_EDATE8, sizeof(__pyx_k_EDATE8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_EDATE8 */ {__pyx_k_Failed_convert_C_to_python_value, sizeof(__pyx_k_Failed_convert_C_to_python_value), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Failed_convert_C_to_python_value */ {__pyx_k_Failed_to_read_number_of_variabl, sizeof(__pyx_k_Failed_to_read_number_of_variabl), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Failed_to_read_number_of_variabl */ {__pyx_k_File_0_does_not_exist, sizeof(__pyx_k_File_0_does_not_exist), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_File_0_does_not_exist */ {__pyx_k_HHMM, sizeof(__pyx_k_HHMM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_HHMM */ {__pyx_k_IS8601DA, sizeof(__pyx_k_IS8601DA), 0, 1, 1}, /* PyObject cname: __pyx_n_u_IS8601DA */ {__pyx_k_IS8601DT, sizeof(__pyx_k_IS8601DT), 0, 1, 1}, /* PyObject cname: __pyx_n_u_IS8601DT */ {__pyx_k_IS8601TM, sizeof(__pyx_k_IS8601TM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_IS8601TM */ {__pyx_k_JDATE, sizeof(__pyx_k_JDATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_JDATE */ {__pyx_k_JDATE5, sizeof(__pyx_k_JDATE5), 0, 1, 1}, /* PyObject cname: __pyx_n_u_JDATE5 */ {__pyx_k_JDATE7, sizeof(__pyx_k_JDATE7), 0, 1, 1}, /* PyObject cname: __pyx_n_u_JDATE7 */ {__pyx_k_Just_defining_a_custom_exceptio, sizeof(__pyx_k_Just_defining_a_custom_exceptio), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Just_defining_a_custom_exceptio */ {__pyx_k_Just_defining_a_custom_exceptio_2, sizeof(__pyx_k_Just_defining_a_custom_exceptio_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Just_defining_a_custom_exceptio_2 */ {__pyx_k_M8_ns, sizeof(__pyx_k_M8_ns), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_M8_ns */ {__pyx_k_MDYAMPM, sizeof(__pyx_k_MDYAMPM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MDYAMPM */ {__pyx_k_MMDDYY, sizeof(__pyx_k_MMDDYY), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYY */ {__pyx_k_MMDDYYB, sizeof(__pyx_k_MMDDYYB), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYB */ {__pyx_k_MMDDYYB10, sizeof(__pyx_k_MMDDYYB10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYB10 */ {__pyx_k_MMDDYYC, sizeof(__pyx_k_MMDDYYC), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYC */ {__pyx_k_MMDDYYC10, sizeof(__pyx_k_MMDDYYC10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYC10 */ {__pyx_k_MMDDYYD, sizeof(__pyx_k_MMDDYYD), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYD */ {__pyx_k_MMDDYYD10, sizeof(__pyx_k_MMDDYYD10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYD10 */ {__pyx_k_MMDDYYN6, sizeof(__pyx_k_MMDDYYN6), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYN6 */ {__pyx_k_MMDDYYN8, sizeof(__pyx_k_MMDDYYN8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYN8 */ {__pyx_k_MMDDYYP, sizeof(__pyx_k_MMDDYYP), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYP */ {__pyx_k_MMDDYYP10, sizeof(__pyx_k_MMDDYYP10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYP10 */ {__pyx_k_MMDDYYS, sizeof(__pyx_k_MMDDYYS), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYS */ {__pyx_k_MMDDYYS10, sizeof(__pyx_k_MMDDYYS10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_MMDDYYS10 */ {__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_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 1, 1}, /* PyObject cname: __pyx_n_u_OrderedDict */ {__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_SDATE, sizeof(__pyx_k_SDATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_SDATE */ {__pyx_k_SDATE10, sizeof(__pyx_k_SDATE10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_SDATE10 */ {__pyx_k_SDATE8, sizeof(__pyx_k_SDATE8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_SDATE8 */ {__pyx_k_STRING_type_with_value, sizeof(__pyx_k_STRING_type_with_value), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_STRING_type_with_value */ {__pyx_k_TIME, sizeof(__pyx_k_TIME), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TIME */ {__pyx_k_TIME11_2, sizeof(__pyx_k_TIME11_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_TIME11_2 */ {__pyx_k_TIME20, sizeof(__pyx_k_TIME20), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TIME20 */ {__pyx_k_TIME20_3, sizeof(__pyx_k_TIME20_3), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_TIME20_3 */ {__pyx_k_TIME5, sizeof(__pyx_k_TIME5), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TIME5 */ {__pyx_k_TIME8, sizeof(__pyx_k_TIME8), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TIME8 */ {__pyx_k_TIMEAMPM, sizeof(__pyx_k_TIMEAMPM), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TIMEAMPM */ {__pyx_k_TOD, sizeof(__pyx_k_TOD), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TOD */ {__pyx_k_This_class_holds_metadata_we_wa, sizeof(__pyx_k_This_class_holds_metadata_we_wa), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_This_class_holds_metadata_we_wa */ {__pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_TypeError */ {__pyx_k_UnicodeError, sizeof(__pyx_k_UnicodeError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_UnicodeError */ {__pyx_k_Unknown_file_format, sizeof(__pyx_k_Unknown_file_format), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Unknown_file_format */ {__pyx_k_Unkown_data_type, sizeof(__pyx_k_Unkown_data_type), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Unkown_data_type */ {__pyx_k_WEEKDATE, sizeof(__pyx_k_WEEKDATE), 0, 1, 1}, /* PyObject cname: __pyx_n_u_WEEKDATE */ {__pyx_k_WEEKDATX, sizeof(__pyx_k_WEEKDATX), 0, 1, 1}, /* PyObject cname: __pyx_n_u_WEEKDATX */ {__pyx_k_YMDHMS16, sizeof(__pyx_k_YMDHMS16), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YMDHMS16 */ {__pyx_k_YMDHMS19, sizeof(__pyx_k_YMDHMS19), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YMDHMS19 */ {__pyx_k_YMDHMS19_2, sizeof(__pyx_k_YMDHMS19_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_YMDHMS19_2 */ {__pyx_k_YMDHMS20, sizeof(__pyx_k_YMDHMS20), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YMDHMS20 */ {__pyx_k_YYMMDD, sizeof(__pyx_k_YYMMDD), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDD */ {__pyx_k_YYMMDD10, sizeof(__pyx_k_YYMMDD10), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDD10 */ {__pyx_k_YYMMDDB, sizeof(__pyx_k_YYMMDDB), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDDB */ {__pyx_k_YYMMDDD, sizeof(__pyx_k_YYMMDDD), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDDD */ {__pyx_k_YYMMDDN, sizeof(__pyx_k_YYMMDDN), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDDN */ {__pyx_k_YYMMDDP, sizeof(__pyx_k_YYMMDDP), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDDP */ {__pyx_k_YYMMDDS, sizeof(__pyx_k_YYMMDDS), 0, 1, 1}, /* PyObject cname: __pyx_n_u_YYMMDDS */ {__pyx_k_You_requested_pandas_as_output_f, sizeof(__pyx_k_You_requested_pandas_as_output_f), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_You_requested_pandas_as_output_f */ {__pyx_k_You_requested_polars_as_output_f, sizeof(__pyx_k_You_requested_polars_as_output_f), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_You_requested_polars_as_output_f */ {__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, 0}, /* PyObject cname: __pyx_kp_u__4 */ {__pyx_k_all, sizeof(__pyx_k_all), 0, 1, 1}, /* PyObject cname: __pyx_n_u_all */ {__pyx_k_allowed_formats, sizeof(__pyx_k_allowed_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_allowed_formats */ {__pyx_k_append, sizeof(__pyx_k_append), 0, 1, 1}, /* PyObject cname: __pyx_n_u_append */ {__pyx_k_astype, sizeof(__pyx_k_astype), 0, 1, 1}, /* PyObject cname: __pyx_n_u_astype */ {__pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 1, 1}, /* PyObject cname: __pyx_n_u_asyncio_coroutines */ {__pyx_k_backend, sizeof(__pyx_k_backend), 0, 1, 1}, /* PyObject cname: __pyx_n_u_backend */ {__pyx_k_center, sizeof(__pyx_k_center), 0, 1, 1}, /* PyObject cname: __pyx_n_u_center */ {__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_col, sizeof(__pyx_k_col), 0, 1, 1}, /* PyObject cname: __pyx_n_u_col */ {__pyx_k_collections, sizeof(__pyx_k_collections), 0, 1, 1}, /* PyObject cname: __pyx_n_u_collections */ {__pyx_k_column_0_is_duplicated_renamed_t, sizeof(__pyx_k_column_0_is_duplicated_renamed_t), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_column_0_is_duplicated_renamed_t */ {__pyx_k_column_labels, sizeof(__pyx_k_column_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_column_labels */ {__pyx_k_column_names, sizeof(__pyx_k_column_names), 0, 1, 1}, /* PyObject cname: __pyx_n_u_column_names */ {__pyx_k_column_names_to_labels, sizeof(__pyx_k_column_names_to_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_column_names_to_labels */ {__pyx_k_columns, sizeof(__pyx_k_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_columns */ {__pyx_k_copy, sizeof(__pyx_k_copy), 0, 1, 1}, /* PyObject cname: __pyx_n_u_copy */ {__pyx_k_counted_value, sizeof(__pyx_k_counted_value), 0, 1, 1}, /* PyObject cname: __pyx_n_u_counted_value */ {__pyx_k_creation_time, sizeof(__pyx_k_creation_time), 0, 1, 1}, /* PyObject cname: __pyx_n_u_creation_time */ {__pyx_k_d, sizeof(__pyx_k_d), 0, 1, 1}, /* PyObject cname: __pyx_n_u_d */ {__pyx_k_d_2, sizeof(__pyx_k_d_2), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_d_2 */ {__pyx_k_data_container, sizeof(__pyx_k_data_container), 0, 1, 1}, /* PyObject cname: __pyx_n_u_data_container */ {__pyx_k_data_container___reduce_cython, sizeof(__pyx_k_data_container___reduce_cython), 0, 1, 1}, /* PyObject cname: __pyx_n_u_data_container___reduce_cython */ {__pyx_k_data_container___setstate_cython, sizeof(__pyx_k_data_container___setstate_cython), 0, 1, 1}, /* PyObject cname: __pyx_n_u_data_container___setstate_cython */ {__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_dict, sizeof(__pyx_k_dict), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dict */ {__pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_disable */ {__pyx_k_doc, sizeof(__pyx_k_doc), 0, 1, 1}, /* PyObject cname: __pyx_n_u_doc */ {__pyx_k_double, sizeof(__pyx_k_double), 0, 1, 1}, /* PyObject cname: __pyx_n_u_double */ {__pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dtype */ {__pyx_k_dtypes, sizeof(__pyx_k_dtypes), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dtypes */ {__pyx_k_duplicated, sizeof(__pyx_k_duplicated), 0, 1, 1}, /* PyObject cname: __pyx_n_u_duplicated */ {__pyx_k_empty, sizeof(__pyx_k_empty), 0, 1, 1}, /* PyObject cname: __pyx_n_u_empty */ {__pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_enable */ {__pyx_k_encode, sizeof(__pyx_k_encode), 0, 1, 1}, /* PyObject cname: __pyx_n_u_encode */ {__pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_enumerate */ {__pyx_k_expanduser, sizeof(__pyx_k_expanduser), 0, 1, 1}, /* PyObject cname: __pyx_n_u_expanduser */ {__pyx_k_extend, sizeof(__pyx_k_extend), 0, 1, 1}, /* PyObject cname: __pyx_n_u_extend */ {__pyx_k_file_encoding, sizeof(__pyx_k_file_encoding), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_encoding */ {__pyx_k_file_label, sizeof(__pyx_k_file_label), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_label */ {__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_fill, sizeof(__pyx_k_fill), 0, 1, 1}, /* PyObject cname: __pyx_n_u_fill */ {__pyx_k_float, sizeof(__pyx_k_float), 0, 1, 1}, /* PyObject cname: __pyx_n_u_float */ {__pyx_k_float64, sizeof(__pyx_k_float64), 0, 1, 1}, /* PyObject cname: __pyx_n_u_float64 */ {__pyx_k_format, sizeof(__pyx_k_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_format */ {__pyx_k_from_dict, sizeof(__pyx_k_from_dict), 0, 1, 1}, /* PyObject cname: __pyx_n_u_from_dict */ {__pyx_k_from_epoch, sizeof(__pyx_k_from_epoch), 0, 1, 1}, /* PyObject cname: __pyx_n_u_from_epoch */ {__pyx_k_fromtimestamp, sizeof(__pyx_k_fromtimestamp), 0, 1, 1}, /* PyObject cname: __pyx_n_u_fromtimestamp */ {__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_func, sizeof(__pyx_k_func), 0, 1, 1}, /* PyObject cname: __pyx_n_u_func */ {__pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_gc */ {__pyx_k_get, sizeof(__pyx_k_get), 0, 1, 1}, /* PyObject cname: __pyx_n_u_get */ {__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_getstate, sizeof(__pyx_k_getstate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_getstate */ {__pyx_k_hi, sizeof(__pyx_k_hi), 0, 1, 1}, /* PyObject cname: __pyx_n_u_hi */ {__pyx_k_init, sizeof(__pyx_k_init), 0, 1, 1}, /* PyObject cname: __pyx_n_u_init */ {__pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 1, 1}, /* PyObject cname: __pyx_n_u_initializing */ {__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_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_coroutine */ {__pyx_k_is_dichotomy, sizeof(__pyx_k_is_dichotomy), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_dichotomy */ {__pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_isenabled */ {__pyx_k_isfile, sizeof(__pyx_k_isfile), 0, 1, 1}, /* PyObject cname: __pyx_n_u_isfile */ {__pyx_k_items, sizeof(__pyx_k_items), 0, 1, 1}, /* PyObject cname: __pyx_n_u_items */ {__pyx_k_keys, sizeof(__pyx_k_keys), 0, 1, 1}, /* PyObject cname: __pyx_n_u_keys */ {__pyx_k_label, sizeof(__pyx_k_label), 0, 1, 1}, /* PyObject cname: __pyx_n_u_label */ {__pyx_k_left, sizeof(__pyx_k_left), 0, 1, 1}, /* PyObject cname: __pyx_n_u_left */ {__pyx_k_lo, sizeof(__pyx_k_lo), 0, 1, 1}, /* PyObject cname: __pyx_n_u_lo */ {__pyx_k_loc, sizeof(__pyx_k_loc), 0, 1, 1}, /* PyObject cname: __pyx_n_u_loc */ {__pyx_k_main, sizeof(__pyx_k_main), 0, 1, 1}, /* PyObject cname: __pyx_n_u_main */ {__pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 1, 1}, /* PyObject cname: __pyx_n_u_metaclass */ {__pyx_k_metadata_container, sizeof(__pyx_k_metadata_container), 0, 1, 1}, /* PyObject cname: __pyx_n_u_metadata_container */ {__pyx_k_metadata_container___init, sizeof(__pyx_k_metadata_container___init), 0, 1, 1}, /* PyObject cname: __pyx_n_u_metadata_container___init */ {__pyx_k_missing_ranges, sizeof(__pyx_k_missing_ranges), 0, 1, 1}, /* PyObject cname: __pyx_n_u_missing_ranges */ {__pyx_k_missing_user_values, sizeof(__pyx_k_missing_user_values), 0, 1, 1}, /* PyObject cname: __pyx_n_u_missing_user_values */ {__pyx_k_modification_time, sizeof(__pyx_k_modification_time), 0, 1, 1}, /* PyObject cname: __pyx_n_u_modification_time */ {__pyx_k_module, sizeof(__pyx_k_module), 0, 1, 1}, /* PyObject cname: __pyx_n_u_module */ {__pyx_k_mr_sets, sizeof(__pyx_k_mr_sets), 0, 1, 1}, /* PyObject cname: __pyx_n_u_mr_sets */ {__pyx_k_mro_entries, sizeof(__pyx_k_mro_entries), 0, 1, 1}, /* PyObject cname: __pyx_n_u_mro_entries */ {__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_nan, sizeof(__pyx_k_nan), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nan */ {__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_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_no_default___reduce___due_to_non */ {__pyx_k_nominal, sizeof(__pyx_k_nominal), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nominal */ {__pyx_k_notes, sizeof(__pyx_k_notes), 0, 1, 1}, /* PyObject cname: __pyx_n_u_notes */ {__pyx_k_np, sizeof(__pyx_k_np), 0, 1, 1}, /* PyObject cname: __pyx_n_u_np */ {__pyx_k_nt, sizeof(__pyx_k_nt), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nt */ {__pyx_k_number_columns, sizeof(__pyx_k_number_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_number_columns */ {__pyx_k_number_rows, sizeof(__pyx_k_number_rows), 0, 1, 1}, /* PyObject cname: __pyx_n_u_number_rows */ {__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_object, sizeof(__pyx_k_object), 0, 1, 1}, /* PyObject cname: __pyx_n_u_object */ {__pyx_k_ordinal, sizeof(__pyx_k_ordinal), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ordinal */ {__pyx_k_original_variable_types, sizeof(__pyx_k_original_variable_types), 0, 1, 1}, /* PyObject cname: __pyx_n_u_original_variable_types */ {__pyx_k_os, sizeof(__pyx_k_os), 0, 1, 1}, /* PyObject cname: __pyx_n_u_os */ {__pyx_k_output_format, sizeof(__pyx_k_output_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_output_format */ {__pyx_k_output_format_must_be_one_of_all, sizeof(__pyx_k_output_format_must_be_one_of_all), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_output_format_must_be_one_of_all */ {__pyx_k_pandas, sizeof(__pyx_k_pandas), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pandas */ {__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_path_must_be_str_bytes_or_unicod, sizeof(__pyx_k_path_must_be_str_bytes_or_unicod), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_path_must_be_str_bytes_or_unicod */ {__pyx_k_polars, sizeof(__pyx_k_polars), 0, 1, 1}, /* PyObject cname: __pyx_n_u_polars */ {__pyx_k_pop, sizeof(__pyx_k_pop), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pop */ {__pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 1, 1}, /* PyObject cname: __pyx_n_u_prepare */ {__pyx_k_pyreadstat__readstat_parser, sizeof(__pyx_k_pyreadstat__readstat_parser), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pyreadstat__readstat_parser */ {__pyx_k_pyreadstat__readstat_parser_pyx, sizeof(__pyx_k_pyreadstat__readstat_parser_pyx), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_pyreadstat__readstat_parser_pyx */ {__pyx_k_pyx_capi, sizeof(__pyx_k_pyx_capi), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pyx_capi */ {__pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pyx_state */ {__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_read, sizeof(__pyx_k_read), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read */ {__pyx_k_readstat_to_numpy_types, sizeof(__pyx_k_readstat_to_numpy_types), 0, 1, 1}, /* PyObject cname: __pyx_n_u_readstat_to_numpy_types */ {__pyx_k_readstat_variable_types, sizeof(__pyx_k_readstat_variable_types), 0, 1, 1}, /* PyObject cname: __pyx_n_u_readstat_variable_types */ {__pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 1, 1}, /* PyObject cname: __pyx_n_u_reduce */ {__pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 1, 1}, /* PyObject cname: __pyx_n_u_reduce_cython */ {__pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 1, 1}, /* PyObject cname: __pyx_n_u_reduce_ex */ {__pyx_k_right, sizeof(__pyx_k_right), 0, 1, 1}, /* PyObject cname: __pyx_n_u_right */ {__pyx_k_s, sizeof(__pyx_k_s), 0, 1, 1}, /* PyObject cname: __pyx_n_u_s */ {__pyx_k_sas_all_formats, sizeof(__pyx_k_sas_all_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas_all_formats */ {__pyx_k_sas_date_formats, sizeof(__pyx_k_sas_date_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas_date_formats */ {__pyx_k_sas_datetime_formats, sizeof(__pyx_k_sas_datetime_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas_datetime_formats */ {__pyx_k_sas_origin, sizeof(__pyx_k_sas_origin), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas_origin */ {__pyx_k_sas_time_formats, sizeof(__pyx_k_sas_time_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas_time_formats */ {__pyx_k_scale, sizeof(__pyx_k_scale), 0, 1, 1}, /* PyObject cname: __pyx_n_u_scale */ {__pyx_k_schema, sizeof(__pyx_k_schema), 0, 1, 1}, /* PyObject cname: __pyx_n_u_schema */ {__pyx_k_seek, sizeof(__pyx_k_seek), 0, 1, 1}, /* PyObject cname: __pyx_n_u_seek */ {__pyx_k_self, sizeof(__pyx_k_self), 0, 1, 1}, /* PyObject cname: __pyx_n_u_self */ {__pyx_k_set_name, sizeof(__pyx_k_set_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_set_name */ {__pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_setstate */ {__pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 1, 1}, /* PyObject cname: __pyx_n_u_setstate_cython */ {__pyx_k_spec, sizeof(__pyx_k_spec), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spec */ {__pyx_k_spss_all_formats, sizeof(__pyx_k_spss_all_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spss_all_formats */ {__pyx_k_spss_date_formats, sizeof(__pyx_k_spss_date_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spss_date_formats */ {__pyx_k_spss_datetime_formats, sizeof(__pyx_k_spss_datetime_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spss_datetime_formats */ {__pyx_k_spss_origin, sizeof(__pyx_k_spss_origin), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spss_origin */ {__pyx_k_spss_time_formats, sizeof(__pyx_k_spss_time_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_spss_time_formats */ {__pyx_k_stable, sizeof(__pyx_k_stable), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stable */ {__pyx_k_stata_all_formats, sizeof(__pyx_k_stata_all_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stata_all_formats */ {__pyx_k_stata_date_formats, sizeof(__pyx_k_stata_date_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stata_date_formats */ {__pyx_k_stata_datetime_formats, sizeof(__pyx_k_stata_datetime_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stata_datetime_formats */ {__pyx_k_stata_origin, sizeof(__pyx_k_stata_origin), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stata_origin */ {__pyx_k_stata_time_formats, sizeof(__pyx_k_stata_time_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_stata_time_formats */ {__pyx_k_string, sizeof(__pyx_k_string), 0, 1, 1}, /* PyObject cname: __pyx_n_u_string */ {__pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_stringsource */ {__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_tC, sizeof(__pyx_k_tC), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_tC */ {__pyx_k_table_name, sizeof(__pyx_k_table_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_table_name */ {__pyx_k_tc, sizeof(__pyx_k_tc), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_tc */ {__pyx_k_tcHH_MM, sizeof(__pyx_k_tcHH_MM), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_tcHH_MM */ {__pyx_k_tcHH_MM_SS, sizeof(__pyx_k_tcHH_MM_SS), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_tcHH_MM_SS */ {__pyx_k_td, sizeof(__pyx_k_td), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_td */ {__pyx_k_tdCCYY_NN_DD, sizeof(__pyx_k_tdCCYY_NN_DD), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_tdCCYY_NN_DD */ {__pyx_k_tdD_m_Y, sizeof(__pyx_k_tdD_m_Y), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_tdD_m_Y */ {__pyx_k_tell, sizeof(__pyx_k_tell), 0, 1, 1}, /* PyObject cname: __pyx_n_u_tell */ {__pyx_k_test, sizeof(__pyx_k_test), 0, 1, 1}, /* PyObject cname: __pyx_n_u_test */ {__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_to_datetime, sizeof(__pyx_k_to_datetime), 0, 1, 1}, /* PyObject cname: __pyx_n_u_to_datetime */ {__pyx_k_to_native, sizeof(__pyx_k_to_native), 0, 1, 1}, /* PyObject cname: __pyx_n_u_to_native */ {__pyx_k_tolist, sizeof(__pyx_k_tolist), 0, 1, 1}, /* PyObject cname: __pyx_n_u_tolist */ {__pyx_k_type, sizeof(__pyx_k_type), 0, 1, 1}, /* PyObject cname: __pyx_n_u_type */ {__pyx_k_undetermined, sizeof(__pyx_k_undetermined), 0, 1, 1}, /* PyObject cname: __pyx_n_u_undetermined */ {__pyx_k_unknown, sizeof(__pyx_k_unknown), 0, 1, 1}, /* PyObject cname: __pyx_n_u_unknown */ {__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_value_labels, sizeof(__pyx_k_value_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_value_labels */ {__pyx_k_variable_alignment, sizeof(__pyx_k_variable_alignment), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_alignment */ {__pyx_k_variable_display_width, sizeof(__pyx_k_variable_display_width), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_display_width */ {__pyx_k_variable_list, sizeof(__pyx_k_variable_list), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_list */ {__pyx_k_variable_measure, sizeof(__pyx_k_variable_measure), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_measure */ {__pyx_k_variable_storage_width, sizeof(__pyx_k_variable_storage_width), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_storage_width */ {__pyx_k_variable_to_label, sizeof(__pyx_k_variable_to_label), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_to_label */ {__pyx_k_variable_value_labels, sizeof(__pyx_k_variable_value_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_value_labels */ {__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_with_columns, sizeof(__pyx_k_with_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_with_columns */ {__pyx_k_with_date_type_in_column, sizeof(__pyx_k_with_date_type_in_column), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_with_date_type_in_column */ {__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_object = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_object); if (!__pyx_builtin_object) __PYX_ERR(0, 75, __pyx_L1_error) __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_range); if (!__pyx_builtin_range) __PYX_ERR(0, 435, __pyx_L1_error) __pyx_builtin_all = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_all); if (!__pyx_builtin_all) __PYX_ERR(0, 1087, __pyx_L1_error) __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 1106, __pyx_L1_error) __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 1205, __pyx_L1_error) __pyx_builtin_UnicodeError = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_UnicodeError); if (!__pyx_builtin_UnicodeError) __PYX_ERR(0, 1253, __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_parser.pyx":1109 * var_format = dc.col_formats[index] * if dtypes[index] != '__pyx_slice[0] = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_slice[0])) __PYX_ERR(0, 1109, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[0]); /* "pyreadstat/_readstat_parser.pyx":1255 * 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, 1255, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]); /* "pyreadstat/_readstat_parser.pyx":31 * import sys * * import narwhals.stable.v2 as nw # <<<<<<<<<<<<<< * import numpy as np * */ __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, 31, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[1]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[1]); __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; __pyx_mstate->__pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type; __pyx_mstate->__pyx_umethod_PyDict_Type_pop.method_name = &__pyx_mstate->__pyx_n_u_pop; 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_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_100000 = PyLong_FromLong(100000L); if (unlikely(!__pyx_mstate->__pyx_int_100000)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } /* #### Code section: init_codeobjects ### */ \ typedef struct { unsigned int argcount : 2; unsigned int num_posonly_args : 1; unsigned int num_kwonly_args : 1; unsigned int nlocals : 2; unsigned int flags : 10; unsigned int first_line : 8; unsigned int line_table_length : 12; } __Pyx_PyCode_New_function_description; /* NewCodeObj.proto */ static PyObject* __Pyx_PyCode_New( const __Pyx_PyCode_New_function_description descr, PyObject * const *varnames, PyObject *filename, PyObject *funcname, const char *line_table, PyObject *tuple_dedup_map ); static int __Pyx_CreateCodeObjects(__pyx_mstatetype *__pyx_mstate) { PyObject* tuple_dedup_map = PyDict_New(); if (unlikely(!tuple_dedup_map)) return -1; { const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 1, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 1, 9}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self}; __pyx_mstate_global->__pyx_codeobj_tab[0] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_k_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[0])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 2, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 3, 9}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_pyx_state}; __pyx_mstate_global->__pyx_codeobj_tab[1] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_k_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[1])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 1, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 130, 174}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self}; __pyx_mstate_global->__pyx_codeobj_tab[2] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat__readstat_parser_pyx, __pyx_mstate->__pyx_n_u_init, __pyx_k_A_Q_a_O1_Q_M_1_1_N_q_a_A_Q_O1, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[2])) goto bad; } Py_DECREF(tuple_dedup_map); return 0; bad: Py_DECREF(tuple_dedup_map); return -1; } /* #### 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) /* CachedMethodType.init */ #if CYTHON_COMPILING_IN_LIMITED_API { PyObject *typesModule=NULL; typesModule = PyImport_ImportModule("types"); if (typesModule) { __pyx_mstate_global->__Pyx_CachedMethodType = PyObject_GetAttrString(typesModule, "MethodType"); Py_DECREF(typesModule); } } // error handling follows #endif 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= 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; } /* ExtTypeTest */ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { __Pyx_TypeName obj_type_name; __Pyx_TypeName type_name; if (unlikely(!type)) { PyErr_SetString(PyExc_SystemError, "Missing type object"); return 0; } if (likely(__Pyx_TypeCheck(obj, type))) return 1; obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj)); type_name = __Pyx_PyType_GetFullyQualifiedName(type); PyErr_Format(PyExc_TypeError, "Cannot convert " __Pyx_FMT_TYPENAME " to " __Pyx_FMT_TYPENAME, obj_type_name, type_name); __Pyx_DECREF_TypeName(obj_type_name); __Pyx_DECREF_TypeName(type_name); return 0; } /* TupleAndListFromArray */ #if !CYTHON_COMPILING_IN_CPYTHON && CYTHON_METH_FASTCALL static CYTHON_INLINE PyObject * __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) { PyObject *res; Py_ssize_t i; if (n <= 0) { return __Pyx_NewRef(__pyx_mstate_global->__pyx_empty_tuple); } res = PyTuple_New(n); if (unlikely(res == NULL)) return NULL; for (i = 0; i < n; i++) { if (unlikely(__Pyx_PyTuple_SET_ITEM(res, i, src[i]) < 0)) { Py_DECREF(res); return NULL; } Py_INCREF(src[i]); } return res; } #elif CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { PyObject *v; Py_ssize_t i; for (i = 0; i < length; i++) { v = dest[i] = src[i]; Py_INCREF(v); } } static CYTHON_INLINE PyObject * __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) { PyObject *res; if (n <= 0) { return __Pyx_NewRef(__pyx_mstate_global->__pyx_empty_tuple); } res = PyTuple_New(n); if (unlikely(res == NULL)) return NULL; __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); return res; } static CYTHON_INLINE PyObject * __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) { PyObject *res; if (n <= 0) { return PyList_New(0); } res = PyList_New(n); if (unlikely(res == NULL)) return NULL; __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); return res; } #endif /* 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 } /* fastcall */ #if CYTHON_METH_FASTCALL static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) { Py_ssize_t i, n = __Pyx_PyTuple_GET_SIZE(kwnames); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely(n == -1)) return NULL; #endif for (i = 0; i < n; i++) { PyObject *namei = __Pyx_PyTuple_GET_ITEM(kwnames, i); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(!namei)) return NULL; #endif if (s == namei) return kwvalues[i]; } for (i = 0; i < n; i++) { PyObject *namei = __Pyx_PyTuple_GET_ITEM(kwnames, i); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(!namei)) return NULL; #endif int eq = __Pyx_PyUnicode_Equals(s, namei, Py_EQ); if (unlikely(eq != 0)) { if (unlikely(eq < 0)) return NULL; return kwvalues[i]; } } return NULL; } #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { Py_ssize_t i, nkwargs; PyObject *dict; #if !CYTHON_ASSUME_SAFE_SIZE nkwargs = PyTuple_Size(kwnames); if (unlikely(nkwargs < 0)) return NULL; #else nkwargs = PyTuple_GET_SIZE(kwnames); #endif dict = PyDict_New(); if (unlikely(!dict)) return NULL; for (i=0; i= 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; } /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, "%s() got multiple values for keyword argument '%U'", func_name, kw_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 } /* 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; } /* 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); } } /* ParseKeywords */ static int __Pyx_ValidateDuplicatePosArgs( PyObject *kwds, PyObject ** const argnames[], PyObject ** const *first_kw_arg, const char* function_name) { PyObject ** const *name = argnames; while (name != first_kw_arg) { PyObject *key = **name; int found = PyDict_Contains(kwds, key); if (unlikely(found)) { if (found == 1) __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; } name++; } return 0; bad: return -1; } #if CYTHON_USE_UNICODE_INTERNALS static CYTHON_INLINE int __Pyx_UnicodeKeywordsEqual(PyObject *s1, PyObject *s2) { int kind; Py_ssize_t len = PyUnicode_GET_LENGTH(s1); if (len != PyUnicode_GET_LENGTH(s2)) return 0; kind = PyUnicode_KIND(s1); if (kind != PyUnicode_KIND(s2)) return 0; const void *data1 = PyUnicode_DATA(s1); const void *data2 = PyUnicode_DATA(s2); return (memcmp(data1, data2, (size_t) len * (size_t) kind) == 0); } #endif static int __Pyx_MatchKeywordArg_str( PyObject *key, PyObject ** const argnames[], PyObject ** const *first_kw_arg, size_t *index_found, const char *function_name) { PyObject ** const *name; #if CYTHON_USE_UNICODE_INTERNALS Py_hash_t key_hash = ((PyASCIIObject*)key)->hash; if (unlikely(key_hash == -1)) { key_hash = PyObject_Hash(key); if (unlikely(key_hash == -1)) goto bad; } #endif name = first_kw_arg; while (*name) { PyObject *name_str = **name; #if CYTHON_USE_UNICODE_INTERNALS if (key_hash == ((PyASCIIObject*)name_str)->hash && __Pyx_UnicodeKeywordsEqual(name_str, key)) { *index_found = (size_t) (name - argnames); return 1; } #else #if CYTHON_ASSUME_SAFE_SIZE if (PyUnicode_GET_LENGTH(name_str) == PyUnicode_GET_LENGTH(key)) #endif { int cmp = PyUnicode_Compare(name_str, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { *index_found = (size_t) (name - argnames); return 1; } } #endif name++; } name = argnames; while (name != first_kw_arg) { PyObject *name_str = **name; #if CYTHON_USE_UNICODE_INTERNALS if (unlikely(key_hash == ((PyASCIIObject*)name_str)->hash)) { if (__Pyx_UnicodeKeywordsEqual(name_str, key)) goto arg_passed_twice; } #else #if CYTHON_ASSUME_SAFE_SIZE if (PyUnicode_GET_LENGTH(name_str) == PyUnicode_GET_LENGTH(key)) #endif { if (unlikely(name_str == key)) goto arg_passed_twice; int cmp = PyUnicode_Compare(name_str, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; } #endif name++; } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; bad: return -1; } static int __Pyx_MatchKeywordArg_nostr( PyObject *key, PyObject ** const argnames[], PyObject ** const *first_kw_arg, size_t *index_found, const char *function_name) { PyObject ** const *name; if (unlikely(!PyUnicode_Check(key))) goto invalid_keyword_type; name = first_kw_arg; while (*name) { int cmp = PyObject_RichCompareBool(**name, key, Py_EQ); if (cmp == 1) { *index_found = (size_t) (name - argnames); return 1; } if (unlikely(cmp == -1)) goto bad; name++; } name = argnames; while (name != first_kw_arg) { int cmp = PyObject_RichCompareBool(**name, key, Py_EQ); if (unlikely(cmp != 0)) { if (cmp == 1) goto arg_passed_twice; else goto bad; } name++; } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; bad: return -1; } static CYTHON_INLINE int __Pyx_MatchKeywordArg( PyObject *key, PyObject ** const argnames[], PyObject ** const *first_kw_arg, size_t *index_found, const char *function_name) { return likely(PyUnicode_CheckExact(key)) ? __Pyx_MatchKeywordArg_str(key, argnames, first_kw_arg, index_found, function_name) : __Pyx_MatchKeywordArg_nostr(key, argnames, first_kw_arg, index_found, function_name); } static void __Pyx_RejectUnknownKeyword( PyObject *kwds, PyObject ** const argnames[], PyObject ** const *first_kw_arg, const char *function_name) { Py_ssize_t pos = 0; PyObject *key = NULL; __Pyx_BEGIN_CRITICAL_SECTION(kwds); while (PyDict_Next(kwds, &pos, &key, NULL)) { PyObject** const *name = first_kw_arg; while (*name && (**name != key)) name++; if (!*name) { #if CYTHON_AVOID_BORROWED_REFS Py_INCREF(key); #endif size_t index_found = 0; int cmp = __Pyx_MatchKeywordArg(key, argnames, first_kw_arg, &index_found, function_name); if (cmp != 1) { if (cmp == 0) { PyErr_Format(PyExc_TypeError, "%s() got an unexpected keyword argument '%U'", function_name, key); } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(key); #endif break; } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(key); #endif } } __Pyx_END_CRITICAL_SECTION(); assert(PyErr_Occurred()); } static int __Pyx_ParseKeywordDict( PyObject *kwds, PyObject ** const argnames[], PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs) { PyObject** const *name; PyObject** const *first_kw_arg = argnames + num_pos_args; Py_ssize_t extracted = 0; #if !CYTHON_COMPILING_IN_PYPY || defined(PyArg_ValidateKeywordArguments) if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return -1; #endif name = first_kw_arg; while (*name && num_kwargs > extracted) { PyObject * key = **name; PyObject *value; int found = 0; #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000 found = PyDict_GetItemRef(kwds, key, &value); #else value = PyDict_GetItemWithError(kwds, key); if (value) { Py_INCREF(value); found = 1; } else { if (unlikely(PyErr_Occurred())) goto bad; } #endif if (found) { if (unlikely(found < 0)) goto bad; values[name-argnames] = value; extracted++; } name++; } if (num_kwargs > extracted) { if (ignore_unknown_kwargs) { if (unlikely(__Pyx_ValidateDuplicatePosArgs(kwds, argnames, first_kw_arg, function_name) == -1)) goto bad; } else { __Pyx_RejectUnknownKeyword(kwds, argnames, first_kw_arg, function_name); goto bad; } } return 0; bad: return -1; } static int __Pyx_ParseKeywordDictToDict( PyObject *kwds, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject** const *name; PyObject** const *first_kw_arg = argnames + num_pos_args; Py_ssize_t len; #if !CYTHON_COMPILING_IN_PYPY || defined(PyArg_ValidateKeywordArguments) if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return -1; #endif if (PyDict_Update(kwds2, kwds) < 0) goto bad; name = first_kw_arg; while (*name) { PyObject *key = **name; PyObject *value; #if !CYTHON_COMPILING_IN_LIMITED_API && (PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)) int found = PyDict_Pop(kwds2, key, &value); if (found) { if (unlikely(found < 0)) goto bad; values[name-argnames] = value; } #elif __PYX_LIMITED_VERSION_HEX >= 0x030d0000 int found = PyDict_GetItemRef(kwds2, key, &value); if (found) { if (unlikely(found < 0)) goto bad; values[name-argnames] = value; if (unlikely(PyDict_DelItem(kwds2, key) < 0)) goto bad; } #else #if CYTHON_COMPILING_IN_CPYTHON value = _PyDict_Pop(kwds2, key, kwds2); #else value = __Pyx_CallUnboundCMethod2(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_pop, kwds2, key, kwds2); #endif if (value == kwds2) { Py_DECREF(value); } else { if (unlikely(!value)) goto bad; values[name-argnames] = value; } #endif name++; } len = PyDict_Size(kwds2); if (len > 0) { return __Pyx_ValidateDuplicatePosArgs(kwds, argnames, first_kw_arg, function_name); } else if (unlikely(len == -1)) { goto bad; } return 0; bad: return -1; } static int __Pyx_ParseKeywordsTuple( PyObject *kwds, PyObject * const *kwvalues, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs) { PyObject *key = NULL; PyObject** const * name; PyObject** const *first_kw_arg = argnames + num_pos_args; for (Py_ssize_t pos = 0; pos < num_kwargs; pos++) { #if CYTHON_AVOID_BORROWED_REFS key = __Pyx_PySequence_ITEM(kwds, pos); #else key = __Pyx_PyTuple_GET_ITEM(kwds, pos); #endif #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(!key)) goto bad; #endif name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { PyObject *value = kwvalues[pos]; values[name-argnames] = __Pyx_NewRef(value); } else { size_t index_found = 0; int cmp = __Pyx_MatchKeywordArg(key, argnames, first_kw_arg, &index_found, function_name); if (cmp == 1) { PyObject *value = kwvalues[pos]; values[index_found] = __Pyx_NewRef(value); } else { if (unlikely(cmp == -1)) goto bad; if (kwds2) { PyObject *value = kwvalues[pos]; if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else if (!ignore_unknown_kwargs) { goto invalid_keyword; } } } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(key); key = NULL; #endif } return 0; invalid_keyword: PyErr_Format(PyExc_TypeError, "%s() got an unexpected keyword argument '%U'", function_name, key); goto bad; bad: #if CYTHON_AVOID_BORROWED_REFS Py_XDECREF(key); #endif return -1; } static int __Pyx_ParseKeywords( PyObject *kwds, PyObject * const *kwvalues, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs) { if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds))) return __Pyx_ParseKeywordsTuple(kwds, kwvalues, argnames, kwds2, values, num_pos_args, num_kwargs, function_name, ignore_unknown_kwargs); else if (kwds2) return __Pyx_ParseKeywordDictToDict(kwds, argnames, kwds2, values, num_pos_args, function_name); else return __Pyx_ParseKeywordDict(kwds, argnames, values, num_pos_args, num_kwargs, function_name, ignore_unknown_kwargs); } /* PyObjectSetAttrStr */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_setattro)) return tp->tp_setattro(obj, attr_name, value); return PyObject_SetAttr(obj, attr_name, value); } #endif /* ModFloat[double] */ static CYTHON_INLINE double __Pyx_mod_double(double a, double b, int b_is_constant) { CYTHON_UNUSED_VAR(b_is_constant); double r = fmod(a, b); r += ((r != 0) & ((r < 0) ^ (b < 0))) * b; return r; } /* 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 /* 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); } /* RaiseUnboundLocalError */ static void __Pyx_RaiseUnboundLocalError(const char *varname) { PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); } /* 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); } /* 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; } /* 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__pyx_empty_unicode, value_tuple); bad: Py_DECREF(value_tuple); return result; #endif } /* UnicodeConcatInPlace */ # if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_unicode_modifiable(PyObject *unicode) { if (Py_REFCNT(unicode) != 1) return 0; if (!PyUnicode_CheckExact(unicode)) return 0; if (PyUnicode_CHECK_INTERNED(unicode)) return 0; return 1; } static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right #if CYTHON_REFNANNY , void* __pyx_refnanny #endif ) { PyObject *left = *p_left; Py_ssize_t left_len, right_len, new_len; if (unlikely(__Pyx_PyUnicode_READY(left) == -1)) return NULL; if (unlikely(__Pyx_PyUnicode_READY(right) == -1)) return NULL; left_len = PyUnicode_GET_LENGTH(left); if (left_len == 0) { Py_INCREF(right); return right; } right_len = PyUnicode_GET_LENGTH(right); if (right_len == 0) { Py_INCREF(left); return left; } if (unlikely(left_len > PY_SSIZE_T_MAX - right_len)) { PyErr_SetString(PyExc_OverflowError, "strings are too large to concat"); return NULL; } new_len = left_len + right_len; if (__Pyx_unicode_modifiable(left) && PyUnicode_CheckExact(right) && PyUnicode_KIND(right) <= PyUnicode_KIND(left) && !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) { int ret; __Pyx_GIVEREF(*p_left); ret = PyUnicode_Resize(p_left, new_len); __Pyx_GOTREF(*p_left); if (unlikely(ret != 0)) return NULL; #if PY_VERSION_HEX >= 0x030d0000 if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL; #else _PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len); #endif __Pyx_INCREF(*p_left); __Pyx_GIVEREF(*p_left); return *p_left; } else { return __Pyx_PyUnicode_Concat(left, right); } } #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 /* SetItemInt */ static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { int r; if (unlikely(!j)) return -1; r = PyObject_SetItem(o, j, v); Py_DECREF(j); return r; } static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, 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) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o)); if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) { Py_INCREF(v); #if CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS PyList_SetItem(o, n, v); #else PyObject* old = PyList_GET_ITEM(o, n); PyList_SET_ITEM(o, n, v); Py_DECREF(old); #endif return 1; } } else { PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping; PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence; if (mm && mm->mp_ass_subscript) { int r; PyObject *key = PyLong_FromSsize_t(i); if (unlikely(!key)) return -1; r = mm->mp_ass_subscript(o, key, v); Py_DECREF(key); return r; } if (likely(sm && sm->sq_ass_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 -1; PyErr_Clear(); } } return sm->sq_ass_item(o, i, v); } } #else if (is_list || !PyMapping_Check(o)) { return PySequence_SetItem(o, i, v); } #endif return __Pyx_SetItemInt_Generic(o, PyLong_FromSsize_t(i), v); } /* 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 /* SliceObject */ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { __Pyx_TypeName obj_type_name; #if CYTHON_USE_TYPE_SLOTS PyMappingMethods* mp = Py_TYPE(obj)->tp_as_mapping; if (likely(mp && mp->mp_ass_subscript)) #endif { int result; PyObject *py_slice, *py_start, *py_stop; if (_py_slice) { py_slice = *_py_slice; } else { PyObject* owned_start = NULL; PyObject* owned_stop = NULL; if (_py_start) { py_start = *_py_start; } else { if (has_cstart) { owned_start = py_start = PyLong_FromSsize_t(cstart); if (unlikely(!py_start)) goto bad; } else py_start = Py_None; } if (_py_stop) { py_stop = *_py_stop; } else { if (has_cstop) { owned_stop = py_stop = PyLong_FromSsize_t(cstop); if (unlikely(!py_stop)) { Py_XDECREF(owned_start); goto bad; } } else py_stop = Py_None; } py_slice = PySlice_New(py_start, py_stop, Py_None); Py_XDECREF(owned_start); Py_XDECREF(owned_stop); if (unlikely(!py_slice)) goto bad; } #if CYTHON_USE_TYPE_SLOTS result = mp->mp_ass_subscript(obj, py_slice, value); #else result = value ? PyObject_SetItem(obj, py_slice, value) : PyObject_DelItem(obj, py_slice); #endif if (!_py_slice) { Py_DECREF(py_slice); } return result; } obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj)); PyErr_Format(PyExc_TypeError, "'" __Pyx_FMT_TYPENAME "' object does not support slice %.10s", obj_type_name, value ? "assignment" : "deletion"); __Pyx_DECREF_TypeName(obj_type_name); bad: return -1; } /* 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; } /* 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; } /* 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); } /* PyObjectGetMethod */ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { PyObject *attr; #if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP __Pyx_TypeName type_name; PyTypeObject *tp = Py_TYPE(obj); PyObject *descr; descrgetfunc f = NULL; PyObject **dictptr, *dict; int meth_found = 0; assert (*method == NULL); if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { attr = __Pyx_PyObject_GetAttrStr(obj, name); goto try_unpack; } if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { return 0; } descr = _PyType_Lookup(tp, name); if (likely(descr != NULL)) { Py_INCREF(descr); #if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) #else #ifdef __Pyx_CyFunction_USED if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) #else if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) #endif #endif { meth_found = 1; } else { f = Py_TYPE(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); Py_DECREF(descr); goto try_unpack; } } } dictptr = _PyObject_GetDictPtr(obj); if (dictptr != NULL && (dict = *dictptr) != NULL) { Py_INCREF(dict); attr = __Pyx_PyDict_GetItemStr(dict, name); if (attr != NULL) { Py_INCREF(attr); Py_DECREF(dict); Py_XDECREF(descr); goto try_unpack; } Py_DECREF(dict); } if (meth_found) { *method = descr; return 1; } if (f != NULL) { attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); Py_DECREF(descr); goto try_unpack; } if (likely(descr != NULL)) { *method = descr; return 0; } type_name = __Pyx_PyType_GetFullyQualifiedName(tp); PyErr_Format(PyExc_AttributeError, "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", type_name, name); __Pyx_DECREF_TypeName(type_name); return 0; #else attr = __Pyx_PyObject_GetAttrStr(obj, name); goto try_unpack; #endif try_unpack: #if CYTHON_UNPACK_METHODS if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { PyObject *function = PyMethod_GET_FUNCTION(attr); Py_INCREF(function); Py_DECREF(attr); *method = function; return 1; } #endif *method = attr; return 0; } /* PyObjectCallMethod1 */ #if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000) static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); Py_DECREF(method); return result; } #endif static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { #if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000 PyObject *args[2] = {obj, arg}; (void) __Pyx_PyObject_GetMethod; (void) __Pyx_PyObject_CallOneArg; (void) __Pyx_PyObject_Call2Args; return PyObject_VectorcallMethod(method_name, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); #else PyObject *method = NULL, *result; int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); if (likely(is_method)) { result = __Pyx_PyObject_Call2Args(method, obj, arg); Py_DECREF(method); return result; } if (unlikely(!method)) return NULL; return __Pyx__PyObject_CallMethod1(method, arg); #endif } /* append */ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { if (likely(PyList_CheckExact(L))) { if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1; } else { PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_mstate_global->__pyx_n_u_append, x); if (unlikely(!retval)) return -1; Py_DECREF(retval); } return 0; } /* 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 /* SliceObject */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { __Pyx_TypeName obj_type_name; #if CYTHON_USE_TYPE_SLOTS PyMappingMethods* mp = Py_TYPE(obj)->tp_as_mapping; if (likely(mp && mp->mp_subscript)) #endif { PyObject* result; PyObject *py_slice, *py_start, *py_stop; if (_py_slice) { py_slice = *_py_slice; } else { PyObject* owned_start = NULL; PyObject* owned_stop = NULL; if (_py_start) { py_start = *_py_start; } else { if (has_cstart) { owned_start = py_start = PyLong_FromSsize_t(cstart); if (unlikely(!py_start)) goto bad; } else py_start = Py_None; } if (_py_stop) { py_stop = *_py_stop; } else { if (has_cstop) { owned_stop = py_stop = PyLong_FromSsize_t(cstop); if (unlikely(!py_stop)) { Py_XDECREF(owned_start); goto bad; } } else py_stop = Py_None; } py_slice = PySlice_New(py_start, py_stop, Py_None); Py_XDECREF(owned_start); Py_XDECREF(owned_stop); if (unlikely(!py_slice)) goto bad; } #if CYTHON_USE_TYPE_SLOTS result = mp->mp_subscript(obj, py_slice); #else result = PyObject_GetItem(obj, py_slice); #endif if (!_py_slice) { Py_DECREF(py_slice); } return result; } obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj)); PyErr_Format(PyExc_TypeError, "'" __Pyx_FMT_TYPENAME "' object is unsliceable", obj_type_name); __Pyx_DECREF_TypeName(obj_type_name); bad: return NULL; } /* 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); } /* 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(); } /* 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 /* py_dict_items */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) { return __Pyx_CallUnboundCMethod0(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_items, d); } /* 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 /* 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 } /* 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)); } /* 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); } /* CallTypeTraverse */ #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000) #else static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg) { #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03090000 if (__Pyx_get_runtime_version() < 0x03090000) return 0; #endif if (!always_call) { PyTypeObject *base = __Pyx_PyObject_GetSlot(o, tp_base, PyTypeObject*); unsigned long flags = PyType_GetFlags(base); if (flags & Py_TPFLAGS_HEAPTYPE) { return 0; } } Py_VISIT((PyObject*)Py_TYPE(o)); return 0; } #endif /* LimitedApiGetTypeDict */ #if CYTHON_COMPILING_IN_LIMITED_API static Py_ssize_t __Pyx_GetTypeDictOffset(void) { PyObject *tp_dictoffset_o; Py_ssize_t tp_dictoffset; tp_dictoffset_o = PyObject_GetAttrString((PyObject*)(&PyType_Type), "__dictoffset__"); if (unlikely(!tp_dictoffset_o)) return -1; tp_dictoffset = PyLong_AsSsize_t(tp_dictoffset_o); Py_DECREF(tp_dictoffset_o); if (unlikely(tp_dictoffset == 0)) { PyErr_SetString( PyExc_TypeError, "'type' doesn't have a dictoffset"); return -1; } else if (unlikely(tp_dictoffset < 0)) { PyErr_SetString( PyExc_TypeError, "'type' has an unexpected negative dictoffset. " "Please report this as Cython bug"); return -1; } return tp_dictoffset; } static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp) { static Py_ssize_t tp_dictoffset = 0; if (unlikely(tp_dictoffset == 0)) { tp_dictoffset = __Pyx_GetTypeDictOffset(); if (unlikely(tp_dictoffset == -1 && PyErr_Occurred())) { tp_dictoffset = 0; // try again next time? return NULL; } } return *(PyObject**)((char*)tp + tp_dictoffset); } #endif /* SetItemOnTypeDict */ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v) { int result; PyObject *tp_dict; #if CYTHON_COMPILING_IN_LIMITED_API tp_dict = __Pyx_GetTypeDict(tp); if (unlikely(!tp_dict)) return -1; #else tp_dict = tp->tp_dict; #endif result = PyDict_SetItem(tp_dict, k, v); if (likely(!result)) { PyType_Modified(tp); if (unlikely(PyObject_HasAttr(v, __pyx_mstate_global->__pyx_n_u_set_name))) { PyObject *setNameResult = PyObject_CallMethodObjArgs(v, __pyx_mstate_global->__pyx_n_u_set_name, (PyObject *) tp, k, NULL); if (!setNameResult) return -1; Py_DECREF(setNameResult); } } return result; } /* FixUpExtensionType */ static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { #if __PYX_LIMITED_VERSION_HEX > 0x030900B1 CYTHON_UNUSED_VAR(spec); CYTHON_UNUSED_VAR(type); CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict); #else const PyType_Slot *slot = spec->slots; int changed = 0; #if !CYTHON_COMPILING_IN_LIMITED_API while (slot && slot->slot && slot->slot != Py_tp_members) slot++; if (slot && slot->slot == Py_tp_members) { #if !CYTHON_COMPILING_IN_CPYTHON const #endif // !CYTHON_COMPILING_IN_CPYTHON) PyMemberDef *memb = (PyMemberDef*) slot->pfunc; while (memb && memb->name) { if (memb->name[0] == '_' && memb->name[1] == '_') { if (strcmp(memb->name, "__weaklistoffset__") == 0) { assert(memb->type == T_PYSSIZET); assert(memb->flags == READONLY); type->tp_weaklistoffset = memb->offset; changed = 1; } else if (strcmp(memb->name, "__dictoffset__") == 0) { assert(memb->type == T_PYSSIZET); assert(memb->flags == READONLY); type->tp_dictoffset = memb->offset; changed = 1; } #if CYTHON_METH_FASTCALL else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { assert(memb->type == T_PYSSIZET); assert(memb->flags == READONLY); #if PY_VERSION_HEX >= 0x030800b4 type->tp_vectorcall_offset = memb->offset; #else type->tp_print = (printfunc) memb->offset; #endif changed = 1; } #endif // CYTHON_METH_FASTCALL else if (strcmp(memb->name, "__module__") == 0) { PyObject *descr; assert(memb->type == T_OBJECT); assert(memb->flags == 0 || memb->flags == READONLY); descr = PyDescr_NewMember(type, memb); if (unlikely(!descr)) return -1; int set_item_result = PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr); Py_DECREF(descr); if (unlikely(set_item_result < 0)) { return -1; } changed = 1; } } memb++; } } #endif // !CYTHON_COMPILING_IN_LIMITED_API slot = spec->slots; while (slot && slot->slot && slot->slot != Py_tp_getset) slot++; if (slot && slot->slot == Py_tp_getset) { PyGetSetDef *getset = (PyGetSetDef*) slot->pfunc; while (getset && getset->name) { if (getset->name[0] == '_' && getset->name[1] == '_' && strcmp(getset->name, "__module__") == 0) { PyObject *descr = PyDescr_NewGetSet(type, getset); if (unlikely(!descr)) return -1; #if CYTHON_COMPILING_IN_LIMITED_API PyObject *pyname = PyUnicode_FromString(getset->name); if (unlikely(!pyname)) { Py_DECREF(descr); return -1; } int set_item_result = __Pyx_SetItemOnTypeDict(type, pyname, descr); Py_DECREF(pyname); #else CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict); int set_item_result = PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr); #endif Py_DECREF(descr); if (unlikely(set_item_result < 0)) { return -1; } changed = 1; } ++getset; } } if (changed) PyType_Modified(type); #endif // PY_VERSION_HEX > 0x030900B1 return 0; } /* PyObjectCallMethod0 */ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { PyObject *method = NULL, *result = NULL; int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); if (likely(is_method)) { result = __Pyx_PyObject_CallOneArg(method, obj); Py_DECREF(method); return result; } if (unlikely(!method)) goto bad; result = __Pyx_PyObject_CallNoArg(method); Py_DECREF(method); bad: return result; } /* ValidateBasesTuple */ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { Py_ssize_t i, n; #if CYTHON_ASSUME_SAFE_SIZE n = PyTuple_GET_SIZE(bases); #else n = PyTuple_Size(bases); if (unlikely(n < 0)) return -1; #endif for (i = 1; i < n; i++) { PyTypeObject *b; #if CYTHON_AVOID_BORROWED_REFS PyObject *b0 = PySequence_GetItem(bases, i); if (!b0) return -1; #elif CYTHON_ASSUME_SAFE_MACROS PyObject *b0 = PyTuple_GET_ITEM(bases, i); #else PyObject *b0 = PyTuple_GetItem(bases, i); if (!b0) return -1; #endif b = (PyTypeObject*) b0; if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) { __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b); PyErr_Format(PyExc_TypeError, "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); __Pyx_DECREF_TypeName(b_name); #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(b0); #endif return -1; } if (dictoffset == 0) { Py_ssize_t b_dictoffset = 0; #if CYTHON_USE_TYPE_SLOTS b_dictoffset = b->tp_dictoffset; #else PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); if (!py_b_dictoffset) goto dictoffset_return; b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); Py_DECREF(py_b_dictoffset); if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; #endif if (b_dictoffset) { { __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b); PyErr_Format(PyExc_TypeError, "extension type '%.200s' has no __dict__ slot, " "but base type '" __Pyx_FMT_TYPENAME "' has: " "either add 'cdef dict __dict__' to the extension type " "or add '__slots__ = [...]' to the base type", type_name, b_name); __Pyx_DECREF_TypeName(b_name); } #if !CYTHON_USE_TYPE_SLOTS dictoffset_return: #endif #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(b0); #endif return -1; } } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(b0); #endif } return 0; } #endif /* PyType_Ready */ CYTHON_UNUSED static int __Pyx_PyType_HasMultipleInheritance(PyTypeObject *t) { while (t) { PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); if (bases) { return 1; } t = __Pyx_PyType_GetSlot(t, tp_base, PyTypeObject*); } return 0; } static int __Pyx_PyType_Ready(PyTypeObject *t) { #if CYTHON_USE_TYPE_SPECS || !CYTHON_COMPILING_IN_CPYTHON || defined(PYSTON_MAJOR_VERSION) (void)__Pyx_PyObject_CallMethod0; #if CYTHON_USE_TYPE_SPECS (void)__Pyx_validate_bases_tuple; #endif return PyType_Ready(t); #else int r; if (!__Pyx_PyType_HasMultipleInheritance(t)) { return PyType_Ready(t); } PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) return -1; #if !defined(PYSTON_MAJOR_VERSION) { int gc_was_enabled; #if PY_VERSION_HEX >= 0x030A00b1 gc_was_enabled = PyGC_Disable(); (void)__Pyx_PyObject_CallMethod0; #else PyObject *ret, *py_status; PyObject *gc = NULL; #if (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) &&\ !CYTHON_COMPILING_IN_GRAAL gc = PyImport_GetModule(__pyx_mstate_global->__pyx_kp_u_gc); #endif if (unlikely(!gc)) gc = PyImport_Import(__pyx_mstate_global->__pyx_kp_u_gc); if (unlikely(!gc)) return -1; py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_mstate_global->__pyx_kp_u_isenabled); if (unlikely(!py_status)) { Py_DECREF(gc); return -1; } gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); Py_DECREF(py_status); if (gc_was_enabled > 0) { ret = __Pyx_PyObject_CallMethod0(gc, __pyx_mstate_global->__pyx_kp_u_disable); if (unlikely(!ret)) { Py_DECREF(gc); return -1; } Py_DECREF(ret); } else if (unlikely(gc_was_enabled == -1)) { Py_DECREF(gc); return -1; } #endif t->tp_flags |= Py_TPFLAGS_HEAPTYPE; #if PY_VERSION_HEX >= 0x030A0000 t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; #endif #else (void)__Pyx_PyObject_CallMethod0; #endif r = PyType_Ready(t); #if !defined(PYSTON_MAJOR_VERSION) t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; #if PY_VERSION_HEX >= 0x030A00b1 if (gc_was_enabled) PyGC_Enable(); #else if (gc_was_enabled) { PyObject *tp, *v, *tb; PyErr_Fetch(&tp, &v, &tb); ret = __Pyx_PyObject_CallMethod0(gc, __pyx_mstate_global->__pyx_kp_u_enable); if (likely(ret || r == -1)) { Py_XDECREF(ret); PyErr_Restore(tp, v, tb); } else { Py_XDECREF(tp); Py_XDECREF(v); Py_XDECREF(tb); r = -1; } } Py_DECREF(gc); #endif } #endif return r; #endif } /* DelItemOnTypeDict */ static int __Pyx__DelItemOnTypeDict(PyTypeObject *tp, PyObject *k) { int result; PyObject *tp_dict; #if CYTHON_COMPILING_IN_LIMITED_API tp_dict = __Pyx_GetTypeDict(tp); if (unlikely(!tp_dict)) return -1; #else tp_dict = tp->tp_dict; #endif result = PyDict_DelItem(tp_dict, k); if (likely(!result)) PyType_Modified(tp); return result; } /* SetupReduce */ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { int ret; PyObject *name_attr; name_attr = __Pyx_PyObject_GetAttrStrNoError(meth, __pyx_mstate_global->__pyx_n_u_name_2); if (likely(name_attr)) { ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); } else { ret = -1; } if (unlikely(ret < 0)) { PyErr_Clear(); ret = 0; } Py_XDECREF(name_attr); return ret; } static int __Pyx_setup_reduce(PyObject* type_obj) { int ret = 0; PyObject *object_reduce = NULL; PyObject *object_getstate = NULL; PyObject *object_reduce_ex = NULL; PyObject *reduce = NULL; PyObject *reduce_ex = NULL; PyObject *reduce_cython = NULL; PyObject *setstate = NULL; PyObject *setstate_cython = NULL; PyObject *getstate = NULL; #if CYTHON_USE_PYTYPE_LOOKUP getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_mstate_global->__pyx_n_u_getstate); #else getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_mstate_global->__pyx_n_u_getstate); if (!getstate && PyErr_Occurred()) { goto __PYX_BAD; } #endif if (getstate) { #if CYTHON_USE_PYTYPE_LOOKUP object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_mstate_global->__pyx_n_u_getstate); #else object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_mstate_global->__pyx_n_u_getstate); if (!object_getstate && PyErr_Occurred()) { goto __PYX_BAD; } #endif if (object_getstate != getstate) { goto __PYX_GOOD; } } #if CYTHON_USE_PYTYPE_LOOKUP object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_mstate_global->__pyx_n_u_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #else object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_mstate_global->__pyx_n_u_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #endif reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_mstate_global->__pyx_n_u_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; if (reduce_ex == object_reduce_ex) { #if CYTHON_USE_PYTYPE_LOOKUP object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_mstate_global->__pyx_n_u_reduce); if (!object_reduce) goto __PYX_BAD; #else object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_mstate_global->__pyx_n_u_reduce); if (!object_reduce) goto __PYX_BAD; #endif reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_mstate_global->__pyx_n_u_reduce); if (unlikely(!reduce)) goto __PYX_BAD; if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_mstate_global->__pyx_n_u_reduce_cython)) { reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_mstate_global->__pyx_n_u_reduce_cython); if (likely(reduce_cython)) { ret = __Pyx_SetItemOnTypeDict((PyTypeObject*)type_obj, __pyx_mstate_global->__pyx_n_u_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; ret = __Pyx_DelItemOnTypeDict((PyTypeObject*)type_obj, __pyx_mstate_global->__pyx_n_u_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; } else if (reduce == object_reduce || PyErr_Occurred()) { goto __PYX_BAD; } setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_mstate_global->__pyx_n_u_setstate); if (!setstate) PyErr_Clear(); if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_mstate_global->__pyx_n_u_setstate_cython)) { setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_mstate_global->__pyx_n_u_setstate_cython); if (likely(setstate_cython)) { ret = __Pyx_SetItemOnTypeDict((PyTypeObject*)type_obj, __pyx_mstate_global->__pyx_n_u_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; ret = __Pyx_DelItemOnTypeDict((PyTypeObject*)type_obj, __pyx_mstate_global->__pyx_n_u_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; } else if (!setstate || PyErr_Occurred()) { goto __PYX_BAD; } } PyType_Modified((PyTypeObject*)type_obj); } } goto __PYX_GOOD; __PYX_BAD: if (!PyErr_Occurred()) { __Pyx_TypeName type_obj_name = __Pyx_PyType_GetFullyQualifiedName((PyTypeObject*)type_obj); PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name); __Pyx_DECREF_TypeName(type_obj_name); } ret = -1; __PYX_GOOD: #if !CYTHON_USE_PYTYPE_LOOKUP Py_XDECREF(object_reduce); Py_XDECREF(object_reduce_ex); Py_XDECREF(object_getstate); Py_XDECREF(getstate); #endif Py_XDECREF(reduce); Py_XDECREF(reduce_ex); Py_XDECREF(reduce_cython); Py_XDECREF(setstate); Py_XDECREF(setstate_cython); return ret; } /* 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 /* 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__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; } /* FetchSharedCythonModule */ static PyObject *__Pyx_FetchSharedCythonABIModule(void) { return __Pyx_PyImport_AddModuleRef(__PYX_ABI_MODULE_NAME); } /* dict_setdefault */ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type) { PyObject* value; CYTHON_MAYBE_UNUSED_VAR(is_safe_type); #if CYTHON_COMPILING_IN_LIMITED_API value = PyObject_CallMethod(d, "setdefault", "OO", key, default_value); #elif PY_VERSION_HEX >= 0x030d0000 PyDict_SetDefaultRef(d, key, default_value, &value); #else value = PyDict_SetDefault(d, key, default_value); if (unlikely(!value)) return NULL; Py_INCREF(value); #endif return value; } /* FetchCommonType */ #if __PYX_LIMITED_VERSION_HEX < 0x030C0000 static PyObject* __Pyx_PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases) { PyObject *result = __Pyx_PyType_FromModuleAndSpec(module, spec, bases); if (result && metaclass) { PyObject *old_tp = (PyObject*)Py_TYPE(result); Py_INCREF((PyObject*)metaclass); #if __PYX_LIMITED_VERSION_HEX >= 0x03090000 Py_SET_TYPE(result, metaclass); #else result->ob_type = metaclass; #endif Py_DECREF(old_tp); } return result; } #else #define __Pyx_PyType_FromMetaclass(me, mo, s, b) PyType_FromMetaclass(me, mo, s, b) #endif static int __Pyx_VerifyCachedType(PyObject *cached_type, const char *name, Py_ssize_t expected_basicsize) { Py_ssize_t basicsize; if (!PyType_Check(cached_type)) { PyErr_Format(PyExc_TypeError, "Shared Cython type %.200s is not a type object", name); return -1; } if (expected_basicsize == 0) { return 0; // size is inherited, nothing useful to check } #if CYTHON_COMPILING_IN_LIMITED_API PyObject *py_basicsize; py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); if (unlikely(!py_basicsize)) return -1; basicsize = PyLong_AsSsize_t(py_basicsize); Py_DECREF(py_basicsize); py_basicsize = NULL; if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) return -1; #else basicsize = ((PyTypeObject*) cached_type)->tp_basicsize; #endif if (basicsize != expected_basicsize) { PyErr_Format(PyExc_TypeError, "Shared Cython type %.200s has the wrong size, try recompiling", name); return -1; } return 0; } static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases) { PyObject *abi_module = NULL, *cached_type = NULL, *abi_module_dict, *new_cached_type, *py_object_name; int get_item_ref_result; const char* object_name = strrchr(spec->name, '.'); object_name = object_name ? object_name+1 : spec->name; py_object_name = PyUnicode_FromString(object_name); if (!py_object_name) return NULL; abi_module = __Pyx_FetchSharedCythonABIModule(); if (!abi_module) goto done; abi_module_dict = PyModule_GetDict(abi_module); if (!abi_module_dict) goto done; get_item_ref_result = __Pyx_PyDict_GetItemRef(abi_module_dict, py_object_name, &cached_type); if (get_item_ref_result == 1) { if (__Pyx_VerifyCachedType( cached_type, object_name, spec->basicsize) < 0) { goto bad; } goto done; } else if (unlikely(get_item_ref_result == -1)) { goto bad; } CYTHON_UNUSED_VAR(module); cached_type = __Pyx_PyType_FromMetaclass(metaclass, abi_module, spec, bases); if (unlikely(!cached_type)) goto bad; if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; new_cached_type = __Pyx_PyDict_SetDefault(abi_module_dict, py_object_name, cached_type, 1); if (unlikely(new_cached_type != cached_type)) { if (unlikely(!new_cached_type)) goto bad; Py_DECREF(cached_type); cached_type = new_cached_type; if (__Pyx_VerifyCachedType( cached_type, object_name, spec->basicsize) < 0) { goto bad; } goto done; } else { Py_DECREF(new_cached_type); } done: Py_XDECREF(abi_module); Py_DECREF(py_object_name); assert(cached_type == NULL || PyType_Check(cached_type)); return (PyTypeObject *) cached_type; bad: Py_XDECREF(cached_type); cached_type = NULL; goto done; } /* CommonTypesMetaclass */ PyObject* __pyx_CommonTypesMetaclass_get_module(CYTHON_UNUSED PyObject *self, CYTHON_UNUSED void* context) { return PyUnicode_FromString(__PYX_ABI_MODULE_NAME); } static PyGetSetDef __pyx_CommonTypesMetaclass_getset[] = { {"__module__", __pyx_CommonTypesMetaclass_get_module, NULL, NULL, NULL}, {0, 0, 0, 0, 0} }; static PyType_Slot __pyx_CommonTypesMetaclass_slots[] = { {Py_tp_getset, (void *)__pyx_CommonTypesMetaclass_getset}, {0, 0} }; static PyType_Spec __pyx_CommonTypesMetaclass_spec = { __PYX_TYPE_MODULE_PREFIX "_common_types_metatype", 0, 0, #if PY_VERSION_HEX >= 0x030A0000 Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION | #endif Py_TPFLAGS_DEFAULT, __pyx_CommonTypesMetaclass_slots }; static int __pyx_CommonTypesMetaclass_init(PyObject *module) { __pyx_mstatetype *mstate = __Pyx_PyModule_GetState(module); PyObject *bases = PyTuple_Pack(1, &PyType_Type); if (unlikely(!bases)) { return -1; } mstate->__pyx_CommonTypesMetaclassType = __Pyx_FetchCommonTypeFromSpec(NULL, module, &__pyx_CommonTypesMetaclass_spec, bases); if (unlikely(mstate->__pyx_CommonTypesMetaclassType == NULL)) { return -1; } return 0; } /* PyMethodNew */ #if CYTHON_COMPILING_IN_LIMITED_API static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { PyObject *result; CYTHON_UNUSED_VAR(typ); if (!self) return __Pyx_NewRef(func); #if __PYX_LIMITED_VERSION_HEX >= 0x030C0000 { PyObject *args[] = {func, self}; result = PyObject_Vectorcall(__pyx_mstate_global->__Pyx_CachedMethodType, args, 2, NULL); } #else result = PyObject_CallFunctionObjArgs(__pyx_mstate_global->__Pyx_CachedMethodType, func, self, NULL); #endif return result; } #else static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { CYTHON_UNUSED_VAR(typ); if (!self) return __Pyx_NewRef(func); return PyMethod_New(func, self); } #endif /* PyVectorcallFastCallDict */ #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) { PyObject *res = NULL; PyObject *kwnames; PyObject **newargs; PyObject **kwvalues; Py_ssize_t i, pos; size_t j; PyObject *key, *value; unsigned long keys_are_strings; #if !CYTHON_ASSUME_SAFE_SIZE Py_ssize_t nkw = PyDict_Size(kw); if (unlikely(nkw == -1)) return NULL; #else Py_ssize_t nkw = PyDict_GET_SIZE(kw); #endif newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); if (unlikely(newargs == NULL)) { PyErr_NoMemory(); return NULL; } for (j = 0; j < nargs; j++) newargs[j] = args[j]; kwnames = PyTuple_New(nkw); if (unlikely(kwnames == NULL)) { PyMem_Free(newargs); return NULL; } kwvalues = newargs + nargs; pos = i = 0; keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; while (PyDict_Next(kw, &pos, &key, &value)) { keys_are_strings &= #if CYTHON_COMPILING_IN_LIMITED_API PyType_GetFlags(Py_TYPE(key)); #else Py_TYPE(key)->tp_flags; #endif Py_INCREF(key); Py_INCREF(value); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(PyTuple_SetItem(kwnames, i, key) < 0)) goto cleanup; #else PyTuple_SET_ITEM(kwnames, i, key); #endif kwvalues[i] = value; i++; } if (unlikely(!keys_are_strings)) { PyErr_SetString(PyExc_TypeError, "keywords must be strings"); goto cleanup; } res = vc(func, newargs, nargs, kwnames); cleanup: Py_DECREF(kwnames); for (i = 0; i < nkw; i++) Py_DECREF(kwvalues[i]); PyMem_Free(newargs); return res; } static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) { Py_ssize_t kw_size = likely(kw == NULL) ? 0 : #if !CYTHON_ASSUME_SAFE_SIZE PyDict_Size(kw); #else PyDict_GET_SIZE(kw); #endif if (kw_size == 0) { return vc(func, args, nargs, NULL); } #if !CYTHON_ASSUME_SAFE_SIZE else if (unlikely(kw_size == -1)) { return NULL; } #endif return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); } #endif /* CythonFunctionShared */ #if CYTHON_COMPILING_IN_LIMITED_API static CYTHON_INLINE int __Pyx__IsSameCyOrCFunctionNoMethod(PyObject *func, void (*cfunc)(void)) { if (__Pyx_CyFunction_Check(func)) { return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; } else if (PyCFunction_Check(func)) { return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; } return 0; } static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void (*cfunc)(void)) { if ((PyObject*)Py_TYPE(func) == __pyx_mstate_global->__Pyx_CachedMethodType) { int result; PyObject *newFunc = PyObject_GetAttr(func, __pyx_mstate_global->__pyx_n_u_func); if (unlikely(!newFunc)) { PyErr_Clear(); // It's only an optimization, so don't throw an error return 0; } result = __Pyx__IsSameCyOrCFunctionNoMethod(newFunc, cfunc); Py_DECREF(newFunc); return result; } return __Pyx__IsSameCyOrCFunctionNoMethod(func, cfunc); } #else static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void (*cfunc)(void)) { if (PyMethod_Check(func)) { func = PyMethod_GET_FUNCTION(func); } return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; } #endif static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API __Pyx_Py_XDECREF_SET( __Pyx_CyFunction_GetClassObj(f), ((classobj) ? __Pyx_NewRef(classobj) : NULL)); #else __Pyx_Py_XDECREF_SET( ((PyCMethodObject *) (f))->mm_class, (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); #endif } static PyObject * __Pyx_CyFunction_get_doc_locked(__pyx_CyFunctionObject *op) { if (unlikely(op->func_doc == NULL)) { #if CYTHON_COMPILING_IN_LIMITED_API op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); if (unlikely(!op->func_doc)) return NULL; #else if (((PyCFunctionObject*)op)->m_ml->ml_doc) { op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); if (unlikely(op->func_doc == NULL)) return NULL; } else { Py_INCREF(Py_None); return Py_None; } #endif } Py_INCREF(op->func_doc); return op->func_doc; } static PyObject * __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) { PyObject *result; CYTHON_UNUSED_VAR(closure); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_doc_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (value == NULL) { value = Py_None; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_doc, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_name_locked(__pyx_CyFunctionObject *op) { if (unlikely(op->func_name == NULL)) { #if CYTHON_COMPILING_IN_LIMITED_API op->func_name = PyObject_GetAttrString(op->func, "__name__"); #else op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); #endif if (unlikely(op->func_name == NULL)) return NULL; } Py_INCREF(op->func_name); return op->func_name; } static PyObject * __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) { PyObject *result = NULL; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_name_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL || !PyUnicode_Check(value))) { PyErr_SetString(PyExc_TypeError, "__name__ must be set to a string object"); return -1; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_name, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); PyObject *result; __Pyx_BEGIN_CRITICAL_SECTION(op); Py_INCREF(op->func_qualname); result = op->func_qualname; __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL || !PyUnicode_Check(value))) { PyErr_SetString(PyExc_TypeError, "__qualname__ must be set to a string object"); return -1; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_qualname, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_dict_locked(__pyx_CyFunctionObject *op) { if (unlikely(op->func_dict == NULL)) { op->func_dict = PyDict_New(); if (unlikely(op->func_dict == NULL)) return NULL; } Py_INCREF(op->func_dict); return op->func_dict; } static PyObject * __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); PyObject *result; __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_dict_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL)) { PyErr_SetString(PyExc_TypeError, "function's dictionary may not be deleted"); return -1; } if (unlikely(!PyDict_Check(value))) { PyErr_SetString(PyExc_TypeError, "setting function's dictionary to a non-dict"); return -1; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_dict, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); Py_INCREF(op->func_globals); return op->func_globals; } static PyObject * __Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(op); CYTHON_UNUSED_VAR(context); Py_INCREF(Py_None); return Py_None; } static PyObject * __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) { PyObject* result = (op->func_code) ? op->func_code : Py_None; CYTHON_UNUSED_VAR(context); Py_INCREF(result); return result; } static int __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { int result = 0; PyObject *res = op->defaults_getter((PyObject *) op); if (unlikely(!res)) return -1; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS op->defaults_tuple = PyTuple_GET_ITEM(res, 0); Py_INCREF(op->defaults_tuple); op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); Py_INCREF(op->defaults_kwdict); #else op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); if (unlikely(!op->defaults_tuple)) result = -1; else { op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); if (unlikely(!op->defaults_kwdict)) result = -1; } #endif Py_DECREF(res); return result; } static int __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); if (!value) { value = Py_None; } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { PyErr_SetString(PyExc_TypeError, "__defaults__ must be set to a tuple object"); return -1; } PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " "currently affect the values used in function calls", 1); Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_defaults_locked(__pyx_CyFunctionObject *op) { PyObject* result = op->defaults_tuple; if (unlikely(!result)) { if (op->defaults_getter) { if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; result = op->defaults_tuple; } else { result = Py_None; } } Py_INCREF(result); return result; } static PyObject * __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { PyObject* result = NULL; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_defaults_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); if (!value) { value = Py_None; } else if (unlikely(value != Py_None && !PyDict_Check(value))) { PyErr_SetString(PyExc_TypeError, "__kwdefaults__ must be set to a dict object"); return -1; } PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " "currently affect the values used in function calls", 1); Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_kwdefaults_locked(__pyx_CyFunctionObject *op) { PyObject* result = op->defaults_kwdict; if (unlikely(!result)) { if (op->defaults_getter) { if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; result = op->defaults_kwdict; } else { result = Py_None; } } Py_INCREF(result); return result; } static PyObject * __Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { PyObject* result; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_kwdefaults_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); if (!value || value == Py_None) { value = NULL; } else if (unlikely(!PyDict_Check(value))) { PyErr_SetString(PyExc_TypeError, "__annotations__ must be set to a dict object"); return -1; } Py_XINCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_annotations, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_annotations_locked(__pyx_CyFunctionObject *op) { PyObject* result = op->func_annotations; if (unlikely(!result)) { result = PyDict_New(); if (unlikely(!result)) return NULL; op->func_annotations = result; } Py_INCREF(result); return result; } static PyObject * __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { PyObject *result; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_annotations_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static PyObject * __Pyx_CyFunction_get_is_coroutine_value(__pyx_CyFunctionObject *op) { int is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; if (is_coroutine) { PyObject *is_coroutine_value, *module, *fromlist, *marker = __pyx_mstate_global->__pyx_n_u_is_coroutine; fromlist = PyList_New(1); if (unlikely(!fromlist)) return NULL; Py_INCREF(marker); #if CYTHON_ASSUME_SAFE_MACROS PyList_SET_ITEM(fromlist, 0, marker); #else if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { Py_DECREF(marker); Py_DECREF(fromlist); return NULL; } #endif module = PyImport_ImportModuleLevelObject(__pyx_mstate_global->__pyx_n_u_asyncio_coroutines, NULL, NULL, fromlist, 0); Py_DECREF(fromlist); if (unlikely(!module)) goto ignore; is_coroutine_value = __Pyx_PyObject_GetAttrStr(module, marker); Py_DECREF(module); if (likely(is_coroutine_value)) { return is_coroutine_value; } ignore: PyErr_Clear(); } return __Pyx_PyBool_FromLong(is_coroutine); } static PyObject * __Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { PyObject *result; CYTHON_UNUSED_VAR(context); if (op->func_is_coroutine) { return __Pyx_NewRef(op->func_is_coroutine); } result = __Pyx_CyFunction_get_is_coroutine_value(op); if (unlikely(!result)) return NULL; __Pyx_BEGIN_CRITICAL_SECTION(op); if (op->func_is_coroutine) { Py_DECREF(result); result = __Pyx_NewRef(op->func_is_coroutine); } else { op->func_is_coroutine = __Pyx_NewRef(result); } __Pyx_END_CRITICAL_SECTION(); return result; } static void __Pyx_CyFunction_raise_argument_count_error(__pyx_CyFunctionObject *func, const char* message, Py_ssize_t size) { #if CYTHON_COMPILING_IN_LIMITED_API PyObject *py_name = __Pyx_CyFunction_get_name(func, NULL); if (!py_name) return; PyErr_Format(PyExc_TypeError, "%.200S() %s (%" CYTHON_FORMAT_SSIZE_T "d given)", py_name, message, size); Py_DECREF(py_name); #else const char* name = ((PyCFunctionObject*)func)->m_ml->ml_name; PyErr_Format(PyExc_TypeError, "%.200s() %s (%" CYTHON_FORMAT_SSIZE_T "d given)", name, message, size); #endif } static void __Pyx_CyFunction_raise_type_error(__pyx_CyFunctionObject *func, const char* message) { #if CYTHON_COMPILING_IN_LIMITED_API PyObject *py_name = __Pyx_CyFunction_get_name(func, NULL); if (!py_name) return; PyErr_Format(PyExc_TypeError, "%.200S() %s", py_name, message); Py_DECREF(py_name); #else const char* name = ((PyCFunctionObject*)func)->m_ml->ml_name; PyErr_Format(PyExc_TypeError, "%.200s() %s", name, message); #endif } #if CYTHON_COMPILING_IN_LIMITED_API static PyObject * __Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); return PyObject_GetAttrString(op->func, "__module__"); } static int __Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); return PyObject_SetAttrString(op->func, "__module__", value); } #endif static PyGetSetDef __pyx_CyFunction_getsets[] = { {"func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, {"__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, {"func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, {"__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, {"__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, {"func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, {"__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, {"func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, {"__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, {"func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, {"__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, {"func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, {"__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, {"func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, {"__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, {"__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, {"__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, {"_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, #if CYTHON_COMPILING_IN_LIMITED_API {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, #endif {0, 0, 0, 0, 0} }; static PyMemberDef __pyx_CyFunction_members[] = { #if !CYTHON_COMPILING_IN_LIMITED_API {"__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, #endif {"__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, #if CYTHON_METH_FASTCALL #if CYTHON_BACKPORT_VECTORCALL || CYTHON_COMPILING_IN_LIMITED_API {"__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, #else {"__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, #endif #if CYTHON_COMPILING_IN_LIMITED_API {"__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, #else {"__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, #endif #endif {0, 0, 0, 0, 0} }; static PyObject * __Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) { PyObject *result = NULL; CYTHON_UNUSED_VAR(args); __Pyx_BEGIN_CRITICAL_SECTION(m); Py_INCREF(m->func_qualname); result = m->func_qualname; __Pyx_END_CRITICAL_SECTION(); return result; } static PyMethodDef __pyx_CyFunction_methods[] = { {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, {0, 0, 0, 0} }; #if CYTHON_COMPILING_IN_LIMITED_API #define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) #else #define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) #endif static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { #if !CYTHON_COMPILING_IN_LIMITED_API PyCFunctionObject *cf = (PyCFunctionObject*) op; #endif if (unlikely(op == NULL)) return NULL; #if CYTHON_COMPILING_IN_LIMITED_API op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); if (unlikely(!op->func)) return NULL; #endif op->flags = flags; __Pyx_CyFunction_weakreflist(op) = NULL; #if !CYTHON_COMPILING_IN_LIMITED_API cf->m_ml = ml; cf->m_self = (PyObject *) op; #endif Py_XINCREF(closure); op->func_closure = closure; #if !CYTHON_COMPILING_IN_LIMITED_API Py_XINCREF(module); cf->m_module = module; #endif op->func_dict = NULL; op->func_name = NULL; Py_INCREF(qualname); op->func_qualname = qualname; op->func_doc = NULL; #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API op->func_classobj = NULL; #else ((PyCMethodObject*)op)->mm_class = NULL; #endif op->func_globals = globals; Py_INCREF(op->func_globals); Py_XINCREF(code); op->func_code = code; op->defaults = NULL; op->defaults_tuple = NULL; op->defaults_kwdict = NULL; op->defaults_getter = NULL; op->func_annotations = NULL; op->func_is_coroutine = NULL; #if CYTHON_METH_FASTCALL switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { case METH_NOARGS: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; break; case METH_O: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; break; case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; break; case METH_FASTCALL | METH_KEYWORDS: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; break; case METH_VARARGS | METH_KEYWORDS: __Pyx_CyFunction_func_vectorcall(op) = NULL; break; default: PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); Py_DECREF(op); return NULL; } #endif return (PyObject *) op; } static int __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) { Py_CLEAR(m->func_closure); #if CYTHON_COMPILING_IN_LIMITED_API Py_CLEAR(m->func); #else Py_CLEAR(((PyCFunctionObject*)m)->m_module); #endif Py_CLEAR(m->func_dict); Py_CLEAR(m->func_name); Py_CLEAR(m->func_qualname); Py_CLEAR(m->func_doc); Py_CLEAR(m->func_globals); Py_CLEAR(m->func_code); #if !CYTHON_COMPILING_IN_LIMITED_API #if PY_VERSION_HEX < 0x030900B1 Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); #else { PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; ((PyCMethodObject *) (m))->mm_class = NULL; Py_XDECREF(cls); } #endif #endif Py_CLEAR(m->defaults_tuple); Py_CLEAR(m->defaults_kwdict); Py_CLEAR(m->func_annotations); Py_CLEAR(m->func_is_coroutine); Py_CLEAR(m->defaults); return 0; } static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) { if (__Pyx_CyFunction_weakreflist(m) != NULL) PyObject_ClearWeakRefs((PyObject *) m); __Pyx_CyFunction_clear(m); __Pyx_PyHeapTypeObject_GC_Del(m); } static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) { PyObject_GC_UnTrack(m); __Pyx__CyFunction_dealloc(m); } static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) { { int e = __Pyx_call_type_traverse((PyObject*)m, 1, visit, arg); if (e) return e; } Py_VISIT(m->func_closure); #if CYTHON_COMPILING_IN_LIMITED_API Py_VISIT(m->func); #else Py_VISIT(((PyCFunctionObject*)m)->m_module); #endif Py_VISIT(m->func_dict); __Pyx_VISIT_CONST(m->func_name); __Pyx_VISIT_CONST(m->func_qualname); Py_VISIT(m->func_doc); Py_VISIT(m->func_globals); __Pyx_VISIT_CONST(m->func_code); #if !CYTHON_COMPILING_IN_LIMITED_API Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); #endif Py_VISIT(m->defaults_tuple); Py_VISIT(m->defaults_kwdict); Py_VISIT(m->func_is_coroutine); Py_VISIT(m->defaults); return 0; } static PyObject* __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) { PyObject *repr; __Pyx_BEGIN_CRITICAL_SECTION(op); repr = PyUnicode_FromFormat("", op->func_qualname, (void *)op); __Pyx_END_CRITICAL_SECTION(); return repr; } static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { #if CYTHON_COMPILING_IN_LIMITED_API PyObject *f = ((__pyx_CyFunctionObject*)func)->func; PyCFunction meth; int flags; meth = PyCFunction_GetFunction(f); if (unlikely(!meth)) return NULL; flags = PyCFunction_GetFlags(f); if (unlikely(flags < 0)) return NULL; #else PyCFunctionObject* f = (PyCFunctionObject*)func; PyCFunction meth = f->m_ml->ml_meth; int flags = f->m_ml->ml_flags; #endif Py_ssize_t size; switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { case METH_VARARGS: if (likely(kw == NULL || PyDict_Size(kw) == 0)) return (*meth)(self, arg); break; case METH_VARARGS | METH_KEYWORDS: return (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, arg, kw); case METH_NOARGS: if (likely(kw == NULL || PyDict_Size(kw) == 0)) { #if CYTHON_ASSUME_SAFE_SIZE size = PyTuple_GET_SIZE(arg); #else size = PyTuple_Size(arg); if (unlikely(size < 0)) return NULL; #endif if (likely(size == 0)) return (*meth)(self, NULL); __Pyx_CyFunction_raise_argument_count_error( (__pyx_CyFunctionObject*)func, "takes no arguments", size); return NULL; } break; case METH_O: if (likely(kw == NULL || PyDict_Size(kw) == 0)) { #if CYTHON_ASSUME_SAFE_SIZE size = PyTuple_GET_SIZE(arg); #else size = PyTuple_Size(arg); if (unlikely(size < 0)) return NULL; #endif if (likely(size == 1)) { PyObject *result, *arg0; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS arg0 = PyTuple_GET_ITEM(arg, 0); #else arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; #endif result = (*meth)(self, arg0); #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) Py_DECREF(arg0); #endif return result; } __Pyx_CyFunction_raise_argument_count_error( (__pyx_CyFunctionObject*)func, "takes exactly one argument", size); return NULL; } break; default: PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); return NULL; } __Pyx_CyFunction_raise_type_error( (__pyx_CyFunctionObject*)func, "takes no keyword arguments"); return NULL; } static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *self, *result; #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)func)->m_self; #endif result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); return result; } static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { PyObject *result; __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); if (vc) { #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); #else (void) &__Pyx_PyVectorcall_FastCallDict; return PyVectorcall_Call(func, args, kw); #endif } #endif if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { Py_ssize_t argc; PyObject *new_args; PyObject *self; #if CYTHON_ASSUME_SAFE_SIZE argc = PyTuple_GET_SIZE(args); #else argc = PyTuple_Size(args); if (unlikely(argc < 0)) return NULL; #endif new_args = PyTuple_GetSlice(args, 1, argc); if (unlikely(!new_args)) return NULL; self = PyTuple_GetItem(args, 0); if (unlikely(!self)) { Py_DECREF(new_args); PyErr_Format(PyExc_TypeError, "unbound method %.200S() needs an argument", cyfunc->func_qualname); return NULL; } result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); Py_DECREF(new_args); } else { result = __Pyx_CyFunction_Call(func, args, kw); } return result; } #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) { int ret = 0; if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { if (unlikely(nargs < 1)) { __Pyx_CyFunction_raise_type_error( cyfunc, "needs an argument"); return -1; } ret = 1; } if (unlikely(kwnames) && unlikely(__Pyx_PyTuple_GET_SIZE(kwnames))) { __Pyx_CyFunction_raise_type_error( cyfunc, "takes no keyword arguments"); return -1; } return ret; } static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } if (unlikely(nargs != 0)) { __Pyx_CyFunction_raise_argument_count_error( cyfunc, "takes no arguments", nargs); return NULL; } return meth(self, NULL); } static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } if (unlikely(nargs != 1)) { __Pyx_CyFunction_raise_argument_count_error( cyfunc, "takes exactly one argument", nargs); return NULL; } return meth(self, args[0]); } static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))meth)(self, args, nargs, kwnames); } static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } return ((__Pyx_PyCMethod)(void(*)(void))meth)(self, cls, args, (size_t)nargs, kwnames); } #endif static PyType_Slot __pyx_CyFunctionType_slots[] = { {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, {Py_tp_methods, (void *)__pyx_CyFunction_methods}, {Py_tp_members, (void *)__pyx_CyFunction_members}, {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, {0, 0}, }; static PyType_Spec __pyx_CyFunctionType_spec = { __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", sizeof(__pyx_CyFunctionObject), 0, #ifdef Py_TPFLAGS_METHOD_DESCRIPTOR Py_TPFLAGS_METHOD_DESCRIPTOR | #endif #if CYTHON_METH_FASTCALL #if defined(Py_TPFLAGS_HAVE_VECTORCALL) Py_TPFLAGS_HAVE_VECTORCALL | #elif defined(_Py_TPFLAGS_HAVE_VECTORCALL) _Py_TPFLAGS_HAVE_VECTORCALL | #endif #endif // CYTHON_METH_FASTCALL #if PY_VERSION_HEX >= 0x030A0000 Py_TPFLAGS_IMMUTABLETYPE | #endif Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, __pyx_CyFunctionType_slots }; static int __pyx_CyFunction_init(PyObject *module) { __pyx_mstatetype *mstate = __Pyx_PyModule_GetState(module); mstate->__pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec( mstate->__pyx_CommonTypesMetaclassType, module, &__pyx_CyFunctionType_spec, NULL); if (unlikely(mstate->__pyx_CyFunctionType == NULL)) { return -1; } return 0; } static CYTHON_INLINE PyObject *__Pyx_CyFunction_InitDefaults(PyObject *func, PyTypeObject *defaults_type) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults = PyObject_CallObject((PyObject*)defaults_type, NULL); // _PyObject_New(defaults_type); if (unlikely(!m->defaults)) return NULL; return m->defaults; } static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults_tuple = tuple; Py_INCREF(tuple); } static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults_kwdict = dict; Py_INCREF(dict); } static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->func_annotations = dict; Py_INCREF(dict); } /* CythonFunction */ static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { PyObject *op = __Pyx_CyFunction_Init( PyObject_GC_New(__pyx_CyFunctionObject, __pyx_mstate_global->__pyx_CyFunctionType), ml, flags, qualname, closure, module, globals, code ); if (likely(op)) { PyObject_GC_Track(op); } return op; } /* CalculateMetaclass */ static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) { Py_ssize_t i, nbases; #if CYTHON_ASSUME_SAFE_SIZE nbases = PyTuple_GET_SIZE(bases); #else nbases = PyTuple_Size(bases); if (nbases < 0) return NULL; #endif for (i=0; i < nbases; i++) { PyTypeObject *tmptype; #if CYTHON_ASSUME_SAFE_MACROS PyObject *tmp = PyTuple_GET_ITEM(bases, i); #else PyObject *tmp = PyTuple_GetItem(bases, i); if (!tmp) return NULL; #endif tmptype = Py_TYPE(tmp); if (!metaclass) { metaclass = tmptype; continue; } if (PyType_IsSubtype(metaclass, tmptype)) continue; if (PyType_IsSubtype(tmptype, metaclass)) { metaclass = tmptype; continue; } PyErr_SetString(PyExc_TypeError, "metaclass conflict: " "the metaclass of a derived class " "must be a (non-strict) subclass " "of the metaclasses of all its bases"); return NULL; } if (!metaclass) { metaclass = &PyType_Type; } Py_INCREF((PyObject*) metaclass); return (PyObject*) metaclass; } /* PyObjectLookupSpecial */ #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error) { PyObject *res; PyTypeObject *tp = Py_TYPE(obj); res = _PyType_Lookup(tp, attr_name); if (likely(res)) { descrgetfunc f = Py_TYPE(res)->tp_descr_get; if (!f) { Py_INCREF(res); } else { res = f(res, obj, (PyObject *)tp); } } else if (with_error) { PyErr_SetObject(PyExc_AttributeError, attr_name); } return res; } #endif /* Py3ClassCreate */ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) { PyObject *ns; if (metaclass) { PyObject *prep = __Pyx_PyObject_GetAttrStrNoError(metaclass, __pyx_mstate_global->__pyx_n_u_prepare); if (prep) { PyObject *pargs[3] = {NULL, name, bases}; ns = __Pyx_PyObject_FastCallDict(prep, pargs+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, mkw); Py_DECREF(prep); } else { if (unlikely(PyErr_Occurred())) return NULL; ns = PyDict_New(); } } else { ns = PyDict_New(); } if (unlikely(!ns)) return NULL; if (unlikely(PyObject_SetItem(ns, __pyx_mstate_global->__pyx_n_u_module, modname) < 0)) goto bad; if (unlikely(PyObject_SetItem(ns, __pyx_mstate_global->__pyx_n_u_qualname, qualname) < 0)) goto bad; if (unlikely(doc && PyObject_SetItem(ns, __pyx_mstate_global->__pyx_n_u_doc, doc) < 0)) goto bad; return ns; bad: Py_DECREF(ns); return NULL; } static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass) { PyObject *result; PyObject *owned_metaclass = NULL; PyObject *margs[4] = {NULL, name, bases, dict}; if (allow_py2_metaclass) { owned_metaclass = PyObject_GetItem(dict, __pyx_mstate_global->__pyx_n_u_metaclass); if (owned_metaclass) { metaclass = owned_metaclass; } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) { PyErr_Clear(); } else { return NULL; } } if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) { metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases); Py_XDECREF(owned_metaclass); if (unlikely(!metaclass)) return NULL; owned_metaclass = metaclass; } result = __Pyx_PyObject_FastCallDict(metaclass, margs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, mkw); Py_XDECREF(owned_metaclass); return result; } /* Py3UpdateBases */ static PyObject* __Pyx_PEP560_update_bases(PyObject *bases) { Py_ssize_t i, j, size_bases; PyObject *base = NULL, *meth, *new_base, *result, *new_bases = NULL; #if CYTHON_ASSUME_SAFE_SIZE size_bases = PyTuple_GET_SIZE(bases); #else size_bases = PyTuple_Size(bases); if (size_bases < 0) return NULL; #endif for (i = 0; i < size_bases; i++) { #if CYTHON_AVOID_BORROWED_REFS Py_CLEAR(base); #endif #if CYTHON_ASSUME_SAFE_MACROS base = PyTuple_GET_ITEM(bases, i); #else base = PyTuple_GetItem(bases, i); if (!base) goto error; #endif #if CYTHON_AVOID_BORROWED_REFS Py_INCREF(base); #endif if (PyType_Check(base)) { if (new_bases) { if (PyList_Append(new_bases, base) < 0) { goto error; } } continue; } meth = __Pyx_PyObject_GetAttrStrNoError(base, __pyx_mstate_global->__pyx_n_u_mro_entries); if (!meth && PyErr_Occurred()) { goto error; } if (!meth) { if (new_bases) { if (PyList_Append(new_bases, base) < 0) { goto error; } } continue; } new_base = __Pyx_PyObject_CallOneArg(meth, bases); Py_DECREF(meth); if (!new_base) { goto error; } if (!PyTuple_Check(new_base)) { PyErr_SetString(PyExc_TypeError, "__mro_entries__ must return a tuple"); Py_DECREF(new_base); goto error; } if (!new_bases) { if (!(new_bases = PyList_New(i))) { goto error; } for (j = 0; j < i; j++) { PyObject *base_from_list; #if CYTHON_ASSUME_SAFE_MACROS base_from_list = PyTuple_GET_ITEM(bases, j); PyList_SET_ITEM(new_bases, j, base_from_list); Py_INCREF(base_from_list); #else base_from_list = PyTuple_GetItem(bases, j); if (!base_from_list) goto error; Py_INCREF(base_from_list); if (PyList_SetItem(new_bases, j, base_from_list) < 0) goto error; #endif } } #if CYTHON_ASSUME_SAFE_SIZE j = PyList_GET_SIZE(new_bases); #else j = PyList_Size(new_bases); if (j < 0) goto error; #endif if (PyList_SetSlice(new_bases, j, j, new_base) < 0) { goto error; } Py_DECREF(new_base); } if (!new_bases) { Py_INCREF(bases); return bases; } result = PyList_AsTuple(new_bases); Py_DECREF(new_bases); #if CYTHON_AVOID_BORROWED_REFS Py_XDECREF(base); #endif return result; error: Py_XDECREF(new_bases); #if CYTHON_AVOID_BORROWED_REFS Py_XDECREF(base); #endif return NULL; } /* 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_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_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 __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format __Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(PyObject *x) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif const __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format neg_one = (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) -1, const_zero = (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) 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_parser_py_datetime_format val; PyObject *tmp = __Pyx_PyNumber_Long(x); if (!tmp) return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) -1; val = __Pyx_PyLong_As___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(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_parser_py_datetime_format, __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_parser_py_datetime_format) > 1 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) >= 2 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) (((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0])); } } break; case 3: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) > 2 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format) >= 3 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) (((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0])); } } break; case 4: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) > 3 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format) >= 4 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) (((((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[3]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)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_parser_py_datetime_format) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if ((sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= sizeof(unsigned long))) { __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if ((sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= sizeof(unsigned PY_LONG_LONG))) { __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format, __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_parser_py_datetime_format) - 1 > 1 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) - 1 > 2 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) (((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)-1)*(((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0]))); } } break; case 2: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) > 1 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) - 1 > 2 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) ((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0]))); } } break; case -3: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) - 1 > 2 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format) - 1 > 3 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) (((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)-1)*(((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0]))); } } break; case 3: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) > 2 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format) - 1 > 3 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) ((((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0]))); } } break; case -4: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) - 1 > 3 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format) - 1 > 4 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) (((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)-1)*(((((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[3]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0]))); } } break; case 4: if ((8 * sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) > 3 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, 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_parser_py_datetime_format) - 1 > 4 * PyLong_SHIFT)) { return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) ((((((((((__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[3]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[2]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[1]) << PyLong_SHIFT) | (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format)digits[0]))); } } break; } } #endif if ((sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= sizeof(long))) { __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if ((sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= sizeof(PY_LONG_LONG))) { __PYX_VERIFY_RETURN_INT_EXC(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format 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_parser_py_datetime_format) -1; #endif if (unlikely(ret)) return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) -1; return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format"); return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format"); return (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) -1; } /* 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_char(char value) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif const char neg_one = (char) -1, const_zero = (char) 0; #ifdef __Pyx_HAS_GCC_DIAGNOSTIC #pragma GCC diagnostic pop #endif const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(char) < sizeof(long)) { return PyLong_FromLong((long) value); } else if (sizeof(char) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(char) <= sizeof(long)) { return PyLong_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(char) <= 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(char), 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(char)); 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___pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format value) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif const __pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format neg_one = (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) -1, const_zero = (__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) 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_parser_py_datetime_format) < sizeof(long)) { return PyLong_FromLong((long) value); } else if (sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= 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_parser_py_datetime_format) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= sizeof(long)) { return PyLong_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(__pyx_t_10pyreadstat_16_readstat_parser_py_datetime_format) <= 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_parser_py_datetime_format), 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_parser_py_datetime_format)); 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 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; } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_off_t(off_t value) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif const off_t neg_one = (off_t) -1, const_zero = (off_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(off_t) < sizeof(long)) { return PyLong_FromLong((long) value); } else if (sizeof(off_t) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY } else if (sizeof(off_t) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(off_t) <= sizeof(long)) { return PyLong_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(off_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(off_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(off_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 } } /* CIntFromPy */ static CYTHON_INLINE off_t __Pyx_PyLong_As_off_t(PyObject *x) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif const off_t neg_one = (off_t) -1, const_zero = (off_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))) { off_t val; PyObject *tmp = __Pyx_PyNumber_Long(x); if (!tmp) return (off_t) -1; val = __Pyx_PyLong_As_off_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(off_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(off_t) > 1 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(off_t) >= 2 * PyLong_SHIFT)) { return (off_t) (((((off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0])); } } break; case 3: if ((8 * sizeof(off_t) > 2 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(off_t) >= 3 * PyLong_SHIFT)) { return (off_t) (((((((off_t)digits[2]) << PyLong_SHIFT) | (off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0])); } } break; case 4: if ((8 * sizeof(off_t) > 3 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_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(off_t) >= 4 * PyLong_SHIFT)) { return (off_t) (((((((((off_t)digits[3]) << PyLong_SHIFT) | (off_t)digits[2]) << PyLong_SHIFT) | (off_t)digits[1]) << PyLong_SHIFT) | (off_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 (off_t) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if ((sizeof(off_t) <= sizeof(unsigned long))) { __PYX_VERIFY_RETURN_INT_EXC(off_t, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if ((sizeof(off_t) <= sizeof(unsigned PY_LONG_LONG))) { __PYX_VERIFY_RETURN_INT_EXC(off_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS if (__Pyx_PyLong_IsCompact(x)) { __PYX_VERIFY_RETURN_INT(off_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(off_t) - 1 > 1 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(off_t) - 1 > 2 * PyLong_SHIFT)) { return (off_t) (((off_t)-1)*(((((off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0]))); } } break; case 2: if ((8 * sizeof(off_t) > 1 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(off_t) - 1 > 2 * PyLong_SHIFT)) { return (off_t) ((((((off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0]))); } } break; case -3: if ((8 * sizeof(off_t) - 1 > 2 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(off_t) - 1 > 3 * PyLong_SHIFT)) { return (off_t) (((off_t)-1)*(((((((off_t)digits[2]) << PyLong_SHIFT) | (off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0]))); } } break; case 3: if ((8 * sizeof(off_t) > 2 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if ((8 * sizeof(off_t) - 1 > 3 * PyLong_SHIFT)) { return (off_t) ((((((((off_t)digits[2]) << PyLong_SHIFT) | (off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0]))); } } break; case -4: if ((8 * sizeof(off_t) - 1 > 3 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_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(off_t) - 1 > 4 * PyLong_SHIFT)) { return (off_t) (((off_t)-1)*(((((((((off_t)digits[3]) << PyLong_SHIFT) | (off_t)digits[2]) << PyLong_SHIFT) | (off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0]))); } } break; case 4: if ((8 * sizeof(off_t) > 3 * PyLong_SHIFT)) { if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { __PYX_VERIFY_RETURN_INT(off_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(off_t) - 1 > 4 * PyLong_SHIFT)) { return (off_t) ((((((((((off_t)digits[3]) << PyLong_SHIFT) | (off_t)digits[2]) << PyLong_SHIFT) | (off_t)digits[1]) << PyLong_SHIFT) | (off_t)digits[0]))); } } break; } } #endif if ((sizeof(off_t) <= sizeof(long))) { __PYX_VERIFY_RETURN_INT_EXC(off_t, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if ((sizeof(off_t) <= sizeof(PY_LONG_LONG))) { __PYX_VERIFY_RETURN_INT_EXC(off_t, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { off_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 (off_t) -1; assert(PyLong_CheckExact(v)); } { int result = PyObject_RichCompareBool(v, Py_False, Py_LT); if (unlikely(result < 0)) { Py_DECREF(v); return (off_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 (off_t) -1; } else { stepval = v; } v = NULL; val = (off_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(off_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 |= ((off_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(off_t) * 8) - bits - (is_unsigned ? 0 : 1); if (unlikely(idigit >= (1L << remaining_bits))) goto raise_overflow; val |= ((off_t) idigit) << bits; } if (!is_unsigned) { if (unlikely(val & (((off_t) 1) << (sizeof(off_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 (off_t) -1; return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to off_t"); return (off_t) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to off_t"); return (off_t) -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__4); } goto done; } #endif /* 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= 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); } } /* VoidPtrExport */ static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) { PyObject *d; PyObject *cobj = 0; if (__Pyx_PyDict_GetItemRef(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_pyx_capi, &d) == -1) goto bad; if (!d) { d = PyDict_New(); if (!d) goto bad; if (__Pyx_PyObject_SetAttrStr(__pyx_m, __pyx_mstate_global->__pyx_n_u_pyx_capi, d) < 0) goto bad; } cobj = PyCapsule_New(p, sig, 0); if (!cobj) goto bad; if (PyDict_SetItem(d, name, cobj) < 0) goto bad; Py_DECREF(cobj); Py_DECREF(d); return 0; bad: Py_XDECREF(cobj); Py_XDECREF(d); return -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; } /* NewCodeObj */ #if CYTHON_COMPILING_IN_LIMITED_API static PyObject* __Pyx__PyCode_New(int a, int p, int k, int l, int s, int f, PyObject *code, PyObject *c, PyObject* n, PyObject *v, PyObject *fv, PyObject *cell, PyObject* fn, PyObject *name, int fline, PyObject *lnos) { PyObject *exception_table = NULL; PyObject *types_module=NULL, *code_type=NULL, *result=NULL; #if __PYX_LIMITED_VERSION_HEX < 0x030b0000 PyObject *version_info; PyObject *py_minor_version = NULL; #endif long minor_version = 0; PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); #if __PYX_LIMITED_VERSION_HEX >= 0x030b0000 minor_version = 11; #else if (!(version_info = PySys_GetObject("version_info"))) goto end; if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; minor_version = PyLong_AsLong(py_minor_version); Py_DECREF(py_minor_version); if (minor_version == -1 && PyErr_Occurred()) goto end; #endif if (!(types_module = PyImport_ImportModule("types"))) goto end; if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; if (minor_version <= 7) { (void)p; result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOOO", a, k, l, s, f, code, c, n, v, fn, name, fline, lnos, fv, cell); } else if (minor_version <= 10) { result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOOO", a,p, k, l, s, f, code, c, n, v, fn, name, fline, lnos, fv, cell); } else { if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOOOO", a,p, k, l, s, f, code, c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); } end: Py_XDECREF(code_type); Py_XDECREF(exception_table); Py_XDECREF(types_module); if (type) { PyErr_Restore(type, value, traceback); } return result; } #elif PY_VERSION_HEX >= 0x030B0000 static PyCodeObject* __Pyx__PyCode_New(int a, int p, int k, int l, int s, int f, PyObject *code, PyObject *c, PyObject* n, PyObject *v, PyObject *fv, PyObject *cell, PyObject* fn, PyObject *name, int fline, PyObject *lnos) { PyCodeObject *result; result = #if PY_VERSION_HEX >= 0x030C0000 PyUnstable_Code_NewWithPosOnlyArgs #else PyCode_NewWithPosOnlyArgs #endif (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, __pyx_mstate_global->__pyx_empty_bytes); return result; } #elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY #define __Pyx__PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #else #define __Pyx__PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #endif static PyObject* __Pyx_PyCode_New( const __Pyx_PyCode_New_function_description descr, PyObject * const *varnames, PyObject *filename, PyObject *funcname, const char *line_table, PyObject *tuple_dedup_map ) { PyObject *code_obj = NULL, *varnames_tuple_dedup = NULL, *code_bytes = NULL, *line_table_bytes = NULL; Py_ssize_t var_count = (Py_ssize_t) descr.nlocals; PyObject *varnames_tuple = PyTuple_New(var_count); if (unlikely(!varnames_tuple)) return NULL; for (Py_ssize_t i=0; i < var_count; i++) { Py_INCREF(varnames[i]); if (__Pyx_PyTuple_SET_ITEM(varnames_tuple, i, varnames[i]) != (0)) goto done; } #if CYTHON_COMPILING_IN_LIMITED_API varnames_tuple_dedup = PyDict_GetItem(tuple_dedup_map, varnames_tuple); if (!varnames_tuple_dedup) { if (unlikely(PyDict_SetItem(tuple_dedup_map, varnames_tuple, varnames_tuple) < 0)) goto done; varnames_tuple_dedup = varnames_tuple; } #else varnames_tuple_dedup = PyDict_SetDefault(tuple_dedup_map, varnames_tuple, varnames_tuple); if (unlikely(!varnames_tuple_dedup)) goto done; #endif #if CYTHON_AVOID_BORROWED_REFS Py_INCREF(varnames_tuple_dedup); #endif if (__PYX_LIMITED_VERSION_HEX >= (0x030b0000) && line_table != NULL && !CYTHON_COMPILING_IN_GRAAL) { line_table_bytes = PyBytes_FromStringAndSize(line_table, descr.line_table_length); if (unlikely(!line_table_bytes)) goto done; Py_ssize_t code_len = (descr.line_table_length * 2 + 4) & ~3; code_bytes = PyBytes_FromStringAndSize(NULL, code_len); if (unlikely(!code_bytes)) goto done; char* c_code_bytes = PyBytes_AsString(code_bytes); if (unlikely(!c_code_bytes)) goto done; memset(c_code_bytes, 0, (size_t) code_len); } code_obj = (PyObject*) __Pyx__PyCode_New( (int) descr.argcount, (int) descr.num_posonly_args, (int) descr.num_kwonly_args, (int) descr.nlocals, 0, (int) descr.flags, code_bytes ? code_bytes : __pyx_mstate_global->__pyx_empty_bytes, __pyx_mstate_global->__pyx_empty_tuple, __pyx_mstate_global->__pyx_empty_tuple, varnames_tuple_dedup, __pyx_mstate_global->__pyx_empty_tuple, __pyx_mstate_global->__pyx_empty_tuple, filename, funcname, (int) descr.first_line, (__PYX_LIMITED_VERSION_HEX >= (0x030b0000) && line_table_bytes) ? line_table_bytes : __pyx_mstate_global->__pyx_empty_bytes ); done: Py_XDECREF(code_bytes); Py_XDECREF(line_table_bytes); #if CYTHON_AVOID_BORROWED_REFS Py_XDECREF(varnames_tuple_dedup); #endif Py_DECREF(varnames_tuple); return code_obj; } /* 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 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 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 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 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 // 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 (; readmodule) { write->id = read->id; write->module = read->module; ++write; } } data->count = write - data->table; for (; writeid = 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; icount; ++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_boundid = (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 */ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1755175692.0 pyreadstat-1.3.3/pyreadstat/_readstat_parser.pxd0000644000076500000240000001357615047355414020501 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# from libc.stddef cimport wchar_t from readstat_api cimport * # Definitions of enum types ctypedef enum py_file_extension: FILE_EXT_SAV FILE_EXT_SAS7BDAT FILE_EXT_DTA FILE_EXT_XPORT FILE_EXT_POR FILE_EXT_SAS7BCAT ctypedef enum py_file_format: FILE_FORMAT_SAS FILE_FORMAT_SPSS FILE_FORMAT_STATA ctypedef enum py_datetime_format: DATE_FORMAT_NOTADATE DATE_FORMAT_DATE DATE_FORMAT_DATETIME DATE_FORMAT_TIME ctypedef enum py_variable_format: VAR_FORMAT_STRING VAR_FORMAT_LONG VAR_FORMAT_FLOAT VAR_FORMAT_MISSING # Definitions of extension types cdef class data_container: """ This extension type holds all the data we need to get from our file from the readstat parser and will be used later to compose our pandas data frame """ cdef int n_obs cdef int n_vars cdef int max_n_obs cdef list col_data cdef list col_data_len cdef list col_names cdef list col_labels cdef list col_dtypes cdef list col_numpy_dtypes cdef list col_dtypes_isobject cdef list col_dytpes_isfloat cdef list col_formats cdef list col_formats_original cdef object origin cdef double unix_to_origin_secs cdef py_file_format file_format cdef bint is_unkown_number_rows cdef str file_label cdef str file_encoding cdef bint metaonly cdef bint dates_as_pandas cdef object label_to_var_name cdef object labels_raw cdef object notes cdef str user_encoding cdef str table_name cdef bint filter_cols cdef list use_cols cdef bint usernan cdef dict missing_ranges cdef dict missing_user_values cdef dict variable_storage_width cdef variable_display_width cdef variable_alignment cdef variable_measure cdef bint no_datetime_conversion cdef int ctime cdef int mtime cdef dict mr_sets cdef str output_format cdef dict readstat_to_numpy_types # definitions of functions cdef py_datetime_format transform_variable_format(str var_format, py_file_format file_format) cdef object transform_datetime(py_datetime_format var_format, double tstamp, py_file_format file_format, object origin, bint dates_as_pandas, str output_format, double unix_to_origin_secs) cdef int handle_metadata(readstat_metadata_t *metadata, void *ctx) except READSTAT_HANDLER_ABORT cdef int handle_variable(int index, readstat_variable_t *variable, char *val_labels, void *ctx) except READSTAT_HANDLER_ABORT cdef int handle_value(int obs_index, readstat_variable_t * variable, readstat_value_t value, void *ctx) except READSTAT_HANDLER_ABORT cdef int handle_value_label(char *val_labels, readstat_value_t value, char *label, void *ctx) except READSTAT_HANDLER_ABORT cdef int handle_note (int note_index, char *note, void *ctx) except READSTAT_HANDLER_ABORT cdef void check_exit_status(readstat_error_t retcode) except * cdef void run_readstat_parser(char * filename, data_container data, py_file_extension file_extension, long row_limit, long row_offset) except * cdef object data_container_to_dict(data_container data) cdef object dict_to_dataframe(object dict_data, data_container dc) cdef object data_container_extract_metadata(data_container data) cdef object run_conversion(object filename_path, py_file_format file_format, py_file_extension file_extension, str encoding, bint metaonly, bint dates_as_pandas, list usecols, bint usernan, bint no_datetime_conversion, long row_limit, long row_offset, str output_format, list extra_datetime_formats, list extra_date_formats, list extra_time_formats) # definitions for stuff about dates cdef list sas_date_formats cdef list sas_datetime_formats cdef list sas_time_formats cdef list sas_all_formats cdef object sas_origin cdef list spss_datetime_formats cdef list spss_date_formats cdef list spss_time_formats cdef list spss_all_formats cdef object spss_origin cdef list stata_datetime_formats cdef list stata_date_formats cdef list stata_time_formats cdef list stata_all_formats cdef object stata_origin # Stuff for opening files on windows in order to handle international characters # Courtesy of Jonathon Love # works only in python 3 #cdef extern from "readstat_io_unistd.h": # cdef struct unistd_io_ctx_t "unistd_io_ctx_s": # int fd cdef extern from "Python.h": wchar_t* PyUnicode_AsWideCharString(object, Py_ssize_t *) except NULL # these ones would make the c file produced by cython not portable between windows and unix # therefore the conditional including of the libraries is handled in C cdef extern from "conditional_includes.h": int _wsopen(const wchar_t *filename, int oflag, int shflag, int pmode) int _O_RDONLY int _O_BINARY int _O_WRONLY int _O_CREAT int _SH_DENYRW # Denies read and write access to a file. int _SH_DENYWR # Denies write access to a file. int _SH_DENYRD # Denies read access to a file. int _SH_DENYNO void assign_fd(void *io_ctx, int fd) long seek_fd(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769166384.0 pyreadstat-1.3.3/pyreadstat/_readstat_parser.pyx0000644000076500000240000014716115134653060020517 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# from cpython.datetime cimport import_datetime, timedelta_new, datetime_new, total_seconds from cpython.exc cimport PyErr_Occurred from cpython.object cimport PyObject from libc.math cimport floor from libc.string cimport memcpy from collections import OrderedDict import datetime import os import warnings import sys import narwhals.stable.v2 as nw import numpy as np from readstat_api cimport * # necessary to work with the datetime C API import_datetime() cdef object unix_origin = datetime_new(1970, 1, 1, 0, 0, 0, 0, None) cdef list sas_date_formats = ["WEEKDATE", "MMDDYY", "DDMMYY", "YYMMDD", "DATE", "DATE9", "YYMMDD10", "DDMMYYB", "DDMMYYB10", "DDMMYYC", "DDMMYYC10", "DDMMYYD", "DDMMYYD10", "DDMMYYN6", "DDMMYYN8", "DDMMYYP", "DDMMYYP10", "DDMMYYS", "DDMMYYS10", "MMDDYYB", "MMDDYYB10", "MMDDYYC", "MMDDYYC10", "MMDDYYD", "MMDDYYD10", "MMDDYYN6", "MMDDYYN8", "MMDDYYP", "MMDDYYP10", "MMDDYYS", "MMDDYYS10", #"MONNAME", "MONTH", "WEEKDAY", "QTR", "QTRR", "YEAR","DAY", "DOWNAME" # these do not print as full dates in sas "WEEKDATX", "DTDATE", "IS8601DA", "E8601DA", "B8601DA", "YYMMDDB", "YYMMDDD", "YYMMDDN", "YYMMDDP", "YYMMDDS",] cdef list sas_datetime_formats = ["DATETIME", "DATETIME18", "DATETIME19", "DATETIME20", "DATETIME21", "DATETIME22", "E8601DT", "DATEAMPM", "MDYAMPM", "IS8601DT", "B8601DT", "B8601DN"] cdef list sas_time_formats = ["TIME", "HHMM", "TIME20.3", "TIME20", "TIME5", "TOD", "TIMEAMPM", "IS8601TM", "E8601TM", "B8601TM", ] # "HOUR" # these do not print as full time formats in sas #cdef list sas_all_formats = sas_date_formats + sas_datetime_formats + sas_time_formats cdef list sas_all_formats cdef object sas_origin = datetime_new(1960, 1, 1, 0, 0, 0, 0, None) cdef object sas_secs_from_unix = total_seconds(unix_origin - sas_origin) cdef list spss_datetime_formats = ["DATETIME", "DATETIME8", 'DATETIME17', 'DATETIME20', 'DATETIME23.2',"YMDHMS16","YMDHMS19","YMDHMS19.2", "YMDHMS20"] cdef list spss_date_formats = ["DATE",'DATE8','DATE11', 'DATE12', "ADATE","ADATE8", "ADATE10", "EDATE", 'EDATE8','EDATE10', "JDATE", "JDATE5", "JDATE7", "SDATE", "SDATE8", "SDATE10",] cdef list spss_time_formats = ["TIME", "DTIME", 'TIME8', 'TIME5', 'TIME11.2'] #cdef list spss_all_formats = spss_date_formats + spss_datetime_formats + spss_time_formats cdef list spss_all_formats cdef object spss_origin = datetime_new(1582, 10, 14, 0, 0, 0, 0, None) cdef object spss_secs_from_unix = total_seconds(unix_origin - spss_origin) cdef list stata_datetime_formats = ["%tC", "%tc"] cdef list stata_date_formats = ["%td", "%d", "%tdD_m_Y", "%tdCCYY-NN-DD"] cdef list stata_time_formats = ["%tcHH:MM:SS", "%tcHH:MM"] #cdef list stata_all_formats = stata_datetime_formats + stata_date_formats + stata_time_formats cdef list stata_all_formats cdef object stata_origin = datetime_new(1960, 1, 1, 0, 0, 0, 0, None) cdef object stata_secs_from_unix = total_seconds(unix_origin - stata_origin) cdef dict readstat_to_numpy_types = {READSTAT_TYPE_STRING: object, READSTAT_TYPE_STRING_REF: object, READSTAT_TYPE_INT8: np.int64, READSTAT_TYPE_INT16: np.int64, READSTAT_TYPE_INT32:np.int64, READSTAT_TYPE_FLOAT: np.float64, READSTAT_TYPE_DOUBLE: np.float64} cdef class data_container: """ This extension type holds all the data we need to get from our file from the readstat parser and will be used later to compose our pandas data frame """ def __cinit__(self): self.n_obs = 0 self.n_vars = 0 self.max_n_obs = 0 self.col_data = list() self.col_data_len = list() self.col_names = list() self.col_labels = list() self.col_dtypes = list() self.col_numpy_dtypes = list() self.col_dtypes_isobject = list() self.col_dytpes_isfloat = list() self.col_formats = list() self.col_formats_original = list() self.origin = None self.unix_to_origin_secs = 0 self.is_unkown_number_rows = 0 self.file_encoding = None self.file_label = None self.metaonly = 0 self.dates_as_pandas = 0 self.label_to_var_name = dict() self.labels_raw = dict() self.notes = list() self.user_encoding = None self.table_name = None self.filter_cols = 0 self.use_cols = list() self.usernan = 0 self.missing_ranges = dict() self.missing_user_values = dict() self.variable_storage_width = dict() self.variable_display_width = dict() self.variable_alignment = dict() self.variable_measure = dict() self.no_datetime_conversion = 0 self.ctime = 0 self.mtime = 0 self.mr_sets = dict() self.output_format = "" class metadata_container: """ This class holds metadata we want to give back to python """ def __init__(self): self.column_names = list() self.column_labels = list() self.column_names_to_labels = dict() self.file_encoding = None self.number_columns = None self.number_rows = None self.variable_value_labels = dict() self.value_labels = dict() self.variable_to_label = dict() self.notes = list() self.original_variable_types = dict() self.readstat_variable_types = dict() self.table_name = None self.missing_ranges = dict() self.missing_user_values = dict() self.variable_storage_width = dict() self.variable_display_width = dict() self.variable_alignment = dict() self.variable_measure = dict() self.creation_time = None self.modification_time = None self.mr_sets = dict() class ReadstatError(Exception): """ Just defining a custom exception to raise when readstat gives an error return code. """ pass class PyreadstatError(Exception): """ Just defining a custom exception to raise when pyreadstat raises an exception. """ pass cdef py_datetime_format transform_variable_format(str var_format, py_file_format file_format): """ Transforms a readstat var_format to a date, datetime or time format label """ if file_format == FILE_FORMAT_SAS: if var_format in sas_all_formats: if var_format in sas_date_formats: return DATE_FORMAT_DATE elif var_format in sas_datetime_formats: return DATE_FORMAT_DATETIME elif var_format in sas_time_formats: return DATE_FORMAT_TIME else: return DATE_FORMAT_NOTADATE elif file_format == FILE_FORMAT_SPSS: if var_format in spss_all_formats: if var_format in spss_date_formats: return DATE_FORMAT_DATE elif var_format in spss_datetime_formats: return DATE_FORMAT_DATETIME elif var_format in spss_time_formats: return DATE_FORMAT_TIME else: return DATE_FORMAT_NOTADATE elif file_format == FILE_FORMAT_STATA: if var_format in stata_all_formats: if var_format in stata_date_formats: return DATE_FORMAT_DATE elif var_format in stata_datetime_formats: return DATE_FORMAT_DATETIME elif var_format in stata_time_formats: return DATE_FORMAT_TIME else: return DATE_FORMAT_NOTADATE cdef object transform_datetime(py_datetime_format var_format, double tstamp, py_file_format file_format, object origin, bint dates_as_pandas, str output_format, double unix_to_origin_secs): """ Transforms a tstamp integer value to a date, time or datetime pyton object. tstamp could represent number of days, seconds or milliseconds """ cdef object tdelta cdef int days cdef int secs cdef double msecs cdef int usecs cdef object mydat # For polars we are going to return an epoch from unix origin, # later we will transform that to datetime or date with polars from_epoch # for any other we return a python datetime, date or time object. # polars also works with these objects, but it is slower if var_format == DATE_FORMAT_DATE: if output_format == "polars": # we want to return days from unix if file_format == FILE_FORMAT_SPSS: # tstamp is in seconds return (tstamp - unix_to_origin_secs)/86400 else: # tstamp is in days return tstamp - (unix_to_origin_secs/86400) if file_format == FILE_FORMAT_SPSS: # tstamp is in seconds days = (floor(tstamp / 86400)) secs = (tstamp % 86400) tdelta = timedelta_new(days, secs, 0) #tdelta = timedelta(seconds=tstamp) else: # tstamp is in days days = tstamp tdelta = timedelta_new(days, 0, 0) #tdelta = timedelta(days=tstamp) mydat = origin + tdelta if dates_as_pandas: return mydat else: return mydat.date() elif var_format == DATE_FORMAT_DATETIME: if output_format == "polars": # we want to return seconds from unix if file_format == FILE_FORMAT_STATA: # tstamp is in millisecons return (tstamp/1000) - unix_to_origin_secs else: # tstamp in seconds return tstamp - unix_to_origin_secs if file_format == FILE_FORMAT_STATA: # tstamp is in millisecons days = (floor(tstamp / 86400000)) msecs = tstamp % 86400000 secs = (msecs/1000) usecs = ((msecs % 1000) * 1000 ) tdelta = timedelta_new(days, secs, usecs) #tdelta = timedelta(milliseconds=tstamp) else: # tstamp in seconds days = (floor(tstamp / 86400)) secs = (tstamp % 86400) tdelta = timedelta_new(days, secs, 0) #tdelta = timedelta(seconds=tstamp) mydat = origin + tdelta return mydat elif var_format == DATE_FORMAT_TIME: if file_format == FILE_FORMAT_STATA: # tstamp is in millisecons days = (floor(tstamp / 86400000)) msecs = tstamp % 86400000 secs = (msecs/1000) usecs = ((msecs % 1000) * 1000 ) tdelta = timedelta_new(days, secs, usecs) #tdelta = timedelta(milliseconds=tstamp) else: # tstamp in seconds days = (floor(tstamp / 86400)) secs = (tstamp % 86400) tdelta = timedelta_new(days, secs, 0) #tdelta = timedelta(seconds=tstamp) mydat = origin + tdelta return mydat.time() cdef object convert_readstat_to_python_value(readstat_value_t value, int index, data_container dc): """ Converts a readstat value to a python value. """ #py_file_format file_format, py_datetime_format var_format cdef readstat_type_t var_type cdef py_datetime_format var_format cdef py_variable_format pyformat cdef object origin cdef bint dates_as_pandas cdef py_file_format file_format cdef object result cdef char * c_str_value cdef str py_str_value cdef int8_t c_int8_value cdef int16_t c_int16_value cdef int32_t c_int32_value cdef int64_t c_int64_value cdef float c_float_value cdef double c_double_value cdef long py_long_value cdef double py_float_value cdef double tstamp cdef str output_format var_type = dc.col_dtypes[index] var_format = dc.col_formats[index] origin = dc.origin unix_to_origin_secs = dc.unix_to_origin_secs dates_as_pandas = dc.dates_as_pandas file_format = dc.file_format output_format = dc.output_format # transform to values cython can deal with if var_type == READSTAT_TYPE_STRING or var_type == READSTAT_TYPE_STRING_REF: c_str_value = readstat_string_value(value) if c_str_value != NULL: py_str_value = c_str_value else: py_str_value = '' pyformat = VAR_FORMAT_STRING elif var_type == READSTAT_TYPE_INT8: c_int8_value = readstat_int8_value(value) py_long_value = c_int8_value pyformat = VAR_FORMAT_LONG elif var_type == READSTAT_TYPE_INT16: c_int16_value = readstat_int16_value(value) py_long_value = c_int16_value pyformat = VAR_FORMAT_LONG elif var_type == READSTAT_TYPE_INT32: c_int32_value = readstat_int32_value(value) py_long_value = c_int32_value pyformat = VAR_FORMAT_LONG elif var_type == READSTAT_TYPE_FLOAT: c_float_value = readstat_float_value(value) py_float_value = c_float_value pyformat = VAR_FORMAT_FLOAT elif var_type == READSTAT_TYPE_DOUBLE: c_double_value = readstat_double_value(value); py_float_value = c_double_value pyformat = VAR_FORMAT_FLOAT else: raise PyreadstatError("Unkown data type") # final transformation and storage if pyformat == VAR_FORMAT_STRING: if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: result = py_str_value else: #str_byte_val = py_str_value.encode("UTF-8") raise PyreadstatError("STRING type with value '%s' with date type in column '%s'" % (py_str_value, dc.col_names[index])) elif pyformat == VAR_FORMAT_LONG: if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: result = py_long_value else: tstamp = py_long_value result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) elif pyformat == VAR_FORMAT_FLOAT: if var_format == DATE_FORMAT_NOTADATE or dc.no_datetime_conversion: result = py_float_value else: #tstamp = py_float_value tstamp = py_float_value result = transform_datetime(var_format, tstamp, file_format, origin, dates_as_pandas, output_format, unix_to_origin_secs) #elif pyformat == VAR_FORMAT_MISSING: # pass else: raise PyreadstatError("Failed convert C to python value") return result cdef int handle_metadata(readstat_metadata_t *metadata, void *ctx) except READSTAT_HANDLER_ABORT: """ This function sets the number of observations(rows), number of variables (columns) in data container and initializes the col_data which will store all the data we need. It also reads other metadata from the file. """ cdef int var_count, obs_count, mr_len cdef data_container dc = ctx #cdef object row cdef char * flabel_orig cdef char * fencoding_orig cdef str flabel, fencoding cdef bint metaonly cdef char * table cdef int ctime cdef int mtime cdef int i = 0 cdef mr_set_t * mr_sets_orig cdef dict mr_sets = {} cdef str name cdef list variable_list = [] metaonly = dc.metaonly var_count = readstat_get_var_count(metadata) if var_count<0: raise PyreadstatError("Failed to read number of variables") obs_count = readstat_get_row_count(metadata) if obs_count <0: # if <0 it means the number of rows is not known, allocate 100 000 obs_count = 100000 dc.is_unkown_number_rows = 1 dc.n_obs = obs_count dc.n_vars = var_count mr_len = readstat_get_multiple_response_sets_length(metadata); mr_sets_orig = readstat_get_multiple_response_sets(metadata); if mr_sets_orig != NULL: i = 0 while i < mr_len: name = mr_sets_orig[i].name variable_list = [] for j in range(mr_sets_orig[i].num_subvars): variable_list.append(mr_sets_orig[i].subvariables[j]) mr_sets[name] = { 'type': chr(mr_sets_orig[i].type), 'is_dichotomy': bool(mr_sets_orig[i].is_dichotomy), 'counted_value': mr_sets_orig[i].counted_value if mr_sets_orig[i].counted_value != -1 else None, 'label': mr_sets_orig[i].label, 'variable_list': variable_list } i += 1 dc.mr_sets = mr_sets dc.col_data_len = [obs_count] * var_count dc.col_numpy_dtypes = [None] * var_count dc.col_dytpes_isfloat = [0] * var_count dc.col_dtypes_isobject = [0] * var_count # read other metadata flabel_orig = readstat_get_file_label(metadata); fencoding_orig = readstat_get_file_encoding(metadata) if flabel_orig != NULL and flabel_orig[0]: flabel = flabel_orig else: flabel = None if fencoding_orig != NULL and fencoding_orig[0]: fencoding = fencoding_orig else: fencoding = None dc.file_encoding = fencoding dc.file_label = flabel table = readstat_get_table_name(metadata) if table != NULL and table[0]: dc.table_name = table dc.ctime = readstat_get_creation_time(metadata) dc.mtime = readstat_get_modified_time(metadata) return READSTAT_HANDLER_OK cdef int handle_variable(int index, readstat_variable_t *variable, char *val_labels, void *ctx) except READSTAT_HANDLER_ABORT: """ This function extracts the name, label, type and format from a variable and stores it in data container for a later access. It also extracts the label set to which the variable is associated, if any. """ cdef char * var_name, cdef char * var_label cdef char * var_format cdef str col_name, col_label, label_name, col_format_original, output_format cdef py_datetime_format col_format_final cdef readstat_type_t var_type cdef py_file_format file_format cdef readstat_label_set_t * lset cdef int n_ranges cdef readstat_value_t loval, hival cdef object pyloval, pyhival cdef list missing_ranges cdef object curnptype cdef object row cdef bint metaonly cdef int obs_count cdef bint iscurnptypefloat cdef bint iscurnptypeobject cdef str newcolname cdef int dupcolcnt cdef data_container dc = ctx output_format = dc.output_format # get variable name, label, format and type and put into our data container var_name = readstat_variable_get_name(variable) if var_name == NULL: col_name = None else: col_name = var_name # if the user introduced a list of columns to include, continue only if the column is in the list if dc.filter_cols and not (col_name in dc.use_cols): dc.n_vars -= 1 return READSTAT_HANDLER_SKIP_VARIABLE index = readstat_variable_get_index_after_skipping(variable) if col_name in dc.col_names: dupcolcnt = 1 while True: newcolname = col_name + "_duplicated" + str(dupcolcnt) if newcolname in col_name: dupcolcnt += 1 continue else: msg = "column '{0}' is duplicated, renamed to '{1}'".format(col_name, newcolname) warnings.warn(msg) col_name = newcolname break dc.col_names.append(col_name) # the name of the value label for the variable if val_labels != NULL: label_name = val_labels if label_name: dc.label_to_var_name[col_name] = label_name var_label = readstat_variable_get_label(variable) if var_label == NULL: col_label = None else: col_label = var_label dc.col_labels.append(col_label) # format, we have to transform it in something more usable var_format = readstat_variable_get_format(variable) if var_format == NULL: #col_format_original = "NULL" col_format_original = None else: col_format_original = var_format file_format = dc.file_format dc.col_formats_original.append(col_format_original) col_format_final = transform_variable_format(col_format_original, file_format) dc.col_formats.append(col_format_final) # readstat type var_type = readstat_variable_get_type(variable) dc.col_dtypes.append(var_type) # equivalent numpy type # if it's a date then we need object if col_format_final != DATE_FORMAT_NOTADATE and dc.no_datetime_conversion == 0: curnptype = object else: curnptype = readstat_to_numpy_types[var_type] iscurnptypefloat = 0 iscurnptypeobject = 0 # book keeping numpy types dc.col_numpy_dtypes[index] = curnptype if curnptype == object: iscurnptypeobject = 1 if curnptype == np.float64: iscurnptypefloat = 1 dc.col_dtypes_isobject[index] = iscurnptypeobject dc.col_dytpes_isfloat[index] = iscurnptypefloat metaonly = dc.metaonly # pre-allocate data if metaonly: if output_format == "pandas": row = np.empty(1, dtype=curnptype) else: row = list() else: obs_count = dc.n_obs if output_format == "pandas": row = np.empty(obs_count, dtype=curnptype) if iscurnptypeobject or iscurnptypefloat: row.fill(np.nan) else: row = [None] * obs_count dc.col_data.append(row) # missing values if dc.usernan: n_ranges = readstat_variable_get_missing_ranges_count(variable) if n_ranges>0: missing_ranges = list() for i in range(0, n_ranges): loval = readstat_variable_get_missing_range_lo(variable, i) pyloval = convert_readstat_to_python_value(loval, index, dc) hival = readstat_variable_get_missing_range_hi(variable, i) pyhival = convert_readstat_to_python_value(hival, index, dc) missing_ranges.append({'lo':pyloval, 'hi':pyhival}) dc.missing_ranges[col_name] = missing_ranges cdef size_t storage_width storage_width = readstat_variable_get_storage_width(variable) dc.variable_storage_width[col_name] = storage_width dc.variable_display_width[col_name] = readstat_variable_get_display_width(variable) cdef readstat_alignment_t align cdef str pyalign align = readstat_variable_get_alignment(variable) if align == READSTAT_ALIGNMENT_UNKNOWN: pyalign = "unknown" elif align == READSTAT_ALIGNMENT_LEFT: pyalign = "left" elif align == READSTAT_ALIGNMENT_CENTER: pyalign = "center" elif align == READSTAT_ALIGNMENT_RIGHT: pyalign = "right" else: pyalign = "undetermined" dc.variable_alignment[col_name] = pyalign cdef readstat_measure_t measure cdef str pymeasure measure = readstat_variable_get_measure(variable) if measure == READSTAT_MEASURE_UNKNOWN: pymeasure = "unknown" elif measure == READSTAT_MEASURE_NOMINAL: pymeasure = "nominal" elif measure == READSTAT_MEASURE_ORDINAL: pymeasure = "ordinal" elif measure == READSTAT_MEASURE_SCALE: pymeasure = "scale" else: pymeasure = "undetermined" dc.variable_measure[col_name] = pymeasure return READSTAT_HANDLER_OK cdef int handle_value(int obs_index, readstat_variable_t * variable, readstat_value_t value, void *ctx) except READSTAT_HANDLER_ABORT: """ This function transforms every value to python types, and to datetime if necessary and stores it into the arrays in data container col_data """ cdef data_container dc cdef int index cdef int max_n_obs cdef bint is_unkown_number_rows cdef int var_max_rows cdef object buf_list cdef bint iscurnptypeobject cdef bint iscurnptypefloat cdef int missing_tag cdef object pyvalue cdef set curset cdef object curnptype cdef str output_format # extract variables we need from data container dc = ctx output_format = dc.output_format index = readstat_variable_get_index_after_skipping(variable) max_n_obs = dc.max_n_obs is_unkown_number_rows = dc.is_unkown_number_rows # check that we still have enough room in our pre-allocated lists # if not, add more room iscurnptypeobject = dc.col_dtypes_isobject[index] iscurnptypefloat = dc.col_dytpes_isfloat[index] if is_unkown_number_rows: if max_n_obs <= obs_index: dc.max_n_obs = obs_index + 1 var_max_rows = dc.col_data_len[index] if var_max_rows <= obs_index: if output_format == "pandas": curnptype = dc.col_numpy_dtypes[index] buf_list = np.empty(100000, dtype=curnptype) if iscurnptypeobject or iscurnptypefloat: buf_list.fill(np.nan) dc.col_data[index] = np.append(dc.col_data[index], buf_list) else: buf_list = [None] * 100000 dc.col_data[index].extend(buf_list) var_max_rows += 100000 dc.col_data_len[index] = var_max_rows # transform to python value types if readstat_value_is_missing(value, variable): # The user does not want to retrieve missing values if not dc.usernan or readstat_value_is_system_missing(value): if output_format == "pandas": if iscurnptypefloat == 1 or iscurnptypeobject == 1: # already allocated pass #dc.col_data[index][obs_index] = np.nan # for any type except float, the numpy type will be object as now we have nans else: dc.col_numpy_dtypes[index] = object dc.col_dtypes_isobject[index] = 1 iscurnptypeobject = 1 dc.col_data[index] = dc.col_data[index].astype(object, copy=False) dc.col_data[index][obs_index:] = np.nan #dc.col_data[index][obs_index] = NAN elif readstat_value_is_defined_missing(value, variable): # SPSS missing values pyvalue = convert_readstat_to_python_value(value, index, dc) dc.col_data[index][obs_index] = pyvalue elif readstat_value_is_tagged_missing(value): iscurnptypeobject = dc.col_dtypes_isobject[index] # SAS and Stata missing values missing_tag = readstat_value_tag(value) # In SAS missing values are A to Z or _ in stata a to z # if (missing_tag >=65 and missing_tag <= 90) or missing_tag == 95 or (missing_tag >=61 and missing_tag <= 122): if output_format == "pandas": if iscurnptypeobject == 1: dc.col_data[index][obs_index] = chr(missing_tag) else: dc.col_numpy_dtypes[index] = object dc.col_dtypes_isobject[index] = 1 dc.col_dytpes_isfloat[index] = 0 iscurnptypeobject = 1 dc.col_data[index] = dc.col_data[index].astype(object, copy=False) dc.col_data[index][obs_index] = chr(missing_tag) else: dc.col_data[index][obs_index] = chr(missing_tag) curset = dc.missing_user_values.get(index) if curset is None: curset = set() curset.add(chr(missing_tag)) dc.missing_user_values[index] = curset else: pyvalue = convert_readstat_to_python_value(value, index, dc) dc.col_data[index][obs_index] = pyvalue return READSTAT_HANDLER_OK cdef int handle_value_label(char *val_labels, readstat_value_t value, char *label, void *ctx) except READSTAT_HANDLER_ABORT: """ Reads the label for the value that belongs to the label set val_labels. In Handle variable we need to do a map from variable name to val_label so that later we can match both things. """ cdef data_container dc = ctx cdef char * c_str_value cdef str py_str_value cdef int8_t c_int8_value cdef int16_t c_int16_value cdef int32_t c_int32_value cdef int64_t c_int64_value cdef float c_float_value cdef double c_double_value cdef long py_long_value cdef double py_float_value cdef py_variable_format pyformat cdef object labels_raw cdef str var_label cdef object cur_dir cdef str value_label_name var_label = val_labels value_label_name = label cdef readstat_type_t value_type value_type = readstat_value_type(value) labels_raw = dc.labels_raw cur_dict = labels_raw.get(var_label) if not cur_dict: cur_dict = dict() if readstat_value_is_tagged_missing(value): # SAS and Stata missing values missing_tag = readstat_value_tag(value) # In SAS missing values are A to Z or _ in stata a to z cur_dict[chr(missing_tag)] = value_label_name else: if value_type == READSTAT_TYPE_STRING or value_type == READSTAT_TYPE_STRING_REF: c_str_value = readstat_string_value(value) py_str_value = c_str_value pyformat = VAR_FORMAT_STRING elif value_type == READSTAT_TYPE_INT8: c_int8_value = readstat_int8_value(value) py_long_value = c_int8_value pyformat = VAR_FORMAT_LONG elif value_type == READSTAT_TYPE_INT16: c_int16_value = readstat_int16_value(value) py_long_value = c_int16_value pyformat = VAR_FORMAT_LONG elif value_type == READSTAT_TYPE_INT32: c_int32_value = readstat_int32_value(value) py_long_value = c_int32_value pyformat = VAR_FORMAT_LONG elif value_type == READSTAT_TYPE_FLOAT: c_float_value = readstat_float_value(value) py_float_value = c_float_value pyformat = VAR_FORMAT_FLOAT elif value_type == READSTAT_TYPE_DOUBLE: c_double_value = readstat_double_value(value); py_float_value = c_double_value pyformat = VAR_FORMAT_FLOAT else: raise PyreadstatError("Unkown data type") if pyformat == VAR_FORMAT_STRING: cur_dict[py_str_value] = value_label_name elif pyformat == VAR_FORMAT_LONG: cur_dict[py_long_value] = value_label_name elif pyformat == VAR_FORMAT_FLOAT: cur_dict[py_float_value] = value_label_name elif pyformat == VAR_FORMAT_MISSING: pass else: raise PyreadstatError("Failed convert C to python value") dc.labels_raw[var_label] = cur_dict return READSTAT_HANDLER_OK cdef int handle_note (int note_index, char *note, void *ctx) except READSTAT_HANDLER_ABORT: """ Collects notes (text annotations) attached to the documents. It happens for spss and stata """ cdef str pynote cdef data_container dc = ctx pynote = note dc.notes.append(pynote) return READSTAT_HANDLER_OK cdef int handle_open(const char *u8_path, void *io_ctx) except READSTAT_HANDLER_ABORT: """ Special open handler for windows in order to be able to handle paths with international characters Courtesy of Jonathon Love. """ cdef int fd cdef Py_ssize_t length if not os.path.isfile(u8_path): return -1 if os.name == "nt": u16_path = PyUnicode_AsWideCharString(u8_path, &length) fd = _wsopen(u16_path, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0) assign_fd(io_ctx, fd) return fd else: return -1 cdef object _file_object_ctx = None cdef int pyobject_open_handler(const char *path, void *io_ctx) noexcept: """File is already open - this is a no-op""" return 0 cdef int pyobject_close_handler(void *io_ctx) noexcept: """User manages file lifetime - this is a no-op""" return 0 cdef ssize_t pyobject_read_handler(void *buf, size_t nbyte, void *io_ctx) noexcept: """Bridge Python file.read() to C read operation""" global _file_object_ctx cdef bytes data cdef ssize_t bytes_read cdef char *data_ptr try: file_obj = _file_object_ctx data = file_obj.read(nbyte) bytes_read = len(data) if bytes_read > 0: data_ptr = data memcpy(buf, data_ptr, bytes_read) return bytes_read except: return -1 cdef readstat_off_t pyobject_seek_handler(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx) noexcept: """Bridge Python file.seek() to C seek operation""" global _file_object_ctx cdef int py_whence try: file_obj = _file_object_ctx if whence == READSTAT_SEEK_SET: py_whence = 0 elif whence == READSTAT_SEEK_CUR: py_whence = 1 else: # READSTAT_SEEK_END py_whence = 2 file_obj.seek(offset, py_whence) return file_obj.tell() except: return -1 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 """ cdef char * err_readstat cdef str err_message if retcode != READSTAT_OK: err_readstat = readstat_error_message(retcode) err_message = err_readstat raise ReadstatError(err_message) cdef void run_readstat_parser(char * filename, data_container data, py_file_extension file_extension, long row_limit, long row_offset, object file_obj=None) except *: """ Runs the parsing of the file by readstat library. If file_obj is provided, it will be used instead of filename for I/O operations. """ global _file_object_ctx cdef readstat_parser_t *parser cdef readstat_error_t error cdef readstat_metadata_handler metadata_handler cdef readstat_variable_handler variable_handler cdef readstat_value_handler value_handler cdef readstat_value_label_handler value_label_handler cdef readstat_note_handler note_handler cdef readstat_open_handler open_handler cdef readstat_close_handler close_handler cdef readstat_read_handler read_handler cdef readstat_seek_handler seek_handler cdef void *ctx cdef str err_message cdef PyObject *pyerr cdef bint metaonly cdef char *err_readstat cdef bytes encoding_byte metaonly = data.metaonly ctx = data #readstat_error_t error = READSTAT_OK; parser = readstat_parser_init() metadata_handler = handle_metadata variable_handler = handle_variable value_handler = handle_value value_label_handler = handle_value_label note_handler = handle_note check_exit_status(readstat_set_metadata_handler(parser, metadata_handler)) check_exit_status(readstat_set_variable_handler(parser, variable_handler)) check_exit_status(readstat_set_value_label_handler(parser, value_label_handler)) check_exit_status(readstat_set_note_handler(parser, note_handler)) # Set up custom I/O handlers for file objects if file_obj is not None: _file_object_ctx = file_obj open_handler = pyobject_open_handler close_handler = pyobject_close_handler read_handler = pyobject_read_handler seek_handler = pyobject_seek_handler readstat_set_open_handler(parser, open_handler) readstat_set_close_handler(parser, close_handler) readstat_set_read_handler(parser, read_handler) readstat_set_seek_handler(parser, seek_handler) elif os.name == "nt": # on windows we need a custom open handler in order to deal with internation characters in the path. open_handler = handle_open readstat_set_open_handler(parser, open_handler) if not metaonly: check_exit_status(readstat_set_value_handler(parser, value_handler)) # if the user set the encoding manually if data.user_encoding: encoding_bytes = data.user_encoding.encode("utf-8") readstat_set_file_character_encoding(parser, encoding_bytes) if row_limit: check_exit_status(readstat_set_row_limit(parser, row_limit)) if row_offset: check_exit_status(readstat_set_row_offset(parser, row_offset)) # parse! if file_extension == FILE_EXT_SAV: error = readstat_parse_sav(parser, filename, ctx); elif file_extension == FILE_EXT_SAS7BDAT: error = readstat_parse_sas7bdat(parser, filename, ctx); elif file_extension == FILE_EXT_DTA: error = readstat_parse_dta(parser, filename, ctx); elif file_extension == FILE_EXT_XPORT: error = readstat_parse_xport(parser, filename, ctx); elif file_extension == FILE_EXT_POR: error = readstat_parse_por(parser, filename, ctx); elif file_extension == FILE_EXT_SAS7BCAT: error = readstat_parse_sas7bcat(parser, filename, ctx); #error = parse_func(parser, filename, ctx); readstat_parser_free(parser) # check if a python error ocurred, if yes, it will be printed by the interpreter, # if not, make sure that the return from parse_func is OK, if not print pyerr = PyErr_Occurred() if pyerr == NULL: check_exit_status(error) cdef object data_container_to_dict(data_container data): """ Transforms a data container object to a pandas data frame """ cdef object final_container cdef list col_data cdef list col_names cdef str cur_name_str cdef int fc_cnt cdef bint is_unkown_number_rows cdef int max_n_obs cdef bint metaonly final_container = OrderedDict() col_data = data.col_data col_names = data.col_names is_unkown_number_rows = data.is_unkown_number_rows max_n_obs = data.max_n_obs metaonly = data.metaonly for fc_cnt in range(0, len(col_names)): cur_name_str = col_names[fc_cnt] cur_data = col_data[fc_cnt] if is_unkown_number_rows and not metaonly: cur_data = cur_data[0:max_n_obs] if not metaonly: final_container[cur_name_str] = cur_data else: final_container[cur_name_str] = list() return final_container cdef object dict_to_dataframe(object dict_data, data_container dc): """ Transforms a dict of numpy arrays to a pandas data frame """ cdef bint dates_as_pandas, allsame cdef int index cdef str column, output_format, col_name cdef py_datetime_format var_format cdef list dtypes, sertypes, datetime_cols, date_cols cdef dict schema = None dates_as_pandas = dc.dates_as_pandas output_format = dc.output_format if dict_data: #schema = None # in polars if missing user values we need to explicitly set the type # of that column to Object if not all the elements are of the same type if output_format != "pandas" and dc.missing_user_values: schema = dict() for indx in range(0, len(dc.col_names)): col_name = dc.col_names[indx] if indx in dc.missing_user_values.keys(): sertypes = [type(x) for x in dict_data[col_name] if x is not None] # all missing, let polars decide if not sertypes: schema[col_name] = None continue allsame = all([x==sertypes[0] for x in sertypes]) # all the same: let polars decide if allsame: schema[col_name] = None # not all the same type, has to be Object else: schema[col_name] = nw.Object else: schema[col_name] = None data_frame = nw.from_dict(dict_data, backend=output_format, schema=schema) natnamespace = nw.get_native_namespace(data_frame) data_frame = data_frame.to_native() if dates_as_pandas and output_format=="pandas": pd = natnamespace dtypes = data_frame.dtypes.tolist() # check that datetime columns are datetime type # this is needed in case all date values are nan for index, column in enumerate(data_frame.columns): var_format = dc.col_formats[index] if dtypes[index] != ' filename_bytes data = data_container() ctx = data data.file_format = file_format data.metaonly = metaonly data.dates_as_pandas = dates_as_pandas data.output_format = output_format if encoding: data.user_encoding = encoding if file_format == FILE_FORMAT_SAS: origin = sas_origin unix_to_origin_secs = sas_secs_from_unix elif file_format == FILE_FORMAT_SPSS: origin = spss_origin unix_to_origin_secs = spss_secs_from_unix elif file_format == FILE_FORMAT_STATA: origin = stata_origin unix_to_origin_secs = stata_secs_from_unix else: raise PyreadstatError("Unknown file format") data.origin = origin data.unix_to_origin_secs = unix_to_origin_secs if usecols is not None: data.filter_cols = 1 data.use_cols = usecols data.usernan = usernan data.no_datetime_conversion = no_datetime_conversion # go! run_readstat_parser(filename, data, file_extension, row_limit, row_offset, file_obj) data_dict = data_container_to_dict(data) if output_format == 'dict': data_frame = data_dict else: data_frame = dict_to_dataframe(data_dict, data) metadata = data_container_extract_metadata(data) return data_frame, metadata ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180457.0 pyreadstat-1.3.3/pyreadstat/_readstat_writer.c0000644000076500000240000416655615134706451020161 0ustar00dialout/* 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 #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 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 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 struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::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 #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 #include #include #include "readstat.h" #include "readstat_io_unistd.h" #include "conditional_includes.h" #ifdef _OPENMP #include #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 #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 #endif template static void __Pyx_pretend_to_initialize(T* ptr) { #if __cplusplus > 201103L if ((std::is_trivially_default_constructible::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 #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 #elif CYTHON_ATOMICS && (defined(__cplusplus) && (\ (__cplusplus >= 201103L) ||\ (defined(_MSC_VER) && _MSC_VER >= 1700))) #include #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 #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 /* 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 /* 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 #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 = 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 = curseries.null_count()>0 * if has_missing: # <<<<<<<<<<<<<< * curseries = curseries.drop_nulls() * */ if (__pyx_v_has_missing) { /* "pyreadstat/_readstat_writer.pyx":278 * has_missing = 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 = 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 = (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 = (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 = (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 = (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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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= 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__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__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= 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 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 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 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 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 // 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 (; readmodule) { write->id = read->id; write->module = read->module; ++write; } } data->count = write - data->table; for (; writeid = 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; icount; ++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_boundid = (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 */ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1755175692.0 pyreadstat-1.3.3/pyreadstat/_readstat_writer.pxd0000644000076500000240000001011215047355414020500 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# from libc.stddef cimport wchar_t from readstat_api cimport * #cdef int write_test() cdef extern from "readstat_io_unistd.h": cdef struct unistd_io_ctx_t "unistd_io_ctx_s": pass cdef extern from "conditional_includes.h": int _wsopen(const wchar_t *filename, int oflag, int shflag, int pmode) int O_RDONLY int O_BINARY int O_WRONLY int O_CREAT int O_TRUNC int _O_RDONLY int _O_BINARY int _O_WRONLY int _O_CREAT int _O_TRUNC int _SH_DENYRW # Denies read and write access to a file. int _SH_DENYWR # Denies write access to a file. int _SH_DENYRD # Denies read access to a file. int _SH_DENYNO int _S_IWRITE int _S_IREAD int open(const char *path, int oflag, int mode) int _close(int fd) cdef extern from "Python.h": wchar_t* PyUnicode_AsWideCharString(object, Py_ssize_t *) except NULL cdef extern from "conditional_includes.h": int _close(int fd) ssize_t _write(int fd, const void *buf, size_t nbyte) int close(int fd) ssize_t write(int fd, const void *buf, size_t nbyte) ctypedef enum dst_file_format: FILE_FORMAT_SAS7BDAT FILE_FORMAT_SAS7BCAT FILE_FORMAT_XPORT FILE_FORMAT_SAV FILE_FORMAT_DTA FILE_FORMAT_POR ctypedef enum pywriter_variable_type: PYWRITER_DOUBLE PYWRITER_INTEGER PYWRITER_CHARACTER PYWRITER_LOGICAL PYWRITER_OBJECT PYWRITER_DATE PYWRITER_DATETIME PYWRITER_TIME PYWRITER_DATE64 PYWRITER_DATETIME64 PYWRITER_TIME64 PYWRITER_DTA_STR_REF cdef object vectorized_convert_datetime_to_number(object df, dst_file_format file_format, list pywriter_types, list pywriter_timeunits, int col_count) cdef object vectorized_convert_date_to_number(object df, dst_file_format file_format, list pywriter_types, int col_count) cdef object vectorized_convert_time_to_number(object df, dst_file_format file_format, list pywriter_types, int col_count) cdef double convert_datetimelike_to_number(dst_file_format file_format, pywriter_variable_type curtype, object curval) except * cdef char * get_datetimelike_format_for_readstat(dst_file_format file_format, pywriter_variable_type curtype) cdef int get_narwhals_str_series_max_length(object series, dict value_labels, bint isobject) cdef int check_series_all_same_types(object series, object type_to_check) cdef list get_narwhals_column_types(object df, dict missing_user_values, dict variable_value_labels, int dta_str_max_len) cdef ssize_t write_bytes(const void *data, size_t _len, void *ctx) #cdef void check_exit_status(readstat_error_t retcode) except * cdef int open_file(bytes filename_path) cdef int close_file(int fd) cdef bytes filepath_to_bytes(object filename_path) 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 * 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, dict variable_display_width, dict variable_measure, dict variable_format, bint row_compression) except * ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1759507247.0 pyreadstat-1.3.3/pyreadstat/_readstat_writer.pyx0000644000076500000240000012662115067771457020555 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ###cython: profile=True # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# import os import warnings import sys import datetime #import calendar from datetime import timezone #from datetime import timezone as _timezone #from libc.math cimport round, NAN import numpy as np import narwhals.stable.v2 as nw from readstat_api cimport * from _readstat_parser import ReadstatError, PyreadstatError 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, 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, 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, } 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() 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 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): """ transforms datetime64 columns in the dataframe to floats """ cdef dict convfacs cdef double offset_secs cdef double mulfac = 1.0 cdef int col_indx cdef list col_indxs cdef double convfac if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR: offset_secs = spss_offset_secs else: offset_secs = sas_offset_secs if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds mulfac = 1000.0 convfacs = {'ns': 1e9, 'us': 1e6, 'ms': 1e3} col_indxs = list() 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)) 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 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 """ cdef double offset_days cdef double mulfac = 1.0 cdef int col_indx 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 mulfac = 86400 else: 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) 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 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 """ cdef double mulfac = 1.0 cdef int col_indx cdef list col_indxs if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds mulfac = 1000.0 col_indxs = list() 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)) 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 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 """ 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 else: offset_days = sas_offset_days offset_secs = sas_offset_secs 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()) tstamp += offset_secs if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds tstamp *= 1000 elif curtype == PYWRITER_DATE: 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: # spss stores in seconds tstamp *= 86400 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 if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds tstamp *= 1000 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 """ if curtype == PYWRITER_DATE or curtype == PYWRITER_DATE64: if file_format == FILE_FORMAT_DTA: return "%td" #elif file_format == FILE_FORMAT_SAV: # return "DATE11" else: return "DATE" elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64: if file_format == FILE_FORMAT_DTA: return "%tc" #elif file_format == FILE_FORMAT_SAV: # return "DATETIME20" else: return "DATETIME" elif curtype == PYWRITER_TIME or curtype == PYWRITER_TIME64: if file_format == FILE_FORMAT_DTA: return "%tcHH:MM:SS" else: return "TIME" else: 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. """ cdef object val cdef bytes temp cdef int max_length = 1 cdef int curlen cdef list labels for val in series: if isobject: val = str(val) temp = val.encode("utf-8") curlen = len(temp) if curlen > max_length: max_length = curlen if value_labels: labels = list(value_labels.keys()) for lab in labels: curlen = len(str(lab)) if curlen > max_length: max_length = curlen return max_length 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 """ for val in series: 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): """ From a narwhals data frame, get a list with tuples column types as first element, max_length as second, is_missing as third and time units as fourth. max_lenght is the max length of a string or string representation of an object, 0 for numeric types. is_missing flags wether the series has missing values (1) or not (0) dta_str_max_len is the max length for a dta string, 0 if the file format is not dta """ cdef int max_length, isobject cdef bint has_missing cdef list result = list() cdef int equal, is_missing if variable_value_labels is None: variable_value_labels = dict() for curseries in df.iter_columns(): col_name = curseries.name col_type = curseries.dtype # 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 has_missing = 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 # they are object because it is a mix of string and number. # it could also be that the type of the series is string because it contains only # 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) 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)) if not len(curseries): result.append((PYWRITER_DOUBLE, 0, 1, None)) continue 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: 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 # therefore if one of these conditions are not met they continuing flowing into the next if # 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: result.append((PYWRITER_DATE, 0, has_missing, None)) continue 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)) continue # 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): 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 # 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: 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 else: if isobject: 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: 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')) continue elif col_type.time_unit == 'ms': result.append((PYWRITER_DATETIME64, 0,has_missing, 'ms')) continue else: result.append((PYWRITER_DATETIME, 0, has_missing, None)) continue 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)) continue # 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: result.append((PYWRITER_OBJECT, max_length, has_missing, None)) continue 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 *: """ Sets value labels for normal values and also tagged missing values (user defined missing for stata and sas) """ cdef readstat_label_set_t *label_set cdef readstat_type_t curtype cdef double double_val 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 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: 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")) continue 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")) 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) raise PyreadstatError(msg) 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) 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: 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): 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")) 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, this happens for SPSS """ cdef int range_values = 0 cdef int discrete_values = 0 cdef int discrete_strings = 0 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: 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 raise PyreadstatError(msg) 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)) 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) 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"))) discrete_strings += 1 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: 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): 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 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: 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: msg = "missing_ranges: values must be both either of numeric or string type" raise PyreadstatError(msg) if discrete_strings > 3: 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" 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: 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 *: """ Sets the variable alignment, ineffective on SPSS, STATA and XPORT (what about SAS7bdat?) """ cdef readstat_alignment_t alignment if alignment_str == "right": alignment = READSTAT_ALIGNMENT_RIGHT elif alignment_str == "left": alignment = READSTAT_ALIGNMENT_LEFT elif alignment_str == "center": 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) 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 *: """ Sets the variable display width (SPSS). Not effective on STATA. (what about SAS7BDAT?) """ 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. """ cdef readstat_measure_t measure if measure_str == "nominal": measure = READSTAT_MEASURE_NOMINAL elif measure_str == "ordinal": measure = READSTAT_MEASURE_ORDINAL elif measure_str == "scale": 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) raise PyreadstatError(msg) readstat_variable_set_measure(variable, measure); 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 """ cdef int fd fd = (ctx)[0] if os.name=='nt': return _write(fd, data, _len) else: 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 """ cdef char * err_readstat cdef str err_message if retcode != READSTAT_OK: err_readstat = readstat_error_message(retcode) err_message = err_readstat raise ReadstatError(err_message) cdef int open_file(bytes filename_bytes): cdef int fd cdef int flags cdef Py_ssize_t length cdef char *path 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) else: path = filename_bytes flags = O_WRONLY | O_CREAT | O_TRUNC fd = open(path, flags, 0644) return fd cdef int close_file(int fd): if os.name == "nt": 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, dst_file_format file_format, list col_names, bytes filename_bytes) except *: """ Running some checks before starting writing """ if not is_pandas and not is_polars: msg = "dataframe must be pandas or polars dataframe" raise PyreadstatError(msg) 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) 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: valid_user_missing = valid_user_missing_sas for key, missing_values in missing_user_values.items(): if not isinstance(missing_values, list): msg = "missing_user_values: values in dictionary must be list" raise PyreadstatError(msg) 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 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: 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(): 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) 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): """ transforms an object with the path to the filename to bytes """ 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()) 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: filename_bytes = filename_path else: raise PyreadstatError("path must be either str or bytes") return filename_bytes 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, dict variable_display_width, dict variable_measure, dict variable_format, bint row_compression) except *: """ main entry point for writing all formats. Some parameters are specific for certain file type and are even incompatible between them. This function relies on the caller to select the right combination of parameters, not checking them otherwise. """ cdef object natnamespace cdef object pd = None cdef bint is_pandas, is_polars cdef bytes filename_bytes cdef list col_names filename_bytes = filepath_to_bytes(filename_path) 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() is_polars = df.implementation.is_polars() col_names = df.columns if is_pandas: pd = natnamespace initial_checks(is_pandas, is_polars, variable_value_labels, missing_user_values, file_format, col_names, filename_bytes) cdef readstat_error_t retcode cdef char *err_readstat cdef str err_message cdef readstat_writer_t *writer cdef bytes file_label_bytes cdef char *file_labl cdef int dta_str_max_len = 0 if file_format == FILE_FORMAT_POR: 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 elif file_format_version >= 111: 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) 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 cdef pywriter_variable_type curtype cdef int max_length cdef char *curformat cdef str tempformat cdef int col_indx cdef bytes cur_col_label cdef int col_label_count = 0 cdef readstat_variable_t *tempvar cdef int row_indx cdef str curvalstr cdef double dtimelikeval #cdef np.ndarray values cdef object values cdef dict value_labels cdef int lblset_cnt = 0 cdef readstat_label_set_t *label_set cdef list col_label_temp cdef bint hasdatetime64 cdef list pywriter_types, pywriter_timeunits cdef object df2 cdef float mulfac, conv2secs cdef readstat_string_ref_t* strref cdef dict strref_map = dict() cdef int strref_cnt cdef object strref_indx cdef int fd = open_file(filename_bytes) writer = readstat_writer_init() try: check_exit_status(readstat_set_data_writer(writer, write_bytes)) if file_label: file_label_bytes = file_label.encode("utf-8") file_labl = file_label_bytes check_exit_status(readstat_writer_set_file_label(writer, file_labl)) if note: if type(note) == str: note = [note] 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)}") if file_format_version > -1: 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)) # table name is used only for xpt files if table_name: table_name_bytes = table_name.encode("utf-8") tab_name = table_name_bytes check_exit_status(readstat_writer_set_table_name(writer, tab_name)) # 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: 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]) else: col_label_temp.append(None) 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") 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 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: 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 # 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) strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8")) strref_map[curvalstr] = strref_cnt strref_cnt += 1 # 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") 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: 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) 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: 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) 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) 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 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: set_variable_measure(variable, cur_measure, variable_name) # 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)) 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: 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") # 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)) # 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 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) 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: df2 = df # inserting rowcnt = 0 for row in df2.iter_rows(): check_exit_status(readstat_begin_row(writer)) for col_indx in range(col_count): 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 if missing_user_values: 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: check_if_missing = pd.isna(curval) # 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)) 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))) continue if curtype == PYWRITER_DOUBLE: check_exit_status(readstat_insert_double_value(writer, tempvar, 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, 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) 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) 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, 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: raise PyreadstatError("Unknown data format to insert") check_exit_status(readstat_end_row(writer)) rowcnt += 1 check_exit_status(readstat_end_writing(writer)) except: raise finally: readstat_writer_free(writer) close_file(fd) return 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1755175692.0 pyreadstat-1.3.3/pyreadstat/_readstat_writer_pandas.pyx0000644000076500000240000012242415047355414022065 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ###cython: profile=True # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# import os import warnings import sys import numpy as np #cimport numpy as np import pandas as pd from pandas.api.types import is_datetime64_any_dtype, is_datetime64_ns_dtype import datetime import calendar from datetime import timezone as _timezone from libc.math cimport round, NAN from readstat_api cimport * from _readstat_parser import ReadstatError, PyreadstatError from _readstat_parser cimport check_exit_status cdef set int_types = {int, np.dtype('int32'), np.dtype('int16'), np.dtype('int8'), np.dtype('uint8'), np.dtype('uint16'), np.int32, np.int16, np.int8, np.uint8, np.uint16} cdef set int_mixed_types = {pd.Int8Dtype(), pd.Int16Dtype(), pd.Int32Dtype(), pd.UInt8Dtype(), pd.UInt16Dtype()} cdef set float_types = {float, np.dtype('int64'), np.dtype('uint64'), np.dtype('uint32'), np.dtype('float'), np.dtype('float32'), np.int64, np.uint64, np.uint32, pd.Int64Dtype(), pd.UInt32Dtype(), pd.UInt64Dtype(), pd.Float64Dtype(), pd.Float32Dtype()} cdef set numeric_types = int_types.union(float_types).union(int_mixed_types) cdef set datetime_types = {datetime.datetime}#, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, pd.DatetimeTZDtype, 'datetime64[ns, UTC]'} cdef set nat_types = {datetime.datetime, np.datetime64, pd._libs.tslibs.timestamps.Timestamp, datetime.time, datetime.date} cdef set pyrwriter_datetimelike_types = {PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME, PYWRITER_DATETIME64_NS, PYWRITER_DATETIME64_US} cdef set pywriter_numeric_types = {PYWRITER_DOUBLE, PYWRITER_INTEGER, PYWRITER_LOGICAL, PYWRITER_DATE, PYWRITER_DATETIME, PYWRITER_TIME} cdef dict pandas_to_readstat_types = {PYWRITER_DOUBLE: READSTAT_TYPE_DOUBLE, PYWRITER_INTEGER: READSTAT_TYPE_INT32, PYWRITER_CHARACTER: READSTAT_TYPE_STRING, PYWRITER_LOGICAL: READSTAT_TYPE_INT32, 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_NS: READSTAT_TYPE_DOUBLE, PYWRITER_DATETIME64_US: READSTAT_TYPE_DOUBLE} cdef double spss_offset_secs = 12219379200 cdef double sas_offset_secs = 315619200 cdef double spss_offset_days = 141428 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)] + ["_"] 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 cdef int dta_old_max_width = 128 cdef int dta_111_max_width = 244 cdef int dta_117_max_width = 2045 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 """ 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 else: offset_days = sas_offset_days offset_secs = sas_offset_secs if curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS: # get timestamp in seconds if type(curval) == pd._libs.tslibs.timestamps.Timestamp: curval = curval.asm8 if type(curval) == datetime.datetime: #tstamp = curval.replace(tzinfo=timezone.utc).timestamp() # works only in python 3 tstamp = calendar.timegm(curval.replace(tzinfo=_timezone.utc).timetuple()) elif type(curval) == np.datetime64: if curval.dtype.name == "datetime64[ns]": tstamp = round(curval.astype(float)/1e9) elif curval.dtype.name == "datetime64[us]": tstamp = round(curval.astype(float)/1e6) elif curval.dtype.name == "datetime64[ms]": tstamp = round(curval.astype(float)/1e3) tstamp += offset_secs if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds tstamp *= 1000 elif curtype == PYWRITER_DATE: 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: # spss stores in seconds tstamp *= 86400 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 if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds tstamp *= 1000 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 """ if curtype == PYWRITER_DATE: if file_format == FILE_FORMAT_DTA: return "%td" #elif file_format == FILE_FORMAT_SAV: # return "DATE11" else: return "DATE" elif curtype == PYWRITER_DATETIME or curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US: if file_format == FILE_FORMAT_DTA: return "%tc" #elif file_format == FILE_FORMAT_SAV: # return "DATETIME20" else: return "DATETIME" elif curtype == PYWRITER_TIME: if file_format == FILE_FORMAT_DTA: return "%tcHH:MM:SS" else: return "TIME" else: raise PyreadstatError("Unknown pywriter variable format") cdef int get_pandas_str_series_max_length(object series, dict value_labels): """ For a pandas string series get the max length of the strings. Assumes there is no NaN among the elements. """ values = series.values cdef str val cdef bytes temp cdef int max_length = 1 cdef int curlen cdef list labels for val in values: temp = val.encode("utf-8") curlen = len(temp) if curlen > max_length: max_length = curlen if value_labels: labels = list(value_labels.keys()) for lab in labels: curlen = len(str(lab)) if curlen > max_length: max_length = curlen return max_length 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 """ values = series.values for val in values: if type(val) != type_to_check: return 0 return 1 cdef list get_pandas_column_types(object df, dict missing_user_values, dict variable_value_labels, int dta_str_max_len): """ From a pandas data frame, get a list with tuples column types as first element, max_length as second and is_missing as third. max_lenght is the max length of a string or string representation of an object, 0 for numeric types. is_missing flags wether the series has missing values (1) or not (0) dta_str_max_len is the max length for a dta string, 0 if the file format is not dta """ cdef int max_length cdef list types = df.dtypes.values.tolist() cdef list columns = df.columns.values.tolist() cdef list result = list() cdef int equal, is_missing if variable_value_labels is None: variable_value_labels = dict() for indx, (col_name, col_type) in enumerate(zip(columns, types)): max_length = 0 curseries = df.iloc[:, indx] curuser_missing = None if missing_user_values: curuser_missing = missing_user_values.get(col_name) # recover original type for categories if type(col_type) is pd.core.dtypes.dtypes.CategoricalDtype: col_type = np.asarray(curseries).dtype if col_type in int_types: result.append((PYWRITER_INTEGER, 0,0)) elif col_type in float_types: if np.any(pd.isna(curseries)): result.append((PYWRITER_DOUBLE, 0, 1)) else: result.append((PYWRITER_DOUBLE, 0, 0)) elif col_type == bool: result.append((PYWRITER_LOGICAL, 0,0)) # np.datetime64[ns] elif is_datetime64_ns_dtype(df[col_name]): if np.any(pd.isna(curseries)): result.append((PYWRITER_DATETIME64_NS, 0,1)) else: result.append((PYWRITER_DATETIME64_NS, 0,0)) elif col_type == np.dtype('= dta_str_max_len: result.append((PYWRITER_DTA_STR_REF, max_length, 1)) else: result.append((PYWRITER_OBJECT, max_length, 1)) continue else: if curuser_missing: result.append((PYWRITER_DOUBLE, 0, 1)) else: result.append((PYWRITER_LOGICAL, 0, 1)) continue else: if col_type in int_mixed_types: result.append((PYWRITER_INTEGER, 0, 0)) continue curtype = type(curseries.iloc[0]) equal = check_series_all_same_types(curseries, curtype) #equal = curseries.apply(lambda x: type(x) == curtype) #if not np.all(equal): if not equal: max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name)) if dta_str_max_len and max_length >= dta_str_max_len: result.append((PYWRITER_DTA_STR_REF, max_length, 1)) else: result.append((PYWRITER_OBJECT, max_length, 0)) continue if curtype in int_types: result.append((PYWRITER_INTEGER, 0, is_missing)) elif curtype in float_types: result.append((PYWRITER_DOUBLE, 0, is_missing)) elif curtype == bool: result.append((PYWRITER_LOGICAL, 0, is_missing)) elif curtype == str: if is_missing: col = curseries.dropna().reset_index(drop=True) max_length = get_pandas_str_series_max_length(col, variable_value_labels.get(col_name)) max_length = max(1, max_length) else: max_length = get_pandas_str_series_max_length(curseries, variable_value_labels.get(col_name)) if dta_str_max_len and max_length >= dta_str_max_len: result.append((PYWRITER_DTA_STR_REF, max_length, is_missing)) else: result.append((PYWRITER_CHARACTER, max_length, is_missing)) elif curtype == datetime.date: result.append((PYWRITER_DATE, 0, is_missing)) elif curtype == datetime.datetime: result.append((PYWRITER_DATETIME, 0, is_missing)) elif curtype == datetime.time: result.append((PYWRITER_TIME, 0, is_missing)) else: curseries = curseries.astype(str) if is_missing: col = curseries.dropna().reset_index(drop=True) max_length = get_pandas_str_series_max_length(col.astype(str), variable_value_labels.get(col_name)) else: max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name)) if dta_str_max_len and max_length >= dta_str_max_len: result.append((PYWRITER_DTA_STR_REF, max_length, 1)) else: result.append((PYWRITER_OBJECT, max_length, is_missing)) else: # generic object max_length = get_pandas_str_series_max_length(curseries.astype(str), variable_value_labels.get(col_name)) is_missing = 0 if np.any(pd.isna(curseries)): is_missing = 1 if dta_str_max_len and max_length >= dta_str_max_len: result.append((PYWRITER_DTA_STR_REF, max_length, 1)) else: result.append((PYWRITER_OBJECT, max_length, is_missing)) return result cdef readstat_label_set_t *set_value_label(readstat_writer_t *writer, dict value_labels, str labelset_name, pywriter_variable_type curpytype, dst_file_format file_format, str variable_name, list user_missing_tags) except *: """ Sets value labels for normal values and also tagged missing values (user defined missing for stata and sas) """ cdef readstat_label_set_t *label_set cdef readstat_type_t curtype cdef double double_val curtype = pandas_to_readstat_types[curpytype] label_set = readstat_add_label_set(writer, curtype, labelset_name.encode("utf-8")) for value, label in value_labels.items(): 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: 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")) continue if curpytype == PYWRITER_DOUBLE: if type(value) not in numeric_types: msg = "variable_value_labels: type of Value %s in variable %s must be numeric" % (str(value), variable_name) raise PyreadstatError(msg) readstat_label_double_value(label_set, value, label.encode("utf-8")) elif curpytype == PYWRITER_INTEGER: if type(value) not in int_types: msg = "variable_value_labels: type of Value %s in variable %s must be int" % (str(value), variable_name) raise PyreadstatError(msg) readstat_label_int32_value(label_set, value, label.encode("utf-8")) 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")) 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_NS, PYWRITER_DATETIME64_US): if type(value) not in nat_types: msg = "variable_value_labels: type of Value %s in variable %s must match the type of the column in pandas and be of type date, datetime or time" % (str(value), variable_name) raise PyreadstatError(msg) double_val = convert_datetimelike_to_number(file_format, curpytype, value) 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 *: """ Adding missing ranges, user defined missing discrete values both numeric and character, this happens for SPSS """ cdef int range_values = 0 cdef int discrete_values = 0 cdef int discrete_strings = 0 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: msg = "dictionaries in missing_ranges must have the keys hi and lo" raise PyreadstatError(msg) if type(hi) in numeric_types and type(lo) in numeric_types: if vartype not in pywriter_numeric_types: msg = "numeric missing_ranges value given for non numeric variable %s" %variablename raise PyreadstatError(msg) 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)) 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) 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"))) discrete_strings += 1 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: msg = "missing_ranges: hi and lo values must be both either of numeric or string type" raise PyreadstatError(msg) else: if type(cur_range) in numeric_types: 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 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: 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: msg = "missing_ranges: values must be both either of numeric or string type" raise PyreadstatError(msg) if discrete_strings > 3: 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" 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: 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 *: """ Sets the variable alignment, ineffective on SPSS, STATA and XPORT (what about SAS7bdat?) """ cdef readstat_alignment_t alignment if alignment_str == "right": alignment = READSTAT_ALIGNMENT_RIGHT elif alignment_str == "left": alignment = READSTAT_ALIGNMENT_LEFT elif alignment_str == "center": 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) 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 *: """ Sets the variable display width (SPSS). Not effective on STATA. (what about SAS7BDAT?) """ 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. """ cdef readstat_measure_t measure if measure_str == "nominal": measure = READSTAT_MEASURE_NOMINAL elif measure_str == "ordinal": measure = READSTAT_MEASURE_ORDINAL elif measure_str == "scale": 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) raise PyreadstatError(msg) readstat_variable_set_measure(variable, measure); 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 """ cdef int fd fd = (ctx)[0] if os.name=='nt': return _write(fd, data, _len) else: 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 """ cdef char * err_readstat cdef str err_message if retcode != READSTAT_OK: err_readstat = readstat_error_message(retcode) err_message = err_readstat raise ReadstatError(err_message) cdef int open_file(bytes filename_path): cdef int fd cdef int flags cdef Py_ssize_t length cdef bytes filename_bytes cdef char *path if os.name == "nt": filename_str = os.fsdecode(filename_path) u16_path = PyUnicode_AsWideCharString(filename_str, &length) flags = _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC fd = _wsopen(u16_path, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE) else: #filename_bytes = filename_path.encode("utf-8") path = filename_path flags = O_WRONLY | O_CREAT | O_TRUNC fd = open(path, flags, 0644) return fd cdef int close_file(int fd): if os.name == "nt": return _close(fd) else: return close(fd) cdef int run_write(df, object filename_path, dst_file_format file_format, str file_label, object column_labels, int file_format_version, str note, str table_name, dict variable_value_labels, dict missing_ranges, dict missing_user_values, dict variable_alignment, dict variable_display_width, dict variable_measure, dict variable_format, bint row_compression) except *: """ main entry point for writing all formats. Some parameters are specific for certain file type and are even incompatible between them. This function relies on the caller to select the right combination of parameters, not checking them otherwise. """ if not isinstance(df, pd.DataFrame): raise PyreadstatError("first argument must be a pandas data frame") if variable_value_labels: for k,v in variable_value_labels.items(): if type(v) != dict: msg = "variable_value_labels: value for key %s must be dict, got %s" % (k, str(type(v))) raise PyreadstatError(msg) 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 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: if val not in valid_user_missing: msg = "missing_user_values supports values a to z for Stata and A to Z and _ for SAS, got %s instead" % str(val) raise PyreadstatError(msg) cdef readstat_error_t retcode cdef char *err_readstat cdef str err_message cdef readstat_writer_t *writer cdef bytes file_label_bytes cdef char *file_labl cdef int dta_str_max_len = 0 cdef list col_names = df.columns.values.tolist() if len(col_names) != len(set(col_names)): msg = "Non unique column names detected in the dataframe!" raise PyreadstatError(msg) 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") 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) if file_format == FILE_FORMAT_POR: 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 elif file_format_version >= 111: dta_str_max_len = dta_111_max_width else: dta_str_max_len = dta_old_max_width cdef list col_types = get_pandas_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)} cdef readstat_variable_t *variable cdef pywriter_variable_type curtype cdef int max_length cdef char *curformat cdef str tempformat cdef int col_indx cdef bytes cur_col_label cdef int col_label_count = 0 cdef readstat_variable_t *tempvar cdef int row_indx cdef str curvalstr cdef double dtimelikeval #cdef np.ndarray values cdef object values cdef dict value_labels cdef int lblset_cnt = 0 cdef readstat_label_set_t *label_set cdef list col_label_temp cdef bint hasdatetime64 cdef list pywriter_types cdef object df2 cdef float mulfac, conv2secs cdef readstat_string_ref_t* strref cdef dict strref_map = dict() cdef int strref_cnt cdef object strref_indx if hasattr(os, 'fsencode'): try: filename_path = os.fsencode(filename_path) except UnicodeError: warnings.warn("file path could not be encoded with %s which is set as your system encoding, trying to encode it as utf-8. Please set your system encoding correctly." % sys.getfilesystemencoding()) 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: filename_bytes = filename_path else: raise PyreadstatError("path must be either str or bytes") filename_path = os.path.expanduser(filename_path) dirname = os.path.dirname(filename_path) if dirname and not os.path.isdir(dirname): raise PyreadstatError(f"the destination folder {dirname} does not exist!") cdef int fd = open_file(filename_path) writer = readstat_writer_init() try: check_exit_status(readstat_set_data_writer(writer, write_bytes)) if file_label: file_label_bytes = file_label.encode("utf-8") file_labl = file_label_bytes check_exit_status(readstat_writer_set_file_label(writer, file_labl)) if note: readstat_add_note(writer, note.encode("utf-8")) if file_format_version > -1: check_exit_status(readstat_writer_set_file_format_version(writer, file_format_version)) if row_compression: check_exit_status(readstat_writer_set_compression(writer, READSTAT_COMPRESS_ROWS)) # table name is used only for xpt files if table_name: table_name_bytes = table_name.encode("utf-8") tab_name = table_name_bytes check_exit_status(readstat_writer_set_table_name(writer, tab_name)) # 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: 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]) else: col_label_temp.append(None) 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") strref_cnt = 0 for col_indx in range(col_count): curtype, max_length, _ = col_types[col_indx] variable_name = col_names[col_indx] variable = readstat_add_variable(writer, variable_name.encode("utf-8"), pandas_to_readstat_types[curtype], max_length) if variable_format: 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) readstat_variable_set_format(variable, curformat) # 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) strref = readstat_add_string_ref(writer, curvalstr.encode("utf-8")) strref_map[curvalstr] = strref_cnt strref_cnt += 1 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") 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) 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, col_names_to_types[variable_name], file_format, variable_name, curuser_missing) readstat_variable_set_label_set(variable, label_set) if missing_ranges: cur_ranges = missing_ranges.get(variable_name) if cur_ranges: 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: # 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 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: cur_measure = variable_measure.get(variable_name) if cur_measure: set_variable_measure(variable, cur_measure, variable_name) # 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)) 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: 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") # 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)) # vectorized transform of datetime64ns columns pywriter_types = [x[0] for x in col_types] hasdatetime64 = PYWRITER_DATETIME64_NS in pywriter_types or PYWRITER_DATETIME64_US in pywriter_types if hasdatetime64: if file_format == FILE_FORMAT_SAV or file_format == FILE_FORMAT_POR: offset_secs = spss_offset_secs else: offset_secs = sas_offset_secs mulfac = 1.0 if file_format == FILE_FORMAT_DTA: # stata stores in milliseconds mulfac = 1000.0 df2 = df.copy() for col_indx in range(col_count): if pywriter_types[col_indx] == PYWRITER_DATETIME64_NS: df2[df2.columns[col_indx]] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac #df2.iloc[:, col_indx] = (np.round(df2.iloc[:, col_indx].values.astype(object).astype(np.float64)/1e9) + offset_secs) * mulfac elif pywriter_types[col_indx] == PYWRITER_DATETIME64_US: df2[df2.columns[col_indx]] = (np.round(df2.iloc[:, col_indx].values.astype(np.float64)/1e6) + offset_secs) * mulfac df2.loc[df2[df2.columns[col_indx]]==-9223056417655, df2.columns[col_indx]] = np.nan else: df2 = df # inserting rowcnt = 0 for row in df2.values: check_exit_status(readstat_begin_row(writer)) for col_indx in range(col_count): 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 if missing_user_values: curuser_missing = missing_user_values.get(col_names[col_indx]) if is_missing: #if curval is None or (type(curval) in numeric_types and np.isnan(curval)): if pd.isna(curval): check_exit_status(readstat_insert_missing_value(writer, tempvar)) 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))) continue if curtype == PYWRITER_DOUBLE: check_exit_status(readstat_insert_double_value(writer, tempvar, 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, 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) 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) check_exit_status(readstat_insert_string_ref(writer, tempvar, strref)) elif curtype == PYWRITER_DATETIME64_NS or curtype == PYWRITER_DATETIME64_US: check_exit_status(readstat_insert_double_value(writer, tempvar, 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: raise PyreadstatError("Unknown data format to insert") check_exit_status(readstat_end_row(writer)) rowcnt += 1 check_exit_status(readstat_end_writing(writer)) except: raise finally: readstat_writer_free(writer) close_file(fd) return 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316780.0 pyreadstat-1.3.3/pyreadstat/conditional_includes.h0000644000076500000240000000254214646232654020777 0ustar00dialout/* The include and declarations in this file exists because when cython translates to c it cannot translate an IF UNAME_SYSNAME=="Windows" to * a c #ifdef. That means the resulting c file will be different if produced on windows or on unix. We want our c files to be portable and * therefore do the right includes for windows here, and just declare dummy symbols for unix. */ #ifdef _WIN32 #include #include #include #include // Stuff for handling paths with international characters on windows void assign_fd(void *io_ctx, int fd) { ((unistd_io_ctx_t*)io_ctx)->fd = fd; } //ssize_t write(int fd, const void *buf, size_t nbyte){return 0;}; //int close(int fd); #else #include #include #include //int open(const char *path, int oflag, int mode); //int close(int fd); int _wsopen(const wchar_t *filename, int oflag, int shflag, int pmode){ return 0; }; int _O_RDONLY; int _O_BINARY; int _O_WRONLY; int _O_TRUNC; int _O_CREAT; int _SH_DENYRW; int _SH_DENYWR; int _SH_DENYRD; int _SH_DENYNO; int _S_IWRITE; int _S_IREAD; void assign_fd(void *io_ctx, int fd){}; int _close(int fd){ return 0; }; ssize_t _write(int fd, const void *buf, size_t nbyte){return 0;}; #endif ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1755175692.0 pyreadstat-1.3.3/pyreadstat/pyfunctions.py0000644000076500000240000001663115047355414017370 0ustar00dialout""" Functions written in pure python """ from copy import deepcopy, copy import warnings import narwhals.stable.v2 as nw # Functions to deal with value labels def set_value_labels(dataframe, metadata, formats_as_category=True, formats_as_ordered_category=False): """ Changes the values in the dataframe according to the value formats in the metadata. It will return a copy of the dataframe. If no appropiate formats were found, the result will be an unchanged copy of the original dataframe. Parameters ---------- dataframe : pandas dataframe resulting from parsing a file metadata : dictionary resulting from parsing a file formats_as_category : bool, optional defaults to True. If True the variables having formats will be transformed into pandas categories. formats_as_ordered_category : bool, optional defaults to False. If True the variables having formats will be transformed into pandas ordered categories. it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of the value of formats_as_category. Returns ------- df_copy : pandas dataframe a copy of the original dataframe with the values changed, if appropiate formats were found, unaltered otherwise """ df_copy = nw.from_native(dataframe).clone() if metadata.value_labels and metadata.variable_to_label: for var_name, label_name in metadata.variable_to_label.items(): labels = metadata.value_labels.get(label_name) if labels: labels = deepcopy(labels) if var_name in df_copy.columns: # unique does not work for polars Object if not df_copy.implementation.is_pandas() and df_copy[var_name].dtype == nw.Object: unvals = list(set(df_copy[var_name].to_list())) else: unvals = df_copy[var_name].unique() for uval in unvals: if uval not in labels: labels[uval] = uval # if all values are null, there will be nothing to replace. However we cannot do replace_strict on null dtype, it raises an error if not df_copy.implementation.is_pandas() and (len(df_copy[var_name])==df_copy[var_name].null_count()): continue # replace_strict requires that all the values are in the map. Could not get map_batches or when/then/otherwise to work elif not df_copy.implementation.is_pandas() and (df_copy[var_name].dtype==nw.Object or not all([type(v)==type(list(labels.values())[0]) for v in labels.values() if v is not None])): # polars is very difficult to convince to mix strings and numbers, so we have to do it this way temp = [labels[x] for x in df_copy[var_name]] newser = nw.new_series(name=var_name, values= temp, dtype=nw.Object, backend=df_copy.implementation) df_copy = df_copy.with_columns(newser.alias(var_name)) if formats_as_category or formats_as_ordered_category: msg = f"You requested formats_as_category=True or formats_as_ordered_category=True, but it was not possible to cast variable '{var_name}' to category" warnings.warn(msg, RuntimeWarning) continue # not sure if we get into this situation ever or what would exactly happen, maybe this is not needed? elif not df_copy.implementation.is_pandas() and df_copy[var_name].dtype==nw.Unknown: msg = f"It was not possible to apply value formats to variable '{var_name}' due to unknown/not supported data type" warnings.warn(msg, RuntimeWarning) continue else: df_copy = df_copy.with_columns(nw.col(var_name).replace_strict(labels)) if formats_as_ordered_category: categories = list(set(labels.values())) original_values = list(labels.keys()) original_values.sort() revdict= dict() for orival in original_values: curcat = labels.get(orival) if not revdict.get(curcat): revdict[curcat] = orival categories.sort(key=revdict.get) df_copy = df_copy.with_columns(nw.col(var_name).cast(nw.Enum(categories))) elif formats_as_category: df_copy = df_copy.with_columns(nw.col(var_name).cast(nw.Categorical)) return df_copy.to_native() def set_catalog_to_sas(sas_dataframe, sas_metadata, catalog_metadata, formats_as_category=True, formats_as_ordered_category=False): """ Changes the values in the dataframe and sas_metadata according to the formats in the catalog. It will return a copy of the dataframe and metadata. If no appropriate formats were found, the result will be an unchanged copy of the original dataframe. Parameters ---------- sas_dataframe : pandas dataframe resulting from parsing a sas7bdat file sas_metadata : pyreadstat metadata object resulting from parsing a sas7bdat file catalog_metadata : pyreadstat metadata object resulting from parsing a sas7bcat (catalog) file formats_as_category : bool, optional defaults to True. If True the variables having formats will be transformed into pandas categories. formats_as_ordered_category : bool, optional defaults to False. If True the variables having formats will be transformed into pandas ordered categories. it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of the value of formats_as_category. Returns ------- df_copy : pandas dataframe a copy of the original dataframe with the values changed, if appropriate formats were found, unaltered otherwise metadata : dict a copy of the original sas_metadata enriched with catalog information if found, otherwise unaltered """ if catalog_metadata.value_labels and sas_metadata.variable_to_label: catalog_metadata_copy = deepcopy(catalog_metadata) metadata = deepcopy(sas_metadata) metadata.value_labels = catalog_metadata_copy.value_labels df_copy = set_value_labels(sas_dataframe, metadata, formats_as_category=formats_as_category, formats_as_ordered_category=formats_as_ordered_category) variable_value_labels = dict() for var_name, var_label in metadata.variable_to_label.items(): current_labels = catalog_metadata_copy.value_labels.get(var_label) if current_labels: variable_value_labels[var_name] = current_labels metadata.variable_value_labels = variable_value_labels else: #df_copy = sas_dataframe.copy() df_copy = nw.from_native(sas_dataframe).clone().to_native() metadata = deepcopy(sas_metadata) return df_copy, metadata ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180458.0 pyreadstat-1.3.3/pyreadstat/pyreadstat.c0000644000076500000240000363426715134706452016776 0ustar00dialout/* 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.pyreadstat", "sources": [ "pyreadstat/pyreadstat.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.pyreadstat" } 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 #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 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 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 struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::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 #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__pyreadstat #define __PYX_HAVE_API__pyreadstat__pyreadstat /* Early includes */ #include #include #include #include "readstat.h" #include "readstat_io_unistd.h" #include "conditional_includes.h" #ifdef _OPENMP #include #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 #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 #endif template static void __Pyx_pretend_to_initialize(T* ptr) { #if __cplusplus > 201103L if ((std::is_trivially_default_constructible::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/pyreadstat.pyx", "pyreadstat/_readstat_parser.pxd", }; /* #### Code section: utility_code_proto_before_types ### */ /* Atomics.proto */ #include #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 #elif CYTHON_ATOMICS && (defined(__cplusplus) && (\ (__cplusplus >= 201103L) ||\ (defined(_MSC_VER) && _MSC_VER >= 1700))) #include #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 #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 /* IncludeStructmemberH.proto */ #include /* 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; struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks; /* "_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; /* "_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; /* "_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; }; /* "pyreadstat/pyreadstat.pyx":542 * # convenience functions to read in chunks * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, # <<<<<<<<<<<<<< * multiprocess=False, num_processes=4, num_rows=None, **kwargs): * """ */ struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks { PyObject_HEAD PyObject *__pyx_v__; PyObject *__pyx_v_chunksize; PyObject *__pyx_v_df; PyObject *__pyx_v_file_path; PyObject *__pyx_v_kwargs; PyObject *__pyx_v_limit; PyObject *__pyx_v_meta; PyObject *__pyx_v_multiprocess; PyObject *__pyx_v_num_processes; PyObject *__pyx_v_num_rows; PyObject *__pyx_v_numrows; PyObject *__pyx_v_offset; PyObject *__pyx_v_read_function; }; /* #### 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); /* TupleAndListFromArray.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); #endif #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_METH_FASTCALL static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); #endif /* IncludeStringH.proto */ #include /* 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); /* fastcall.proto */ #if CYTHON_AVOID_BORROWED_REFS #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_PySequence_ITEM(args, i) #elif CYTHON_ASSUME_SAFE_MACROS #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_NewRef(__Pyx_PyTuple_GET_ITEM(args, i)) #else #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_XNewRef(PyTuple_GetItem(args, i)) #endif #define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) #define __Pyx_KwValues_VARARGS(args, nargs) NULL #define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) #define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) #if CYTHON_METH_FASTCALL #define __Pyx_ArgRef_FASTCALL(args, i) __Pyx_NewRef(args[i]) #define __Pyx_NumKwargs_FASTCALL(kwds) __Pyx_PyTuple_GET_SIZE(kwds) #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); #else #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) #endif #else #define __Pyx_ArgRef_FASTCALL __Pyx_ArgRef_VARARGS #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS #endif #define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) #if CYTHON_METH_FASTCALL || (CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) #define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(args + start, stop - start) #else #define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) #endif /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static CYTHON_INLINE int __Pyx_ParseKeywords( PyObject *kwds, PyObject *const *kwvalues, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs ); /* 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) /* 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); /* 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 /* 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 /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* ArgTypeTest.proto */ #define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ ((likely(__Pyx_IS_TYPE(obj, type) | (none_allowed && (obj == Py_None)))) ? 1 :\ __Pyx__ArgTypeTest(obj, type, name, exact)) static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); /* 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); /* PyObjectDelAttr.proto */ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 #define __Pyx_PyObject_DelAttr(o, n) PyObject_SetAttr(o, n, NULL) #else #define __Pyx_PyObject_DelAttr(o, n) PyObject_DelAttr(o, n) #endif /* PyObjectSetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); #else #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_DelAttr(o,n) #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) #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 /* 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 /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /* 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)); } /* py_dict_pop.proto */ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(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 /* PyObjectCallNoArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); /* PyObjectCallOneArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* PyObjectGetMethod.proto */ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); /* PyObjectCallMethod0.proto */ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); /* RaiseNoneIterError.proto */ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); /* UnpackTupleError.proto */ static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /* UnpackTuple2.proto */ static CYTHON_INLINE int __Pyx_unpack_tuple2( PyObject* tuple, PyObject** value1, PyObject** value2, int is_tuple, int has_known_size, int decref_tuple); static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); static int __Pyx_unpack_tuple2_generic( PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); /* dict_iter.proto */ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, Py_ssize_t* p_orig_length, int* p_is_dict); static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); /* MergeKeywords.proto */ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); /* pybytes_as_double.proto */ static double __Pyx_SlowPyString_AsDouble(PyObject *obj); static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length); static CYTHON_INLINE double __Pyx_PyBytes_AsDouble(PyObject *obj) { char* as_c_string; Py_ssize_t size; #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE as_c_string = PyBytes_AS_STRING(obj); size = PyBytes_GET_SIZE(obj); #else if (PyBytes_AsStringAndSize(obj, &as_c_string, &size) < 0) { return (double)-1; } #endif return __Pyx__PyBytes_AsDouble(obj, as_c_string, size); } static CYTHON_INLINE double __Pyx_PyByteArray_AsDouble(PyObject *obj) { char* as_c_string; Py_ssize_t size; #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE as_c_string = PyByteArray_AS_STRING(obj); size = PyByteArray_GET_SIZE(obj); #else as_c_string = PyByteArray_AsString(obj); if (as_c_string == NULL) { return (double)-1; } size = PyByteArray_Size(obj); #endif return __Pyx__PyBytes_AsDouble(obj, as_c_string, size); } /* pyunicode_as_double.proto */ #if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS static const char* __Pyx__PyUnicode_AsDouble_Copy(const void* data, const int kind, char* buffer, Py_ssize_t start, Py_ssize_t end) { int last_was_punctuation; Py_ssize_t i; last_was_punctuation = 1; for (i=start; i <= end; i++) { Py_UCS4 chr = PyUnicode_READ(kind, data, i); int is_punctuation = (chr == '_') | (chr == '.'); *buffer = (char)chr; buffer += (chr != '_'); if (unlikely(chr > 127)) goto parse_failure; if (unlikely(last_was_punctuation & is_punctuation)) goto parse_failure; last_was_punctuation = is_punctuation; } if (unlikely(last_was_punctuation)) goto parse_failure; *buffer = '\0'; return buffer; parse_failure: return NULL; } static double __Pyx__PyUnicode_AsDouble_inf_nan(const void* data, int kind, Py_ssize_t start, Py_ssize_t length) { int matches = 1; Py_UCS4 chr; Py_UCS4 sign = PyUnicode_READ(kind, data, start); int is_signed = (sign == '-') | (sign == '+'); start += is_signed; length -= is_signed; switch (PyUnicode_READ(kind, data, start)) { #ifdef Py_NAN case 'n': case 'N': if (unlikely(length != 3)) goto parse_failure; chr = PyUnicode_READ(kind, data, start+1); matches &= (chr == 'a') | (chr == 'A'); chr = PyUnicode_READ(kind, data, start+2); matches &= (chr == 'n') | (chr == 'N'); if (unlikely(!matches)) goto parse_failure; return (sign == '-') ? -Py_NAN : Py_NAN; #endif case 'i': case 'I': if (unlikely(length < 3)) goto parse_failure; chr = PyUnicode_READ(kind, data, start+1); matches &= (chr == 'n') | (chr == 'N'); chr = PyUnicode_READ(kind, data, start+2); matches &= (chr == 'f') | (chr == 'F'); if (likely(length == 3 && matches)) return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL; if (unlikely(length != 8)) goto parse_failure; chr = PyUnicode_READ(kind, data, start+3); matches &= (chr == 'i') | (chr == 'I'); chr = PyUnicode_READ(kind, data, start+4); matches &= (chr == 'n') | (chr == 'N'); chr = PyUnicode_READ(kind, data, start+5); matches &= (chr == 'i') | (chr == 'I'); chr = PyUnicode_READ(kind, data, start+6); matches &= (chr == 't') | (chr == 'T'); chr = PyUnicode_READ(kind, data, start+7); matches &= (chr == 'y') | (chr == 'Y'); if (unlikely(!matches)) goto parse_failure; return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL; case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; default: goto parse_failure; } return 0.0; parse_failure: return -1.0; } static double __Pyx_PyUnicode_AsDouble_WithSpaces(PyObject *obj) { double value; const char *last; char *end; Py_ssize_t start, length = PyUnicode_GET_LENGTH(obj); const int kind = PyUnicode_KIND(obj); const void* data = PyUnicode_DATA(obj); start = 0; while (Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, start))) start++; while (start < length - 1 && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, length - 1))) length--; length -= start; if (unlikely(length <= 0)) goto fallback; value = __Pyx__PyUnicode_AsDouble_inf_nan(data, kind, start, length); if (unlikely(value == -1.0)) goto fallback; if (value != 0.0) return value; if (length < 40) { char number[40]; last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length); if (unlikely(!last)) goto fallback; value = PyOS_string_to_double(number, &end, NULL); } else { char *number = (char*) PyMem_Malloc((length + 1) * sizeof(char)); if (unlikely(!number)) goto fallback; last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length); if (unlikely(!last)) { PyMem_Free(number); goto fallback; } value = PyOS_string_to_double(number, &end, NULL); PyMem_Free(number); } if (likely(end == last) || (value == (double)-1 && PyErr_Occurred())) { return value; } fallback: return __Pyx_SlowPyString_AsDouble(obj); } #endif static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj) { #if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS if (unlikely(__Pyx_PyUnicode_READY(obj) == -1)) return (double)-1; if (likely(PyUnicode_IS_ASCII(obj))) { const char *s; Py_ssize_t length; s = PyUnicode_AsUTF8AndSize(obj, &length); return __Pyx__PyBytes_AsDouble(obj, s, length); } return __Pyx_PyUnicode_AsDouble_WithSpaces(obj); #else return __Pyx_SlowPyString_AsDouble(obj); #endif } /* PyLongCompare.proto */ static CYTHON_INLINE int __Pyx_PyLong_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); /* 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 /* 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 /* 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 /* 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 /* 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 /* 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 /* dict_getitem_default.proto */ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /* 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); /* 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 /* 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 /* py_dict_items.proto */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d); /* 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 /* py_dict_keys.proto */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d); /* PySequenceContains.proto */ static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { int result = PySequence_Contains(seq, item); return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); } /* PyObject_Unicode.proto */ #define __Pyx_PyObject_Unicode(obj)\ (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj)) /* 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 /* RaiseUnexpectedTypeError.proto */ static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj); /* CallTypeTraverse.proto */ #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000) #define __Pyx_call_type_traverse(o, always_call, visit, arg) 0 #else static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg); #endif /* LimitedApiGetTypeDict.proto */ #if CYTHON_COMPILING_IN_LIMITED_API static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp); #endif /* SetItemOnTypeDict.proto */ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v); #define __Pyx_SetItemOnTypeDict(tp, k, v) __Pyx__SetItemOnTypeDict((PyTypeObject*)tp, k, v) /* FixUpExtensionType.proto */ static CYTHON_INLINE int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); /* ValidateBasesTuple.proto */ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); #endif /* PyType_Ready.proto */ CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); /* 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 #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); /* FetchSharedCythonModule.proto */ static PyObject *__Pyx_FetchSharedCythonABIModule(void); /* dict_setdefault.proto */ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type); /* FetchCommonType.proto */ static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases); /* CommonTypesMetaclass.proto */ static int __pyx_CommonTypesMetaclass_init(PyObject *module); #define __Pyx_CommonTypesMetaclass_USED /* PyMethodNew.proto */ static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ); /* PyVectorcallFastCallDict.proto */ #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); #endif /* CythonFunctionShared.proto */ #define __Pyx_CyFunction_USED #define __Pyx_CYFUNCTION_STATICMETHOD 0x01 #define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 #define __Pyx_CYFUNCTION_CCLASS 0x04 #define __Pyx_CYFUNCTION_COROUTINE 0x08 #define __Pyx_CyFunction_GetClosure(f)\ (((__pyx_CyFunctionObject *) (f))->func_closure) #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API #define __Pyx_CyFunction_GetClassObj(f)\ (((__pyx_CyFunctionObject *) (f))->func_classobj) #else #define __Pyx_CyFunction_GetClassObj(f)\ ((PyObject*) ((PyCMethodObject *) (f))->mm_class) #endif #define __Pyx_CyFunction_SetClassObj(f, classobj)\ __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) #define __Pyx_CyFunction_Defaults(type, f)\ ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) #define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) typedef struct { #if CYTHON_COMPILING_IN_LIMITED_API PyObject_HEAD PyObject *func; #elif PY_VERSION_HEX < 0x030900B1 PyCFunctionObject func; #else PyCMethodObject func; #endif #if CYTHON_BACKPORT_VECTORCALL ||\ (CYTHON_COMPILING_IN_LIMITED_API && CYTHON_METH_FASTCALL) __pyx_vectorcallfunc func_vectorcall; #endif #if CYTHON_COMPILING_IN_LIMITED_API PyObject *func_weakreflist; #endif PyObject *func_dict; PyObject *func_name; PyObject *func_qualname; PyObject *func_doc; PyObject *func_globals; PyObject *func_code; PyObject *func_closure; #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API PyObject *func_classobj; #endif PyObject *defaults; int flags; PyObject *defaults_tuple; PyObject *defaults_kwdict; PyObject *(*defaults_getter)(PyObject *); PyObject *func_annotations; PyObject *func_is_coroutine; } __pyx_CyFunctionObject; #undef __Pyx_CyOrPyCFunction_Check #define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_mstate_global->__pyx_CyFunctionType) #define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_mstate_global->__pyx_CyFunctionType, &PyCFunction_Type) #define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_mstate_global->__pyx_CyFunctionType) static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void (*cfunc)(void)); #undef __Pyx_IsSameCFunction #define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject *globals, PyObject* code); static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); static CYTHON_INLINE PyObject *__Pyx_CyFunction_InitDefaults(PyObject *func, PyTypeObject *defaults_type); static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, PyObject *tuple); static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, PyObject *dict); static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, PyObject *dict); static int __pyx_CyFunction_init(PyObject *module); #if CYTHON_METH_FASTCALL static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); #if CYTHON_BACKPORT_VECTORCALL || CYTHON_COMPILING_IN_LIMITED_API #define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) #else #define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) #endif #endif /* CythonFunction.proto */ static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject *globals, PyObject* code); /* 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); /* GCCDiagnostics.proto */ #if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #define __Pyx_HAS_GCC_DIAGNOSTIC #endif /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyLong_As_int(PyObject *); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_int(int value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_long(long value); /* 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 /* IterNextPlain.proto */ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next_Plain(PyObject *iterator); #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000 static PyObject *__Pyx_GetBuiltinNext_LimitedAPI(void); #endif /* PyObjectCallMethod1.proto */ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); /* ReturnWithStopIteration.proto */ static CYTHON_INLINE void __Pyx_ReturnWithStopIteration(PyObject* value, int async, int iternext); /* CoroutineBase.proto */ struct __pyx_CoroutineObject; typedef PyObject *(*__pyx_coroutine_body_t)(struct __pyx_CoroutineObject *, PyThreadState *, PyObject *); #if CYTHON_USE_EXC_INFO_STACK #define __Pyx_ExcInfoStruct _PyErr_StackItem #else typedef struct { PyObject *exc_type; PyObject *exc_value; PyObject *exc_traceback; } __Pyx_ExcInfoStruct; #endif typedef struct __pyx_CoroutineObject { PyObject_HEAD __pyx_coroutine_body_t body; PyObject *closure; __Pyx_ExcInfoStruct gi_exc_state; PyObject *gi_weakreflist; PyObject *classobj; PyObject *yieldfrom; __Pyx_pyiter_sendfunc yieldfrom_am_send; PyObject *gi_name; PyObject *gi_qualname; PyObject *gi_modulename; PyObject *gi_code; PyObject *gi_frame; #if CYTHON_USE_SYS_MONITORING && (CYTHON_PROFILE || CYTHON_TRACE) PyMonitoringState __pyx_pymonitoring_state[__Pyx_MonitoringEventTypes_CyGen_count]; uint64_t __pyx_pymonitoring_version; #endif int resume_label; char is_running; } __pyx_CoroutineObject; static __pyx_CoroutineObject *__Pyx__Coroutine_New( PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, PyObject *name, PyObject *qualname, PyObject *module_name); static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, PyObject *name, PyObject *qualname, PyObject *module_name); static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self); static int __Pyx_Coroutine_clear(PyObject *self); static __Pyx_PySendResult __Pyx_Coroutine_AmSend(PyObject *self, PyObject *value, PyObject **retval); static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); static __Pyx_PySendResult __Pyx_Coroutine_Close(PyObject *self, PyObject **retval); static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); #if CYTHON_USE_EXC_INFO_STACK #define __Pyx_Coroutine_SwapException(self) #define __Pyx_Coroutine_ResetAndClearException(self) __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state) #else #define __Pyx_Coroutine_SwapException(self) {\ __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback);\ __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state);\ } #define __Pyx_Coroutine_ResetAndClearException(self) {\ __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback);\ (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL;\ } #endif #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue) #else #define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue) #endif static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state); static char __Pyx_Coroutine_test_and_set_is_running(__pyx_CoroutineObject *gen); static void __Pyx_Coroutine_unset_is_running(__pyx_CoroutineObject *gen); static char __Pyx_Coroutine_get_is_running(__pyx_CoroutineObject *gen); static PyObject *__Pyx_Coroutine_get_is_running_getter(PyObject *gen, void *closure); #if __PYX_HAS_PY_AM_SEND == 2 static void __Pyx_SetBackportTypeAmSend(PyTypeObject *type, __Pyx_PyAsyncMethodsStruct *static_amsend_methods, __Pyx_pyiter_sendfunc am_send); #endif static PyObject *__Pyx_Coroutine_fail_reduce_ex(PyObject *self, PyObject *arg); /* Generator.proto */ #define __Pyx_Generator_USED #define __Pyx_Generator_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_mstate_global->__pyx_GeneratorType) #define __Pyx_Generator_New(body, code, closure, name, qualname, module_name)\ __Pyx__Coroutine_New(__pyx_mstate_global->__pyx_GeneratorType, body, code, closure, name, qualname, module_name) static PyObject *__Pyx_Generator_Next(PyObject *self); static int __pyx_Generator_init(PyObject *module); static CYTHON_INLINE PyObject *__Pyx_Generator_GetInlinedResult(PyObject *self); /* 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); /* 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 PyObject *(*__pyx_f_10pyreadstat_16_readstat_parser_run_conversion)(PyObject *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension, PyObject *, int, int, PyObject *, int, int, long, long, PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ /* Module declarations from "pyreadstat._readstat_writer" */ static int (*__pyx_f_10pyreadstat_16_readstat_writer_run_write)(PyObject *, PyObject *, __pyx_t_10pyreadstat_16_readstat_writer_dst_file_format, PyObject *, PyObject *, int, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int); /*proto*/ /* Module declarations from "pyreadstat.pyreadstat" */ /* #### Code section: typeinfo ### */ /* #### Code section: before_global_var ### */ #define __Pyx_MODULE_NAME "pyreadstat.pyreadstat" extern int __pyx_module_is_main_pyreadstat__pyreadstat; int __pyx_module_is_main_pyreadstat__pyreadstat = 0; /* Implementation of "pyreadstat.pyreadstat" */ /* #### Code section: global_var ### */ static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_max; /* #### 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_df[] = "df"; static const char __pyx_k_gc[] = "gc"; static const char __pyx_k_mp[] = "mp"; static const char __pyx_k_np[] = "np"; static const char __pyx_k_nw[] = "nw"; static const char __pyx_k_v2[] = "v2"; static const char __pyx_k_div[] = "div"; static const char __pyx_k_dta[] = "dta"; static const char __pyx_k_get[] = "get"; static const char __pyx_k_how[] = "how"; static const char __pyx_k_inf[] = "inf"; static const char __pyx_k_key[] = "key"; static const char __pyx_k_map[] = "map"; static const char __pyx_k_max[] = "max"; static const char __pyx_k_pop[] = "pop"; static const char __pyx_k_por[] = "por"; static const char __pyx_k_Pool[] = "Pool"; static const char __pyx_k_dict[] = "dict"; static const char __pyx_k_divs[] = "divs"; static const char __pyx_k_drop[] = "drop"; static const char __pyx_k_func[] = "__func__"; static const char __pyx_k_indx[] = "indx"; static const char __pyx_k_jobs[] = "jobs"; static const char __pyx_k_keys[] = "keys"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_meta[] = "meta"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_next[] = "next"; static const char __pyx_k_note[] = "note"; static const char __pyx_k_pool[] = "pool"; static const char __pyx_k_send[] = "send"; static const char __pyx_k_spec[] = "__spec__"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_chunk[] = "chunk"; static const char __pyx_k_close[] = "close"; static const char __pyx_k_final[] = "final"; static const char __pyx_k_items[] = "items"; static const char __pyx_k_limit[] = "limit"; static const char __pyx_k_numpy[] = "numpy"; static const char __pyx_k_range[] = "range"; static const char __pyx_k_throw[] = "throw"; static const char __pyx_k_value[] = "value"; static const char __pyx_k_xport[] = "xport"; static const char __pyx_k_chunks[] = "chunks"; static const char __pyx_k_concat[] = "concat"; static const char __pyx_k_enable[] = "enable"; static const char __pyx_k_format[] = "format"; static const char __pyx_k_kwargs[] = "kwargs"; static const char __pyx_k_module[] = "__module__"; static const char __pyx_k_offset[] = "offset"; static const char __pyx_k_stable[] = "stable"; static const char __pyx_k_worker[] = "worker"; static const char __pyx_k_22DJa_Q[] = "\320\0002\3202D\300J\310a\330\030,\320,=\270Q"; static const char __pyx_k_catalog[] = "catalog"; static const char __pyx_k_columns[] = "columns"; static const char __pyx_k_disable[] = "disable"; static const char __pyx_k_integer[] = "integer"; static const char __pyx_k_numrows[] = "numrows"; static const char __pyx_k_offsets[] = "offsets"; static const char __pyx_k_usecols[] = "usecols"; static const char __pyx_k_usernan[] = "usernan"; static const char __pyx_k_version[] = "version"; static const char __pyx_k_add_note[] = "add_note"; static const char __pyx_k_col_name[] = "col_name"; static const char __pyx_k_compress[] = "compress"; static const char __pyx_k_dst_path[] = "dst_path"; static const char __pyx_k_encoding[] = "encoding"; static const char __pyx_k_ispandas[] = "ispandas"; static const char __pyx_k_metadata[] = "metadata"; static const char __pyx_k_metaonly[] = "metaonly"; static const char __pyx_k_narwhals[] = "narwhals"; static const char __pyx_k_num_rows[] = "num_rows"; static const char __pyx_k_prev_div[] = "prev_div"; static const char __pyx_k_qualname[] = "__qualname__"; static const char __pyx_k_read_dta[] = "read_dta"; static const char __pyx_k_read_por[] = "read_por"; static const char __pyx_k_read_sav[] = "read_sav"; static const char __pyx_k_sas7bcat[] = "sas7bcat"; static const char __pyx_k_sas7bdat[] = "sas7bdat"; static const char __pyx_k_sav_zsav[] = "sav/zsav"; static const char __pyx_k_set_name[] = "__set_name__"; static const char __pyx_k_vertical[] = "vertical"; static const char __pyx_k_chunksize[] = "chunksize"; static const char __pyx_k_cpu_count[] = "cpu_count"; static const char __pyx_k_enumerate[] = "enumerate"; static const char __pyx_k_file_path[] = "file_path"; static const char __pyx_k_is_pandas[] = "is_pandas"; static const char __pyx_k_isenabled[] = "isenabled"; static const char __pyx_k_processes[] = "processes"; static const char __pyx_k_row_limit[] = "row_limit"; static const char __pyx_k_to_native[] = "to_native"; static const char __pyx_k_var_width[] = "var_width"; static const char __pyx_k_write_dta[] = "write_dta"; static const char __pyx_k_write_por[] = "write_por"; static const char __pyx_k_write_sav[] = "write_sav"; static const char __pyx_k_col_format[] = "col_format"; static const char __pyx_k_data_frame[] = "data_frame"; static const char __pyx_k_file_label[] = "file_label"; static const char __pyx_k_read_xport[] = "read_xport"; static const char __pyx_k_row_offset[] = "row_offset"; static const char __pyx_k_table_name[] = "table_name"; static const char __pyx_k_N_var_width[] = "N{var_width}"; static const char __pyx_k_concatenate[] = "concatenate"; static const char __pyx_k_file_format[] = "file_format"; static const char __pyx_k_from_native[] = "from_native"; static const char __pyx_k_number_rows[] = "number_rows"; static const char __pyx_k_prev_offset[] = "prev_offset"; static const char __pyx_k_pyfunctions[] = "pyfunctions"; static const char __pyx_k_reset_index[] = "reset_index"; static const char __pyx_k_write_xport[] = "write_xport"; static const char __pyx_k_catalog_file[] = "catalog_file"; static const char __pyx_k_initializing[] = "_initializing"; static const char __pyx_k_is_coroutine[] = "_is_coroutine"; static const char __pyx_k_metadataonly[] = "metadataonly"; static const char __pyx_k_multiprocess[] = "multiprocess"; static const char __pyx_k_row_compress[] = "row_compress"; static const char __pyx_k_user_missing[] = "user_missing"; static const char __pyx_k_F_var_width_0[] = "F{var_width}.0"; static const char __pyx_k_class_getitem[] = "__class_getitem__"; static const char __pyx_k_column_labels[] = "column_labels"; static const char __pyx_k_filename_path[] = "filename_path"; static const char __pyx_k_num_processes[] = "num_processes"; static const char __pyx_k_output_format[] = "output_format"; static const char __pyx_k_read_function[] = "read_function"; static const char __pyx_k_read_sas7bcat[] = "read_sas7bcat"; static const char __pyx_k_read_sas7bdat[] = "read_sas7bdat"; static const char __pyx_k_file_extension[] = "file_extension"; static const char __pyx_k_implementation[] = "implementation"; static const char __pyx_k_missing_ranges[] = "missing_ranges"; static const char __pyx_k_PyreadstatError[] = "PyreadstatError"; static const char __pyx_k_dates_as_pandas[] = "dates_as_pandas"; static const char __pyx_k_formats_presets[] = "formats_presets"; static const char __pyx_k_multiprocessing[] = "multiprocessing"; static const char __pyx_k_readstat_parser[] = "_readstat_parser"; static const char __pyx_k_row_compression[] = "row_compression"; static const char __pyx_k_variable_format[] = "variable_format"; static const char __pyx_k_set_value_labels[] = "set_value_labels"; static const char __pyx_k_variable_measure[] = "variable_measure"; static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_extra_date_formats[] = "extra_date_formats"; static const char __pyx_k_extra_time_formats[] = "extra_time_formats"; static const char __pyx_k_narwhals_stable_v2[] = "narwhals.stable.v2"; static const char __pyx_k_restricted_integer[] = "restricted_integer"; static const char __pyx_k_set_catalog_to_sas[] = "set_catalog_to_sas"; static const char __pyx_k_variable_alignment[] = "variable_alignment"; static const char __pyx_k_apply_value_formats[] = "apply_value_formats"; static const char __pyx_k_file_format_version[] = "file_format_version"; static const char __pyx_k_formats_as_category[] = "formats_as_category"; static const char __pyx_k_missing_user_values[] = "missing_user_values"; static const char __pyx_k_read_file_in_chunks[] = "read_file_in_chunks"; static const char __pyx_k_Version_not_supported[] = "Version not supported"; static const char __pyx_k_pyreadstat_pyreadstat[] = "pyreadstat.pyreadstat"; static const char __pyx_k_variable_value_labels[] = "variable_value_labels"; static const char __pyx_k_extra_datetime_formats[] = "extra_datetime_formats"; static const char __pyx_k_no_datetime_conversion[] = "no_datetime_conversion"; static const char __pyx_k_variable_display_width[] = "variable_display_width"; static const char __pyx_k_dates_as_pandas_datetime[] = "dates_as_pandas_datetime"; static const char __pyx_k_pyreadstat_pyreadstat_pyx[] = "pyreadstat/pyreadstat.pyx"; static const char __pyx_k_read_file_multiprocessing[] = "read_file_multiprocessing"; static const char __pyx_k_disable_datetime_conversion[] = "disable_datetime_conversion"; static const char __pyx_k_formats_as_ordered_category[] = "formats_as_ordered_category"; static const char __pyx_k_read_sas7bcat_not_supported[] = "read_sas7bcat not supported"; static const char __pyx_k_00PPQ_JJ_ppq_00AASSkkl_1_q_1_q[] = "\320\000\034\320\0340\3200P\320PQ\330\r'\320'J\320J]\320]p\320pq\330\r0\3200A\320AS\320Sk\320kl\330\r+\2501\360|\001\000\005\032\230\021\330\004\007\200q\330\010\023\2201\340\004 \240\001\330\004\007\200q\330\010\032\230!\340\004\030\230\001\330\004\007\200q\330\010\022\220!\340\004'\240q\330\004\007\200q\330\010!\240\021\340\0046\260a\330\004<\270A\330\004\020\220\013\230>\250\021\250/\270\035\320FV\320V`\320`a\330*;\2709\300I\320Me\320ek\320kv\320v|\320|}\330*9\3209Q\320Qe\320ef\330\004\014\210O\2301\340\004\007\200q\330\010\025\320\025%\240Q\240l\260*\320\250\021\250/\270\035\320FV\320V`\320`a\330*;\2709\300I\320Me\320ek\320kv\320v|\320|}\330*9\3209Q\320Qe\320ef\330\004\014\210O\2301\340\004\013\210<\220q"; static const char __pyx_k_55UUV_OObbuuv_55FFXXY_44RRSH_q[] = "\320\000!\320!5\3205U\320UV\330\022,\320,O\320Ob\320bu\320uv\330\0225\3205F\320FX\320XY\330\0224\3204R\320RS\360H\002\000\005\032\230\021\330\004\007\200q\330\010\023\2201\340\004 \240\001\330\004\007\200q\330\010\032\230!\340\004\030\230\001\330\004\007\200q\330\010\022\220!\340\004'\240q\330\004\007\200q\330\010!\240\021\340\0046\260a\330\004<\270A\330\004\020\220\013\230>\250\021\250/\270\035\320FV\320V`\320`a\330*;\2709\300I\320Me\320ek\320kv\320v|\320|}\330*9\3209Q\320Qe\320ef\330\004\014\210O\2301\340\004\007\200q\330\010\014\210J\220m\2401\240N\260)\2701\330\010\024\220K\320\0371\260\021\260,\270j\310\t\320Qe\320ef\330 <\270A\340\004\013\210<\220q"; static const char __pyx_k_88LA_T_iq_S_Yc_iq_t1_1Bj_A_d_1[] = "\320\0008\3208L\310A\360<\000\005\010\200~\220T\230\021\330\010\016\210i\220q\230\001\340\004\007\200~\220S\230\t\240\024\240Y\250c\260\021\330\010\016\210i\220q\230\001\340\004\007\200t\2101\340\010\033\2301\230B\230j\250\004\250A\330\004\010\210\006\210d\220!\320\023#\2401\330\004\021\220\026\220t\2301\230N\250!\330\004\020\220\006\220d\230!\230=\250\005\250Q\250a\330\004\007\200w\210m\2301\230K\240}\260H\270A\330\004\016\210d\220!\340\004\007\200x\210s\220!\330\010\013\2109\220C\220q\330\014\022\220)\2301\230A\330\010\022\220!\330\t\021\220\023\220A\330\010\017\210w\220m\2401\240M\260\021\340\004\021\220\025\220h\230b\240\014\250D\260\001\330\004\013\2101\210H\220C\220~\240S\250\005\250R\250r\260\030\270\022\320;N\310d\320RV\320V[\320[a\320ab\320bc\330\004\022\220!\330\004\022\220!\330\004\017\210q\330\004\010\210\006\210g\220Y\230a\230q\330\010\021\220\034\230R\230q\330\010\026\220a\330\010\023\2201\330\010\017\210w\220b\230\010\240\001\330\004\013\2102\210_\230K\240x\250{\270(\300$\300h\310m\320[\\\330\004\013\2102\210U\220!\220:\230Q\330\004\005\330\010\021\220\024\220T\230\021\230(\240!\340\010\t\340\010\014\210F\220!\330\004\024\220F\230$\230a\230q\330\004\007\200~\220S\230\001\330\010\017\210v\220Q\220b\230\005\230Q\330\010\024\220A\330\010\014\210G\2201\330\014\021\220\021\220'\230\022\230<\240q\250\001\250\025\250a\250u\260D\270\t\300\021\360\006\000\t\022\220\021\220\"\220L\240\001\240\023\240D\250\005\250Q\330\010\020\220\002\220'\230\021\230(\240$\240a\330\010\023\2201\330\010\013\2105\220\017\230z\250\021\330\014\027\220q\330\010\020\220\005\220Z\230q\330\010\013\2101\330\014\024\220E\230\034\240Q\240e\2501\330\004\013\2107\220!"; static const char __pyx_k_JJZZnno_11K1_A_1_y_A_oQa_q_a_q[] = "\320\000\034\320\034/\320/J\320JZ\320Zn\320no\330\0201\3201K\3101\330\020,\250A\360^\001\000\005$\2401\340\004 \240\001\330\004\007\200y\220\004\220A\330\010\016\210o\230Q\230a\330\004\007\200q\330\010\036\230a\330\004\007\200q\330\010\032\230!\330\004\026\220a\330\004$\240A\330\004#\2401\360\010\000\005\030\320\027,\320,<\270J\300a\330\004\007\200q\330\010\014\210J\220n\240O\2606\270\021\330\014\017\210{\230#\230_\250E\260\023\260D\270\t\300\023\300B\300a\330\020\034\230C\230q\240\003\2401\240C\240q\250\003\2501\250B\250a\250q\330\020\037\230q\240\014\250O\2701\270K\300w\310a\310z\320YZ\340\004\r\210Q\210d\320\022,\320,>\270l\310!\330\010\035\230V\240<\320/F\320FV\320VW\330\010\034\320\0344\3204F\320FW\320WX"; static const char __pyx_k_J_LAB_xs_a_A_a_A_a_A_a_T_a_S_a[] = "\320\000\034\320\034/\320/J\310!\330\014-\320-L\310A\360B\001\000\005\010\200x\210s\220!\330\010\036\230a\330\t\021\220\023\220A\330\010\036\230a\330\t\021\220\023\220A\330\010\036\230a\330\t\021\220\023\220A\330\010\036\230a\330\t\021\220\024\220T\230\021\330\010\036\230a\330\t\021\220\024\220S\230\001\330\010\036\230a\340\010\016\210i\220q\230\001\340\004\024\220A\330\004\032\230!\330\004\037\230q\330\004#\2401\330\004'\240q\330\004!\240\021\340\004 \240\001\340\004\r\210Q\210d\320\022,\320,>\270l\310/\320YZ\330\005\013\210<\320\027.\320.>\320>S\320ST\330\005\035\320\035/\320/@\300\001"; static const char __pyx_k_read_sas7bcat_is_not_supported[] = "read_sas7bcat is not supported"; static const char __pyx_k_00PPQ_JJ_ppq_00AASST_MQ_q_1_q_q[] = "\320\000\034\320\0340\3200P\320PQ\330\r'\320'J\320J]\320]p\320pq\330\r0\3200A\320AS\320ST\330\r/\320/M\310Q\360|\001\000\005\032\230\021\330\004\007\200q\330\010\023\2201\340\004 \240\001\330\004\007\200q\330\010\032\230!\340\004\030\230\001\330\004\007\200q\330\010\022\220!\340\004'\240q\330\004\007\200q\330\010!\240\021\340\0046\260a\330\004<\270A\330\004\020\220\013\230>\250\021\250/\270\035\320FV\320V`\320`a\330*;\2709\300I\320Me\320ek\320kv\320v|\320|}\330*9\3209Q\320Qe\320ef\330\004\014\210O\2301\340\004\007\200q\330\010\025\320\025%\240Q\240l\260*\320 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; PyObject *__pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks; PyTypeObject *__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_keys; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop; PyObject *__pyx_tuple[5]; PyObject *__pyx_codeobj_tab[12]; PyObject *__pyx_string_tab[172]; PyObject *__pyx_int_0; PyObject *__pyx_int_1; PyObject *__pyx_int_4; PyObject *__pyx_int_100000; /* #### Code section: module_state_contents ### */ #if CYTHON_USE_FREELISTS struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *__pyx_freelist_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks[8]; int __pyx_freecount_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks; #endif /* CommonTypesMetaclass.module_state_decls */ PyTypeObject *__pyx_CommonTypesMetaclassType; /* CachedMethodType.module_state_decls */ #if CYTHON_COMPILING_IN_LIMITED_API PyObject *__Pyx_CachedMethodType; #endif /* CodeObjectCache.module_state_decls */ struct __Pyx_CodeObjectCache __pyx_code_cache; /* IterNextPlain.module_state_decls */ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000 PyObject *__Pyx_GetBuiltinNext_LimitedAPI_cache; #endif /* #### 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_kp_u_F_var_width_0 __pyx_string_tab[1] #define __pyx_kp_u_N_var_width __pyx_string_tab[2] #define __pyx_kp_u_Note_that_Cython_is_deliberately __pyx_string_tab[3] #define __pyx_n_u_Pool __pyx_string_tab[4] #define __pyx_n_u_PyreadstatError __pyx_string_tab[5] #define __pyx_kp_u_The_number_of_rows_of_the_file_c __pyx_string_tab[6] #define __pyx_kp_u_Version_not_supported __pyx_string_tab[7] #define __pyx_kp_u__2 __pyx_string_tab[8] #define __pyx_kp_u__3 __pyx_string_tab[9] #define __pyx_n_u__4 __pyx_string_tab[10] #define __pyx_kp_u_add_note __pyx_string_tab[11] #define __pyx_n_u_apply_value_formats __pyx_string_tab[12] #define __pyx_n_u_asyncio_coroutines __pyx_string_tab[13] #define __pyx_n_u_catalog __pyx_string_tab[14] #define __pyx_n_u_catalog_file __pyx_string_tab[15] #define __pyx_n_u_chunk __pyx_string_tab[16] #define __pyx_n_u_chunks __pyx_string_tab[17] #define __pyx_n_u_chunksize __pyx_string_tab[18] #define __pyx_n_u_class_getitem __pyx_string_tab[19] #define __pyx_n_u_cline_in_traceback __pyx_string_tab[20] #define __pyx_n_u_close __pyx_string_tab[21] #define __pyx_n_u_col_format __pyx_string_tab[22] #define __pyx_n_u_col_name __pyx_string_tab[23] #define __pyx_n_u_column_labels __pyx_string_tab[24] #define __pyx_n_u_columns __pyx_string_tab[25] #define __pyx_n_u_compress __pyx_string_tab[26] #define __pyx_kp_u_compress_and_row_compress_cannot __pyx_string_tab[27] #define __pyx_n_u_concat __pyx_string_tab[28] #define __pyx_n_u_concatenate __pyx_string_tab[29] #define __pyx_n_u_cpu_count __pyx_string_tab[30] #define __pyx_n_u_data_frame __pyx_string_tab[31] #define __pyx_n_u_dates_as_pandas __pyx_string_tab[32] #define __pyx_n_u_dates_as_pandas_datetime __pyx_string_tab[33] #define __pyx_n_u_df __pyx_string_tab[34] #define __pyx_n_u_dict __pyx_string_tab[35] #define __pyx_kp_u_disable __pyx_string_tab[36] #define __pyx_n_u_disable_datetime_conversion __pyx_string_tab[37] #define __pyx_n_u_div __pyx_string_tab[38] #define __pyx_n_u_divs __pyx_string_tab[39] #define __pyx_n_u_drop __pyx_string_tab[40] #define __pyx_n_u_dst_path __pyx_string_tab[41] #define __pyx_n_u_dta __pyx_string_tab[42] #define __pyx_kp_u_enable __pyx_string_tab[43] #define __pyx_n_u_encoding __pyx_string_tab[44] #define __pyx_n_u_enumerate __pyx_string_tab[45] #define __pyx_n_u_extra_date_formats __pyx_string_tab[46] #define __pyx_n_u_extra_datetime_formats __pyx_string_tab[47] #define __pyx_n_u_extra_time_formats __pyx_string_tab[48] #define __pyx_n_u_file_extension __pyx_string_tab[49] #define __pyx_n_u_file_format __pyx_string_tab[50] #define __pyx_n_u_file_format_version __pyx_string_tab[51] #define __pyx_n_u_file_label __pyx_string_tab[52] #define __pyx_n_u_file_path __pyx_string_tab[53] #define __pyx_n_u_filename_path __pyx_string_tab[54] #define __pyx_n_u_final __pyx_string_tab[55] #define __pyx_n_u_format __pyx_string_tab[56] #define __pyx_n_u_formats_as_category __pyx_string_tab[57] #define __pyx_n_u_formats_as_ordered_category __pyx_string_tab[58] #define __pyx_n_u_formats_presets __pyx_string_tab[59] #define __pyx_n_u_from_native __pyx_string_tab[60] #define __pyx_n_u_func __pyx_string_tab[61] #define __pyx_kp_u_gc __pyx_string_tab[62] #define __pyx_n_u_get __pyx_string_tab[63] #define __pyx_n_u_how __pyx_string_tab[64] #define __pyx_n_u_implementation __pyx_string_tab[65] #define __pyx_n_u_indx __pyx_string_tab[66] #define __pyx_n_u_inf __pyx_string_tab[67] #define __pyx_n_u_initializing __pyx_string_tab[68] #define __pyx_n_u_integer __pyx_string_tab[69] #define __pyx_n_u_is_coroutine __pyx_string_tab[70] #define __pyx_n_u_is_pandas __pyx_string_tab[71] #define __pyx_kp_u_isenabled __pyx_string_tab[72] #define __pyx_n_u_ispandas __pyx_string_tab[73] #define __pyx_n_u_items __pyx_string_tab[74] #define __pyx_n_u_jobs __pyx_string_tab[75] #define __pyx_n_u_key __pyx_string_tab[76] #define __pyx_n_u_keys __pyx_string_tab[77] #define __pyx_n_u_kwargs __pyx_string_tab[78] #define __pyx_n_u_limit __pyx_string_tab[79] #define __pyx_n_u_main __pyx_string_tab[80] #define __pyx_n_u_map __pyx_string_tab[81] #define __pyx_n_u_max __pyx_string_tab[82] #define __pyx_n_u_meta __pyx_string_tab[83] #define __pyx_n_u_metadata __pyx_string_tab[84] #define __pyx_n_u_metadataonly __pyx_string_tab[85] #define __pyx_n_u_metaonly __pyx_string_tab[86] #define __pyx_n_u_missing_ranges __pyx_string_tab[87] #define __pyx_n_u_missing_user_values __pyx_string_tab[88] #define __pyx_n_u_module __pyx_string_tab[89] #define __pyx_n_u_mp __pyx_string_tab[90] #define __pyx_n_u_multiprocess __pyx_string_tab[91] #define __pyx_n_u_multiprocessing __pyx_string_tab[92] #define __pyx_n_u_name __pyx_string_tab[93] #define __pyx_n_u_narwhals __pyx_string_tab[94] #define __pyx_n_u_narwhals_stable_v2 __pyx_string_tab[95] #define __pyx_n_u_next __pyx_string_tab[96] #define __pyx_n_u_no_datetime_conversion __pyx_string_tab[97] #define __pyx_n_u_note __pyx_string_tab[98] #define __pyx_n_u_np __pyx_string_tab[99] #define __pyx_n_u_num_processes __pyx_string_tab[100] #define __pyx_n_u_num_rows __pyx_string_tab[101] #define __pyx_kp_u_num_rows_must_be_specified_for_r __pyx_string_tab[102] #define __pyx_n_u_number_rows __pyx_string_tab[103] #define __pyx_n_u_numpy __pyx_string_tab[104] #define __pyx_n_u_numrows __pyx_string_tab[105] #define __pyx_n_u_nw __pyx_string_tab[106] #define __pyx_n_u_offset __pyx_string_tab[107] #define __pyx_n_u_offsets __pyx_string_tab[108] #define __pyx_n_u_output_format __pyx_string_tab[109] #define __pyx_n_u_pool __pyx_string_tab[110] #define __pyx_n_u_pop __pyx_string_tab[111] #define __pyx_n_u_por __pyx_string_tab[112] #define __pyx_n_u_prev_div __pyx_string_tab[113] #define __pyx_n_u_prev_offset __pyx_string_tab[114] #define __pyx_n_u_processes __pyx_string_tab[115] #define __pyx_n_u_pyfunctions __pyx_string_tab[116] #define __pyx_n_u_pyreadstat_pyreadstat __pyx_string_tab[117] #define __pyx_kp_u_pyreadstat_pyreadstat_pyx __pyx_string_tab[118] #define __pyx_n_u_qualname __pyx_string_tab[119] #define __pyx_n_u_range __pyx_string_tab[120] #define __pyx_n_u_read_dta __pyx_string_tab[121] #define __pyx_n_u_read_file_in_chunks __pyx_string_tab[122] #define __pyx_n_u_read_file_multiprocessing __pyx_string_tab[123] #define __pyx_n_u_read_function __pyx_string_tab[124] #define __pyx_n_u_read_por __pyx_string_tab[125] #define __pyx_n_u_read_sas7bcat __pyx_string_tab[126] #define __pyx_kp_u_read_sas7bcat_is_not_supported __pyx_string_tab[127] #define __pyx_kp_u_read_sas7bcat_not_supported __pyx_string_tab[128] #define __pyx_n_u_read_sas7bdat __pyx_string_tab[129] #define __pyx_n_u_read_sav __pyx_string_tab[130] #define __pyx_n_u_read_xport __pyx_string_tab[131] #define __pyx_n_u_readstat_parser __pyx_string_tab[132] #define __pyx_n_u_reset_index __pyx_string_tab[133] #define __pyx_n_u_restricted_integer __pyx_string_tab[134] #define __pyx_n_u_row_compress __pyx_string_tab[135] #define __pyx_n_u_row_compression __pyx_string_tab[136] #define __pyx_n_u_row_limit __pyx_string_tab[137] #define __pyx_n_u_row_offset __pyx_string_tab[138] #define __pyx_n_u_sas7bcat __pyx_string_tab[139] #define __pyx_n_u_sas7bdat __pyx_string_tab[140] #define __pyx_kp_u_sav_zsav __pyx_string_tab[141] #define __pyx_n_u_send __pyx_string_tab[142] #define __pyx_n_u_set_catalog_to_sas __pyx_string_tab[143] #define __pyx_n_u_set_name __pyx_string_tab[144] #define __pyx_n_u_set_value_labels __pyx_string_tab[145] #define __pyx_n_u_spec __pyx_string_tab[146] #define __pyx_n_u_stable __pyx_string_tab[147] #define __pyx_n_u_table_name __pyx_string_tab[148] #define __pyx_n_u_test __pyx_string_tab[149] #define __pyx_n_u_throw __pyx_string_tab[150] #define __pyx_n_u_to_native __pyx_string_tab[151] #define __pyx_n_u_usecols __pyx_string_tab[152] #define __pyx_n_u_user_missing __pyx_string_tab[153] #define __pyx_n_u_usernan __pyx_string_tab[154] #define __pyx_n_u_v2 __pyx_string_tab[155] #define __pyx_n_u_value __pyx_string_tab[156] #define __pyx_n_u_var_width __pyx_string_tab[157] #define __pyx_n_u_variable_alignment __pyx_string_tab[158] #define __pyx_n_u_variable_display_width __pyx_string_tab[159] #define __pyx_n_u_variable_format __pyx_string_tab[160] #define __pyx_n_u_variable_measure __pyx_string_tab[161] #define __pyx_n_u_variable_value_labels __pyx_string_tab[162] #define __pyx_n_u_version __pyx_string_tab[163] #define __pyx_n_u_vertical __pyx_string_tab[164] #define __pyx_n_u_worker __pyx_string_tab[165] #define __pyx_n_u_write_dta __pyx_string_tab[166] #define __pyx_n_u_write_por __pyx_string_tab[167] #define __pyx_n_u_write_sav __pyx_string_tab[168] #define __pyx_n_u_write_xport __pyx_string_tab[169] #define __pyx_n_u_x __pyx_string_tab[170] #define __pyx_n_u_xport __pyx_string_tab[171] /* #### 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); Py_CLEAR(clear_module_state->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks); Py_CLEAR(clear_module_state->__pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks); for (int i=0; i<5; ++i) { Py_CLEAR(clear_module_state->__pyx_tuple[i]); } for (int i=0; i<12; ++i) { Py_CLEAR(clear_module_state->__pyx_codeobj_tab[i]); } for (int i=0; i<172; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); } Py_CLEAR(clear_module_state->__pyx_int_0); Py_CLEAR(clear_module_state->__pyx_int_1); Py_CLEAR(clear_module_state->__pyx_int_4); Py_CLEAR(clear_module_state->__pyx_int_100000); 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); Py_VISIT(traverse_module_state->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks); Py_VISIT(traverse_module_state->__pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks); for (int i=0; i<5; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_tuple[i]); } for (int i=0; i<12; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_codeobj_tab[i]); } for (int i=0; i<172; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); } __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_4); __Pyx_VISIT_CONST(traverse_module_state->__pyx_int_100000); return 0; } #endif /* #### Code section: module_code ### */ /* "pyreadstat/pyreadstat.pyx":37 * # Parsing functions * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_1read_sas7bdat(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_read_sas7bdat, "\n Read a SAS sas7bdat file.\n It accepts the path to a sas7bcat.\n \n Parameters\n ----------\n filename_path : str, bytes, Path-like object or file-like object\n path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded.\n metadataonly : bool, optional\n by default False. IF true, no data will be read but only metadata, so that you can get all elements in the\n metadata object. The data frame will be set with the correct column names but no data.\n dates_as_pandas_datetime : bool, optional\n by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas.\n catalog_file : str, optional\n path to a sas7bcat file. By default is None. If not None, will parse the catalog file and replace the values\n by the formats in the catalog, if any appropiate is found. If this is not the behavior you are looking for,\n Use read_sas7bcat to parse the catalog independently\n of the sas7bdat and set_catalog_to_sas to apply the resulting format into sas7bdat files.\n formats_as_category : bool, optional\n Will take effect only if the catalog_file was specified. If True the variables whose values were replaced\n by the formats will be transformed into categories.\n formats_as_ordered_category : bool, optional\n defaults to False. If True the variables having formats will be transformed into ordered categories/enums.\n it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of\n the value of formats_as_category.\n encoding : str, optional\n Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an\n iconv-compatible name\n usecols : list, optional\n a list with c""olumn names to read from the file. Only those columns will be imported. Case sensitive!\n user_missing : bool, optional\n by default False, in this case user defined missing values are delivered as nan. If true, the missing values\n will be deliver as is, and an extra piece of information will be set in the metadata (missing_user_values)\n to be able to interpret those values as missing.\n disable_datetime_conversion : bool, optional\n if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns\n will remain as numbers. In order to convert them later to an appropiate python object, the user can use the\n information about the original variable format stored in the metadata object in original_variable_types.\n Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where\n there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates\n beyond that will rise an Overflow error in pyreadstat).\n row_limit : int, optional\n maximum number of rows to read. The default is 0 meaning unlimited.\n row_offset : int, optional\n start reading rows after this offset. By default 0, meaning start with the first row not skipping anything.\n output_format : str, optional\n one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the\n user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a \n dataframe is avoided.\n extra_datetime_formats: list of str, optional\n formats to be parsed as python datetime objects\n extra_date_formats: list of str, optional\n formats to be parsed as python date objects\n ex""tra_time_formats: list of str, optional\n formats to be parsed as python time objects\n \n\n Returns\n -------\n data_frame : dataframe or dict\n a dataframe or dict with the data.\n metadata\n object with metadata. The members variables_value_labels will be empty unless a valid catalog file is\n supplied.\n Look at the documentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_1read_sas7bdat = {"read_sas7bdat", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_1read_sas7bdat, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_read_sas7bdat}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_1read_sas7bdat(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_filename_path = 0; PyObject *__pyx_v_metadataonly = 0; PyObject *__pyx_v_dates_as_pandas_datetime = 0; PyObject *__pyx_v_catalog_file = 0; PyObject *__pyx_v_formats_as_category = 0; PyObject *__pyx_v_formats_as_ordered_category = 0; PyObject *__pyx_v_encoding = 0; PyObject *__pyx_v_usecols = 0; PyObject *__pyx_v_user_missing = 0; PyObject *__pyx_v_disable_datetime_conversion = 0; int __pyx_v_row_limit; int __pyx_v_row_offset; PyObject *__pyx_v_output_format = 0; PyObject *__pyx_v_extra_datetime_formats = 0; PyObject *__pyx_v_extra_date_formats = 0; PyObject *__pyx_v_extra_time_formats = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_sas7bdat (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_filename_path,&__pyx_mstate_global->__pyx_n_u_metadataonly,&__pyx_mstate_global->__pyx_n_u_dates_as_pandas_datetime,&__pyx_mstate_global->__pyx_n_u_catalog_file,&__pyx_mstate_global->__pyx_n_u_formats_as_category,&__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category,&__pyx_mstate_global->__pyx_n_u_encoding,&__pyx_mstate_global->__pyx_n_u_usecols,&__pyx_mstate_global->__pyx_n_u_user_missing,&__pyx_mstate_global->__pyx_n_u_disable_datetime_conversion,&__pyx_mstate_global->__pyx_n_u_row_limit,&__pyx_mstate_global->__pyx_n_u_row_offset,&__pyx_mstate_global->__pyx_n_u_output_format,&__pyx_mstate_global->__pyx_n_u_extra_datetime_formats,&__pyx_mstate_global->__pyx_n_u_extra_date_formats,&__pyx_mstate_global->__pyx_n_u_extra_time_formats,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 37, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 16: values[15] = __Pyx_ArgRef_FASTCALL(__pyx_args, 15); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[15])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 15: values[14] = __Pyx_ArgRef_FASTCALL(__pyx_args, 14); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[14])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "read_sas7bdat", 0) < 0) __PYX_ERR(0, 37, __pyx_L3_error) if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); /* "pyreadstat/pyreadstat.pyx":38 * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":39 * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[9]) values[9] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":40 * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SAS sas7bdat file. */ if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[14]) values[14] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[15]) values[15] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_sas7bdat", 0, 1, 16, i); __PYX_ERR(0, 37, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 16: values[15] = __Pyx_ArgRef_FASTCALL(__pyx_args, 15); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[15])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 15: values[14] = __Pyx_ArgRef_FASTCALL(__pyx_args, 14); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[14])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 37, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 37, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":37 * # Parsing functions * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":38 * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":39 * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":40 * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SAS sas7bdat file. */ if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[14]) values[14] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[15]) values[15] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_filename_path = values[0]; __pyx_v_metadataonly = values[1]; __pyx_v_dates_as_pandas_datetime = values[2]; __pyx_v_catalog_file = values[3]; __pyx_v_formats_as_category = values[4]; __pyx_v_formats_as_ordered_category = values[5]; __pyx_v_encoding = ((PyObject*)values[6]); __pyx_v_usecols = ((PyObject*)values[7]); __pyx_v_user_missing = values[8]; __pyx_v_disable_datetime_conversion = values[9]; if (values[10]) { __pyx_v_row_limit = __Pyx_PyLong_As_int(values[10]); if (unlikely((__pyx_v_row_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L3_error) } else { __pyx_v_row_limit = ((int)((int)0)); } if (values[11]) { __pyx_v_row_offset = __Pyx_PyLong_As_int(values[11]); if (unlikely((__pyx_v_row_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L3_error) } else { __pyx_v_row_offset = ((int)((int)0)); } __pyx_v_output_format = ((PyObject*)values[12]); __pyx_v_extra_datetime_formats = ((PyObject*)values[13]); __pyx_v_extra_date_formats = ((PyObject*)values[14]); __pyx_v_extra_time_formats = ((PyObject*)values[15]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_sas7bdat", 0, 1, 16, __pyx_nargs); __PYX_ERR(0, 37, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.read_sas7bdat", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_encoding), (&PyUnicode_Type), 1, "encoding", 1))) __PYX_ERR(0, 38, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_usecols), (&PyList_Type), 1, "usecols", 1))) __PYX_ERR(0, 38, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output_format), (&PyUnicode_Type), 1, "output_format", 1))) __PYX_ERR(0, 39, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_datetime_formats), (&PyList_Type), 1, "extra_datetime_formats", 1))) __PYX_ERR(0, 40, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_date_formats), (&PyList_Type), 1, "extra_date_formats", 1))) __PYX_ERR(0, 40, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_time_formats), (&PyList_Type), 1, "extra_time_formats", 1))) __PYX_ERR(0, 40, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_read_sas7bdat(__pyx_self, __pyx_v_filename_path, __pyx_v_metadataonly, __pyx_v_dates_as_pandas_datetime, __pyx_v_catalog_file, __pyx_v_formats_as_category, __pyx_v_formats_as_ordered_category, __pyx_v_encoding, __pyx_v_usecols, __pyx_v_user_missing, __pyx_v_disable_datetime_conversion, __pyx_v_row_limit, __pyx_v_row_offset, __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); /* "pyreadstat/pyreadstat.pyx":37 * # Parsing functions * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_read_sas7bdat(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_path, PyObject *__pyx_v_metadataonly, PyObject *__pyx_v_dates_as_pandas_datetime, PyObject *__pyx_v_catalog_file, PyObject *__pyx_v_formats_as_category, PyObject *__pyx_v_formats_as_ordered_category, PyObject *__pyx_v_encoding, PyObject *__pyx_v_usecols, PyObject *__pyx_v_user_missing, PyObject *__pyx_v_disable_datetime_conversion, int __pyx_v_row_limit, int __pyx_v_row_offset, PyObject *__pyx_v_output_format, PyObject *__pyx_v_extra_datetime_formats, PyObject *__pyx_v_extra_date_formats, PyObject *__pyx_v_extra_time_formats) { int __pyx_v_metaonly; int __pyx_v_dates_as_pandas; int __pyx_v_usernan; int __pyx_v_no_datetime_conversion; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_metadata = NULL; CYTHON_UNUSED PyObject *__pyx_v__ = NULL; PyObject *__pyx_v_catalog = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *(*__pyx_t_6)(PyObject *); size_t __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_sas7bdat", 0); /* "pyreadstat/pyreadstat.pyx":108 * """ * * cdef bint metaonly = 0 # <<<<<<<<<<<<<< * if metadataonly: * metaonly = 1 */ __pyx_v_metaonly = 0; /* "pyreadstat/pyreadstat.pyx":109 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_metadataonly); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 109, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":110 * cdef bint metaonly = 0 * if metadataonly: * metaonly = 1 # <<<<<<<<<<<<<< * * cdef bint dates_as_pandas = 0 */ __pyx_v_metaonly = 1; /* "pyreadstat/pyreadstat.pyx":109 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ } /* "pyreadstat/pyreadstat.pyx":112 * metaonly = 1 * * cdef bint dates_as_pandas = 0 # <<<<<<<<<<<<<< * if dates_as_pandas_datetime: * dates_as_pandas = 1 */ __pyx_v_dates_as_pandas = 0; /* "pyreadstat/pyreadstat.pyx":113 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dates_as_pandas_datetime); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 113, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":114 * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: * dates_as_pandas = 1 # <<<<<<<<<<<<<< * * cdef bint usernan = 0 */ __pyx_v_dates_as_pandas = 1; /* "pyreadstat/pyreadstat.pyx":113 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ } /* "pyreadstat/pyreadstat.pyx":116 * dates_as_pandas = 1 * * cdef bint usernan = 0 # <<<<<<<<<<<<<< * if user_missing: * usernan = 1 */ __pyx_v_usernan = 0; /* "pyreadstat/pyreadstat.pyx":117 * * cdef bint usernan = 0 * if user_missing: # <<<<<<<<<<<<<< * usernan = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_user_missing); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 117, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":118 * cdef bint usernan = 0 * if user_missing: * usernan = 1 # <<<<<<<<<<<<<< * * cdef bint no_datetime_conversion = 0 */ __pyx_v_usernan = 1; /* "pyreadstat/pyreadstat.pyx":117 * * cdef bint usernan = 0 * if user_missing: # <<<<<<<<<<<<<< * usernan = 1 * */ } /* "pyreadstat/pyreadstat.pyx":120 * usernan = 1 * * cdef bint no_datetime_conversion = 0 # <<<<<<<<<<<<<< * if disable_datetime_conversion: * no_datetime_conversion = 1 */ __pyx_v_no_datetime_conversion = 0; /* "pyreadstat/pyreadstat.pyx":121 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_disable_datetime_conversion); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 121, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":122 * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: * no_datetime_conversion = 1 # <<<<<<<<<<<<<< * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS */ __pyx_v_no_datetime_conversion = 1; /* "pyreadstat/pyreadstat.pyx":121 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ } /* "pyreadstat/pyreadstat.pyx":124 * no_datetime_conversion = 1 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS # <<<<<<<<<<<<<< * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BDAT * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, */ __pyx_v_file_format = __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS; /* "pyreadstat/pyreadstat.pyx":125 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BDAT # <<<<<<<<<<<<<< * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, */ __pyx_v_file_extension = __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAS7BDAT; /* "pyreadstat/pyreadstat.pyx":126 * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BDAT * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, # <<<<<<<<<<<<<< * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) */ __pyx_t_2 = __pyx_f_10pyreadstat_16_readstat_parser_run_conversion(__pyx_v_filename_path, __pyx_v_file_format, __pyx_v_file_extension, __pyx_v_encoding, __pyx_v_metaonly, __pyx_v_dates_as_pandas, __pyx_v_usecols, __pyx_v_usernan, __pyx_v_no_datetime_conversion, ((long)__pyx_v_row_limit), ((long)__pyx_v_row_offset), __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) __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, 126, __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_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 126, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L8_unpacking_done; __pyx_L7_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 126, __pyx_L1_error) __pyx_L8_unpacking_done:; } __pyx_v_data_frame = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_metadata = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":129 * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "sas7bdat" # <<<<<<<<<<<<<< * * if catalog_file: */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_format, __pyx_mstate_global->__pyx_n_u_sas7bdat) < 0) __PYX_ERR(0, 129, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":131 * metadata.file_format = "sas7bdat" * * if catalog_file: # <<<<<<<<<<<<<< * _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) * data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_catalog_file); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 131, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":132 * * if catalog_file: * _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) # <<<<<<<<<<<<<< * data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_read_sas7bcat); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = 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_7 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_v_catalog_file}; __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_encoding, __pyx_v_encoding, __pyx_t_5, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 132, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 132, __pyx_L1_error) __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, 132, __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_5 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_5); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_5); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L10_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_4); if (unlikely(!__pyx_t_5)) goto __pyx_L10_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_4), 2) < 0) __PYX_ERR(0, 132, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L11_unpacking_done; __pyx_L10_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 132, __pyx_L1_error) __pyx_L11_unpacking_done:; } __pyx_v__ = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_catalog = __pyx_t_5; __pyx_t_5 = 0; /* "pyreadstat/pyreadstat.pyx":133 * if catalog_file: * _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) * data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, # <<<<<<<<<<<<<< * formats_as_ordered_category=formats_as_ordered_category) * */ __pyx_t_5 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_set_catalog_to_sas); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* "pyreadstat/pyreadstat.pyx":134 * _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) * data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) # <<<<<<<<<<<<<< * * return data_frame, metadata */ __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_5); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[4 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_5, __pyx_v_data_frame, __pyx_v_metadata, __pyx_v_catalog}; __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_category, __pyx_v_formats_as_category, __pyx_t_4, __pyx_callargs+4, 0) < 0) __PYX_ERR(0, 133, __pyx_L1_error) if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category, __pyx_v_formats_as_ordered_category, __pyx_t_4, __pyx_callargs+4, 1) < 0) __PYX_ERR(0, 133, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_7, (4-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error) __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, 133, __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_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 133, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L13_unpacking_done; __pyx_L12_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 133, __pyx_L1_error) __pyx_L13_unpacking_done:; } /* "pyreadstat/pyreadstat.pyx":133 * if catalog_file: * _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) * data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, # <<<<<<<<<<<<<< * formats_as_ordered_category=formats_as_ordered_category) * */ __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_metadata, __pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":131 * metadata.file_format = "sas7bdat" * * if catalog_file: # <<<<<<<<<<<<<< * _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) * data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, */ } /* "pyreadstat/pyreadstat.pyx":136 * formats_as_ordered_category=formats_as_ordered_category) * * return data_frame, metadata # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 136, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 136, __pyx_L1_error); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":37 * # Parsing functions * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_sas7bdat", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XDECREF(__pyx_v__); __Pyx_XDECREF(__pyx_v_catalog); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":139 * * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, # <<<<<<<<<<<<<< * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_3read_xport(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_2read_xport, "\n Read a SAS xport file.\n\n Parameters\n ----------\n filename_path : str, bytes, Path-like object or file-like object\n path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded.\n metadataonly : bool, optional\n by default False. IF true, no data will be read but only metadata, so that you can get all elements in the\n metadata object. The data frame will be set with the correct column names but no data.\n dates_as_pandas_datetime : bool, optional\n by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas.\n encoding : str, optional\n Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an\n iconv-compatible name\n usecols : list, optional\n a list with column names to read from the file. Only those columns will be imported. Case sensitive!\n disable_datetime_conversion : bool, optional\n if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns\n will remain as numbers. In order to convert them later to an appropiate python object, the user can use the\n information about the original variable format stored in the metadata object in original_variable_types.\n Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where\n there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates\n beyond that will rise an Overflow error in pyreadstat).\n row_limit : int, optional\n maximum number of rows to read. The default is 0 meaning unlimited.\n row_offset : int, optional\n start reading rows after this offset. By default 0, meaning start with the first row not sk""ipping anything.\n output_format : str, optional\n one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the\n user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a \n dataframe is avoided.\n extra_datetime_formats: list of str, optional\n formats to be parsed as python datetime objects\n extra_date_formats: list of str, optional\n formats to be parsed as python date objects\n extra_time_formats: list of str, optional\n formats to be parsed as python time objects\n\n Returns\n -------\n data_frame : dataframe or dict\n a dataframe or dict with the data.\n metadata :\n object with metadata. Look at the documentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_3read_xport = {"read_xport", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_3read_xport, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_2read_xport}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_3read_xport(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_filename_path = 0; PyObject *__pyx_v_metadataonly = 0; PyObject *__pyx_v_dates_as_pandas_datetime = 0; PyObject *__pyx_v_encoding = 0; PyObject *__pyx_v_usecols = 0; PyObject *__pyx_v_disable_datetime_conversion = 0; int __pyx_v_row_limit; int __pyx_v_row_offset; PyObject *__pyx_v_output_format = 0; PyObject *__pyx_v_extra_datetime_formats = 0; PyObject *__pyx_v_extra_date_formats = 0; PyObject *__pyx_v_extra_time_formats = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_xport (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_filename_path,&__pyx_mstate_global->__pyx_n_u_metadataonly,&__pyx_mstate_global->__pyx_n_u_dates_as_pandas_datetime,&__pyx_mstate_global->__pyx_n_u_encoding,&__pyx_mstate_global->__pyx_n_u_usecols,&__pyx_mstate_global->__pyx_n_u_disable_datetime_conversion,&__pyx_mstate_global->__pyx_n_u_row_limit,&__pyx_mstate_global->__pyx_n_u_row_offset,&__pyx_mstate_global->__pyx_n_u_output_format,&__pyx_mstate_global->__pyx_n_u_extra_datetime_formats,&__pyx_mstate_global->__pyx_n_u_extra_date_formats,&__pyx_mstate_global->__pyx_n_u_extra_time_formats,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 139, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "read_xport", 0) < 0) __PYX_ERR(0, 139, __pyx_L3_error) if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":140 * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, # <<<<<<<<<<<<<< * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":141 * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SAS xport file. */ if (!values[8]) values[8] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[10]) values[10] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[11]) values[11] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_xport", 0, 1, 12, i); __PYX_ERR(0, 139, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 139, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 139, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":139 * * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, # <<<<<<<<<<<<<< * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[3]) values[3] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":140 * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, # <<<<<<<<<<<<<< * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":141 * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SAS xport file. */ if (!values[8]) values[8] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[10]) values[10] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[11]) values[11] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_filename_path = values[0]; __pyx_v_metadataonly = values[1]; __pyx_v_dates_as_pandas_datetime = values[2]; __pyx_v_encoding = ((PyObject*)values[3]); __pyx_v_usecols = ((PyObject*)values[4]); __pyx_v_disable_datetime_conversion = values[5]; if (values[6]) { __pyx_v_row_limit = __Pyx_PyLong_As_int(values[6]); if (unlikely((__pyx_v_row_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 140, __pyx_L3_error) } else { __pyx_v_row_limit = ((int)((int)0)); } if (values[7]) { __pyx_v_row_offset = __Pyx_PyLong_As_int(values[7]); if (unlikely((__pyx_v_row_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 140, __pyx_L3_error) } else { __pyx_v_row_offset = ((int)((int)0)); } __pyx_v_output_format = ((PyObject*)values[8]); __pyx_v_extra_datetime_formats = ((PyObject*)values[9]); __pyx_v_extra_date_formats = ((PyObject*)values[10]); __pyx_v_extra_time_formats = ((PyObject*)values[11]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_xport", 0, 1, 12, __pyx_nargs); __PYX_ERR(0, 139, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.read_xport", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_encoding), (&PyUnicode_Type), 1, "encoding", 1))) __PYX_ERR(0, 139, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_usecols), (&PyList_Type), 1, "usecols", 1))) __PYX_ERR(0, 140, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output_format), (&PyUnicode_Type), 1, "output_format", 1))) __PYX_ERR(0, 141, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_datetime_formats), (&PyList_Type), 1, "extra_datetime_formats", 1))) __PYX_ERR(0, 141, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_date_formats), (&PyList_Type), 1, "extra_date_formats", 1))) __PYX_ERR(0, 141, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_time_formats), (&PyList_Type), 1, "extra_time_formats", 1))) __PYX_ERR(0, 141, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_2read_xport(__pyx_self, __pyx_v_filename_path, __pyx_v_metadataonly, __pyx_v_dates_as_pandas_datetime, __pyx_v_encoding, __pyx_v_usecols, __pyx_v_disable_datetime_conversion, __pyx_v_row_limit, __pyx_v_row_offset, __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); /* "pyreadstat/pyreadstat.pyx":139 * * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, # <<<<<<<<<<<<<< * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_2read_xport(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_path, PyObject *__pyx_v_metadataonly, PyObject *__pyx_v_dates_as_pandas_datetime, PyObject *__pyx_v_encoding, PyObject *__pyx_v_usecols, PyObject *__pyx_v_disable_datetime_conversion, int __pyx_v_row_limit, int __pyx_v_row_offset, PyObject *__pyx_v_output_format, PyObject *__pyx_v_extra_datetime_formats, PyObject *__pyx_v_extra_date_formats, PyObject *__pyx_v_extra_time_formats) { int __pyx_v_metaonly; int __pyx_v_dates_as_pandas; int __pyx_v_usernan; int __pyx_v_no_datetime_conversion; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_metadata = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *(*__pyx_t_6)(PyObject *); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_xport", 0); /* "pyreadstat/pyreadstat.pyx":189 * """ * * cdef bint metaonly = 0 # <<<<<<<<<<<<<< * if metadataonly: * metaonly = 1 */ __pyx_v_metaonly = 0; /* "pyreadstat/pyreadstat.pyx":190 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_metadataonly); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 190, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":191 * cdef bint metaonly = 0 * if metadataonly: * metaonly = 1 # <<<<<<<<<<<<<< * * cdef bint dates_as_pandas = 0 */ __pyx_v_metaonly = 1; /* "pyreadstat/pyreadstat.pyx":190 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ } /* "pyreadstat/pyreadstat.pyx":193 * metaonly = 1 * * cdef bint dates_as_pandas = 0 # <<<<<<<<<<<<<< * if dates_as_pandas_datetime: * dates_as_pandas = 1 */ __pyx_v_dates_as_pandas = 0; /* "pyreadstat/pyreadstat.pyx":194 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dates_as_pandas_datetime); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 194, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":195 * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: * dates_as_pandas = 1 # <<<<<<<<<<<<<< * * cdef bint usernan = 0 */ __pyx_v_dates_as_pandas = 1; /* "pyreadstat/pyreadstat.pyx":194 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ } /* "pyreadstat/pyreadstat.pyx":197 * dates_as_pandas = 1 * * cdef bint usernan = 0 # <<<<<<<<<<<<<< * * cdef bint no_datetime_conversion = 0 */ __pyx_v_usernan = 0; /* "pyreadstat/pyreadstat.pyx":199 * cdef bint usernan = 0 * * cdef bint no_datetime_conversion = 0 # <<<<<<<<<<<<<< * if disable_datetime_conversion: * no_datetime_conversion = 1 */ __pyx_v_no_datetime_conversion = 0; /* "pyreadstat/pyreadstat.pyx":200 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_disable_datetime_conversion); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 200, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":201 * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: * no_datetime_conversion = 1 # <<<<<<<<<<<<<< * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS */ __pyx_v_no_datetime_conversion = 1; /* "pyreadstat/pyreadstat.pyx":200 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ } /* "pyreadstat/pyreadstat.pyx":203 * no_datetime_conversion = 1 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS # <<<<<<<<<<<<<< * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_XPORT * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, */ __pyx_v_file_format = __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS; /* "pyreadstat/pyreadstat.pyx":204 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_XPORT # <<<<<<<<<<<<<< * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, */ __pyx_v_file_extension = __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_XPORT; /* "pyreadstat/pyreadstat.pyx":205 * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_XPORT * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, # <<<<<<<<<<<<<< * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) */ __pyx_t_2 = __pyx_f_10pyreadstat_16_readstat_parser_run_conversion(__pyx_v_filename_path, __pyx_v_file_format, __pyx_v_file_extension, __pyx_v_encoding, __pyx_v_metaonly, __pyx_v_dates_as_pandas, __pyx_v_usecols, __pyx_v_usernan, __pyx_v_no_datetime_conversion, ((long)__pyx_v_row_limit), ((long)__pyx_v_row_offset), __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 205, __pyx_L1_error) __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, 205, __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_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 205, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 205, __pyx_L1_error) __pyx_L7_unpacking_done:; } __pyx_v_data_frame = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_metadata = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":208 * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "xport" # <<<<<<<<<<<<<< * * return data_frame, metadata */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_format, __pyx_mstate_global->__pyx_n_u_xport) < 0) __PYX_ERR(0, 208, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":210 * metadata.file_format = "xport" * * return data_frame, metadata # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 210, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 210, __pyx_L1_error); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":139 * * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, # <<<<<<<<<<<<<< * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_xport", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":213 * * * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_5read_dta(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_4read_dta, "\n Read a STATA dta file\n\n Parameters\n ----------\n filename_path : str, bytes, Path-like object or file-like object\n path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded.\n metadataonly : bool, optional\n by default False. IF true, no data will be read but only metadata, so that you can get all elements in the\n metadata object. The data frame will be set with the correct column names but no data.\n dates_as_pandas_datetime : bool, optional\n by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas.\n apply_value_formats : bool, optional\n by default False. If true it will change values in the dataframe for they value labels in the metadata,\n if any appropiate are found.\n formats_as_category : bool, optional\n by default True. Takes effect only if apply_value_formats is True. If True, variables with values changed\n for their formatted version will be transformed into categories.\n formats_as_ordered_category : bool, optional\n defaults to False. If True the variables having formats will be transformed into ordered categories/enum.\n it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of\n the value of formats_as_category.\n encoding : str, optional\n Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an\n iconv-compatible name\n usecols : list, optional\n a list with column names to read from the file. Only those columns will be imported. Case sensitive!\n user_missing : bool, optional\n by default False, in this case user defined missing values are delivered as nan. If true, the missing values\n will be deliver as ""is, and an extra piece of information will be set in the metadata (missing_user_values)\n to be able to interpret those values as missing.\n disable_datetime_conversion : bool, optional\n if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns\n will remain as numbers. In order to convert them later to an appropiate python object, the user can use the\n information about the original variable format stored in the metadata object in original_variable_types.\n Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where\n there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates\n beyond that will rise an Overflow error in pyreadstat).\n row_limit : int, optional\n maximum number of rows to read. The default is 0 meaning unlimited.\n row_offset : int, optional\n start reading rows after this offset. By default 0, meaning start with the first row not skipping anything.\n output_format : str, optional\n one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the\n user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a \n dataframe is avoided.\n extra_datetime_formats: list of str, optional\n formats to be parsed as python datetime objects\n extra_date_formats: list of str, optional\n formats to be parsed as python date objects\n extra_time_formats: list of str, optional\n formats to be parsed as python time objects\n\n Returns\n -------\n data_frame : dataframe or dict\n a dataframe or dict with the data.\n metadata :\n object with metadata. Look at the d""ocumentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_5read_dta = {"read_dta", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_5read_dta, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_4read_dta}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_5read_dta(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_filename_path = 0; PyObject *__pyx_v_metadataonly = 0; PyObject *__pyx_v_dates_as_pandas_datetime = 0; PyObject *__pyx_v_apply_value_formats = 0; PyObject *__pyx_v_formats_as_category = 0; PyObject *__pyx_v_formats_as_ordered_category = 0; PyObject *__pyx_v_encoding = 0; PyObject *__pyx_v_usecols = 0; PyObject *__pyx_v_user_missing = 0; PyObject *__pyx_v_disable_datetime_conversion = 0; int __pyx_v_row_limit; int __pyx_v_row_offset; PyObject *__pyx_v_output_format = 0; PyObject *__pyx_v_extra_datetime_formats = 0; PyObject *__pyx_v_extra_date_formats = 0; PyObject *__pyx_v_extra_time_formats = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_dta (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_filename_path,&__pyx_mstate_global->__pyx_n_u_metadataonly,&__pyx_mstate_global->__pyx_n_u_dates_as_pandas_datetime,&__pyx_mstate_global->__pyx_n_u_apply_value_formats,&__pyx_mstate_global->__pyx_n_u_formats_as_category,&__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category,&__pyx_mstate_global->__pyx_n_u_encoding,&__pyx_mstate_global->__pyx_n_u_usecols,&__pyx_mstate_global->__pyx_n_u_user_missing,&__pyx_mstate_global->__pyx_n_u_disable_datetime_conversion,&__pyx_mstate_global->__pyx_n_u_row_limit,&__pyx_mstate_global->__pyx_n_u_row_offset,&__pyx_mstate_global->__pyx_n_u_output_format,&__pyx_mstate_global->__pyx_n_u_extra_datetime_formats,&__pyx_mstate_global->__pyx_n_u_extra_date_formats,&__pyx_mstate_global->__pyx_n_u_extra_time_formats,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 213, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 16: values[15] = __Pyx_ArgRef_FASTCALL(__pyx_args, 15); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[15])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 15: values[14] = __Pyx_ArgRef_FASTCALL(__pyx_args, 14); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[14])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "read_dta", 0) < 0) __PYX_ERR(0, 213, __pyx_L3_error) if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":214 * * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":215 * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[9]) values[9] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":216 * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a STATA dta file */ if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[14]) values[14] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[15]) values[15] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_dta", 0, 1, 16, i); __PYX_ERR(0, 213, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 16: values[15] = __Pyx_ArgRef_FASTCALL(__pyx_args, 15); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[15])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 15: values[14] = __Pyx_ArgRef_FASTCALL(__pyx_args, 14); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[14])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 213, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 213, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":214 * * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":215 * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":216 * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a STATA dta file */ if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[14]) values[14] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[15]) values[15] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_filename_path = values[0]; __pyx_v_metadataonly = values[1]; __pyx_v_dates_as_pandas_datetime = values[2]; __pyx_v_apply_value_formats = values[3]; __pyx_v_formats_as_category = values[4]; __pyx_v_formats_as_ordered_category = values[5]; __pyx_v_encoding = ((PyObject*)values[6]); __pyx_v_usecols = ((PyObject*)values[7]); __pyx_v_user_missing = values[8]; __pyx_v_disable_datetime_conversion = values[9]; if (values[10]) { __pyx_v_row_limit = __Pyx_PyLong_As_int(values[10]); if (unlikely((__pyx_v_row_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L3_error) } else { __pyx_v_row_limit = ((int)((int)0)); } if (values[11]) { __pyx_v_row_offset = __Pyx_PyLong_As_int(values[11]); if (unlikely((__pyx_v_row_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L3_error) } else { __pyx_v_row_offset = ((int)((int)0)); } __pyx_v_output_format = ((PyObject*)values[12]); __pyx_v_extra_datetime_formats = ((PyObject*)values[13]); __pyx_v_extra_date_formats = ((PyObject*)values[14]); __pyx_v_extra_time_formats = ((PyObject*)values[15]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_dta", 0, 1, 16, __pyx_nargs); __PYX_ERR(0, 213, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.read_dta", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_encoding), (&PyUnicode_Type), 1, "encoding", 1))) __PYX_ERR(0, 214, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_usecols), (&PyList_Type), 1, "usecols", 1))) __PYX_ERR(0, 214, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output_format), (&PyUnicode_Type), 1, "output_format", 1))) __PYX_ERR(0, 215, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_datetime_formats), (&PyList_Type), 1, "extra_datetime_formats", 1))) __PYX_ERR(0, 216, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_date_formats), (&PyList_Type), 1, "extra_date_formats", 1))) __PYX_ERR(0, 216, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_time_formats), (&PyList_Type), 1, "extra_time_formats", 1))) __PYX_ERR(0, 216, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_4read_dta(__pyx_self, __pyx_v_filename_path, __pyx_v_metadataonly, __pyx_v_dates_as_pandas_datetime, __pyx_v_apply_value_formats, __pyx_v_formats_as_category, __pyx_v_formats_as_ordered_category, __pyx_v_encoding, __pyx_v_usecols, __pyx_v_user_missing, __pyx_v_disable_datetime_conversion, __pyx_v_row_limit, __pyx_v_row_offset, __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); /* "pyreadstat/pyreadstat.pyx":213 * * * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_4read_dta(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_path, PyObject *__pyx_v_metadataonly, PyObject *__pyx_v_dates_as_pandas_datetime, PyObject *__pyx_v_apply_value_formats, PyObject *__pyx_v_formats_as_category, PyObject *__pyx_v_formats_as_ordered_category, PyObject *__pyx_v_encoding, PyObject *__pyx_v_usecols, PyObject *__pyx_v_user_missing, PyObject *__pyx_v_disable_datetime_conversion, int __pyx_v_row_limit, int __pyx_v_row_offset, PyObject *__pyx_v_output_format, PyObject *__pyx_v_extra_datetime_formats, PyObject *__pyx_v_extra_date_formats, PyObject *__pyx_v_extra_time_formats) { int __pyx_v_metaonly; int __pyx_v_dates_as_pandas; int __pyx_v_usernan; int __pyx_v_no_datetime_conversion; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_metadata = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *(*__pyx_t_6)(PyObject *); size_t __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_dta", 0); /* "pyreadstat/pyreadstat.pyx":278 * """ * * cdef bint metaonly = 0 # <<<<<<<<<<<<<< * if metadataonly: * metaonly = 1 */ __pyx_v_metaonly = 0; /* "pyreadstat/pyreadstat.pyx":279 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_metadataonly); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 279, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":280 * cdef bint metaonly = 0 * if metadataonly: * metaonly = 1 # <<<<<<<<<<<<<< * * cdef bint dates_as_pandas = 0 */ __pyx_v_metaonly = 1; /* "pyreadstat/pyreadstat.pyx":279 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ } /* "pyreadstat/pyreadstat.pyx":282 * metaonly = 1 * * cdef bint dates_as_pandas = 0 # <<<<<<<<<<<<<< * if dates_as_pandas_datetime: * dates_as_pandas = 1 */ __pyx_v_dates_as_pandas = 0; /* "pyreadstat/pyreadstat.pyx":283 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dates_as_pandas_datetime); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 283, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":284 * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: * dates_as_pandas = 1 # <<<<<<<<<<<<<< * * cdef bint usernan = 0 */ __pyx_v_dates_as_pandas = 1; /* "pyreadstat/pyreadstat.pyx":283 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ } /* "pyreadstat/pyreadstat.pyx":286 * dates_as_pandas = 1 * * cdef bint usernan = 0 # <<<<<<<<<<<<<< * if user_missing: * usernan = 1 */ __pyx_v_usernan = 0; /* "pyreadstat/pyreadstat.pyx":287 * * cdef bint usernan = 0 * if user_missing: # <<<<<<<<<<<<<< * usernan = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_user_missing); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 287, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":288 * cdef bint usernan = 0 * if user_missing: * usernan = 1 # <<<<<<<<<<<<<< * * cdef bint no_datetime_conversion = 0 */ __pyx_v_usernan = 1; /* "pyreadstat/pyreadstat.pyx":287 * * cdef bint usernan = 0 * if user_missing: # <<<<<<<<<<<<<< * usernan = 1 * */ } /* "pyreadstat/pyreadstat.pyx":290 * usernan = 1 * * cdef bint no_datetime_conversion = 0 # <<<<<<<<<<<<<< * if disable_datetime_conversion: * no_datetime_conversion = 1 */ __pyx_v_no_datetime_conversion = 0; /* "pyreadstat/pyreadstat.pyx":291 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_disable_datetime_conversion); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 291, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":292 * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: * no_datetime_conversion = 1 # <<<<<<<<<<<<<< * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_STATA */ __pyx_v_no_datetime_conversion = 1; /* "pyreadstat/pyreadstat.pyx":291 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ } /* "pyreadstat/pyreadstat.pyx":294 * no_datetime_conversion = 1 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_STATA # <<<<<<<<<<<<<< * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_DTA * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, */ __pyx_v_file_format = __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_STATA; /* "pyreadstat/pyreadstat.pyx":295 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_STATA * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_DTA # <<<<<<<<<<<<<< * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, */ __pyx_v_file_extension = __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_DTA; /* "pyreadstat/pyreadstat.pyx":296 * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_STATA * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_DTA * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, # <<<<<<<<<<<<<< * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) */ __pyx_t_2 = __pyx_f_10pyreadstat_16_readstat_parser_run_conversion(__pyx_v_filename_path, __pyx_v_file_format, __pyx_v_file_extension, __pyx_v_encoding, __pyx_v_metaonly, __pyx_v_dates_as_pandas, __pyx_v_usecols, __pyx_v_usernan, __pyx_v_no_datetime_conversion, ((long)__pyx_v_row_limit), ((long)__pyx_v_row_offset), __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 296, __pyx_L1_error) __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, 296, __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_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 296, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 296, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 296, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 296, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 296, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 296, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L8_unpacking_done; __pyx_L7_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 296, __pyx_L1_error) __pyx_L8_unpacking_done:; } __pyx_v_data_frame = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_metadata = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":299 * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "dta" # <<<<<<<<<<<<<< * * if apply_value_formats: */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_format, __pyx_mstate_global->__pyx_n_u_dta) < 0) __PYX_ERR(0, 299, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":301 * metadata.file_format = "dta" * * if apply_value_formats: # <<<<<<<<<<<<<< * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_apply_value_formats); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 301, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":302 * * if apply_value_formats: * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, # <<<<<<<<<<<<<< * formats_as_ordered_category=formats_as_ordered_category) * */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_set_value_labels); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* "pyreadstat/pyreadstat.pyx":303 * if apply_value_formats: * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) # <<<<<<<<<<<<<< * * return data_frame, metadata */ __pyx_t_7 = 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_7 = 0; } #endif { PyObject *__pyx_callargs[3 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_4, __pyx_v_data_frame, __pyx_v_metadata}; __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_category, __pyx_v_formats_as_category, __pyx_t_5, __pyx_callargs+3, 0) < 0) __PYX_ERR(0, 302, __pyx_L1_error) if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category, __pyx_v_formats_as_ordered_category, __pyx_t_5, __pyx_callargs+3, 1) < 0) __PYX_ERR(0, 302, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":301 * metadata.file_format = "dta" * * if apply_value_formats: # <<<<<<<<<<<<<< * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) */ } /* "pyreadstat/pyreadstat.pyx":305 * formats_as_ordered_category=formats_as_ordered_category) * * return data_frame, metadata # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 305, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 305, __pyx_L1_error); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":213 * * * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_dta", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":308 * * * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_7read_sav(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_6read_sav, "\n Read a SPSS sav or zsav (compressed) files\n\n Parameters\n ----------\n filename_path : str, bytes, Path-like object or file-like object\n path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded.\n metadataonly : bool, optional\n by default False. IF true, no data will be read but only metadata, so that you can get all elements in the\n metadata object. The data frame will be set with the correct column names but no data.\n dates_as_pandas_datetime : bool, optional\n by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas.\n apply_value_formats : bool, optional\n by default False. If true it will change values in the dataframe for they value labels in the metadata,\n if any appropiate are found.\n formats_as_category : bool, optional\n by default True. Takes effect only if apply_value_formats is True. If True, variables with values changed\n for their formatted version will be transformed into categories.\n formats_as_ordered_category : bool, optional\n defaults to False. If True the variables having formats will be transformed into ordered categories/enum.\n it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of\n the value of formats_as_category.\n encoding : str, optional\n Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an\n iconv-compatible name\n usecols : list, optional\n a list with column names to read from the file. Only those columns will be imported. Case sensitive!\n user_missing : bool, optional\n by default False, in this case user defined missing values are delivered as nan. If true, the missing values\n "" will be deliver as is, and an extra piece of information will be set in the metadata (missing_ranges)\n to be able to interpret those values as missing.\n disable_datetime_conversion : bool, optional\n if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns\n will remain as numbers. In order to convert them later to an appropiate python object, the user can use the\n information about the original variable format stored in the metadata object in original_variable_types.\n Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where\n there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates\n beyond that will rise an Overflow error in pyreadstat).\n row_limit : int, optional\n maximum number of rows to read. The default is 0 meaning unlimited.\n row_offset : int, optional\n start reading rows after this offset. By default 0, meaning start with the first row not skipping anything.\n output_format : str, optional\n one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the\n user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a \n dataframe is avoided.\n extra_datetime_formats: list of str, optional\n formats to be parsed as python datetime objects\n extra_date_formats: list of str, optional\n formats to be parsed as python date objects\n extra_time_formats: list of str, optional\n formats to be parsed as python time objects\n\n Returns\n -------\n data_frame : dataframe or dict\n a dataframe or dict with the data.\n metadata :\n object with metadat""a. Look at the documentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_7read_sav = {"read_sav", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_7read_sav, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_6read_sav}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_7read_sav(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_filename_path = 0; PyObject *__pyx_v_metadataonly = 0; PyObject *__pyx_v_dates_as_pandas_datetime = 0; PyObject *__pyx_v_apply_value_formats = 0; PyObject *__pyx_v_formats_as_category = 0; PyObject *__pyx_v_formats_as_ordered_category = 0; PyObject *__pyx_v_encoding = 0; PyObject *__pyx_v_usecols = 0; PyObject *__pyx_v_user_missing = 0; PyObject *__pyx_v_disable_datetime_conversion = 0; int __pyx_v_row_limit; int __pyx_v_row_offset; PyObject *__pyx_v_output_format = 0; PyObject *__pyx_v_extra_datetime_formats = 0; PyObject *__pyx_v_extra_date_formats = 0; PyObject *__pyx_v_extra_time_formats = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_sav (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_filename_path,&__pyx_mstate_global->__pyx_n_u_metadataonly,&__pyx_mstate_global->__pyx_n_u_dates_as_pandas_datetime,&__pyx_mstate_global->__pyx_n_u_apply_value_formats,&__pyx_mstate_global->__pyx_n_u_formats_as_category,&__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category,&__pyx_mstate_global->__pyx_n_u_encoding,&__pyx_mstate_global->__pyx_n_u_usecols,&__pyx_mstate_global->__pyx_n_u_user_missing,&__pyx_mstate_global->__pyx_n_u_disable_datetime_conversion,&__pyx_mstate_global->__pyx_n_u_row_limit,&__pyx_mstate_global->__pyx_n_u_row_offset,&__pyx_mstate_global->__pyx_n_u_output_format,&__pyx_mstate_global->__pyx_n_u_extra_datetime_formats,&__pyx_mstate_global->__pyx_n_u_extra_date_formats,&__pyx_mstate_global->__pyx_n_u_extra_time_formats,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 308, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 16: values[15] = __Pyx_ArgRef_FASTCALL(__pyx_args, 15); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[15])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 15: values[14] = __Pyx_ArgRef_FASTCALL(__pyx_args, 14); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[14])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "read_sav", 0) < 0) __PYX_ERR(0, 308, __pyx_L3_error) if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":309 * * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, * list extra_date_formats=None, list extra_time_formats=None): */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":310 * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, # <<<<<<<<<<<<<< * list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[9]) values[9] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":311 * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, * list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SPSS sav or zsav (compressed) files */ if (!values[14]) values[14] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[15]) values[15] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_sav", 0, 1, 16, i); __PYX_ERR(0, 308, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 16: values[15] = __Pyx_ArgRef_FASTCALL(__pyx_args, 15); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[15])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 15: values[14] = __Pyx_ArgRef_FASTCALL(__pyx_args, 14); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[14])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 308, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 308, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":309 * * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, * list extra_date_formats=None, list extra_time_formats=None): */ if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":310 * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, # <<<<<<<<<<<<<< * list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":311 * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, * list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SPSS sav or zsav (compressed) files */ if (!values[14]) values[14] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[15]) values[15] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_filename_path = values[0]; __pyx_v_metadataonly = values[1]; __pyx_v_dates_as_pandas_datetime = values[2]; __pyx_v_apply_value_formats = values[3]; __pyx_v_formats_as_category = values[4]; __pyx_v_formats_as_ordered_category = values[5]; __pyx_v_encoding = ((PyObject*)values[6]); __pyx_v_usecols = ((PyObject*)values[7]); __pyx_v_user_missing = values[8]; __pyx_v_disable_datetime_conversion = values[9]; if (values[10]) { __pyx_v_row_limit = __Pyx_PyLong_As_int(values[10]); if (unlikely((__pyx_v_row_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 310, __pyx_L3_error) } else { __pyx_v_row_limit = ((int)((int)0)); } if (values[11]) { __pyx_v_row_offset = __Pyx_PyLong_As_int(values[11]); if (unlikely((__pyx_v_row_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 310, __pyx_L3_error) } else { __pyx_v_row_offset = ((int)((int)0)); } __pyx_v_output_format = ((PyObject*)values[12]); __pyx_v_extra_datetime_formats = ((PyObject*)values[13]); __pyx_v_extra_date_formats = ((PyObject*)values[14]); __pyx_v_extra_time_formats = ((PyObject*)values[15]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_sav", 0, 1, 16, __pyx_nargs); __PYX_ERR(0, 308, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.read_sav", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_encoding), (&PyUnicode_Type), 1, "encoding", 1))) __PYX_ERR(0, 309, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_usecols), (&PyList_Type), 1, "usecols", 1))) __PYX_ERR(0, 309, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output_format), (&PyUnicode_Type), 1, "output_format", 1))) __PYX_ERR(0, 310, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_datetime_formats), (&PyList_Type), 1, "extra_datetime_formats", 1))) __PYX_ERR(0, 310, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_date_formats), (&PyList_Type), 1, "extra_date_formats", 1))) __PYX_ERR(0, 311, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_time_formats), (&PyList_Type), 1, "extra_time_formats", 1))) __PYX_ERR(0, 311, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_6read_sav(__pyx_self, __pyx_v_filename_path, __pyx_v_metadataonly, __pyx_v_dates_as_pandas_datetime, __pyx_v_apply_value_formats, __pyx_v_formats_as_category, __pyx_v_formats_as_ordered_category, __pyx_v_encoding, __pyx_v_usecols, __pyx_v_user_missing, __pyx_v_disable_datetime_conversion, __pyx_v_row_limit, __pyx_v_row_offset, __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); /* "pyreadstat/pyreadstat.pyx":308 * * * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_6read_sav(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_path, PyObject *__pyx_v_metadataonly, PyObject *__pyx_v_dates_as_pandas_datetime, PyObject *__pyx_v_apply_value_formats, PyObject *__pyx_v_formats_as_category, PyObject *__pyx_v_formats_as_ordered_category, PyObject *__pyx_v_encoding, PyObject *__pyx_v_usecols, PyObject *__pyx_v_user_missing, PyObject *__pyx_v_disable_datetime_conversion, int __pyx_v_row_limit, int __pyx_v_row_offset, PyObject *__pyx_v_output_format, PyObject *__pyx_v_extra_datetime_formats, PyObject *__pyx_v_extra_date_formats, PyObject *__pyx_v_extra_time_formats) { int __pyx_v_metaonly; int __pyx_v_dates_as_pandas; int __pyx_v_usernan; int __pyx_v_no_datetime_conversion; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_metadata = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *(*__pyx_t_6)(PyObject *); size_t __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_sav", 0); /* "pyreadstat/pyreadstat.pyx":373 * """ * * cdef bint metaonly = 0 # <<<<<<<<<<<<<< * if metadataonly: * metaonly = 1 */ __pyx_v_metaonly = 0; /* "pyreadstat/pyreadstat.pyx":374 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_metadataonly); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 374, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":375 * cdef bint metaonly = 0 * if metadataonly: * metaonly = 1 # <<<<<<<<<<<<<< * * cdef bint dates_as_pandas = 0 */ __pyx_v_metaonly = 1; /* "pyreadstat/pyreadstat.pyx":374 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ } /* "pyreadstat/pyreadstat.pyx":377 * metaonly = 1 * * cdef bint dates_as_pandas = 0 # <<<<<<<<<<<<<< * if dates_as_pandas_datetime: * dates_as_pandas = 1 */ __pyx_v_dates_as_pandas = 0; /* "pyreadstat/pyreadstat.pyx":378 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dates_as_pandas_datetime); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 378, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":379 * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: * dates_as_pandas = 1 # <<<<<<<<<<<<<< * * cdef bint usernan = 0 */ __pyx_v_dates_as_pandas = 1; /* "pyreadstat/pyreadstat.pyx":378 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ } /* "pyreadstat/pyreadstat.pyx":381 * dates_as_pandas = 1 * * cdef bint usernan = 0 # <<<<<<<<<<<<<< * if user_missing: * usernan = 1 */ __pyx_v_usernan = 0; /* "pyreadstat/pyreadstat.pyx":382 * * cdef bint usernan = 0 * if user_missing: # <<<<<<<<<<<<<< * usernan = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_user_missing); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 382, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":383 * cdef bint usernan = 0 * if user_missing: * usernan = 1 # <<<<<<<<<<<<<< * * cdef bint no_datetime_conversion = 0 */ __pyx_v_usernan = 1; /* "pyreadstat/pyreadstat.pyx":382 * * cdef bint usernan = 0 * if user_missing: # <<<<<<<<<<<<<< * usernan = 1 * */ } /* "pyreadstat/pyreadstat.pyx":385 * usernan = 1 * * cdef bint no_datetime_conversion = 0 # <<<<<<<<<<<<<< * if disable_datetime_conversion: * no_datetime_conversion = 1 */ __pyx_v_no_datetime_conversion = 0; /* "pyreadstat/pyreadstat.pyx":386 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_disable_datetime_conversion); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 386, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":387 * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: * no_datetime_conversion = 1 # <<<<<<<<<<<<<< * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS */ __pyx_v_no_datetime_conversion = 1; /* "pyreadstat/pyreadstat.pyx":386 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ } /* "pyreadstat/pyreadstat.pyx":389 * no_datetime_conversion = 1 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS # <<<<<<<<<<<<<< * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAV * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, */ __pyx_v_file_format = __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS; /* "pyreadstat/pyreadstat.pyx":390 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAV # <<<<<<<<<<<<<< * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, */ __pyx_v_file_extension = __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAV; /* "pyreadstat/pyreadstat.pyx":391 * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAV * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, # <<<<<<<<<<<<<< * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) */ __pyx_t_2 = __pyx_f_10pyreadstat_16_readstat_parser_run_conversion(__pyx_v_filename_path, __pyx_v_file_format, __pyx_v_file_extension, __pyx_v_encoding, __pyx_v_metaonly, __pyx_v_dates_as_pandas, __pyx_v_usecols, __pyx_v_usernan, __pyx_v_no_datetime_conversion, ((long)__pyx_v_row_limit), ((long)__pyx_v_row_offset), __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __pyx_L1_error) __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_3 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 391, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L8_unpacking_done; __pyx_L7_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 391, __pyx_L1_error) __pyx_L8_unpacking_done:; } __pyx_v_data_frame = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_metadata = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":394 * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "sav/zsav" # <<<<<<<<<<<<<< * * if apply_value_formats: */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_format, __pyx_mstate_global->__pyx_kp_u_sav_zsav) < 0) __PYX_ERR(0, 394, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":396 * metadata.file_format = "sav/zsav" * * if apply_value_formats: # <<<<<<<<<<<<<< * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_apply_value_formats); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 396, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":397 * * if apply_value_formats: * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, # <<<<<<<<<<<<<< * formats_as_ordered_category=formats_as_ordered_category) * */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_set_value_labels); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* "pyreadstat/pyreadstat.pyx":398 * if apply_value_formats: * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) # <<<<<<<<<<<<<< * * return data_frame, metadata */ __pyx_t_7 = 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_7 = 0; } #endif { PyObject *__pyx_callargs[3 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_4, __pyx_v_data_frame, __pyx_v_metadata}; __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_category, __pyx_v_formats_as_category, __pyx_t_5, __pyx_callargs+3, 0) < 0) __PYX_ERR(0, 397, __pyx_L1_error) if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category, __pyx_v_formats_as_ordered_category, __pyx_t_5, __pyx_callargs+3, 1) < 0) __PYX_ERR(0, 397, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":396 * metadata.file_format = "sav/zsav" * * if apply_value_formats: # <<<<<<<<<<<<<< * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, * formats_as_ordered_category=formats_as_ordered_category) */ } /* "pyreadstat/pyreadstat.pyx":400 * formats_as_ordered_category=formats_as_ordered_category) * * return data_frame, metadata # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 400, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 400, __pyx_L1_error); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":308 * * * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_sav", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":403 * * * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_9read_por(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_8read_por, "\n Read a SPSS por file. Files are assumed to be UTF-8 encoded, the encoding cannot be set to other.\n\n Parameters\n ----------\n filename_path : str, bytes, Path-like object or file-like object\n path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded.\n metadataonly : bool, optional\n by default False. IF true, no data will be read but only metadata, so that you can get all elements in the\n metadata object. The data frame will be set with the correct column names but no data.\n Notice that number_rows will be None as por files do not have the number of rows recorded in the file metadata.\n dates_as_pandas_datetime : bool, optional\n by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas.\n apply_value_formats : bool, optional\n by default False. If true it will change values in the dataframe for they value labels in the metadata,\n if any appropiate are found.\n formats_as_category : bool, optional\n by default True. Takes effect only if apply_value_formats is True. If True, variables with values changed\n for their formatted version will be transformed into categories.\n formats_as_ordered_category : bool, optional\n defaults to False. If True the variables having formats will be transformed into ordered categories/enum.\n it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of\n the value of formats_as_category.\n usecols : list, optional\n a list with column names to read from the file. Only those columns will be imported. Case sensitive!\n disable_datetime_conversion : bool, optional\n if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns\n "" will remain as numbers. In order to convert them later to an appropiate python object, the user can use the\n information about the original variable format stored in the metadata object in original_variable_types.\n Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where\n there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates\n beyond that will rise an Overflow error in pyreadstat).\n row_limit : int, optional\n maximum number of rows to read. The default is 0 meaning unlimited.\n row_offset : int, optional\n start reading rows after this offset. By default 0, meaning start with the first row not skipping anything.\n output_format : str, optional\n one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the\n user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a \n dataframe is avoided.\n extra_datetime_formats: list of str, optional\n formats to be parsed as python datetime objects\n extra_date_formats: list of str, optional\n formats to be parsed as python date objects\n extra_time_formats: list of str, optional\n formats to be parsed as python time objects\n\n Returns\n -------\n data_frame : dataframe or dict\n a dataframe or dict with the data.\n metadata :\n object with metadata. Look at the documentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_9read_por = {"read_por", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_9read_por, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_8read_por}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_9read_por(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_filename_path = 0; PyObject *__pyx_v_metadataonly = 0; PyObject *__pyx_v_dates_as_pandas_datetime = 0; PyObject *__pyx_v_apply_value_formats = 0; PyObject *__pyx_v_formats_as_category = 0; CYTHON_UNUSED PyObject *__pyx_v_formats_as_ordered_category = 0; PyObject *__pyx_v_usecols = 0; PyObject *__pyx_v_disable_datetime_conversion = 0; int __pyx_v_row_limit; int __pyx_v_row_offset; PyObject *__pyx_v_output_format = 0; PyObject *__pyx_v_extra_datetime_formats = 0; PyObject *__pyx_v_extra_date_formats = 0; PyObject *__pyx_v_extra_time_formats = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_por (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_filename_path,&__pyx_mstate_global->__pyx_n_u_metadataonly,&__pyx_mstate_global->__pyx_n_u_dates_as_pandas_datetime,&__pyx_mstate_global->__pyx_n_u_apply_value_formats,&__pyx_mstate_global->__pyx_n_u_formats_as_category,&__pyx_mstate_global->__pyx_n_u_formats_as_ordered_category,&__pyx_mstate_global->__pyx_n_u_usecols,&__pyx_mstate_global->__pyx_n_u_disable_datetime_conversion,&__pyx_mstate_global->__pyx_n_u_row_limit,&__pyx_mstate_global->__pyx_n_u_row_offset,&__pyx_mstate_global->__pyx_n_u_output_format,&__pyx_mstate_global->__pyx_n_u_extra_datetime_formats,&__pyx_mstate_global->__pyx_n_u_extra_date_formats,&__pyx_mstate_global->__pyx_n_u_extra_time_formats,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 403, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "read_por", 0) < 0) __PYX_ERR(0, 403, __pyx_L3_error) if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":404 * * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":405 * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[7]) values[7] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[10]) values[10] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":406 * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SPSS por file. Files are assumed to be UTF-8 encoded, the encoding cannot be set to other. */ if (!values[11]) values[11] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_por", 0, 1, 14, i); __PYX_ERR(0, 403, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 14: values[13] = __Pyx_ArgRef_FASTCALL(__pyx_args, 13); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[13])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 13: values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 403, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 403, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_True))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":404 * * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, # <<<<<<<<<<<<<< * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); /* "pyreadstat/pyreadstat.pyx":405 * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ if (!values[10]) values[10] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":406 * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): # <<<<<<<<<<<<<< * r""" * Read a SPSS por file. Files are assumed to be UTF-8 encoded, the encoding cannot be set to other. */ if (!values[11]) values[11] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[12]) values[12] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[13]) values[13] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_filename_path = values[0]; __pyx_v_metadataonly = values[1]; __pyx_v_dates_as_pandas_datetime = values[2]; __pyx_v_apply_value_formats = values[3]; __pyx_v_formats_as_category = values[4]; __pyx_v_formats_as_ordered_category = values[5]; __pyx_v_usecols = ((PyObject*)values[6]); __pyx_v_disable_datetime_conversion = values[7]; if (values[8]) { __pyx_v_row_limit = __Pyx_PyLong_As_int(values[8]); if (unlikely((__pyx_v_row_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 405, __pyx_L3_error) } else { __pyx_v_row_limit = ((int)((int)0)); } if (values[9]) { __pyx_v_row_offset = __Pyx_PyLong_As_int(values[9]); if (unlikely((__pyx_v_row_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 405, __pyx_L3_error) } else { __pyx_v_row_offset = ((int)((int)0)); } __pyx_v_output_format = ((PyObject*)values[10]); __pyx_v_extra_datetime_formats = ((PyObject*)values[11]); __pyx_v_extra_date_formats = ((PyObject*)values[12]); __pyx_v_extra_time_formats = ((PyObject*)values[13]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_por", 0, 1, 14, __pyx_nargs); __PYX_ERR(0, 403, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.read_por", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_usecols), (&PyList_Type), 1, "usecols", 1))) __PYX_ERR(0, 404, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output_format), (&PyUnicode_Type), 1, "output_format", 1))) __PYX_ERR(0, 405, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_datetime_formats), (&PyList_Type), 1, "extra_datetime_formats", 1))) __PYX_ERR(0, 406, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_date_formats), (&PyList_Type), 1, "extra_date_formats", 1))) __PYX_ERR(0, 406, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extra_time_formats), (&PyList_Type), 1, "extra_time_formats", 1))) __PYX_ERR(0, 406, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_8read_por(__pyx_self, __pyx_v_filename_path, __pyx_v_metadataonly, __pyx_v_dates_as_pandas_datetime, __pyx_v_apply_value_formats, __pyx_v_formats_as_category, __pyx_v_formats_as_ordered_category, __pyx_v_usecols, __pyx_v_disable_datetime_conversion, __pyx_v_row_limit, __pyx_v_row_offset, __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); /* "pyreadstat/pyreadstat.pyx":403 * * * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_8read_por(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_path, PyObject *__pyx_v_metadataonly, PyObject *__pyx_v_dates_as_pandas_datetime, PyObject *__pyx_v_apply_value_formats, PyObject *__pyx_v_formats_as_category, CYTHON_UNUSED PyObject *__pyx_v_formats_as_ordered_category, PyObject *__pyx_v_usecols, PyObject *__pyx_v_disable_datetime_conversion, int __pyx_v_row_limit, int __pyx_v_row_offset, PyObject *__pyx_v_output_format, PyObject *__pyx_v_extra_datetime_formats, PyObject *__pyx_v_extra_date_formats, PyObject *__pyx_v_extra_time_formats) { int __pyx_v_metaonly; int __pyx_v_dates_as_pandas; int __pyx_v_usernan; int __pyx_v_no_datetime_conversion; PyObject *__pyx_v_encoding = 0; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_metadata = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *(*__pyx_t_6)(PyObject *); size_t __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_por", 0); /* "pyreadstat/pyreadstat.pyx":462 * """ * * cdef bint metaonly = 0 # <<<<<<<<<<<<<< * if metadataonly: * metaonly = 1 */ __pyx_v_metaonly = 0; /* "pyreadstat/pyreadstat.pyx":463 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_metadataonly); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 463, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":464 * cdef bint metaonly = 0 * if metadataonly: * metaonly = 1 # <<<<<<<<<<<<<< * * cdef bint dates_as_pandas = 0 */ __pyx_v_metaonly = 1; /* "pyreadstat/pyreadstat.pyx":463 * * cdef bint metaonly = 0 * if metadataonly: # <<<<<<<<<<<<<< * metaonly = 1 * */ } /* "pyreadstat/pyreadstat.pyx":466 * metaonly = 1 * * cdef bint dates_as_pandas = 0 # <<<<<<<<<<<<<< * if dates_as_pandas_datetime: * dates_as_pandas = 1 */ __pyx_v_dates_as_pandas = 0; /* "pyreadstat/pyreadstat.pyx":467 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dates_as_pandas_datetime); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 467, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":468 * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: * dates_as_pandas = 1 # <<<<<<<<<<<<<< * * cdef bint usernan = 0 */ __pyx_v_dates_as_pandas = 1; /* "pyreadstat/pyreadstat.pyx":467 * * cdef bint dates_as_pandas = 0 * if dates_as_pandas_datetime: # <<<<<<<<<<<<<< * dates_as_pandas = 1 * */ } /* "pyreadstat/pyreadstat.pyx":470 * dates_as_pandas = 1 * * cdef bint usernan = 0 # <<<<<<<<<<<<<< * * cdef bint no_datetime_conversion = 0 */ __pyx_v_usernan = 0; /* "pyreadstat/pyreadstat.pyx":472 * cdef bint usernan = 0 * * cdef bint no_datetime_conversion = 0 # <<<<<<<<<<<<<< * if disable_datetime_conversion: * no_datetime_conversion = 1 */ __pyx_v_no_datetime_conversion = 0; /* "pyreadstat/pyreadstat.pyx":473 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_disable_datetime_conversion); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 473, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":474 * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: * no_datetime_conversion = 1 # <<<<<<<<<<<<<< * * cdef str encoding = None */ __pyx_v_no_datetime_conversion = 1; /* "pyreadstat/pyreadstat.pyx":473 * * cdef bint no_datetime_conversion = 0 * if disable_datetime_conversion: # <<<<<<<<<<<<<< * no_datetime_conversion = 1 * */ } /* "pyreadstat/pyreadstat.pyx":476 * no_datetime_conversion = 1 * * cdef str encoding = None # <<<<<<<<<<<<<< * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS */ __Pyx_INCREF(Py_None); __pyx_v_encoding = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":478 * cdef str encoding = None * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS # <<<<<<<<<<<<<< * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_POR * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, */ __pyx_v_file_format = __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SPSS; /* "pyreadstat/pyreadstat.pyx":479 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_POR # <<<<<<<<<<<<<< * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, */ __pyx_v_file_extension = __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_POR; /* "pyreadstat/pyreadstat.pyx":480 * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_POR * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, # <<<<<<<<<<<<<< * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) */ __pyx_t_2 = __pyx_f_10pyreadstat_16_readstat_parser_run_conversion(__pyx_v_filename_path, __pyx_v_file_format, __pyx_v_file_extension, __pyx_v_encoding, __pyx_v_metaonly, __pyx_v_dates_as_pandas, __pyx_v_usecols, __pyx_v_usernan, __pyx_v_no_datetime_conversion, ((long)__pyx_v_row_limit), ((long)__pyx_v_row_offset), __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 480, __pyx_L1_error) __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, 480, __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_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 480, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 480, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 480, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 480, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 480, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 480, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 480, __pyx_L1_error) __pyx_L7_unpacking_done:; } __pyx_v_data_frame = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_metadata = __pyx_t_4; __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":483 * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "por" # <<<<<<<<<<<<<< * if apply_value_formats: * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category) */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_format, __pyx_mstate_global->__pyx_n_u_por) < 0) __PYX_ERR(0, 483, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":484 * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "por" * if apply_value_formats: # <<<<<<<<<<<<<< * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category) * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_apply_value_formats); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 484, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":485 * metadata.file_format = "por" * if apply_value_formats: * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category) # <<<<<<<<<<<<<< * * return data_frame, metadata */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_set_value_labels); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = 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_7 = 0; } #endif { PyObject *__pyx_callargs[3 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_v_data_frame, __pyx_v_metadata}; __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_formats_as_category, __pyx_v_formats_as_category, __pyx_t_5, __pyx_callargs+3, 0) < 0) __PYX_ERR(0, 485, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF_SET(__pyx_v_data_frame, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":484 * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "por" * if apply_value_formats: # <<<<<<<<<<<<<< * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category) * */ } /* "pyreadstat/pyreadstat.pyx":487 * data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category) * * return data_frame, metadata # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 487, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 487, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 487, __pyx_L1_error); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":403 * * * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_por", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_encoding); __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":490 * * * def read_sas7bcat(filename_path, str encoding=None, str output_format=None): # <<<<<<<<<<<<<< * r""" * Read a SAS sas7bcat file. The returning dataframe will be empty. The metadata object will contain a dictionary */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_11read_sas7bcat(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_10read_sas7bcat, "\n Read a SAS sas7bcat file. The returning dataframe will be empty. The metadata object will contain a dictionary\n value_labels that contains the formats. When parsing the sas7bdat file, in the metadata, the dictionary\n variable_to_label contains a map from variable name to the formats.\n In order to apply the catalog to the sas7bdat file use set_catalog_to_sas or pass the catalog file as an argument\n to read_sas7bdat directly.\n SAS catalog files are difficult ones, some of them can be read only in specific SAS version, may contain strange\n encodings etc. Therefore it may be that many catalog files are not readable from this application.\n\n Parameters\n ----------\n filename_path : str, bytes, Path-like object or file-like object\n path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded.\n encoding : str, optional\n Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an\n iconv-compatible name\n output_format : str, optional\n one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned. \n Notice that for this function the resulting object is always empty, this is done for consistency with other functions\n but has no impact on performance.\n\n Returns\n -------\n data_frame : dataframe or dict\n a dataframe with the data (no data in this case, so will be always empty).\n metadata :\n object with metadata. The member value_labels is the one that contains the formats.\n Look at the documentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_11read_sas7bcat = {"read_sas7bcat", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_11read_sas7bcat, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_10read_sas7bcat}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_11read_sas7bcat(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_filename_path = 0; PyObject *__pyx_v_encoding = 0; PyObject *__pyx_v_output_format = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[3] = {0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_sas7bcat (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_filename_path,&__pyx_mstate_global->__pyx_n_u_encoding,&__pyx_mstate_global->__pyx_n_u_output_format,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 490, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 490, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 490, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 490, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "read_sas7bcat", 0) < 0) __PYX_ERR(0, 490, __pyx_L3_error) if (!values[1]) values[1] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_sas7bcat", 0, 1, 3, i); __PYX_ERR(0, 490, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 490, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 490, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 490, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[1]) values[1] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_filename_path = values[0]; __pyx_v_encoding = ((PyObject*)values[1]); __pyx_v_output_format = ((PyObject*)values[2]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_sas7bcat", 0, 1, 3, __pyx_nargs); __PYX_ERR(0, 490, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.read_sas7bcat", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_encoding), (&PyUnicode_Type), 1, "encoding", 1))) __PYX_ERR(0, 490, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output_format), (&PyUnicode_Type), 1, "output_format", 1))) __PYX_ERR(0, 490, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_10read_sas7bcat(__pyx_self, __pyx_v_filename_path, __pyx_v_encoding, __pyx_v_output_format); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_10read_sas7bcat(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_path, PyObject *__pyx_v_encoding, PyObject *__pyx_v_output_format) { int __pyx_v_metaonly; int __pyx_v_dates_as_pandas; PyObject *__pyx_v_usecols = 0; int __pyx_v_usernan; int __pyx_v_no_datetime_conversion; long __pyx_v_row_limit; long __pyx_v_row_offset; PyObject *__pyx_v_extra_datetime_formats = 0; PyObject *__pyx_v_extra_date_formats = 0; PyObject *__pyx_v_extra_time_formats = 0; __pyx_t_10pyreadstat_16_readstat_parser_py_file_format __pyx_v_file_format; __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension __pyx_v_file_extension; PyObject *__pyx_v_data_frame = NULL; PyObject *__pyx_v_metadata = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *(*__pyx_t_5)(PyObject *); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_sas7bcat", 0); /* "pyreadstat/pyreadstat.pyx":520 * Look at the documentation for more information. * """ * cdef bint metaonly = 1 # <<<<<<<<<<<<<< * cdef bint dates_as_pandas = 0 * cdef list usecols = None */ __pyx_v_metaonly = 1; /* "pyreadstat/pyreadstat.pyx":521 * """ * cdef bint metaonly = 1 * cdef bint dates_as_pandas = 0 # <<<<<<<<<<<<<< * cdef list usecols = None * cdef bint usernan = 0 */ __pyx_v_dates_as_pandas = 0; /* "pyreadstat/pyreadstat.pyx":522 * cdef bint metaonly = 1 * cdef bint dates_as_pandas = 0 * cdef list usecols = None # <<<<<<<<<<<<<< * cdef bint usernan = 0 * cdef bint no_datetime_conversion = 0 */ __Pyx_INCREF(Py_None); __pyx_v_usecols = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":523 * cdef bint dates_as_pandas = 0 * cdef list usecols = None * cdef bint usernan = 0 # <<<<<<<<<<<<<< * cdef bint no_datetime_conversion = 0 * cdef long row_limit=0 */ __pyx_v_usernan = 0; /* "pyreadstat/pyreadstat.pyx":524 * cdef list usecols = None * cdef bint usernan = 0 * cdef bint no_datetime_conversion = 0 # <<<<<<<<<<<<<< * cdef long row_limit=0 * cdef long row_offset=0 */ __pyx_v_no_datetime_conversion = 0; /* "pyreadstat/pyreadstat.pyx":525 * cdef bint usernan = 0 * cdef bint no_datetime_conversion = 0 * cdef long row_limit=0 # <<<<<<<<<<<<<< * cdef long row_offset=0 * cdef list extra_datetime_formats=None */ __pyx_v_row_limit = 0; /* "pyreadstat/pyreadstat.pyx":526 * cdef bint no_datetime_conversion = 0 * cdef long row_limit=0 * cdef long row_offset=0 # <<<<<<<<<<<<<< * cdef list extra_datetime_formats=None * cdef list extra_date_formats=None */ __pyx_v_row_offset = 0; /* "pyreadstat/pyreadstat.pyx":527 * cdef long row_limit=0 * cdef long row_offset=0 * cdef list extra_datetime_formats=None # <<<<<<<<<<<<<< * cdef list extra_date_formats=None * cdef list extra_time_formats=None */ __Pyx_INCREF(Py_None); __pyx_v_extra_datetime_formats = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":528 * cdef long row_offset=0 * cdef list extra_datetime_formats=None * cdef list extra_date_formats=None # <<<<<<<<<<<<<< * cdef list extra_time_formats=None * */ __Pyx_INCREF(Py_None); __pyx_v_extra_date_formats = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":529 * cdef list extra_datetime_formats=None * cdef list extra_date_formats=None * cdef list extra_time_formats=None # <<<<<<<<<<<<<< * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS */ __Pyx_INCREF(Py_None); __pyx_v_extra_time_formats = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":531 * cdef list extra_time_formats=None * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS # <<<<<<<<<<<<<< * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BCAT * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, */ __pyx_v_file_format = __pyx_e_10pyreadstat_16_readstat_parser_FILE_FORMAT_SAS; /* "pyreadstat/pyreadstat.pyx":532 * * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BCAT # <<<<<<<<<<<<<< * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, */ __pyx_v_file_extension = __pyx_e_10pyreadstat_16_readstat_parser_FILE_EXT_SAS7BCAT; /* "pyreadstat/pyreadstat.pyx":533 * cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS * cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BCAT * data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, # <<<<<<<<<<<<<< * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) */ __pyx_t_1 = __pyx_f_10pyreadstat_16_readstat_parser_run_conversion(__pyx_v_filename_path, __pyx_v_file_format, __pyx_v_file_extension, __pyx_v_encoding, __pyx_v_metaonly, __pyx_v_dates_as_pandas, __pyx_v_usecols, __pyx_v_usernan, __pyx_v_no_datetime_conversion, __pyx_v_row_limit, __pyx_v_row_offset, __pyx_v_output_format, __pyx_v_extra_datetime_formats, __pyx_v_extra_date_formats, __pyx_v_extra_time_formats); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 533, __pyx_L1_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 != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 533, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 533, __pyx_L1_error) __pyx_t_5 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L4_unpacking_done; __pyx_L3_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 533, __pyx_L1_error) __pyx_L4_unpacking_done:; } __pyx_v_data_frame = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_metadata = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":536 * dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, * output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) * metadata.file_format = "sas7bcat" # <<<<<<<<<<<<<< * * return data_frame, metadata */ if (__Pyx_PyObject_SetAttrStr(__pyx_v_metadata, __pyx_mstate_global->__pyx_n_u_file_format, __pyx_mstate_global->__pyx_n_u_sas7bcat) < 0) __PYX_ERR(0, 536, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":538 * metadata.file_format = "sas7bcat" * * return data_frame, metadata # <<<<<<<<<<<<<< * * # convenience functions to read in chunks */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 538, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_data_frame); __Pyx_GIVEREF(__pyx_v_data_frame); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_data_frame) != (0)) __PYX_ERR(0, 538, __pyx_L1_error); __Pyx_INCREF(__pyx_v_metadata); __Pyx_GIVEREF(__pyx_v_metadata); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_metadata) != (0)) __PYX_ERR(0, 538, __pyx_L1_error); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":490 * * * def read_sas7bcat(filename_path, str encoding=None, str output_format=None): # <<<<<<<<<<<<<< * r""" * Read a SAS sas7bcat file. The returning dataframe will be empty. The metadata object will contain a dictionary */ /* 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_AddTraceback("pyreadstat.pyreadstat.read_sas7bcat", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_usecols); __Pyx_XDECREF(__pyx_v_extra_datetime_formats); __Pyx_XDECREF(__pyx_v_extra_date_formats); __Pyx_XDECREF(__pyx_v_extra_time_formats); __Pyx_XDECREF(__pyx_v_data_frame); __Pyx_XDECREF(__pyx_v_metadata); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_gb_10pyreadstat_10pyreadstat_14generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ /* "pyreadstat/pyreadstat.pyx":542 * # convenience functions to read in chunks * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, # <<<<<<<<<<<<<< * multiprocess=False, num_processes=4, num_rows=None, **kwargs): * """ */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_13read_file_in_chunks(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_12read_file_in_chunks, "\n Returns a generator that will allow to read a file in chunks.\n\n If using multiprocessing, for Xport, Por and some defective sav files where the number of rows in the dataset canot be obtained from the metadata, \n the parameter num_rows must be set to a number equal or larger than the number of rows in the dataset. That information must\n be obtained by the user before running this function.\n\n Parameters\n ----------\n read_function : pyreadstat function\n a pyreadstat reading function\n file_path : string\n path to the file to be read\n chunksize : integer, optional\n size of the chunks to read\n offset : integer, optional\n start reading the file after certain number of rows\n limit : integer, optional\n stop reading the file after certain number of rows, will be added to offset\n multiprocess: bool, optional\n use multiprocessing to read each chunk?\n num_processes: integer, optional\n in case multiprocess is true, how many workers/processes to spawn?\n num_rows: integer, optional\n number of rows in the dataset. If using multiprocessing it is obligatory for files where\n the number of rows cannot be obtained from the medatata, such as por and \n some defective xport and sav files. The user must obtain this value by reading the file without multiprocessing first or any other means. A number\n larger than the actual number of rows will work as well. Discarded if the number of rows can be obtained from the metadata or not using\n multiprocessing.\n kwargs : dict, optional\n any other keyword argument to pass to the read_function. row_limit and row_offset will be discarded if present.\n\n Yields\n -------\n data_frame : dataframe\n a dataframe with the data\n metadata :\n object with metadata. ""\n Look at the documentation for more information.\n\n it : generator\n A generator that reads the file in chunks.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_13read_file_in_chunks = {"read_file_in_chunks", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_13read_file_in_chunks, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_12read_file_in_chunks}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_13read_file_in_chunks(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_read_function = 0; PyObject *__pyx_v_file_path = 0; PyObject *__pyx_v_chunksize = 0; PyObject *__pyx_v_offset = 0; PyObject *__pyx_v_limit = 0; PyObject *__pyx_v_multiprocess = 0; PyObject *__pyx_v_num_processes = 0; PyObject *__pyx_v_num_rows = 0; PyObject *__pyx_v_kwargs = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[8] = {0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_file_in_chunks (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; __Pyx_GOTREF(__pyx_v_kwargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_read_function,&__pyx_mstate_global->__pyx_n_u_file_path,&__pyx_mstate_global->__pyx_n_u_chunksize,&__pyx_mstate_global->__pyx_n_u_offset,&__pyx_mstate_global->__pyx_n_u_limit,&__pyx_mstate_global->__pyx_n_u_multiprocess,&__pyx_mstate_global->__pyx_n_u_num_processes,&__pyx_mstate_global->__pyx_n_u_num_rows,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 542, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values, kwd_pos_args, __pyx_kwds_len, "read_file_in_chunks", 1) < 0) __PYX_ERR(0, 542, __pyx_L3_error) if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_100000))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_0))); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_0))); /* "pyreadstat/pyreadstat.pyx":543 * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, * multiprocess=False, num_processes=4, num_rows=None, **kwargs): # <<<<<<<<<<<<<< * """ * Returns a generator that will allow to read a file in chunks. */ if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_4))); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject *)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_file_in_chunks", 0, 2, 8, i); __PYX_ERR(0, 542, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 542, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 542, __pyx_L3_error) values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 542, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_100000))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_0))); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_0))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject *)((PyObject*)__pyx_mstate_global->__pyx_int_4))); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject *)Py_None)); } __pyx_v_read_function = values[0]; __pyx_v_file_path = values[1]; __pyx_v_chunksize = values[2]; __pyx_v_offset = values[3]; __pyx_v_limit = values[4]; __pyx_v_multiprocess = values[5]; __pyx_v_num_processes = values[6]; __pyx_v_num_rows = values[7]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_file_in_chunks", 0, 2, 8, __pyx_nargs); __PYX_ERR(0, 542, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_CLEAR(__pyx_v_kwargs); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_file_in_chunks", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_12read_file_in_chunks(__pyx_self, __pyx_v_read_function, __pyx_v_file_path, __pyx_v_chunksize, __pyx_v_offset, __pyx_v_limit, __pyx_v_multiprocess, __pyx_v_num_processes, __pyx_v_num_rows, __pyx_v_kwargs); /* "pyreadstat/pyreadstat.pyx":542 * # convenience functions to read in chunks * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, # <<<<<<<<<<<<<< * multiprocess=False, num_processes=4, num_rows=None, **kwargs): * """ */ /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_DECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_12read_file_in_chunks(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_read_function, PyObject *__pyx_v_file_path, PyObject *__pyx_v_chunksize, PyObject *__pyx_v_offset, PyObject *__pyx_v_limit, PyObject *__pyx_v_multiprocess, PyObject *__pyx_v_num_processes, PyObject *__pyx_v_num_rows, PyObject *__pyx_v_kwargs) { struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_file_in_chunks", 0); __pyx_cur_scope = (struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *)__pyx_tp_new_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks(__pyx_mstate_global->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks, __pyx_mstate_global->__pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *)Py_None); __Pyx_INCREF(Py_None); __PYX_ERR(0, 542, __pyx_L1_error) } else { __Pyx_GOTREF((PyObject *)__pyx_cur_scope); } __pyx_cur_scope->__pyx_v_read_function = __pyx_v_read_function; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_read_function); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_read_function); __pyx_cur_scope->__pyx_v_file_path = __pyx_v_file_path; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_file_path); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_file_path); __pyx_cur_scope->__pyx_v_chunksize = __pyx_v_chunksize; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chunksize); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chunksize); __pyx_cur_scope->__pyx_v_offset = __pyx_v_offset; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_offset); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_offset); __pyx_cur_scope->__pyx_v_limit = __pyx_v_limit; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_limit); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_limit); __pyx_cur_scope->__pyx_v_multiprocess = __pyx_v_multiprocess; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_multiprocess); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_multiprocess); __pyx_cur_scope->__pyx_v_num_processes = __pyx_v_num_processes; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_num_processes); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_num_processes); __pyx_cur_scope->__pyx_v_num_rows = __pyx_v_num_rows; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_num_rows); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_num_rows); __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs); { __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_10pyreadstat_10pyreadstat_14generator, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0]), (PyObject *) __pyx_cur_scope, __pyx_mstate_global->__pyx_n_u_read_file_in_chunks, __pyx_mstate_global->__pyx_n_u_read_file_in_chunks, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat); if (unlikely(!gen)) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; } /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("pyreadstat.pyreadstat.read_file_in_chunks", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_DECREF((PyObject *)__pyx_cur_scope); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_gb_10pyreadstat_10pyreadstat_14generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *__pyx_cur_scope = ((struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *)__pyx_generator->closure); PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; size_t __pyx_t_5; PyObject *__pyx_t_6 = NULL; PyObject *(*__pyx_t_7)(PyObject *); int __pyx_t_8; Py_ssize_t __pyx_t_9; PyObject *__pyx_t_10 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_file_in_chunks", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L24_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; if (unlikely(__pyx_sent_value != Py_None)) { if (unlikely(__pyx_sent_value)) PyErr_SetString(PyExc_TypeError, "can't send non-None value to a just-started generator"); __PYX_ERR(0, 542, __pyx_L1_error) } /* "pyreadstat/pyreadstat.pyx":588 * """ * * if read_function == read_sas7bcat: # <<<<<<<<<<<<<< * raise Exception("read_sas7bcat not supported") * */ __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_read_sas7bcat); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_read_function, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(__pyx_t_3)) { /* "pyreadstat/pyreadstat.pyx":589 * * if read_function == read_sas7bcat: * raise Exception("read_sas7bcat not supported") # <<<<<<<<<<<<<< * * if "row_offset" in kwargs: */ __pyx_t_1 = NULL; __Pyx_INCREF((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_4 = ((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_5 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_read_sas7bcat_not_supported}; __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_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 589, __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, 589, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":588 * """ * * if read_function == read_sas7bcat: # <<<<<<<<<<<<<< * raise Exception("read_sas7bcat not supported") * */ } /* "pyreadstat/pyreadstat.pyx":591 * raise Exception("read_sas7bcat not supported") * * if "row_offset" in kwargs: # <<<<<<<<<<<<<< * _ = kwargs.pop("row_offset") * */ __pyx_t_3 = (__Pyx_PyDict_ContainsTF(__pyx_mstate_global->__pyx_n_u_row_offset, __pyx_cur_scope->__pyx_v_kwargs, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 591, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/pyreadstat.pyx":592 * * if "row_offset" in kwargs: * _ = kwargs.pop("row_offset") # <<<<<<<<<<<<<< * * if "row_limit" in kwargs: */ __pyx_t_2 = __Pyx_PyDict_Pop(__pyx_cur_scope->__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_row_offset, ((PyObject *)NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_cur_scope->__pyx_v__ = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":591 * raise Exception("read_sas7bcat not supported") * * if "row_offset" in kwargs: # <<<<<<<<<<<<<< * _ = kwargs.pop("row_offset") * */ } /* "pyreadstat/pyreadstat.pyx":594 * _ = kwargs.pop("row_offset") * * if "row_limit" in kwargs: # <<<<<<<<<<<<<< * _ = kwargs.pop("row_limit") * */ __pyx_t_3 = (__Pyx_PyDict_ContainsTF(__pyx_mstate_global->__pyx_n_u_row_limit, __pyx_cur_scope->__pyx_v_kwargs, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 594, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/pyreadstat.pyx":595 * * if "row_limit" in kwargs: * _ = kwargs.pop("row_limit") # <<<<<<<<<<<<<< * * if "num_processes" in kwargs: */ __pyx_t_2 = __Pyx_PyDict_Pop(__pyx_cur_scope->__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_row_limit, ((PyObject *)NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v__); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v__, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":594 * _ = kwargs.pop("row_offset") * * if "row_limit" in kwargs: # <<<<<<<<<<<<<< * _ = kwargs.pop("row_limit") * */ } /* "pyreadstat/pyreadstat.pyx":597 * _ = kwargs.pop("row_limit") * * if "num_processes" in kwargs: # <<<<<<<<<<<<<< * _ = kwargs.pop("num_processes") * */ __pyx_t_3 = (__Pyx_PyDict_ContainsTF(__pyx_mstate_global->__pyx_n_u_num_processes, __pyx_cur_scope->__pyx_v_kwargs, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 597, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/pyreadstat.pyx":598 * * if "num_processes" in kwargs: * _ = kwargs.pop("num_processes") # <<<<<<<<<<<<<< * * _, meta = read_function(file_path, metadataonly=True) */ __pyx_t_2 = __Pyx_PyDict_Pop(__pyx_cur_scope->__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_num_processes, ((PyObject *)NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v__); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v__, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":597 * _ = kwargs.pop("row_limit") * * if "num_processes" in kwargs: # <<<<<<<<<<<<<< * _ = kwargs.pop("num_processes") * */ } /* "pyreadstat/pyreadstat.pyx":600 * _ = kwargs.pop("num_processes") * * _, meta = read_function(file_path, metadataonly=True) # <<<<<<<<<<<<<< * numrows = meta.number_rows * if numrows: */ __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_read_function); __pyx_t_1 = __pyx_cur_scope->__pyx_v_read_function; __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); assert(__pyx_t_4); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_1, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_cur_scope->__pyx_v_file_path}; __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_metadataonly, Py_True, __pyx_t_6, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 600, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_1, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 600, __pyx_L1_error) __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, 600, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_6); } else { __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); __pyx_t_6 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_6); } #else __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_1 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); index = 1; __pyx_t_6 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 2) < 0) __PYX_ERR(0, 600, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L9_unpacking_done; __pyx_L8_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 600, __pyx_L1_error) __pyx_L9_unpacking_done:; } __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v__); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v__, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_t_6); __pyx_cur_scope->__pyx_v_meta = __pyx_t_6; __pyx_t_6 = 0; /* "pyreadstat/pyreadstat.pyx":601 * * _, meta = read_function(file_path, metadataonly=True) * numrows = meta.number_rows # <<<<<<<<<<<<<< * if numrows: * if not limit: */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_meta, __pyx_mstate_global->__pyx_n_u_number_rows); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_cur_scope->__pyx_v_numrows = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":602 * _, meta = read_function(file_path, metadataonly=True) * numrows = meta.number_rows * if numrows: # <<<<<<<<<<<<<< * if not limit: * limit = numrows */ __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_numrows); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 602, __pyx_L1_error) if (__pyx_t_3) { /* "pyreadstat/pyreadstat.pyx":603 * numrows = meta.number_rows * if numrows: * if not limit: # <<<<<<<<<<<<<< * limit = numrows * else: */ __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_limit); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 603, __pyx_L1_error) __pyx_t_8 = (!__pyx_t_3); if (__pyx_t_8) { /* "pyreadstat/pyreadstat.pyx":604 * if numrows: * if not limit: * limit = numrows # <<<<<<<<<<<<<< * else: * limit = min(offset+limit, numrows) */ __Pyx_INCREF(__pyx_cur_scope->__pyx_v_numrows); __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_limit); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_limit, __pyx_cur_scope->__pyx_v_numrows); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_numrows); /* "pyreadstat/pyreadstat.pyx":603 * numrows = meta.number_rows * if numrows: * if not limit: # <<<<<<<<<<<<<< * limit = numrows * else: */ goto __pyx_L11; } /* "pyreadstat/pyreadstat.pyx":606 * limit = numrows * else: * limit = min(offset+limit, numrows) # <<<<<<<<<<<<<< * else: * if limit: */ /*else*/ { __Pyx_INCREF(__pyx_cur_scope->__pyx_v_numrows); __pyx_t_2 = __pyx_cur_scope->__pyx_v_numrows; __pyx_t_6 = PyNumber_Add(__pyx_cur_scope->__pyx_v_offset, __pyx_cur_scope->__pyx_v_limit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 606, __pyx_L1_error) __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_8) { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; } else { __Pyx_INCREF(__pyx_t_6); __pyx_t_1 = __pyx_t_6; } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_limit); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_limit, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; } __pyx_L11:; /* "pyreadstat/pyreadstat.pyx":602 * _, meta = read_function(file_path, metadataonly=True) * numrows = meta.number_rows * if numrows: # <<<<<<<<<<<<<< * if not limit: * limit = numrows */ goto __pyx_L10; } /* "pyreadstat/pyreadstat.pyx":608 * limit = min(offset+limit, numrows) * else: * if limit: # <<<<<<<<<<<<<< * limit = offset + limit * df = [0] */ /*else*/ { __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_limit); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 608, __pyx_L1_error) if (__pyx_t_8) { /* "pyreadstat/pyreadstat.pyx":609 * else: * if limit: * limit = offset + limit # <<<<<<<<<<<<<< * df = [0] * while len(df): */ __pyx_t_2 = PyNumber_Add(__pyx_cur_scope->__pyx_v_offset, __pyx_cur_scope->__pyx_v_limit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 609, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_limit); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_limit, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":608 * limit = min(offset+limit, numrows) * else: * if limit: # <<<<<<<<<<<<<< * limit = offset + limit * df = [0] */ } } __pyx_L10:; /* "pyreadstat/pyreadstat.pyx":610 * if limit: * limit = offset + limit * df = [0] # <<<<<<<<<<<<<< * while len(df): * if limit and (offset >= limit): */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0); if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 610, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); __pyx_cur_scope->__pyx_v_df = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":611 * limit = offset + limit * df = [0] * while len(df): # <<<<<<<<<<<<<< * if limit and (offset >= limit): * break */ while (1) { __pyx_t_9 = PyObject_Length(__pyx_cur_scope->__pyx_v_df); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 611, __pyx_L1_error) __pyx_t_8 = (__pyx_t_9 != 0); if (!__pyx_t_8) break; /* "pyreadstat/pyreadstat.pyx":612 * df = [0] * while len(df): * if limit and (offset >= limit): # <<<<<<<<<<<<<< * break * if multiprocess: */ __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_limit); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 612, __pyx_L1_error) if (__pyx_t_3) { } else { __pyx_t_8 = __pyx_t_3; goto __pyx_L16_bool_binop_done; } __pyx_t_2 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_offset, __pyx_cur_scope->__pyx_v_limit, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 612, __pyx_L1_error) __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 612, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = __pyx_t_3; __pyx_L16_bool_binop_done:; if (__pyx_t_8) { /* "pyreadstat/pyreadstat.pyx":613 * while len(df): * if limit and (offset >= limit): * break # <<<<<<<<<<<<<< * if multiprocess: * df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, */ goto __pyx_L14_break; /* "pyreadstat/pyreadstat.pyx":612 * df = [0] * while len(df): * if limit and (offset >= limit): # <<<<<<<<<<<<<< * break * if multiprocess: */ } /* "pyreadstat/pyreadstat.pyx":614 * if limit and (offset >= limit): * break * if multiprocess: # <<<<<<<<<<<<<< * df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, * row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) */ __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_multiprocess); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 614, __pyx_L1_error) if (__pyx_t_8) { /* "pyreadstat/pyreadstat.pyx":615 * break * if multiprocess: * df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, # <<<<<<<<<<<<<< * row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) * else: */ __pyx_t_1 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_read_file_multiprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_10 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_num_processes, __pyx_cur_scope->__pyx_v_num_processes) < 0) __PYX_ERR(0, 615, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":616 * if multiprocess: * df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, * row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) # <<<<<<<<<<<<<< * else: * df, meta = read_function(file_path, row_offset=offset, row_limit=chunksize, **kwargs) */ if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_row_offset, __pyx_cur_scope->__pyx_v_offset) < 0) __PYX_ERR(0, 615, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_row_limit, __pyx_cur_scope->__pyx_v_chunksize) < 0) __PYX_ERR(0, 615, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_num_rows, __pyx_cur_scope->__pyx_v_num_rows) < 0) __PYX_ERR(0, 615, __pyx_L1_error) __pyx_t_4 = __pyx_t_10; __pyx_t_10 = 0; if (__Pyx_MergeKeywords(__pyx_t_4, __pyx_cur_scope->__pyx_v_kwargs) < 0) __PYX_ERR(0, 616, __pyx_L1_error) __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_cur_scope->__pyx_v_read_function, __pyx_cur_scope->__pyx_v_file_path}; __pyx_t_2 = __Pyx_PyObject_FastCallDict(__pyx_t_6, __pyx_callargs+__pyx_t_5, (3-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 615, __pyx_L1_error) __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, 615, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_6); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_6 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_6); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); index = 0; __pyx_t_6 = __pyx_t_7(__pyx_t_1); if (unlikely(!__pyx_t_6)) goto __pyx_L19_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); index = 1; __pyx_t_4 = __pyx_t_7(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L19_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_1), 2) < 0) __PYX_ERR(0, 615, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L20_unpacking_done; __pyx_L19_unpacking_failed:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 615, __pyx_L1_error) __pyx_L20_unpacking_done:; } /* "pyreadstat/pyreadstat.pyx":615 * break * if multiprocess: * df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, # <<<<<<<<<<<<<< * row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) * else: */ __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_df); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_df, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_meta); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_meta, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":614 * if limit and (offset >= limit): * break * if multiprocess: # <<<<<<<<<<<<<< * df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, * row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) */ goto __pyx_L18; } /* "pyreadstat/pyreadstat.pyx":618 * row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) * else: * df, meta = read_function(file_path, row_offset=offset, row_limit=chunksize, **kwargs) # <<<<<<<<<<<<<< * if len(df): * yield df, meta */ /*else*/ { __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_read_function); __pyx_t_6 = __pyx_cur_scope->__pyx_v_read_function; __pyx_t_10 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_row_offset, __pyx_cur_scope->__pyx_v_offset) < 0) __PYX_ERR(0, 618, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_row_limit, __pyx_cur_scope->__pyx_v_chunksize) < 0) __PYX_ERR(0, 618, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_t_10 = 0; if (__Pyx_MergeKeywords(__pyx_t_1, __pyx_cur_scope->__pyx_v_kwargs) < 0) __PYX_ERR(0, 618, __pyx_L1_error) __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_4); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_cur_scope->__pyx_v_file_path}; __pyx_t_2 = __Pyx_PyObject_FastCallDict(__pyx_t_6, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 618, __pyx_L1_error) __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, 618, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_6); __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_1); } else { __pyx_t_6 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_6); __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); } #else __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_6 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L21_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); index = 1; __pyx_t_1 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L21_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 2) < 0) __PYX_ERR(0, 618, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L22_unpacking_done; __pyx_L21_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 618, __pyx_L1_error) __pyx_L22_unpacking_done:; } __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_df); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_df, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_meta); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_meta, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L18:; /* "pyreadstat/pyreadstat.pyx":619 * else: * df, meta = read_function(file_path, row_offset=offset, row_limit=chunksize, **kwargs) * if len(df): # <<<<<<<<<<<<<< * yield df, meta * offset += chunksize */ __pyx_t_9 = PyObject_Length(__pyx_cur_scope->__pyx_v_df); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 619, __pyx_L1_error) __pyx_t_8 = (__pyx_t_9 != 0); if (__pyx_t_8) { /* "pyreadstat/pyreadstat.pyx":620 * df, meta = read_function(file_path, row_offset=offset, row_limit=chunksize, **kwargs) * if len(df): * yield df, meta # <<<<<<<<<<<<<< * offset += chunksize * */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 620, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_df); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_df); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_df) != (0)) __PYX_ERR(0, 620, __pyx_L1_error); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_meta); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_meta); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_meta) != (0)) __PYX_ERR(0, 620, __pyx_L1_error); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); __Pyx_Coroutine_ResetAndClearException(__pyx_generator); /* return from generator, yielding value */ __pyx_generator->resume_label = 1; return __pyx_r; __pyx_L24_resume_from_yield:; if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 620, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":621 * if len(df): * yield df, meta * offset += chunksize # <<<<<<<<<<<<<< * * def read_file_multiprocessing(read_function, file_path, num_processes=None, num_rows=None, **kwargs): */ __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_cur_scope->__pyx_v_offset, __pyx_cur_scope->__pyx_v_chunksize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 621, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_offset); __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_offset, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":619 * else: * df, meta = read_function(file_path, row_offset=offset, row_limit=chunksize, **kwargs) * if len(df): # <<<<<<<<<<<<<< * yield df, meta * offset += chunksize */ } } __pyx_L14_break:; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); /* "pyreadstat/pyreadstat.pyx":542 * # convenience functions to read in chunks * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, # <<<<<<<<<<<<<< * multiprocess=False, num_processes=4, num_rows=None, **kwargs): * """ */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_10); if (__Pyx_PyErr_Occurred()) { __Pyx_AddTraceback("read_file_in_chunks", __pyx_clineno, __pyx_lineno, __pyx_filename); } __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); #if !CYTHON_USE_EXC_INFO_STACK __Pyx_Coroutine_ResetAndClearException(__pyx_generator); #endif __pyx_generator->resume_label = -1; __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":623 * offset += chunksize * * def read_file_multiprocessing(read_function, file_path, num_processes=None, num_rows=None, **kwargs): # <<<<<<<<<<<<<< * """ * Reads a file in parallel using multiprocessing. */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_16read_file_multiprocessing(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_15read_file_multiprocessing, "\n Reads a file in parallel using multiprocessing.\n For Xport, Por and some defective sav files where the number of rows in the dataset canot be obtained from the metadata, \n the parameter num_rows must be set to a number equal or larger than the number of rows in the dataset. That information must\n be obtained by the user before running this function.\n\n Parameters\n ----------\n read_function : pyreadstat function\n a pyreadstat reading function\n file_path : string\n path to the file to be read\n num_processes : integer, optional\n number of processes to spawn, by default the min 4 and the max cores on the computer\n num_rows: integer, optional\n number of rows in the dataset. Obligatory for files where the number of rows cannot be obtained from the medatata, such as por and \n some defective xport and sav files. The user must obtain this value by reading the file without multiprocessing first or any other means. A number\n larger than the actual number of rows will work as well. Discarded if the number of rows can be obtained from the metadata.\n kwargs : dict, optional\n any other keyword argument to pass to the read_function. \n\n Returns\n -------\n data_frame : dataframe\n a dataframe with the data\n metadata :\n object with metadata. Look at the documentation for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_16read_file_multiprocessing = {"read_file_multiprocessing", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_16read_file_multiprocessing, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_15read_file_multiprocessing}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_16read_file_multiprocessing(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_read_function = 0; PyObject *__pyx_v_file_path = 0; PyObject *__pyx_v_num_processes = 0; PyObject *__pyx_v_num_rows = 0; PyObject *__pyx_v_kwargs = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[4] = {0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_file_multiprocessing (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; __Pyx_GOTREF(__pyx_v_kwargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_read_function,&__pyx_mstate_global->__pyx_n_u_file_path,&__pyx_mstate_global->__pyx_n_u_num_processes,&__pyx_mstate_global->__pyx_n_u_num_rows,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 623, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 623, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 623, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 623, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 623, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values, kwd_pos_args, __pyx_kwds_len, "read_file_multiprocessing", 1) < 0) __PYX_ERR(0, 623, __pyx_L3_error) if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("read_file_multiprocessing", 0, 2, 4, i); __PYX_ERR(0, 623, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 623, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 623, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 623, __pyx_L3_error) values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 623, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[2]) values[2] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); } __pyx_v_read_function = values[0]; __pyx_v_file_path = values[1]; __pyx_v_num_processes = values[2]; __pyx_v_num_rows = values[3]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_file_multiprocessing", 0, 2, 4, __pyx_nargs); __PYX_ERR(0, 623, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("pyreadstat.pyreadstat.read_file_multiprocessing", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_15read_file_multiprocessing(__pyx_self, __pyx_v_read_function, __pyx_v_file_path, __pyx_v_num_processes, __pyx_v_num_rows, __pyx_v_kwargs); /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_DECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_15read_file_multiprocessing(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_read_function, PyObject *__pyx_v_file_path, PyObject *__pyx_v_num_processes, PyObject *__pyx_v_num_rows, PyObject *__pyx_v_kwargs) { CYTHON_UNUSED PyObject *__pyx_v__ = NULL; PyObject *__pyx_v_row_offset = NULL; PyObject *__pyx_v_row_limit = NULL; PyObject *__pyx_v_meta = NULL; PyObject *__pyx_v_numrows = NULL; PyObject *__pyx_v_final = NULL; PyObject *__pyx_v_divs = NULL; PyObject *__pyx_v_offsets = NULL; PyObject *__pyx_v_prev_offset = NULL; PyObject *__pyx_v_prev_div = NULL; CYTHON_UNUSED PyObject *__pyx_v_indx = NULL; PyObject *__pyx_v_div = NULL; PyObject *__pyx_v_offset = NULL; PyObject *__pyx_v_jobs = NULL; PyObject *__pyx_v_pool = NULL; PyObject *__pyx_v_chunks = NULL; PyObject *__pyx_v_output_format = NULL; PyObject *__pyx_v_keys = NULL; PyObject *__pyx_v_key = NULL; int __pyx_v_ispandas; PyObject *__pyx_v_x = NULL; PyObject *__pyx_v_chunksize = NULL; PyObject *__pyx_v_chunk = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; size_t __pyx_t_6; long __pyx_t_7; PyObject *__pyx_t_8 = NULL; double __pyx_t_9; PyObject *__pyx_t_10 = NULL; PyObject *(*__pyx_t_11)(PyObject *); Py_ssize_t __pyx_t_12; PyObject *(*__pyx_t_13)(PyObject *); PyObject *__pyx_t_14 = NULL; int __pyx_t_15; PyObject *__pyx_t_16 = NULL; PyObject *__pyx_t_17 = NULL; PyObject *__pyx_t_18 = NULL; int __pyx_t_19; int __pyx_t_20; char const *__pyx_t_21; PyObject *__pyx_t_22 = NULL; PyObject *__pyx_t_23 = NULL; PyObject *__pyx_t_24 = NULL; Py_ssize_t __pyx_t_25; PyObject *(*__pyx_t_26)(PyObject *); PyObject *__pyx_t_27 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_file_multiprocessing", 0); __Pyx_INCREF(__pyx_v_num_processes); /* "pyreadstat/pyreadstat.pyx":653 * """ * * if read_function in (read_sas7bcat,): # <<<<<<<<<<<<<< * raise Exception("read_sas7bcat is not supported") * */ __Pyx_INCREF(__pyx_v_read_function); __pyx_t_1 = __pyx_v_read_function; __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_read_sas7bcat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 653, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 653, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 653, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = __pyx_t_4; if (unlikely(__pyx_t_5)) { /* "pyreadstat/pyreadstat.pyx":654 * * if read_function in (read_sas7bcat,): * raise Exception("read_sas7bcat is not supported") # <<<<<<<<<<<<<< * * if read_function == read_por and num_rows is None: */ __pyx_t_3 = NULL; __Pyx_INCREF((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_2 = ((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_read_sas7bcat_is_not_supported}; __pyx_t_1 = __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_1)) __PYX_ERR(0, 654, __pyx_L1_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, 654, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":653 * """ * * if read_function in (read_sas7bcat,): # <<<<<<<<<<<<<< * raise Exception("read_sas7bcat is not supported") * */ } /* "pyreadstat/pyreadstat.pyx":656 * raise Exception("read_sas7bcat is not supported") * * if read_function == read_por and num_rows is None: # <<<<<<<<<<<<<< * raise Exception("num_rows must be specified for read_por to be a number equal or larger than the number of rows in the dataset.") * */ __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_read_por); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_RichCompare(__pyx_v_read_function, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_4) { } else { __pyx_t_5 = __pyx_t_4; goto __pyx_L5_bool_binop_done; } __pyx_t_4 = (__pyx_v_num_rows == Py_None); __pyx_t_5 = __pyx_t_4; __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_5)) { /* "pyreadstat/pyreadstat.pyx":657 * * if read_function == read_por and num_rows is None: * raise Exception("num_rows must be specified for read_por to be a number equal or larger than the number of rows in the dataset.") # <<<<<<<<<<<<<< * * if not num_processes: */ __pyx_t_1 = NULL; __Pyx_INCREF((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_3 = ((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_num_rows_must_be_specified_for_r}; __pyx_t_2 = __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_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 657, __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, 657, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":656 * raise Exception("read_sas7bcat is not supported") * * if read_function == read_por and num_rows is None: # <<<<<<<<<<<<<< * raise Exception("num_rows must be specified for read_por to be a number equal or larger than the number of rows in the dataset.") * */ } /* "pyreadstat/pyreadstat.pyx":659 * raise Exception("num_rows must be specified for read_por to be a number equal or larger than the number of rows in the dataset.") * * if not num_processes: # <<<<<<<<<<<<<< * # let's be conservative with the number of workers * num_processes = min(mp.cpu_count(), 4) */ __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_num_processes); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 659, __pyx_L1_error) __pyx_t_4 = (!__pyx_t_5); if (__pyx_t_4) { /* "pyreadstat/pyreadstat.pyx":661 * if not num_processes: * # let's be conservative with the number of workers * num_processes = min(mp.cpu_count(), 4) # <<<<<<<<<<<<<< * _ = kwargs.pop('metadataonly', None) * row_offset = kwargs.pop("row_offset", 0) */ __pyx_t_7 = 4; __pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_mp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_cpu_count); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_8, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_3 = __Pyx_PyLong_From_long(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_4) { __pyx_t_1 = __Pyx_PyLong_From_long(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __pyx_t_1; __pyx_t_1 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = __pyx_t_2; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __pyx_t_8; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_num_processes, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":659 * raise Exception("num_rows must be specified for read_por to be a number equal or larger than the number of rows in the dataset.") * * if not num_processes: # <<<<<<<<<<<<<< * # let's be conservative with the number of workers * num_processes = min(mp.cpu_count(), 4) */ } /* "pyreadstat/pyreadstat.pyx":662 * # let's be conservative with the number of workers * num_processes = min(mp.cpu_count(), 4) * _ = kwargs.pop('metadataonly', None) # <<<<<<<<<<<<<< * row_offset = kwargs.pop("row_offset", 0) * row_limit = kwargs.pop("row_limit", float('inf')) */ __pyx_t_2 = __Pyx_PyDict_Pop(__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_metadataonly, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 662, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v__ = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":663 * num_processes = min(mp.cpu_count(), 4) * _ = kwargs.pop('metadataonly', None) * row_offset = kwargs.pop("row_offset", 0) # <<<<<<<<<<<<<< * row_limit = kwargs.pop("row_limit", float('inf')) * _, meta = read_function(file_path, metadataonly=True, **kwargs) */ __pyx_t_2 = __Pyx_PyDict_Pop(__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_row_offset, __pyx_mstate_global->__pyx_int_0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 663, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_row_offset = __pyx_t_2; __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":664 * _ = kwargs.pop('metadataonly', None) * row_offset = kwargs.pop("row_offset", 0) * row_limit = kwargs.pop("row_limit", float('inf')) # <<<<<<<<<<<<<< * _, meta = read_function(file_path, metadataonly=True, **kwargs) * numrows = meta.number_rows */ __pyx_t_9 = __Pyx_PyUnicode_AsDouble(__pyx_mstate_global->__pyx_n_u_inf); if (unlikely(__pyx_t_9 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 664, __pyx_L1_error) __pyx_t_2 = PyFloat_FromDouble(__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 664, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_8 = __Pyx_PyDict_Pop(__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_row_limit, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 664, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_row_limit = __pyx_t_8; __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":665 * row_offset = kwargs.pop("row_offset", 0) * row_limit = kwargs.pop("row_limit", float('inf')) * _, meta = read_function(file_path, metadataonly=True, **kwargs) # <<<<<<<<<<<<<< * numrows = meta.number_rows * */ __pyx_t_2 = NULL; __Pyx_INCREF(__pyx_v_read_function); __pyx_t_1 = __pyx_v_read_function; __pyx_t_10 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (PyDict_SetItem(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_metadataonly, Py_True) < 0) __PYX_ERR(0, 665, __pyx_L1_error) __pyx_t_3 = __pyx_t_10; __pyx_t_10 = 0; if (__Pyx_MergeKeywords(__pyx_t_3, __pyx_v_kwargs) < 0) __PYX_ERR(0, 665, __pyx_L1_error) __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_1, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_file_path}; __pyx_t_8 = __Pyx_PyObject_FastCallDict(__pyx_t_1, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_3); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { PyObject* sequence = __pyx_t_8; 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, 665, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { Py_ssize_t index = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 665, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); index = 0; __pyx_t_1 = __pyx_t_11(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); index = 1; __pyx_t_3 = __pyx_t_11(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_2), 2) < 0) __PYX_ERR(0, 665, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L9_unpacking_done; __pyx_L8_unpacking_failed:; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 665, __pyx_L1_error) __pyx_L9_unpacking_done:; } __Pyx_DECREF_SET(__pyx_v__, __pyx_t_1); __pyx_t_1 = 0; __pyx_v_meta = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":666 * row_limit = kwargs.pop("row_limit", float('inf')) * _, meta = read_function(file_path, metadataonly=True, **kwargs) * numrows = meta.number_rows # <<<<<<<<<<<<<< * * if numrows is None: */ __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_meta, __pyx_mstate_global->__pyx_n_u_number_rows); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 666, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_numrows = __pyx_t_8; __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":668 * numrows = meta.number_rows * * if numrows is None: # <<<<<<<<<<<<<< * if num_rows is None: * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") */ __pyx_t_4 = (__pyx_v_numrows == Py_None); if (__pyx_t_4) { /* "pyreadstat/pyreadstat.pyx":669 * * if numrows is None: * if num_rows is None: # <<<<<<<<<<<<<< * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") * numrows = num_rows */ __pyx_t_4 = (__pyx_v_num_rows == Py_None); if (unlikely(__pyx_t_4)) { /* "pyreadstat/pyreadstat.pyx":670 * if numrows is None: * if num_rows is None: * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") # <<<<<<<<<<<<<< * numrows = num_rows * elif numrows == 0: */ __pyx_t_3 = NULL; __Pyx_INCREF((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_1 = ((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_The_number_of_rows_of_the_file_c}; __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_1, __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_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 670, __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, 670, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":669 * * if numrows is None: * if num_rows is None: # <<<<<<<<<<<<<< * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") * numrows = num_rows */ } /* "pyreadstat/pyreadstat.pyx":671 * if num_rows is None: * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") * numrows = num_rows # <<<<<<<<<<<<<< * elif numrows == 0: * final, meta = read_function(file_path, **kwargs) */ __Pyx_INCREF(__pyx_v_num_rows); __Pyx_DECREF_SET(__pyx_v_numrows, __pyx_v_num_rows); /* "pyreadstat/pyreadstat.pyx":668 * numrows = meta.number_rows * * if numrows is None: # <<<<<<<<<<<<<< * if num_rows is None: * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") */ goto __pyx_L10; } /* "pyreadstat/pyreadstat.pyx":672 * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") * numrows = num_rows * elif numrows == 0: # <<<<<<<<<<<<<< * final, meta = read_function(file_path, **kwargs) * */ __pyx_t_4 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_numrows, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 672, __pyx_L1_error) if (__pyx_t_4) { /* "pyreadstat/pyreadstat.pyx":673 * numrows = num_rows * elif numrows == 0: * final, meta = read_function(file_path, **kwargs) # <<<<<<<<<<<<<< * * numrows = min(max(numrows - row_offset, 0), row_limit) */ __pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_read_function); __pyx_t_3 = __pyx_v_read_function; __pyx_t_2 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_file_path}; __pyx_t_8 = __Pyx_PyObject_FastCallDict(__pyx_t_3, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { PyObject* sequence = __pyx_t_8; 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, 673, __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_2 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_2); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { Py_ssize_t index = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); index = 0; __pyx_t_3 = __pyx_t_11(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_2 = __pyx_t_11(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_1), 2) < 0) __PYX_ERR(0, 673, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L13_unpacking_done; __pyx_L12_unpacking_failed:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 673, __pyx_L1_error) __pyx_L13_unpacking_done:; } __pyx_v_final = __pyx_t_3; __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_meta, __pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":672 * raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") * numrows = num_rows * elif numrows == 0: # <<<<<<<<<<<<<< * final, meta = read_function(file_path, **kwargs) * */ } __pyx_L10:; /* "pyreadstat/pyreadstat.pyx":675 * final, meta = read_function(file_path, **kwargs) * * numrows = min(max(numrows - row_offset, 0), row_limit) # <<<<<<<<<<<<<< * divs = [numrows // num_processes + (1 if x < numrows % num_processes else 0) for x in range (num_processes)] * offsets = list() */ __Pyx_INCREF(__pyx_v_row_limit); __pyx_t_8 = __pyx_v_row_limit; __pyx_t_7 = 0; __pyx_t_2 = PyNumber_Subtract(__pyx_v_numrows, __pyx_v_row_offset); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyLong_From_long(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_10 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if (__pyx_t_4) { __pyx_t_10 = __Pyx_PyLong_From_long(__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_3 = __pyx_t_10; __pyx_t_10 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_10 = PyObject_RichCompare(__pyx_t_8, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 675, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if (__pyx_t_4) { __Pyx_INCREF(__pyx_t_8); __pyx_t_3 = __pyx_t_8; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __pyx_t_3; __Pyx_INCREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_numrows, __pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":676 * * numrows = min(max(numrows - row_offset, 0), row_limit) * divs = [numrows // num_processes + (1 if x < numrows % num_processes else 0) for x in range (num_processes)] # <<<<<<<<<<<<<< * offsets = list() * prev_offset = row_offset */ __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = NULL; __Pyx_INCREF(__pyx_builtin_range); __pyx_t_10 = __pyx_builtin_range; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_num_processes}; __pyx_t_3 = __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_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { __pyx_t_10 = __pyx_t_3; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0; __pyx_t_13 = NULL; } else { __pyx_t_12 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_13 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 676, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; for (;;) { if (likely(!__pyx_t_13)) { if (likely(PyList_CheckExact(__pyx_t_10))) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_10); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 676, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } __pyx_t_3 = __Pyx_PyList_GetItemRef(__pyx_t_10, __pyx_t_12); ++__pyx_t_12; } else { { Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_10); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 676, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_3 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_12)); #else __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_10, __pyx_t_12); #endif ++__pyx_t_12; } if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 676, __pyx_L1_error) } else { __pyx_t_3 = __pyx_t_13(__pyx_t_10); 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, 676, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_FloorDivide(__pyx_v_numrows, __pyx_v_num_processes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyNumber_Remainder(__pyx_v_numrows, __pyx_v_num_processes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_14 = PyObject_RichCompare(__pyx_v_x, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (__pyx_t_4) { __Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __pyx_t_2 = __pyx_mstate_global->__pyx_int_1; } else { __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __pyx_t_2 = __pyx_mstate_global->__pyx_int_0; } __pyx_t_14 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 676, __pyx_L1_error) __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_divs = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":677 * numrows = min(max(numrows - row_offset, 0), row_limit) * divs = [numrows // num_processes + (1 if x < numrows % num_processes else 0) for x in range (num_processes)] * offsets = list() # <<<<<<<<<<<<<< * prev_offset = row_offset * prev_div = 0 */ __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 677, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_offsets = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":678 * divs = [numrows // num_processes + (1 if x < numrows % num_processes else 0) for x in range (num_processes)] * offsets = list() * prev_offset = row_offset # <<<<<<<<<<<<<< * prev_div = 0 * for indx, div in enumerate(divs): */ __Pyx_INCREF(__pyx_v_row_offset); __pyx_v_prev_offset = __pyx_v_row_offset; /* "pyreadstat/pyreadstat.pyx":679 * offsets = list() * prev_offset = row_offset * prev_div = 0 # <<<<<<<<<<<<<< * for indx, div in enumerate(divs): * offset = prev_offset + prev_div */ __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __pyx_v_prev_div = __pyx_mstate_global->__pyx_int_0; /* "pyreadstat/pyreadstat.pyx":680 * prev_offset = row_offset * prev_div = 0 * for indx, div in enumerate(divs): # <<<<<<<<<<<<<< * offset = prev_offset + prev_div * prev_offset = offset */ __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __pyx_t_8 = __pyx_mstate_global->__pyx_int_0; __pyx_t_10 = __pyx_v_divs; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0; for (;;) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_10); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 680, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } __pyx_t_14 = __Pyx_PyList_GetItemRef(__pyx_t_10, __pyx_t_12); ++__pyx_t_12; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 680, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_XDECREF_SET(__pyx_v_div, __pyx_t_14); __pyx_t_14 = 0; __Pyx_INCREF(__pyx_t_8); __Pyx_XDECREF_SET(__pyx_v_indx, __pyx_t_8); __pyx_t_14 = __Pyx_PyLong_AddObjC(__pyx_t_8, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 680, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = __pyx_t_14; __pyx_t_14 = 0; /* "pyreadstat/pyreadstat.pyx":681 * prev_div = 0 * for indx, div in enumerate(divs): * offset = prev_offset + prev_div # <<<<<<<<<<<<<< * prev_offset = offset * prev_div = div */ __pyx_t_14 = PyNumber_Add(__pyx_v_prev_offset, __pyx_v_prev_div); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 681, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_XDECREF_SET(__pyx_v_offset, __pyx_t_14); __pyx_t_14 = 0; /* "pyreadstat/pyreadstat.pyx":682 * for indx, div in enumerate(divs): * offset = prev_offset + prev_div * prev_offset = offset # <<<<<<<<<<<<<< * prev_div = div * offsets.append((offset, div)) */ __Pyx_INCREF(__pyx_v_offset); __Pyx_DECREF_SET(__pyx_v_prev_offset, __pyx_v_offset); /* "pyreadstat/pyreadstat.pyx":683 * offset = prev_offset + prev_div * prev_offset = offset * prev_div = div # <<<<<<<<<<<<<< * offsets.append((offset, div)) * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] */ __Pyx_INCREF(__pyx_v_div); __Pyx_DECREF_SET(__pyx_v_prev_div, __pyx_v_div); /* "pyreadstat/pyreadstat.pyx":684 * prev_offset = offset * prev_div = div * offsets.append((offset, div)) # <<<<<<<<<<<<<< * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] * pool = mp.Pool(processes=num_processes) */ __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 684, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_INCREF(__pyx_v_offset); __Pyx_GIVEREF(__pyx_v_offset); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_offset) != (0)) __PYX_ERR(0, 684, __pyx_L1_error); __Pyx_INCREF(__pyx_v_div); __Pyx_GIVEREF(__pyx_v_div); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_div) != (0)) __PYX_ERR(0, 684, __pyx_L1_error); __pyx_t_15 = __Pyx_PyList_Append(__pyx_v_offsets, __pyx_t_14); if (unlikely(__pyx_t_15 == ((int)-1))) __PYX_ERR(0, 684, __pyx_L1_error) __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; /* "pyreadstat/pyreadstat.pyx":680 * prev_offset = row_offset * prev_div = 0 * for indx, div in enumerate(divs): # <<<<<<<<<<<<<< * offset = prev_offset + prev_div * prev_offset = offset */ } __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":685 * prev_div = div * offsets.append((offset, div)) * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] # <<<<<<<<<<<<<< * pool = mp.Pool(processes=num_processes) * try: */ __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_10 = __pyx_v_offsets; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0; for (;;) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_10); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 685, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } __pyx_t_14 = __Pyx_PyList_GetItemRef(__pyx_t_10, __pyx_t_12); ++__pyx_t_12; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { PyObject* sequence = __pyx_t_14; 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, 685, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } else { Py_ssize_t index = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); index = 0; __pyx_t_2 = __pyx_t_11(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L22_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_3 = __pyx_t_11(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L22_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_1), 2) < 0) __PYX_ERR(0, 685, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L23_unpacking_done; __pyx_L22_unpacking_failed:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 685, __pyx_L1_error) __pyx_L23_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_offset, __pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF_SET(__pyx_v_chunksize, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_14 = PyTuple_New(5); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_INCREF(__pyx_v_read_function); __Pyx_GIVEREF(__pyx_v_read_function); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_read_function) != (0)) __PYX_ERR(0, 685, __pyx_L1_error); __Pyx_INCREF(__pyx_v_file_path); __Pyx_GIVEREF(__pyx_v_file_path); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_file_path) != (0)) __PYX_ERR(0, 685, __pyx_L1_error); __Pyx_INCREF(__pyx_v_offset); __Pyx_GIVEREF(__pyx_v_offset); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_v_offset) != (0)) __PYX_ERR(0, 685, __pyx_L1_error); __Pyx_INCREF(__pyx_v_chunksize); __Pyx_GIVEREF(__pyx_v_chunksize); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_v_chunksize) != (0)) __PYX_ERR(0, 685, __pyx_L1_error); __Pyx_INCREF(__pyx_v_kwargs); __Pyx_GIVEREF(__pyx_v_kwargs); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_v_kwargs) != (0)) __PYX_ERR(0, 685, __pyx_L1_error); if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 685, __pyx_L1_error) __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_jobs = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":686 * offsets.append((offset, div)) * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] * pool = mp.Pool(processes=num_processes) # <<<<<<<<<<<<<< * try: * chunks = pool.map(worker, jobs) */ __pyx_t_10 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_mstate_global->__pyx_n_u_mp); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 686, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_mstate_global->__pyx_n_u_Pool); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 686, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_10); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_10, NULL}; __pyx_t_14 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 686, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_processes, __pyx_v_num_processes, __pyx_t_14, __pyx_callargs+1, 0) < 0) __PYX_ERR(0, 686, __pyx_L1_error) __pyx_t_8 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_14); __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 686, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } __pyx_v_pool = __pyx_t_8; __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":687 * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] * pool = mp.Pool(processes=num_processes) * try: # <<<<<<<<<<<<<< * chunks = pool.map(worker, jobs) * except: */ /*try:*/ { { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); __Pyx_XGOTREF(__pyx_t_16); __Pyx_XGOTREF(__pyx_t_17); __Pyx_XGOTREF(__pyx_t_18); /*try:*/ { /* "pyreadstat/pyreadstat.pyx":688 * pool = mp.Pool(processes=num_processes) * try: * chunks = pool.map(worker, jobs) # <<<<<<<<<<<<<< * except: * raise */ __pyx_t_3 = __pyx_v_pool; __Pyx_INCREF(__pyx_t_3); __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_mstate_global->__pyx_n_u_worker); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 688, __pyx_L28_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_6 = 0; { PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_t_14, __pyx_v_jobs}; __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_map, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 688, __pyx_L28_error) __Pyx_GOTREF(__pyx_t_8); } __pyx_v_chunks = __pyx_t_8; __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":687 * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] * pool = mp.Pool(processes=num_processes) * try: # <<<<<<<<<<<<<< * chunks = pool.map(worker, jobs) * except: */ } __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; goto __pyx_L33_try_end; __pyx_L28_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":689 * try: * chunks = pool.map(worker, jobs) * except: # <<<<<<<<<<<<<< * raise * finally: */ /*except:*/ { __Pyx_AddTraceback("pyreadstat.pyreadstat.read_file_multiprocessing", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_14, &__pyx_t_3) < 0) __PYX_ERR(0, 689, __pyx_L30_except_error) __Pyx_XGOTREF(__pyx_t_8); __Pyx_XGOTREF(__pyx_t_14); __Pyx_XGOTREF(__pyx_t_3); /* "pyreadstat/pyreadstat.pyx":690 * chunks = pool.map(worker, jobs) * except: * raise # <<<<<<<<<<<<<< * finally: * pool.close() */ __Pyx_GIVEREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_14); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ErrRestoreWithState(__pyx_t_8, __pyx_t_14, __pyx_t_3); __pyx_t_8 = 0; __pyx_t_14 = 0; __pyx_t_3 = 0; __PYX_ERR(0, 690, __pyx_L30_except_error) } /* "pyreadstat/pyreadstat.pyx":687 * jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] * pool = mp.Pool(processes=num_processes) * try: # <<<<<<<<<<<<<< * chunks = pool.map(worker, jobs) * except: */ __pyx_L30_except_error:; __Pyx_XGIVEREF(__pyx_t_16); __Pyx_XGIVEREF(__pyx_t_17); __Pyx_XGIVEREF(__pyx_t_18); __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18); goto __pyx_L26_error; __pyx_L33_try_end:; } } /* "pyreadstat/pyreadstat.pyx":692 * raise * finally: * pool.close() # <<<<<<<<<<<<<< * output_format = kwargs.get("output_format") * if output_format == 'dict': */ /*finally:*/ { /*normal exit:*/{ __pyx_t_14 = __pyx_v_pool; __Pyx_INCREF(__pyx_t_14); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_14, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_close, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L27; } __pyx_L26_error:; /*exception exit:*/{ __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_ExceptionSwap(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24); if ( unlikely(__Pyx_GetException(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16); __Pyx_XGOTREF(__pyx_t_18); __Pyx_XGOTREF(__pyx_t_17); __Pyx_XGOTREF(__pyx_t_16); __Pyx_XGOTREF(__pyx_t_22); __Pyx_XGOTREF(__pyx_t_23); __Pyx_XGOTREF(__pyx_t_24); __pyx_t_19 = __pyx_lineno; __pyx_t_20 = __pyx_clineno; __pyx_t_21 = __pyx_filename; { __pyx_t_14 = __pyx_v_pool; __Pyx_INCREF(__pyx_t_14); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_14, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_close, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 692, __pyx_L37_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __Pyx_XGIVEREF(__pyx_t_22); __Pyx_XGIVEREF(__pyx_t_23); __Pyx_XGIVEREF(__pyx_t_24); __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_23, __pyx_t_24); __Pyx_XGIVEREF(__pyx_t_18); __Pyx_XGIVEREF(__pyx_t_17); __Pyx_XGIVEREF(__pyx_t_16); __Pyx_ErrRestore(__pyx_t_18, __pyx_t_17, __pyx_t_16); __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_lineno = __pyx_t_19; __pyx_clineno = __pyx_t_20; __pyx_filename = __pyx_t_21; goto __pyx_L1_error; __pyx_L37_error:; __Pyx_XGIVEREF(__pyx_t_22); __Pyx_XGIVEREF(__pyx_t_23); __Pyx_XGIVEREF(__pyx_t_24); __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_23, __pyx_t_24); __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; goto __pyx_L1_error; } __pyx_L27:; } /* "pyreadstat/pyreadstat.pyx":693 * finally: * pool.close() * output_format = kwargs.get("output_format") # <<<<<<<<<<<<<< * if output_format == 'dict': * keys = chunks[0].keys() */ __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_mstate_global->__pyx_n_u_output_format, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 693, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_output_format = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":694 * pool.close() * output_format = kwargs.get("output_format") * if output_format == 'dict': # <<<<<<<<<<<<<< * keys = chunks[0].keys() * final = dict() */ __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_output_format, __pyx_mstate_global->__pyx_n_u_dict, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 694, __pyx_L1_error) if (__pyx_t_4) { /* "pyreadstat/pyreadstat.pyx":695 * output_format = kwargs.get("output_format") * if output_format == 'dict': * keys = chunks[0].keys() # <<<<<<<<<<<<<< * final = dict() * for key in keys: */ __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_chunks, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_14 = __pyx_t_8; __Pyx_INCREF(__pyx_t_14); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_14, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_keys, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_v_keys = __pyx_t_3; __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":696 * if output_format == 'dict': * keys = chunks[0].keys() * final = dict() # <<<<<<<<<<<<<< * for key in keys: * final[key] = np.concatenate([chunk[key] for chunk in chunks]) */ __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 696, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_final, __pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":697 * keys = chunks[0].keys() * final = dict() * for key in keys: # <<<<<<<<<<<<<< * final[key] = np.concatenate([chunk[key] for chunk in chunks]) * else: */ if (likely(PyList_CheckExact(__pyx_v_keys)) || PyTuple_CheckExact(__pyx_v_keys)) { __pyx_t_3 = __pyx_v_keys; __Pyx_INCREF(__pyx_t_3); __pyx_t_12 = 0; __pyx_t_13 = NULL; } else { __pyx_t_12 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_keys); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 697, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_13 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 697, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_13)) { 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, 697, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } __pyx_t_8 = __Pyx_PyList_GetItemRef(__pyx_t_3, __pyx_t_12); ++__pyx_t_12; } 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, 697, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_8 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_12)); #else __pyx_t_8 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_12); #endif ++__pyx_t_12; } if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 697, __pyx_L1_error) } else { __pyx_t_8 = __pyx_t_13(__pyx_t_3); if (unlikely(!__pyx_t_8)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 697, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":698 * final = dict() * for key in keys: * final[key] = np.concatenate([chunk[key] for chunk in chunks]) # <<<<<<<<<<<<<< * else: * #final = pd.concat(chunks, axis=0, ignore_index=True) */ __pyx_t_14 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_concatenate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = PyList_New(0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (likely(PyList_CheckExact(__pyx_v_chunks)) || PyTuple_CheckExact(__pyx_v_chunks)) { __pyx_t_1 = __pyx_v_chunks; __Pyx_INCREF(__pyx_t_1); __pyx_t_25 = 0; __pyx_t_26 = NULL; } else { __pyx_t_25 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_chunks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_26 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 698, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_26)) { 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, 698, __pyx_L1_error) #endif if (__pyx_t_25 >= __pyx_temp) break; } __pyx_t_27 = __Pyx_PyList_GetItemRef(__pyx_t_1, __pyx_t_25); ++__pyx_t_25; } 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, 698, __pyx_L1_error) #endif if (__pyx_t_25 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_27 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_25)); #else __pyx_t_27 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_25); #endif ++__pyx_t_25; } if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 698, __pyx_L1_error) } else { __pyx_t_27 = __pyx_t_26(__pyx_t_1); if (unlikely(!__pyx_t_27)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) __PYX_ERR(0, 698, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_27); __Pyx_XDECREF_SET(__pyx_v_chunk, __pyx_t_27); __pyx_t_27 = 0; __pyx_t_27 = __Pyx_PyObject_GetItem(__pyx_v_chunk, __pyx_v_key); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_27); if (unlikely(__Pyx_ListComp_Append(__pyx_t_10, (PyObject*)__pyx_t_27))) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_2); assert(__pyx_t_14); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_14); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_2, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_t_10}; __pyx_t_8 = __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_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } if (unlikely((PyObject_SetItem(__pyx_v_final, __pyx_v_key, __pyx_t_8) < 0))) __PYX_ERR(0, 698, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "pyreadstat/pyreadstat.pyx":697 * keys = chunks[0].keys() * final = dict() * for key in keys: # <<<<<<<<<<<<<< * final[key] = np.concatenate([chunk[key] for chunk in chunks]) * else: */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":694 * pool.close() * output_format = kwargs.get("output_format") * if output_format == 'dict': # <<<<<<<<<<<<<< * keys = chunks[0].keys() * final = dict() */ goto __pyx_L38; } /* "pyreadstat/pyreadstat.pyx":701 * else: * #final = pd.concat(chunks, axis=0, ignore_index=True) * chunks = [nw.from_native(x) for x in chunks] # <<<<<<<<<<<<<< * final = nw.concat(chunks, how='vertical') * ispandas = False */ /*else*/ { __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 701, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (likely(PyList_CheckExact(__pyx_v_chunks)) || PyTuple_CheckExact(__pyx_v_chunks)) { __pyx_t_8 = __pyx_v_chunks; __Pyx_INCREF(__pyx_t_8); __pyx_t_12 = 0; __pyx_t_13 = NULL; } else { __pyx_t_12 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_chunks); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 701, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_13 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_8); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 701, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_13)) { if (likely(PyList_CheckExact(__pyx_t_8))) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 701, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } __pyx_t_2 = __Pyx_PyList_GetItemRef(__pyx_t_8, __pyx_t_12); ++__pyx_t_12; } else { { Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_8); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 701, __pyx_L1_error) #endif if (__pyx_t_12 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = __Pyx_NewRef(PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_12)); #else __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_8, __pyx_t_12); #endif ++__pyx_t_12; } if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __pyx_L1_error) } else { __pyx_t_2 = __pyx_t_13(__pyx_t_8); 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, 701, __pyx_L1_error) PyErr_Clear(); } break; } } __Pyx_GOTREF(__pyx_t_2); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_10 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 701, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_mstate_global->__pyx_n_u_from_native); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 701, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1); assert(__pyx_t_10); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_1, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_v_x}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __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_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 701, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_chunks, __pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":702 * #final = pd.concat(chunks, axis=0, ignore_index=True) * chunks = [nw.from_native(x) for x in chunks] * final = nw.concat(chunks, how='vertical') # <<<<<<<<<<<<<< * ispandas = False * if final.implementation.is_pandas(): */ __pyx_t_8 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_nw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_concat); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = 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_6 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_8, __pyx_v_chunks}; __pyx_t_2 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_how, __pyx_mstate_global->__pyx_n_u_vertical, __pyx_t_2, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 702, __pyx_L1_error) __pyx_t_3 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_1, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_XDECREF_SET(__pyx_v_final, __pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":703 * chunks = [nw.from_native(x) for x in chunks] * final = nw.concat(chunks, how='vertical') * ispandas = False # <<<<<<<<<<<<<< * if final.implementation.is_pandas(): * ispandas = True */ __pyx_v_ispandas = 0; /* "pyreadstat/pyreadstat.pyx":704 * final = nw.concat(chunks, how='vertical') * ispandas = False * if final.implementation.is_pandas(): # <<<<<<<<<<<<<< * ispandas = True * final = final.to_native() */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_final, __pyx_mstate_global->__pyx_n_u_implementation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_pandas, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 704, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_4) { /* "pyreadstat/pyreadstat.pyx":705 * ispandas = False * if final.implementation.is_pandas(): * ispandas = True # <<<<<<<<<<<<<< * final = final.to_native() * if ispandas: */ __pyx_v_ispandas = 1; /* "pyreadstat/pyreadstat.pyx":704 * final = nw.concat(chunks, how='vertical') * ispandas = False * if final.implementation.is_pandas(): # <<<<<<<<<<<<<< * ispandas = True * final = final.to_native() */ } /* "pyreadstat/pyreadstat.pyx":706 * if final.implementation.is_pandas(): * ispandas = True * final = final.to_native() # <<<<<<<<<<<<<< * if ispandas: * final = final.reset_index(drop=True) */ __pyx_t_2 = __pyx_v_final; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_to_native, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 706, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF_SET(__pyx_v_final, __pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":707 * ispandas = True * final = final.to_native() * if ispandas: # <<<<<<<<<<<<<< * final = final.reset_index(drop=True) * return final, meta */ if (__pyx_v_ispandas) { /* "pyreadstat/pyreadstat.pyx":708 * final = final.to_native() * if ispandas: * final = final.reset_index(drop=True) # <<<<<<<<<<<<<< * return final, meta * */ __pyx_t_2 = __pyx_v_final; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, NULL}; __pyx_t_1 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_drop, Py_True, __pyx_t_1, __pyx_callargs+1, 0) < 0) __PYX_ERR(0, 708, __pyx_L1_error) __pyx_t_3 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_reset_index, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF_SET(__pyx_v_final, __pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":707 * ispandas = True * final = final.to_native() * if ispandas: # <<<<<<<<<<<<<< * final = final.reset_index(drop=True) * return final, meta */ } } __pyx_L38:; /* "pyreadstat/pyreadstat.pyx":709 * if ispandas: * final = final.reset_index(drop=True) * return final, meta # <<<<<<<<<<<<<< * * # Write API */ __Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 709, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_final); __Pyx_GIVEREF(__pyx_v_final); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_final) != (0)) __PYX_ERR(0, 709, __pyx_L1_error); __Pyx_INCREF(__pyx_v_meta); __Pyx_GIVEREF(__pyx_v_meta); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_meta) != (0)) __PYX_ERR(0, 709, __pyx_L1_error); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; /* "pyreadstat/pyreadstat.pyx":623 * offset += chunksize * * def read_file_multiprocessing(read_function, file_path, num_processes=None, num_rows=None, **kwargs): # <<<<<<<<<<<<<< * """ * Reads a file in parallel using multiprocessing. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_14); __Pyx_XDECREF(__pyx_t_27); __Pyx_AddTraceback("pyreadstat.pyreadstat.read_file_multiprocessing", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v__); __Pyx_XDECREF(__pyx_v_row_offset); __Pyx_XDECREF(__pyx_v_row_limit); __Pyx_XDECREF(__pyx_v_meta); __Pyx_XDECREF(__pyx_v_numrows); __Pyx_XDECREF(__pyx_v_final); __Pyx_XDECREF(__pyx_v_divs); __Pyx_XDECREF(__pyx_v_offsets); __Pyx_XDECREF(__pyx_v_prev_offset); __Pyx_XDECREF(__pyx_v_prev_div); __Pyx_XDECREF(__pyx_v_indx); __Pyx_XDECREF(__pyx_v_div); __Pyx_XDECREF(__pyx_v_offset); __Pyx_XDECREF(__pyx_v_jobs); __Pyx_XDECREF(__pyx_v_pool); __Pyx_XDECREF(__pyx_v_chunks); __Pyx_XDECREF(__pyx_v_output_format); __Pyx_XDECREF(__pyx_v_keys); __Pyx_XDECREF(__pyx_v_key); __Pyx_XDECREF(__pyx_v_x); __Pyx_XDECREF(__pyx_v_chunksize); __Pyx_XDECREF(__pyx_v_chunk); __Pyx_XDECREF(__pyx_v_num_processes); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":713 * # Write API * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_18write_sav(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_17write_sav, "\n Writes a dataframe to a SPSS sav or zsav file.\n\n Parameters\n ----------\n df : dataframe\n dataframe to write to sav or zsav\n dst_path : str or pathlib.Path\n full path to the result sav or zsav file\n file_label : str, optional\n a label for the file\n column_labels : list or dict, optional\n labels for columns (variables), if list must be the same length as the number of columns. Variables with no\n labels must be represented by None. If dict values must be variable names and values variable labels.\n In such case there is no need to include all variables; labels for non existent\n variables will be ignored with no warning or error.\n compress : boolean, optional\n if true a zsav will be written, by default False, a sav is written\n row_compress : boolean, optional\n if true it applies row compression, by default False, compress and row_compress cannot be both true at the same time\n note : str or list of str, optional\n a note or list of notes to add to the file\n variable_value_labels : dict, optional\n value labels, a dictionary with key variable name and value a dictionary with key values and\n values labels. Variable names must match variable names in the dataframe otherwise will be\n ignored. Value types must match the type of the column in the dataframe.\n missing_ranges : dict, optional\n user defined missing values. Must be a dictionary with keys as variable names matching variable\n names in the dataframe. The values must be a list. Each element in that list can either be\n either a discrete numeric or string value (max 3 per variable) or a dictionary with keys 'hi' and 'lo' to\n indicate the upper and lower range for numeric values (max 1 range value + 1 discrete value per\n variable). hi and lo may also be the same value in which case it will be interpreted as a discrete\n missin""g value.\n For this to be effective, values in the dataframe must be the same as reported here and not NaN.\n variable_display_width : dict, optional\n set the display width for variables. Must be a dictonary with keys being variable names and\n values being integers.\n variable_measure: dict, optional\n sets the measure type for a variable. Must be a dictionary with keys being variable names and\n values being strings one of \"nominal\", \"ordinal\", \"scale\" or \"unknown\" (default).\n variable_format: dict, optional\n sets the format of a variable. Must be a dictionary with keys being the variable names and \n values being strings defining the format. See README, setting variable formats section,\n for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_18write_sav = {"write_sav", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_18write_sav, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_17write_sav}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_18write_sav(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_df = 0; PyObject *__pyx_v_dst_path = 0; PyObject *__pyx_v_file_label = 0; PyObject *__pyx_v_column_labels = 0; PyObject *__pyx_v_compress = 0; PyObject *__pyx_v_row_compress = 0; PyObject *__pyx_v_note = 0; PyObject *__pyx_v_variable_value_labels = 0; PyObject *__pyx_v_missing_ranges = 0; PyObject *__pyx_v_variable_display_width = 0; PyObject *__pyx_v_variable_measure = 0; PyObject *__pyx_v_variable_format = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_sav (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_df,&__pyx_mstate_global->__pyx_n_u_dst_path,&__pyx_mstate_global->__pyx_n_u_file_label,&__pyx_mstate_global->__pyx_n_u_column_labels,&__pyx_mstate_global->__pyx_n_u_compress,&__pyx_mstate_global->__pyx_n_u_row_compress,&__pyx_mstate_global->__pyx_n_u_note,&__pyx_mstate_global->__pyx_n_u_variable_value_labels,&__pyx_mstate_global->__pyx_n_u_missing_ranges,&__pyx_mstate_global->__pyx_n_u_variable_display_width,&__pyx_mstate_global->__pyx_n_u_variable_measure,&__pyx_mstate_global->__pyx_n_u_variable_format,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 713, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "write_sav", 0) < 0) __PYX_ERR(0, 713, __pyx_L3_error) if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject *)Py_None)); /* "pyreadstat/pyreadstat.pyx":714 * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, # <<<<<<<<<<<<<< * dict variable_measure=None, dict variable_format=None): * """ */ if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":715 * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SPSS sav or zsav file. */ if (!values[10]) values[10] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[11]) values[11] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("write_sav", 0, 2, 12, i); __PYX_ERR(0, 713, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 12: values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 11: values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 10: values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 9: values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 713, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 713, __pyx_L3_error) values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 713, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); /* "pyreadstat/pyreadstat.pyx":713 * # Write API * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): */ if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[5]) values[5] = __Pyx_NewRef(((PyObject *)((PyObject*)Py_False))); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject *)Py_None)); /* "pyreadstat/pyreadstat.pyx":714 * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, # <<<<<<<<<<<<<< * dict variable_measure=None, dict variable_format=None): * """ */ if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[8]) values[8] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[9]) values[9] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":715 * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SPSS sav or zsav file. */ if (!values[10]) values[10] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[11]) values[11] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_df = values[0]; __pyx_v_dst_path = values[1]; __pyx_v_file_label = ((PyObject*)values[2]); __pyx_v_column_labels = values[3]; __pyx_v_compress = values[4]; __pyx_v_row_compress = values[5]; __pyx_v_note = values[6]; __pyx_v_variable_value_labels = ((PyObject*)values[7]); __pyx_v_missing_ranges = ((PyObject*)values[8]); __pyx_v_variable_display_width = ((PyObject*)values[9]); __pyx_v_variable_measure = ((PyObject*)values[10]); __pyx_v_variable_format = ((PyObject*)values[11]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_sav", 0, 2, 12, __pyx_nargs); __PYX_ERR(0, 713, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.write_sav", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file_label), (&PyUnicode_Type), 1, "file_label", 1))) __PYX_ERR(0, 713, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_value_labels), (&PyDict_Type), 1, "variable_value_labels", 1))) __PYX_ERR(0, 714, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_missing_ranges), (&PyDict_Type), 1, "missing_ranges", 1))) __PYX_ERR(0, 714, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_display_width), (&PyDict_Type), 1, "variable_display_width", 1))) __PYX_ERR(0, 714, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_measure), (&PyDict_Type), 1, "variable_measure", 1))) __PYX_ERR(0, 715, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_format), (&PyDict_Type), 1, "variable_format", 1))) __PYX_ERR(0, 715, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_17write_sav(__pyx_self, __pyx_v_df, __pyx_v_dst_path, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_compress, __pyx_v_row_compress, __pyx_v_note, __pyx_v_variable_value_labels, __pyx_v_missing_ranges, __pyx_v_variable_display_width, __pyx_v_variable_measure, __pyx_v_variable_format); /* "pyreadstat/pyreadstat.pyx":713 * # Write API * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_17write_sav(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_df, PyObject *__pyx_v_dst_path, PyObject *__pyx_v_file_label, PyObject *__pyx_v_column_labels, PyObject *__pyx_v_compress, PyObject *__pyx_v_row_compress, PyObject *__pyx_v_note, PyObject *__pyx_v_variable_value_labels, PyObject *__pyx_v_missing_ranges, PyObject *__pyx_v_variable_display_width, PyObject *__pyx_v_variable_measure, PyObject *__pyx_v_variable_format) { int __pyx_v_file_format_version; PyObject *__pyx_v_var_width = 0; int __pyx_v_row_compression; PyObject *__pyx_v_table_name = 0; PyObject *__pyx_v_missing_user_values = 0; PyObject *__pyx_v_variable_alignment = 0; PyObject *__pyx_v_formats_presets = NULL; PyObject *__pyx_v_col_name = NULL; PyObject *__pyx_v_col_format = NULL; PyObject *__pyx_r = 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 *); Py_ssize_t __pyx_t_12; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_sav", 0); /* "pyreadstat/pyreadstat.pyx":762 * """ * * cdef int file_format_version = 2 # <<<<<<<<<<<<<< * cdef str var_width * cdef bint row_compression = 0 */ __pyx_v_file_format_version = 2; /* "pyreadstat/pyreadstat.pyx":764 * cdef int file_format_version = 2 * cdef str var_width * cdef bint row_compression = 0 # <<<<<<<<<<<<<< * if compress and row_compress: * raise PyreadstatError("compress and row_compress cannot be both True") */ __pyx_v_row_compression = 0; /* "pyreadstat/pyreadstat.pyx":765 * cdef str var_width * cdef bint row_compression = 0 * if compress and row_compress: # <<<<<<<<<<<<<< * raise PyreadstatError("compress and row_compress cannot be both True") * if compress: */ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_compress); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 765, __pyx_L1_error) if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_row_compress); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 765, __pyx_L1_error) __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_1)) { /* "pyreadstat/pyreadstat.pyx":766 * cdef bint row_compression = 0 * if compress and row_compress: * raise PyreadstatError("compress and row_compress cannot be both True") # <<<<<<<<<<<<<< * if compress: * file_format_version = 3 */ __pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 766, __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_mstate_global->__pyx_kp_u_compress_and_row_compress_cannot}; __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, 766, __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, 766, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":765 * cdef str var_width * cdef bint row_compression = 0 * if compress and row_compress: # <<<<<<<<<<<<<< * raise PyreadstatError("compress and row_compress cannot be both True") * if compress: */ } /* "pyreadstat/pyreadstat.pyx":767 * if compress and row_compress: * raise PyreadstatError("compress and row_compress cannot be both True") * if compress: # <<<<<<<<<<<<<< * file_format_version = 3 * if row_compress: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_compress); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 767, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":768 * raise PyreadstatError("compress and row_compress cannot be both True") * if compress: * file_format_version = 3 # <<<<<<<<<<<<<< * if row_compress: * row_compression = 1 */ __pyx_v_file_format_version = 3; /* "pyreadstat/pyreadstat.pyx":767 * if compress and row_compress: * raise PyreadstatError("compress and row_compress cannot be both True") * if compress: # <<<<<<<<<<<<<< * file_format_version = 3 * if row_compress: */ } /* "pyreadstat/pyreadstat.pyx":769 * if compress: * file_format_version = 3 * if row_compress: # <<<<<<<<<<<<<< * row_compression = 1 * cdef table_name = "" */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_row_compress); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 769, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":770 * file_format_version = 3 * if row_compress: * row_compression = 1 # <<<<<<<<<<<<<< * cdef table_name = "" * cdef dict missing_user_values = None */ __pyx_v_row_compression = 1; /* "pyreadstat/pyreadstat.pyx":769 * if compress: * file_format_version = 3 * if row_compress: # <<<<<<<<<<<<<< * row_compression = 1 * cdef table_name = "" */ } /* "pyreadstat/pyreadstat.pyx":771 * if row_compress: * row_compression = 1 * cdef table_name = "" # <<<<<<<<<<<<<< * cdef dict missing_user_values = None * cdef dict variable_alignment = None */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __pyx_v_table_name = __pyx_mstate_global->__pyx_kp_u_; /* "pyreadstat/pyreadstat.pyx":772 * row_compression = 1 * cdef table_name = "" * cdef dict missing_user_values = None # <<<<<<<<<<<<<< * cdef dict variable_alignment = None * */ __Pyx_INCREF(Py_None); __pyx_v_missing_user_values = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":773 * cdef table_name = "" * cdef dict missing_user_values = None * cdef dict variable_alignment = None # <<<<<<<<<<<<<< * * */ __Pyx_INCREF(Py_None); __pyx_v_variable_alignment = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":777 * * # formats * formats_presets = {'restricted_integer':'N{var_width}', 'integer':'F{var_width}.0'} # <<<<<<<<<<<<<< * if variable_format: * for col_name, col_format in variable_format.items(): */ __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 777, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_restricted_integer, __pyx_mstate_global->__pyx_kp_u_N_var_width) < 0) __PYX_ERR(0, 777, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_integer, __pyx_mstate_global->__pyx_kp_u_F_var_width_0) < 0) __PYX_ERR(0, 777, __pyx_L1_error) __pyx_v_formats_presets = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":778 * # formats * formats_presets = {'restricted_integer':'N{var_width}', 'integer':'F{var_width}.0'} * if variable_format: # <<<<<<<<<<<<<< * for col_name, col_format in variable_format.items(): * if col_format in formats_presets.keys() and col_name in df.columns: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_variable_format); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 778, __pyx_L1_error) if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":779 * formats_presets = {'restricted_integer':'N{var_width}', 'integer':'F{var_width}.0'} * if variable_format: * for col_name, col_format in variable_format.items(): # <<<<<<<<<<<<<< * if col_format in formats_presets.keys() and col_name in df.columns: * var_width = str(len(str(max(df[col_name])))) */ if (unlikely(__pyx_v_variable_format == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); __PYX_ERR(0, 779, __pyx_L1_error) } __pyx_t_3 = __Pyx_PyDict_Items(__pyx_v_variable_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 779, __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, 779, __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, 779, __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, 779, __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, 779, __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, 779, __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, 779, __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, 779, __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, 779, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 779, __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, 779, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 779, __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, 779, __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_L11_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_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 779, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L12_unpacking_done; __pyx_L11_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, 779, __pyx_L1_error) __pyx_L12_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_col_name, __pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF_SET(__pyx_v_col_format, __pyx_t_9); __pyx_t_9 = 0; /* "pyreadstat/pyreadstat.pyx":780 * if variable_format: * for col_name, col_format in variable_format.items(): * if col_format in formats_presets.keys() and col_name in df.columns: # <<<<<<<<<<<<<< * var_width = str(len(str(max(df[col_name])))) * variable_format[col_name] = formats_presets[col_format].format(var_width=var_width) */ __pyx_t_3 = __Pyx_PyDict_Keys(__pyx_v_formats_presets); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 780, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_col_format, __pyx_t_3, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 780, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L14_bool_binop_done; } __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_df, __pyx_mstate_global->__pyx_n_u_columns); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 780, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_col_name, __pyx_t_3, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 780, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L14_bool_binop_done:; if (__pyx_t_1) { /* "pyreadstat/pyreadstat.pyx":781 * for col_name, col_format in variable_format.items(): * if col_format in formats_presets.keys() and col_name in df.columns: * var_width = str(len(str(max(df[col_name])))) # <<<<<<<<<<<<<< * variable_format[col_name] = formats_presets[col_format].format(var_width=var_width) * */ __pyx_t_9 = NULL; __Pyx_INCREF(__pyx_builtin_max); __pyx_t_4 = __pyx_builtin_max; __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_df, __pyx_v_col_name); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_10}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __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_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_t_4 = __Pyx_PyObject_Unicode(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_12 = __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyLong_FromSsize_t(__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_Unicode(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF_SET(__pyx_v_var_width, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":782 * if col_format in formats_presets.keys() and col_name in df.columns: * var_width = str(len(str(max(df[col_name])))) * variable_format[col_name] = formats_presets[col_format].format(var_width=var_width) # <<<<<<<<<<<<<< * * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_SAV, file_label, column_labels, */ __pyx_t_10 = __Pyx_PyDict_GetItem(__pyx_v_formats_presets, __pyx_v_col_format); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_4 = __pyx_t_10; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, NULL}; __pyx_t_9 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_var_width, __pyx_v_var_width, __pyx_t_9, __pyx_callargs+1, 0) < 0) __PYX_ERR(0, 782, __pyx_L1_error) __pyx_t_3 = __Pyx_Object_VectorcallMethod_CallFromBuilder(__pyx_mstate_global->__pyx_n_u_format, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_9); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } if (unlikely(__pyx_v_variable_format == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 782, __pyx_L1_error) } if (unlikely((PyDict_SetItem(__pyx_v_variable_format, __pyx_v_col_name, __pyx_t_3) < 0))) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":780 * if variable_format: * for col_name, col_format in variable_format.items(): * if col_format in formats_presets.keys() and col_name in df.columns: # <<<<<<<<<<<<<< * var_width = str(len(str(max(df[col_name])))) * variable_format[col_name] = formats_presets[col_format].format(var_width=var_width) */ } /* "pyreadstat/pyreadstat.pyx":779 * formats_presets = {'restricted_integer':'N{var_width}', 'integer':'F{var_width}.0'} * if variable_format: * for col_name, col_format in variable_format.items(): # <<<<<<<<<<<<<< * if col_format in formats_presets.keys() and col_name in df.columns: * var_width = str(len(str(max(df[col_name])))) */ } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "pyreadstat/pyreadstat.pyx":778 * # formats * formats_presets = {'restricted_integer':'N{var_width}', 'integer':'F{var_width}.0'} * if variable_format: # <<<<<<<<<<<<<< * for col_name, col_format in variable_format.items(): * if col_format in formats_presets.keys() and col_name in df.columns: */ } /* "pyreadstat/pyreadstat.pyx":785 * * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_SAV, file_label, column_labels, * file_format_version, note, table_name, variable_value_labels, missing_ranges, missing_user_values, # <<<<<<<<<<<<<< * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * */ if (!(likely(PyUnicode_CheckExact(__pyx_v_table_name)) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_v_table_name))) __PYX_ERR(0, 785, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":784 * variable_format[col_name] = formats_presets[col_format].format(var_width=var_width) * * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_SAV, file_label, column_labels, # <<<<<<<<<<<<<< * file_format_version, note, table_name, variable_value_labels, missing_ranges, missing_user_values, * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) */ __pyx_f_10pyreadstat_16_readstat_writer_run_write(__pyx_v_df, __pyx_v_dst_path, __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_SAV, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_file_format_version, __pyx_v_note, ((PyObject*)__pyx_v_table_name), __pyx_v_variable_value_labels, __pyx_v_missing_ranges, __pyx_v_missing_user_values, __pyx_v_variable_alignment, __pyx_v_variable_display_width, __pyx_v_variable_measure, __pyx_v_variable_format, __pyx_v_row_compression); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 784, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":713 * # Write API * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); 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_AddTraceback("pyreadstat.pyreadstat.write_sav", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_var_width); __Pyx_XDECREF(__pyx_v_table_name); __Pyx_XDECREF(__pyx_v_missing_user_values); __Pyx_XDECREF(__pyx_v_variable_alignment); __Pyx_XDECREF(__pyx_v_formats_presets); __Pyx_XDECREF(__pyx_v_col_name); __Pyx_XDECREF(__pyx_v_col_format); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":788 * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): * """ */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_20write_dta(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_19write_dta, "\n Writes a dataframe to a STATA dta file\n\n Parameters\n ----------\n df : dataframe\n dataframe to write to sav or zsav\n dst_path : str or pathlib.Path\n full path to the result dta file\n file_label : str, optional\n a label for the file\n column_labels : list or dict, optional\n labels for columns (variables), if list must be the same length as the number of columns. Variables with no\n labels must be represented by None. If dict values must be variable names and values variable labels.\n In such case there is no need to include all variables; labels for non existent\n variables will be ignored with no warning or error.\n version : int, optional\n dta file version, supported from 8 to 15, default is 15\n variable_value_labels : dict, optional\n value labels, a dictionary with key variable name and value a dictionary with key values and\n values labels. Variable names must match variable names in the dataframe otherwise will be\n ignored. Value types must match the type of the column in the dataframe.\n missing_user_values : dict, optional\n user defined missing values for numeric variables. Must be a dictionary with keys being variable\n names and values being a list of missing values. Missing values must be a single character\n between a and z.\n variable_format: dict, optional\n sets the format of a variable. Must be a dictionary with keys being the variable names and \n values being strings defining the format. See README, setting variable formats section,\n for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_20write_dta = {"write_dta", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_20write_dta, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_19write_dta}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_20write_dta(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_df = 0; PyObject *__pyx_v_dst_path = 0; PyObject *__pyx_v_file_label = 0; PyObject *__pyx_v_column_labels = 0; int __pyx_v_version; PyObject *__pyx_v_variable_value_labels = 0; PyObject *__pyx_v_missing_user_values = 0; PyObject *__pyx_v_variable_format = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[8] = {0,0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_dta (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_df,&__pyx_mstate_global->__pyx_n_u_dst_path,&__pyx_mstate_global->__pyx_n_u_file_label,&__pyx_mstate_global->__pyx_n_u_column_labels,&__pyx_mstate_global->__pyx_n_u_version,&__pyx_mstate_global->__pyx_n_u_variable_value_labels,&__pyx_mstate_global->__pyx_n_u_missing_user_values,&__pyx_mstate_global->__pyx_n_u_variable_format,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 788, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "write_dta", 0) < 0) __PYX_ERR(0, 788, __pyx_L3_error) if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); /* "pyreadstat/pyreadstat.pyx":789 * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a STATA dta file */ if (!values[5]) values[5] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("write_dta", 0, 2, 8, i); __PYX_ERR(0, 788, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 8: values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 788, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 788, __pyx_L3_error) values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 788, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); /* "pyreadstat/pyreadstat.pyx":788 * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): * """ */ if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); /* "pyreadstat/pyreadstat.pyx":789 * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a STATA dta file */ if (!values[5]) values[5] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); if (!values[7]) values[7] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_df = values[0]; __pyx_v_dst_path = values[1]; __pyx_v_file_label = ((PyObject*)values[2]); __pyx_v_column_labels = values[3]; if (values[4]) { __pyx_v_version = __Pyx_PyLong_As_int(values[4]); if (unlikely((__pyx_v_version == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 788, __pyx_L3_error) } else { __pyx_v_version = ((int)((int)15)); } __pyx_v_variable_value_labels = ((PyObject*)values[5]); __pyx_v_missing_user_values = ((PyObject*)values[6]); __pyx_v_variable_format = ((PyObject*)values[7]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_dta", 0, 2, 8, __pyx_nargs); __PYX_ERR(0, 788, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.write_dta", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file_label), (&PyUnicode_Type), 1, "file_label", 1))) __PYX_ERR(0, 788, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_value_labels), (&PyDict_Type), 1, "variable_value_labels", 1))) __PYX_ERR(0, 789, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_missing_user_values), (&PyDict_Type), 1, "missing_user_values", 1))) __PYX_ERR(0, 789, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_format), (&PyDict_Type), 1, "variable_format", 1))) __PYX_ERR(0, 789, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_19write_dta(__pyx_self, __pyx_v_df, __pyx_v_dst_path, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_version, __pyx_v_variable_value_labels, __pyx_v_missing_user_values, __pyx_v_variable_format); /* "pyreadstat/pyreadstat.pyx":788 * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): * """ */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_19write_dta(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_df, PyObject *__pyx_v_dst_path, PyObject *__pyx_v_file_label, PyObject *__pyx_v_column_labels, int __pyx_v_version, PyObject *__pyx_v_variable_value_labels, PyObject *__pyx_v_missing_user_values, PyObject *__pyx_v_variable_format) { long __pyx_v_file_format_version; PyObject *__pyx_v_note = 0; PyObject *__pyx_v_table_name = 0; PyObject *__pyx_v_missing_ranges = 0; PyObject *__pyx_v_variable_alignment = 0; PyObject *__pyx_v_variable_display_width = 0; PyObject *__pyx_v_variable_measure = 0; int __pyx_v_row_compression; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; size_t __pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_dta", 0); /* "pyreadstat/pyreadstat.pyx":822 * """ * * if version == 15: # <<<<<<<<<<<<<< * file_format_version = 119 * elif version == 14: */ switch (__pyx_v_version) { case 15: /* "pyreadstat/pyreadstat.pyx":823 * * if version == 15: * file_format_version = 119 # <<<<<<<<<<<<<< * elif version == 14: * file_format_version = 118 */ __pyx_v_file_format_version = 0x77; /* "pyreadstat/pyreadstat.pyx":822 * """ * * if version == 15: # <<<<<<<<<<<<<< * file_format_version = 119 * elif version == 14: */ break; case 14: /* "pyreadstat/pyreadstat.pyx":825 * file_format_version = 119 * elif version == 14: * file_format_version = 118 # <<<<<<<<<<<<<< * elif version == 13: * file_format_version = 117 */ __pyx_v_file_format_version = 0x76; /* "pyreadstat/pyreadstat.pyx":824 * if version == 15: * file_format_version = 119 * elif version == 14: # <<<<<<<<<<<<<< * file_format_version = 118 * elif version == 13: */ break; case 13: /* "pyreadstat/pyreadstat.pyx":827 * file_format_version = 118 * elif version == 13: * file_format_version = 117 # <<<<<<<<<<<<<< * elif version == 12: * file_format_version = 115 */ __pyx_v_file_format_version = 0x75; /* "pyreadstat/pyreadstat.pyx":826 * elif version == 14: * file_format_version = 118 * elif version == 13: # <<<<<<<<<<<<<< * file_format_version = 117 * elif version == 12: */ break; case 12: /* "pyreadstat/pyreadstat.pyx":829 * file_format_version = 117 * elif version == 12: * file_format_version = 115 # <<<<<<<<<<<<<< * elif version in {10, 11}: * file_format_version = 114 */ __pyx_v_file_format_version = 0x73; /* "pyreadstat/pyreadstat.pyx":828 * elif version == 13: * file_format_version = 117 * elif version == 12: # <<<<<<<<<<<<<< * file_format_version = 115 * elif version in {10, 11}: */ break; case 10: /* "pyreadstat/pyreadstat.pyx":830 * elif version == 12: * file_format_version = 115 * elif version in {10, 11}: # <<<<<<<<<<<<<< * file_format_version = 114 * elif version in {8, 9}: */ case 11: /* "pyreadstat/pyreadstat.pyx":831 * file_format_version = 115 * elif version in {10, 11}: * file_format_version = 114 # <<<<<<<<<<<<<< * elif version in {8, 9}: * file_format_version = 113 */ __pyx_v_file_format_version = 0x72; /* "pyreadstat/pyreadstat.pyx":830 * elif version == 12: * file_format_version = 115 * elif version in {10, 11}: # <<<<<<<<<<<<<< * file_format_version = 114 * elif version in {8, 9}: */ break; case 8: /* "pyreadstat/pyreadstat.pyx":832 * elif version in {10, 11}: * file_format_version = 114 * elif version in {8, 9}: # <<<<<<<<<<<<<< * file_format_version = 113 * else: */ case 9: /* "pyreadstat/pyreadstat.pyx":833 * file_format_version = 114 * elif version in {8, 9}: * file_format_version = 113 # <<<<<<<<<<<<<< * else: * raise Exception("Version not supported") */ __pyx_v_file_format_version = 0x71; /* "pyreadstat/pyreadstat.pyx":832 * elif version in {10, 11}: * file_format_version = 114 * elif version in {8, 9}: # <<<<<<<<<<<<<< * file_format_version = 113 * else: */ break; default: /* "pyreadstat/pyreadstat.pyx":835 * file_format_version = 113 * else: * raise Exception("Version not supported") # <<<<<<<<<<<<<< * * cdef str note = "" */ __pyx_t_2 = NULL; __Pyx_INCREF((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_3 = ((PyObject *)(((PyTypeObject*)PyExc_Exception))); __pyx_t_4 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Version_not_supported}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 835, __pyx_L1_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, 835, __pyx_L1_error) break; } /* "pyreadstat/pyreadstat.pyx":837 * raise Exception("Version not supported") * * cdef str note = "" # <<<<<<<<<<<<<< * cdef str table_name = "" * cdef dict missing_ranges = None */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __pyx_v_note = __pyx_mstate_global->__pyx_kp_u_; /* "pyreadstat/pyreadstat.pyx":838 * * cdef str note = "" * cdef str table_name = "" # <<<<<<<<<<<<<< * cdef dict missing_ranges = None * cdef dict variable_alignment = None */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __pyx_v_table_name = __pyx_mstate_global->__pyx_kp_u_; /* "pyreadstat/pyreadstat.pyx":839 * cdef str note = "" * cdef str table_name = "" * cdef dict missing_ranges = None # <<<<<<<<<<<<<< * cdef dict variable_alignment = None * cdef dict variable_display_width = None */ __Pyx_INCREF(Py_None); __pyx_v_missing_ranges = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":840 * cdef str table_name = "" * cdef dict missing_ranges = None * cdef dict variable_alignment = None # <<<<<<<<<<<<<< * cdef dict variable_display_width = None * cdef dict variable_measure = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_alignment = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":841 * cdef dict missing_ranges = None * cdef dict variable_alignment = None * cdef dict variable_display_width = None # <<<<<<<<<<<<<< * cdef dict variable_measure = None * #cdef dict variable_format = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_display_width = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":842 * cdef dict variable_alignment = None * cdef dict variable_display_width = None * cdef dict variable_measure = None # <<<<<<<<<<<<<< * #cdef dict variable_format = None * cdef bint row_compression = 0 */ __Pyx_INCREF(Py_None); __pyx_v_variable_measure = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":844 * cdef dict variable_measure = None * #cdef dict variable_format = None * cdef bint row_compression = 0 # <<<<<<<<<<<<<< * * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_DTA, file_label, column_labels, file_format_version, */ __pyx_v_row_compression = 0; /* "pyreadstat/pyreadstat.pyx":846 * cdef bint row_compression = 0 * * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_DTA, file_label, column_labels, file_format_version, # <<<<<<<<<<<<<< * note, table_name, variable_value_labels, missing_ranges, missing_user_values, variable_alignment, * variable_display_width, variable_measure, variable_format, row_compression) */ __pyx_f_10pyreadstat_16_readstat_writer_run_write(__pyx_v_df, __pyx_v_dst_path, __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_DTA, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_file_format_version, __pyx_v_note, __pyx_v_table_name, __pyx_v_variable_value_labels, __pyx_v_missing_ranges, __pyx_v_missing_user_values, __pyx_v_variable_alignment, __pyx_v_variable_display_width, __pyx_v_variable_measure, __pyx_v_variable_format, __pyx_v_row_compression); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 846, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":788 * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): * """ */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pyreadstat.pyreadstat.write_dta", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_note); __Pyx_XDECREF(__pyx_v_table_name); __Pyx_XDECREF(__pyx_v_missing_ranges); __Pyx_XDECREF(__pyx_v_variable_alignment); __Pyx_XDECREF(__pyx_v_variable_display_width); __Pyx_XDECREF(__pyx_v_variable_measure); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":850 * variable_display_width, variable_measure, variable_format, row_compression) * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, # <<<<<<<<<<<<<< * dict variable_format=None): * """ */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_22write_xport(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_21write_xport, "\n Writes a dataframe to a SAS Xport (xpt) file.\n If no table_name is specified the dataset has by default the name DATASET (take it into account if\n reading the file from SAS.)\n Versions 5 and 8 are supported, default is 8.\n\n Parameters\n ----------\n df : dataframe\n dataframe to write to xport\n dst_path : str or pathlib.Path\n full path to the result xport file\n file_label : str, optional\n a label for the file\n column_labels : list or dict, optional\n labels for columns (variables), if list must be the same length as the number of columns. Variables with no\n labels must be represented by None. If dict values must be variable names and values variable labels.\n In such case there is no need to include all variables; labels for non existent\n variables will be ignored with no warning or error.\n table_name : str, optional\n name of the dataset, by default DATASET\n file_format_version : int, optional\n XPORT file version, either 8 or 5, default is 8\n variable_format: dict, optional\n sets the format of a variable. Must be a dictionary with keys being the variable names and \n values being strings defining the format. See README, setting variable formats section,\n for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_22write_xport = {"write_xport", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_22write_xport, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_21write_xport}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_22write_xport(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_df = 0; PyObject *__pyx_v_dst_path = 0; PyObject *__pyx_v_file_label = 0; PyObject *__pyx_v_column_labels = 0; PyObject *__pyx_v_table_name = 0; int __pyx_v_file_format_version; PyObject *__pyx_v_variable_format = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[7] = {0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_xport (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_df,&__pyx_mstate_global->__pyx_n_u_dst_path,&__pyx_mstate_global->__pyx_n_u_file_label,&__pyx_mstate_global->__pyx_n_u_column_labels,&__pyx_mstate_global->__pyx_n_u_table_name,&__pyx_mstate_global->__pyx_n_u_file_format_version,&__pyx_mstate_global->__pyx_n_u_variable_format,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 850, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "write_xport", 0) < 0) __PYX_ERR(0, 850, __pyx_L3_error) if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":851 * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, * dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SAS Xport (xpt) file. */ if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("write_xport", 0, 2, 7, i); __PYX_ERR(0, 850, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 7: values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 6: values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 850, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 850, __pyx_L3_error) values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 850, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); /* "pyreadstat/pyreadstat.pyx":850 * variable_display_width, variable_measure, variable_format, row_compression) * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, # <<<<<<<<<<<<<< * dict variable_format=None): * """ */ if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject*)Py_None)); /* "pyreadstat/pyreadstat.pyx":851 * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, * dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SAS Xport (xpt) file. */ if (!values[6]) values[6] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_df = values[0]; __pyx_v_dst_path = values[1]; __pyx_v_file_label = ((PyObject*)values[2]); __pyx_v_column_labels = values[3]; __pyx_v_table_name = ((PyObject*)values[4]); if (values[5]) { __pyx_v_file_format_version = __Pyx_PyLong_As_int(values[5]); if (unlikely((__pyx_v_file_format_version == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 850, __pyx_L3_error) } else { __pyx_v_file_format_version = ((int)((int)8)); } __pyx_v_variable_format = ((PyObject*)values[6]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_xport", 0, 2, 7, __pyx_nargs); __PYX_ERR(0, 850, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.write_xport", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file_label), (&PyUnicode_Type), 1, "file_label", 1))) __PYX_ERR(0, 850, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_table_name), (&PyUnicode_Type), 1, "table_name", 1))) __PYX_ERR(0, 850, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_format), (&PyDict_Type), 1, "variable_format", 1))) __PYX_ERR(0, 851, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_21write_xport(__pyx_self, __pyx_v_df, __pyx_v_dst_path, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_table_name, __pyx_v_file_format_version, __pyx_v_variable_format); /* "pyreadstat/pyreadstat.pyx":850 * variable_display_width, variable_measure, variable_format, row_compression) * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, # <<<<<<<<<<<<<< * dict variable_format=None): * """ */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_21write_xport(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_df, PyObject *__pyx_v_dst_path, PyObject *__pyx_v_file_label, PyObject *__pyx_v_column_labels, PyObject *__pyx_v_table_name, int __pyx_v_file_format_version, PyObject *__pyx_v_variable_format) { PyObject *__pyx_v_variable_value_labels = 0; PyObject *__pyx_v_note = 0; PyObject *__pyx_v_missing_ranges = 0; PyObject *__pyx_v_missing_user_values = 0; PyObject *__pyx_v_variable_alignment = 0; PyObject *__pyx_v_variable_display_width = 0; PyObject *__pyx_v_variable_measure = 0; int __pyx_v_row_compression; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_xport", 0); /* "pyreadstat/pyreadstat.pyx":881 * """ * * cdef dict variable_value_labels = None # <<<<<<<<<<<<<< * cdef str note = "" * cdef dict missing_ranges = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_value_labels = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":882 * * cdef dict variable_value_labels = None * cdef str note = "" # <<<<<<<<<<<<<< * cdef dict missing_ranges = None * cdef dict missing_user_values = None */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __pyx_v_note = __pyx_mstate_global->__pyx_kp_u_; /* "pyreadstat/pyreadstat.pyx":883 * cdef dict variable_value_labels = None * cdef str note = "" * cdef dict missing_ranges = None # <<<<<<<<<<<<<< * cdef dict missing_user_values = None * cdef dict variable_alignment = None */ __Pyx_INCREF(Py_None); __pyx_v_missing_ranges = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":884 * cdef str note = "" * cdef dict missing_ranges = None * cdef dict missing_user_values = None # <<<<<<<<<<<<<< * cdef dict variable_alignment = None * cdef dict variable_display_width = None */ __Pyx_INCREF(Py_None); __pyx_v_missing_user_values = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":885 * cdef dict missing_ranges = None * cdef dict missing_user_values = None * cdef dict variable_alignment = None # <<<<<<<<<<<<<< * cdef dict variable_display_width = None * cdef dict variable_measure = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_alignment = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":886 * cdef dict missing_user_values = None * cdef dict variable_alignment = None * cdef dict variable_display_width = None # <<<<<<<<<<<<<< * cdef dict variable_measure = None * #cdef dict variable_format = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_display_width = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":887 * cdef dict variable_alignment = None * cdef dict variable_display_width = None * cdef dict variable_measure = None # <<<<<<<<<<<<<< * #cdef dict variable_format = None * cdef bint row_compression = 0 */ __Pyx_INCREF(Py_None); __pyx_v_variable_measure = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":889 * cdef dict variable_measure = None * #cdef dict variable_format = None * cdef bint row_compression = 0 # <<<<<<<<<<<<<< * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_XPORT, file_label, column_labels, * file_format_version, note, table_name, variable_value_labels, missing_ranges,missing_user_values, */ __pyx_v_row_compression = 0; /* "pyreadstat/pyreadstat.pyx":890 * #cdef dict variable_format = None * cdef bint row_compression = 0 * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_XPORT, file_label, column_labels, # <<<<<<<<<<<<<< * file_format_version, note, table_name, variable_value_labels, missing_ranges,missing_user_values, * variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) */ __pyx_f_10pyreadstat_16_readstat_writer_run_write(__pyx_v_df, __pyx_v_dst_path, __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_XPORT, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_file_format_version, __pyx_v_note, __pyx_v_table_name, __pyx_v_variable_value_labels, __pyx_v_missing_ranges, __pyx_v_missing_user_values, __pyx_v_variable_alignment, __pyx_v_variable_display_width, __pyx_v_variable_measure, __pyx_v_variable_format, __pyx_v_row_compression); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 890, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":850 * variable_display_width, variable_measure, variable_format, row_compression) * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, # <<<<<<<<<<<<<< * dict variable_format=None): * """ */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("pyreadstat.pyreadstat.write_xport", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_variable_value_labels); __Pyx_XDECREF(__pyx_v_note); __Pyx_XDECREF(__pyx_v_missing_ranges); __Pyx_XDECREF(__pyx_v_missing_user_values); __Pyx_XDECREF(__pyx_v_variable_alignment); __Pyx_XDECREF(__pyx_v_variable_display_width); __Pyx_XDECREF(__pyx_v_variable_measure); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pyreadstat/pyreadstat.pyx":894 * variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) * * def write_por(df, dst_path, str file_label="", object column_labels=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SPSS POR file. */ /* Python wrapper */ static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_24write_por(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10pyreadstat_10pyreadstat_23write_por, "\n Writes a dataframe to a SPSS POR file.\n\n Parameters\n ----------\n df : dataframe\n data frame to write to por\n dst_path : str or pathlib.Path\n full path to the result por file\n file_label : str, optional\n a label for the file\n column_labels : list or dict, optional\n labels for columns (variables), if list must be the same length as the number of columns. Variables with no\n labels must be represented by None. If dict values must be variable names and values variable labels.\n In such case there is no need to include all variables; labels for non existent\n variables will be ignored with no warning or error.\n variable_format: dict, optional\n sets the format of a variable. Must be a dictionary with keys being the variable names and \n values being strings defining the format. See README, setting variable formats section,\n for more information.\n "); static PyMethodDef __pyx_mdef_10pyreadstat_10pyreadstat_24write_por = {"write_por", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10pyreadstat_10pyreadstat_24write_por, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10pyreadstat_10pyreadstat_23write_por}; static PyObject *__pyx_pw_10pyreadstat_10pyreadstat_24write_por(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_df = 0; PyObject *__pyx_v_dst_path = 0; PyObject *__pyx_v_file_label = 0; PyObject *__pyx_v_column_labels = 0; PyObject *__pyx_v_variable_format = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject* values[5] = {0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_por (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_df,&__pyx_mstate_global->__pyx_n_u_dst_path,&__pyx_mstate_global->__pyx_n_u_file_label,&__pyx_mstate_global->__pyx_n_u_column_labels,&__pyx_mstate_global->__pyx_n_u_variable_format,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 894, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "write_por", 0) < 0) __PYX_ERR(0, 894, __pyx_L3_error) if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject*)Py_None)); for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("write_por", 0, 2, 5, i); __PYX_ERR(0, 894, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 5: values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 894, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 894, __pyx_L3_error) values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 894, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } if (!values[2]) values[2] = __Pyx_NewRef(((PyObject*)((PyObject*)__pyx_mstate_global->__pyx_kp_u_))); if (!values[3]) values[3] = __Pyx_NewRef(((PyObject *)Py_None)); if (!values[4]) values[4] = __Pyx_NewRef(((PyObject*)Py_None)); } __pyx_v_df = values[0]; __pyx_v_dst_path = values[1]; __pyx_v_file_label = ((PyObject*)values[2]); __pyx_v_column_labels = values[3]; __pyx_v_variable_format = ((PyObject*)values[4]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_por", 0, 2, 5, __pyx_nargs); __PYX_ERR(0, 894, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("pyreadstat.pyreadstat.write_por", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file_label), (&PyUnicode_Type), 1, "file_label", 1))) __PYX_ERR(0, 894, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_variable_format), (&PyDict_Type), 1, "variable_format", 1))) __PYX_ERR(0, 894, __pyx_L1_error) __pyx_r = __pyx_pf_10pyreadstat_10pyreadstat_23write_por(__pyx_self, __pyx_v_df, __pyx_v_dst_path, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_variable_format); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } goto __pyx_L7_cleaned_up; __pyx_L0:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __pyx_L7_cleaned_up:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10pyreadstat_10pyreadstat_23write_por(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_df, PyObject *__pyx_v_dst_path, PyObject *__pyx_v_file_label, PyObject *__pyx_v_column_labels, PyObject *__pyx_v_variable_format) { PyObject *__pyx_v_note = 0; int __pyx_v_file_format_version; PyObject *__pyx_v_variable_value_labels = 0; PyObject *__pyx_v_missing_ranges = 0; PyObject *__pyx_v_missing_user_values = 0; PyObject *__pyx_v_variable_alignment = 0; PyObject *__pyx_v_variable_display_width = 0; PyObject *__pyx_v_variable_measure = 0; PyObject *__pyx_v_table_name = 0; int __pyx_v_row_compression; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_por", 0); /* "pyreadstat/pyreadstat.pyx":918 * * # atm version 5 and 8 are supported by readstat but only 5 can be later be read by SAS * cdef str note=None # <<<<<<<<<<<<<< * cdef int file_format_version = 0 * cdef dict variable_value_labels=None */ __Pyx_INCREF(Py_None); __pyx_v_note = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":919 * # atm version 5 and 8 are supported by readstat but only 5 can be later be read by SAS * cdef str note=None * cdef int file_format_version = 0 # <<<<<<<<<<<<<< * cdef dict variable_value_labels=None * cdef dict missing_ranges = None */ __pyx_v_file_format_version = 0; /* "pyreadstat/pyreadstat.pyx":920 * cdef str note=None * cdef int file_format_version = 0 * cdef dict variable_value_labels=None # <<<<<<<<<<<<<< * cdef dict missing_ranges = None * cdef dict missing_user_values = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_value_labels = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":921 * cdef int file_format_version = 0 * cdef dict variable_value_labels=None * cdef dict missing_ranges = None # <<<<<<<<<<<<<< * cdef dict missing_user_values = None * cdef dict variable_alignment = None */ __Pyx_INCREF(Py_None); __pyx_v_missing_ranges = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":922 * cdef dict variable_value_labels=None * cdef dict missing_ranges = None * cdef dict missing_user_values = None # <<<<<<<<<<<<<< * cdef dict variable_alignment = None * cdef dict variable_display_width = None */ __Pyx_INCREF(Py_None); __pyx_v_missing_user_values = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":923 * cdef dict missing_ranges = None * cdef dict missing_user_values = None * cdef dict variable_alignment = None # <<<<<<<<<<<<<< * cdef dict variable_display_width = None * cdef dict variable_measure = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_alignment = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":924 * cdef dict missing_user_values = None * cdef dict variable_alignment = None * cdef dict variable_display_width = None # <<<<<<<<<<<<<< * cdef dict variable_measure = None * cdef str table_name = "" */ __Pyx_INCREF(Py_None); __pyx_v_variable_display_width = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":925 * cdef dict variable_alignment = None * cdef dict variable_display_width = None * cdef dict variable_measure = None # <<<<<<<<<<<<<< * cdef str table_name = "" * #cdef dict variable_format = None */ __Pyx_INCREF(Py_None); __pyx_v_variable_measure = ((PyObject*)Py_None); /* "pyreadstat/pyreadstat.pyx":926 * cdef dict variable_display_width = None * cdef dict variable_measure = None * cdef str table_name = "" # <<<<<<<<<<<<<< * #cdef dict variable_format = None * cdef bint row_compression = 0 */ __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_); __pyx_v_table_name = __pyx_mstate_global->__pyx_kp_u_; /* "pyreadstat/pyreadstat.pyx":928 * cdef str table_name = "" * #cdef dict variable_format = None * cdef bint row_compression = 0 # <<<<<<<<<<<<<< * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_POR, file_label, column_labels, * file_format_version, note, table_name, variable_value_labels, missing_ranges,missing_user_values, */ __pyx_v_row_compression = 0; /* "pyreadstat/pyreadstat.pyx":929 * #cdef dict variable_format = None * cdef bint row_compression = 0 * run_write(df, dst_path, _readstat_writer.FILE_FORMAT_POR, file_label, column_labels, # <<<<<<<<<<<<<< * file_format_version, note, table_name, variable_value_labels, missing_ranges,missing_user_values, * variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) */ __pyx_f_10pyreadstat_16_readstat_writer_run_write(__pyx_v_df, __pyx_v_dst_path, __pyx_e_10pyreadstat_16_readstat_writer_FILE_FORMAT_POR, __pyx_v_file_label, __pyx_v_column_labels, __pyx_v_file_format_version, __pyx_v_note, __pyx_v_table_name, __pyx_v_variable_value_labels, __pyx_v_missing_ranges, __pyx_v_missing_user_values, __pyx_v_variable_alignment, __pyx_v_variable_display_width, __pyx_v_variable_measure, __pyx_v_variable_format, __pyx_v_row_compression); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 929, __pyx_L1_error) /* "pyreadstat/pyreadstat.pyx":894 * variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) * * def write_por(df, dst_path, str file_label="", object column_labels=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SPSS POR file. */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("pyreadstat.pyreadstat.write_por", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_note); __Pyx_XDECREF(__pyx_v_variable_value_labels); __Pyx_XDECREF(__pyx_v_missing_ranges); __Pyx_XDECREF(__pyx_v_missing_user_values); __Pyx_XDECREF(__pyx_v_variable_alignment); __Pyx_XDECREF(__pyx_v_variable_display_width); __Pyx_XDECREF(__pyx_v_variable_measure); __Pyx_XDECREF(__pyx_v_table_name); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* #### Code section: module_exttypes ### */ static PyObject *__pyx_tp_new_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o; #if CYTHON_COMPILING_IN_LIMITED_API allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); o = alloc_func(t, 0); #else #if CYTHON_USE_FREELISTS if (likely((int)(__pyx_mstate_global->__pyx_freecount_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks > 0) & (int)(t->tp_basicsize == sizeof(struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks)))) { o = (PyObject*)__pyx_mstate_global->__pyx_freelist_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks[--__pyx_mstate_global->__pyx_freecount_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks]; memset(o, 0, sizeof(struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks)); (void) PyObject_INIT(o, t); PyObject_GC_Track(o); } else #endif { o = (*t->tp_alloc)(t, 0); if (unlikely(!o)) return 0; } #endif return o; } static void __pyx_tp_dealloc_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks(PyObject *o) { struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *p = (struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks) { if (PyObject_CallFinalizerFromDealloc(o)) return; } } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->__pyx_v__); Py_CLEAR(p->__pyx_v_chunksize); Py_CLEAR(p->__pyx_v_df); Py_CLEAR(p->__pyx_v_file_path); Py_CLEAR(p->__pyx_v_kwargs); Py_CLEAR(p->__pyx_v_limit); Py_CLEAR(p->__pyx_v_meta); Py_CLEAR(p->__pyx_v_multiprocess); Py_CLEAR(p->__pyx_v_num_processes); Py_CLEAR(p->__pyx_v_num_rows); Py_CLEAR(p->__pyx_v_numrows); Py_CLEAR(p->__pyx_v_offset); Py_CLEAR(p->__pyx_v_read_function); #if CYTHON_USE_FREELISTS if (((int)(__pyx_mstate_global->__pyx_freecount_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks < 8) & (int)(Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks)))) { __pyx_mstate_global->__pyx_freelist_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks[__pyx_mstate_global->__pyx_freecount_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks++] = ((struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *)o); } else #endif { #if CYTHON_USE_TYPE_SLOTS (*Py_TYPE(o)->tp_free)(o); #else { freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); if (tp_free) tp_free(o); } #endif } } static int __pyx_tp_traverse_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *p = (struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks *)o; { e = __Pyx_call_type_traverse(o, 1, v, a); if (e) return e; } if (p->__pyx_v__) { e = (*v)(p->__pyx_v__, a); if (e) return e; } if (p->__pyx_v_chunksize) { e = (*v)(p->__pyx_v_chunksize, a); if (e) return e; } if (p->__pyx_v_df) { e = (*v)(p->__pyx_v_df, a); if (e) return e; } if (p->__pyx_v_file_path) { e = (*v)(p->__pyx_v_file_path, a); if (e) return e; } if (p->__pyx_v_kwargs) { e = (*v)(p->__pyx_v_kwargs, a); if (e) return e; } if (p->__pyx_v_limit) { e = (*v)(p->__pyx_v_limit, a); if (e) return e; } if (p->__pyx_v_meta) { e = (*v)(p->__pyx_v_meta, a); if (e) return e; } if (p->__pyx_v_multiprocess) { e = (*v)(p->__pyx_v_multiprocess, a); if (e) return e; } if (p->__pyx_v_num_processes) { e = (*v)(p->__pyx_v_num_processes, a); if (e) return e; } if (p->__pyx_v_num_rows) { e = (*v)(p->__pyx_v_num_rows, a); if (e) return e; } if (p->__pyx_v_numrows) { e = (*v)(p->__pyx_v_numrows, a); if (e) return e; } if (p->__pyx_v_offset) { e = (*v)(p->__pyx_v_offset, a); if (e) return e; } if (p->__pyx_v_read_function) { e = (*v)(p->__pyx_v_read_function, a); if (e) return e; } return 0; } #if CYTHON_USE_TYPE_SPECS static PyType_Slot __pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks_slots[] = { {Py_tp_dealloc, (void *)__pyx_tp_dealloc_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks}, {Py_tp_traverse, (void *)__pyx_tp_traverse_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks}, {Py_tp_new, (void *)__pyx_tp_new_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks}, {0, 0}, }; static PyType_Spec __pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks_spec = { "pyreadstat.pyreadstat.__pyx_scope_struct__read_file_in_chunks", sizeof(struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks), 0, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, __pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks_slots, }; #else static PyTypeObject __pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks = { PyVarObject_HEAD_INIT(0, 0) "pyreadstat.pyreadstat.""__pyx_scope_struct__read_file_in_chunks", /*tp_name*/ sizeof(struct __pyx_obj_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_as_async*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ 0, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ #if !CYTHON_USE_TYPE_SPECS 0, /*tp_dictoffset*/ #endif 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if CYTHON_USE_TP_FINALIZE 0, /*tp_finalize*/ #else NULL, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) 0, /*tp_vectorcall*/ #endif #if __PYX_NEED_TP_PRINT_SLOT == 1 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /*tp_watched*/ #endif #if PY_VERSION_HEX >= 0x030d00A4 0, /*tp_versions_used*/ #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 0, /*tp_pypy_flags*/ #endif }; #endif 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_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); __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); /*--- Function export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_init_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_type_init_code", 0); /*--- Type init code ---*/ #if CYTHON_USE_TYPE_SPECS __pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks)) __PYX_ERR(0, 542, __pyx_L1_error) if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks_spec, __pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks) < 0) __PYX_ERR(0, 542, __pyx_L1_error) #else __pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks = &__pyx_type_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks; #endif #if !CYTHON_COMPILING_IN_LIMITED_API #endif #if !CYTHON_USE_TYPE_SPECS if (__Pyx_PyType_Ready(__pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks) < 0) __PYX_ERR(0, 542, __pyx_L1_error) #endif #if !CYTHON_COMPILING_IN_LIMITED_API if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks->tp_dictoffset && __pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks->tp_getattro == PyObject_GenericGetAttr)) { __pyx_mstate->__pyx_ptype_10pyreadstat_10pyreadstat___pyx_scope_struct__read_file_in_chunks->tp_getattro = PyObject_GenericGetAttr; } #endif __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } 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, "run_conversion", (void (**)(void))&__pyx_f_10pyreadstat_16_readstat_parser_run_conversion, "PyObject *(PyObject *, __pyx_t_10pyreadstat_16_readstat_parser_py_file_format, __pyx_t_10pyreadstat_16_readstat_parser_py_file_extension, PyObject *, int, int, PyObject *, int, int, long, long, PyObject *, PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule("pyreadstat._readstat_writer"); 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, "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_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_pyreadstat(PyObject* module); /*proto*/ static PyModuleDef_Slot __pyx_moduledef_slots[] = { {Py_mod_create, (void*)__pyx_pymod_create}, {Py_mod_exec, (void*)__pyx_pymod_exec_pyreadstat}, #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, "pyreadstat", 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_pyreadstat(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC PyInit_pyreadstat(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_pyreadstat(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; 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 'pyreadstat' 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 "pyreadstat" 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_pyreadstat", 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__pyreadstat) { if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_name, __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.pyreadstat")) { if (unlikely((PyDict_SetItemString(modules, "pyreadstat.pyreadstat", __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); (void)__Pyx_modinit_function_export_code(__pyx_mstate); if (unlikely((__Pyx_modinit_type_init_code(__pyx_mstate) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) 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/pyreadstat.pyx":21 * ## if want to profile: # cython: profile=True * * import multiprocessing as mp # <<<<<<<<<<<<<< * * import narwhals.stable.v2 as nw */ __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_multiprocessing, 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_mp, __pyx_t_2) < 0) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":23 * import multiprocessing as mp * * import narwhals.stable.v2 as nw # <<<<<<<<<<<<<< * import numpy as np * */ __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_narwhals_stable_v2, __pyx_mstate_global->__pyx_tuple[0]); 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_nw, __pyx_t_2) < 0) __PYX_ERR(0, 23, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":24 * * import narwhals.stable.v2 as nw * import numpy as np # <<<<<<<<<<<<<< * * from _readstat_parser cimport py_file_format, py_file_extension, run_conversion */ __pyx_t_2 = __Pyx_ImportDottedModuleRelFirst(__pyx_mstate_global->__pyx_n_u_numpy, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_np, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":27 * * from _readstat_parser cimport py_file_format, py_file_extension, run_conversion * from _readstat_parser import PyreadstatError # <<<<<<<<<<<<<< * from _readstat_writer cimport run_write * cimport _readstat_parser, _readstat_writer */ __pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_readstat_parser, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __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_PyreadstatError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_PyreadstatError, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":30 * from _readstat_writer cimport run_write * cimport _readstat_parser, _readstat_writer * from worker import worker # <<<<<<<<<<<<<< * from pyfunctions import set_value_labels, set_catalog_to_sas * */ __pyx_t_3 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_worker); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_worker, __pyx_t_3, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __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_worker); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_worker, __pyx_t_3) < 0) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":31 * cimport _readstat_parser, _readstat_writer * from worker import worker * from pyfunctions import set_value_labels, set_catalog_to_sas # <<<<<<<<<<<<<< * * # Public interface */ __pyx_t_2 = __Pyx_PyList_Pack(2, __pyx_mstate_global->__pyx_n_u_set_value_labels, __pyx_mstate_global->__pyx_n_u_set_catalog_to_sas); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_pyfunctions, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __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_set_value_labels); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_set_value_labels, __pyx_t_2) < 0) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_set_catalog_to_sas); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_set_catalog_to_sas, __pyx_t_2) < 0) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":39 * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ __pyx_t_3 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* "pyreadstat/pyreadstat.pyx":37 * # Parsing functions * * def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ __pyx_t_4 = PyTuple_Pack(15, ((PyObject*)Py_False), ((PyObject*)Py_False), Py_None, ((PyObject*)Py_True), ((PyObject*)Py_False), Py_None, Py_None, ((PyObject*)Py_False), ((PyObject*)Py_False), __pyx_t_3, __pyx_t_2, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_1read_sas7bdat, 0, __pyx_mstate_global->__pyx_n_u_read_sas7bdat, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_sas7bdat, __pyx_t_2) < 0) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":140 * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, # <<<<<<<<<<<<<< * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ __pyx_t_2 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); /* "pyreadstat/pyreadstat.pyx":139 * * * def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, # <<<<<<<<<<<<<< * list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, * str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): */ __pyx_t_3 = PyTuple_Pack(11, ((PyObject*)Py_False), ((PyObject*)Py_False), Py_None, Py_None, ((PyObject*)Py_False), __pyx_t_2, __pyx_t_4, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_3read_xport, 0, __pyx_mstate_global->__pyx_n_u_read_xport, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_xport, __pyx_t_4) < 0) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":215 * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ __pyx_t_4 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* "pyreadstat/pyreadstat.pyx":213 * * * def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ __pyx_t_2 = PyTuple_Pack(15, ((PyObject*)Py_False), ((PyObject*)Py_False), ((PyObject*)Py_False), ((PyObject*)Py_True), ((PyObject*)Py_False), Py_None, Py_None, ((PyObject*)Py_False), ((PyObject*)Py_False), __pyx_t_4, __pyx_t_3, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_5read_dta, 0, __pyx_mstate_global->__pyx_n_u_read_dta, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_dta, __pyx_t_3) < 0) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "pyreadstat/pyreadstat.pyx":310 * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, # <<<<<<<<<<<<<< * list extra_date_formats=None, list extra_time_formats=None): * r""" */ __pyx_t_3 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* "pyreadstat/pyreadstat.pyx":308 * * * def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, */ __pyx_t_4 = PyTuple_Pack(15, ((PyObject*)Py_False), ((PyObject*)Py_False), ((PyObject*)Py_False), ((PyObject*)Py_True), ((PyObject*)Py_False), Py_None, Py_None, ((PyObject*)Py_False), ((PyObject*)Py_False), __pyx_t_3, __pyx_t_2, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_7read_sav, 0, __pyx_mstate_global->__pyx_n_u_read_sav, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_sav, __pyx_t_2) < 0) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pyreadstat/pyreadstat.pyx":405 * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, # <<<<<<<<<<<<<< * list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): * r""" */ __pyx_t_2 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyLong_From_int(((int)0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); /* "pyreadstat/pyreadstat.pyx":403 * * * def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, # <<<<<<<<<<<<<< * formats_as_category=True, formats_as_ordered_category=False, list usecols=None, * disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, */ __pyx_t_3 = PyTuple_Pack(13, ((PyObject*)Py_False), ((PyObject*)Py_False), ((PyObject*)Py_False), ((PyObject*)Py_True), ((PyObject*)Py_False), Py_None, ((PyObject*)Py_False), __pyx_t_2, __pyx_t_4, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_9read_por, 0, __pyx_mstate_global->__pyx_n_u_read_por, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[5])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_por, __pyx_t_4) < 0) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":490 * * * def read_sas7bcat(filename_path, str encoding=None, str output_format=None): # <<<<<<<<<<<<<< * r""" * Read a SAS sas7bcat file. The returning dataframe will be empty. The metadata object will contain a dictionary */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_11read_sas7bcat, 0, __pyx_mstate_global->__pyx_n_u_read_sas7bcat, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[6])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[1]); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_sas7bcat, __pyx_t_4) < 0) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":542 * # convenience functions to read in chunks * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, # <<<<<<<<<<<<<< * multiprocess=False, num_processes=4, num_rows=None, **kwargs): * """ */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_13read_file_in_chunks, 0, __pyx_mstate_global->__pyx_n_u_read_file_in_chunks, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[2]); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_file_in_chunks, __pyx_t_4) < 0) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":623 * offset += chunksize * * def read_file_multiprocessing(read_function, file_path, num_processes=None, num_rows=None, **kwargs): # <<<<<<<<<<<<<< * """ * Reads a file in parallel using multiprocessing. */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_16read_file_multiprocessing, 0, __pyx_mstate_global->__pyx_n_u_read_file_multiprocessing, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[7])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 623, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[1]); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_read_file_multiprocessing, __pyx_t_4) < 0) __PYX_ERR(0, 623, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":713 * # Write API * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_18write_sav, 0, __pyx_mstate_global->__pyx_n_u_write_sav, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[8])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[3]); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_write_sav, __pyx_t_4) < 0) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":788 * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): * """ */ __pyx_t_4 = __Pyx_PyLong_From_int(((int)15)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 788, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); /* "pyreadstat/pyreadstat.pyx":789 * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a STATA dta file */ __pyx_t_3 = PyTuple_Pack(6, ((PyObject*)__pyx_mstate_global->__pyx_kp_u_), Py_None, __pyx_t_4, Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 788, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":788 * variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) * * def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): * """ */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_20write_dta, 0, __pyx_mstate_global->__pyx_n_u_write_dta, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[9])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 788, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_write_dta, __pyx_t_4) < 0) __PYX_ERR(0, 788, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":850 * variable_display_width, variable_measure, variable_format, row_compression) * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, # <<<<<<<<<<<<<< * dict variable_format=None): * """ */ __pyx_t_4 = __Pyx_PyLong_From_int(((int)8)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); /* "pyreadstat/pyreadstat.pyx":851 * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, * dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SAS Xport (xpt) file. */ __pyx_t_3 = PyTuple_Pack(5, ((PyObject*)__pyx_mstate_global->__pyx_kp_u_), Py_None, Py_None, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":850 * variable_display_width, variable_measure, variable_format, row_compression) * * def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, # <<<<<<<<<<<<<< * dict variable_format=None): * """ */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_22write_xport, 0, __pyx_mstate_global->__pyx_n_u_write_xport, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[10])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_write_xport, __pyx_t_4) < 0) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":894 * variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) * * def write_por(df, dst_path, str file_label="", object column_labels=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SPSS POR file. */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_10pyreadstat_10pyreadstat_24write_por, 0, __pyx_mstate_global->__pyx_n_u_write_por, NULL, __pyx_mstate_global->__pyx_n_u_pyreadstat_pyreadstat, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[11])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 894, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[4]); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_write_por, __pyx_t_4) < 0) __PYX_ERR(0, 894, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "pyreadstat/pyreadstat.pyx":1 * # cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # <<<<<<<<<<<<<< * * # ############################################################################# */ __pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_4) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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); if (__pyx_m) { if (__pyx_mstate->__pyx_d && stringtab_initialized) { __Pyx_AddTraceback("init pyreadstat.pyreadstat", __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.pyreadstat"); } __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 192 <= 65535 const unsigned short n; #elif 192 / 2 < INT_MAX const unsigned int n; #elif 192 / 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_F_var_width_0, sizeof(__pyx_k_F_var_width_0), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_F_var_width_0 */ {__pyx_k_N_var_width, sizeof(__pyx_k_N_var_width), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_N_var_width */ {__pyx_k_Note_that_Cython_is_deliberately, sizeof(__pyx_k_Note_that_Cython_is_deliberately), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Note_that_Cython_is_deliberately */ {__pyx_k_Pool, sizeof(__pyx_k_Pool), 0, 1, 1}, /* PyObject cname: __pyx_n_u_Pool */ {__pyx_k_PyreadstatError, sizeof(__pyx_k_PyreadstatError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_PyreadstatError */ {__pyx_k_The_number_of_rows_of_the_file_c, sizeof(__pyx_k_The_number_of_rows_of_the_file_c), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_The_number_of_rows_of_the_file_c */ {__pyx_k_Version_not_supported, sizeof(__pyx_k_Version_not_supported), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Version_not_supported */ {__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_add_note, sizeof(__pyx_k_add_note), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_add_note */ {__pyx_k_apply_value_formats, sizeof(__pyx_k_apply_value_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_apply_value_formats */ {__pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 1, 1}, /* PyObject cname: __pyx_n_u_asyncio_coroutines */ {__pyx_k_catalog, sizeof(__pyx_k_catalog), 0, 1, 1}, /* PyObject cname: __pyx_n_u_catalog */ {__pyx_k_catalog_file, sizeof(__pyx_k_catalog_file), 0, 1, 1}, /* PyObject cname: __pyx_n_u_catalog_file */ {__pyx_k_chunk, sizeof(__pyx_k_chunk), 0, 1, 1}, /* PyObject cname: __pyx_n_u_chunk */ {__pyx_k_chunks, sizeof(__pyx_k_chunks), 0, 1, 1}, /* PyObject cname: __pyx_n_u_chunks */ {__pyx_k_chunksize, sizeof(__pyx_k_chunksize), 0, 1, 1}, /* PyObject cname: __pyx_n_u_chunksize */ {__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_close, sizeof(__pyx_k_close), 0, 1, 1}, /* PyObject cname: __pyx_n_u_close */ {__pyx_k_col_format, sizeof(__pyx_k_col_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_col_format */ {__pyx_k_col_name, sizeof(__pyx_k_col_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_col_name */ {__pyx_k_column_labels, sizeof(__pyx_k_column_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_column_labels */ {__pyx_k_columns, sizeof(__pyx_k_columns), 0, 1, 1}, /* PyObject cname: __pyx_n_u_columns */ {__pyx_k_compress, sizeof(__pyx_k_compress), 0, 1, 1}, /* PyObject cname: __pyx_n_u_compress */ {__pyx_k_compress_and_row_compress_cannot, sizeof(__pyx_k_compress_and_row_compress_cannot), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_compress_and_row_compress_cannot */ {__pyx_k_concat, sizeof(__pyx_k_concat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_concat */ {__pyx_k_concatenate, sizeof(__pyx_k_concatenate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_concatenate */ {__pyx_k_cpu_count, sizeof(__pyx_k_cpu_count), 0, 1, 1}, /* PyObject cname: __pyx_n_u_cpu_count */ {__pyx_k_data_frame, sizeof(__pyx_k_data_frame), 0, 1, 1}, /* PyObject cname: __pyx_n_u_data_frame */ {__pyx_k_dates_as_pandas, sizeof(__pyx_k_dates_as_pandas), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dates_as_pandas */ {__pyx_k_dates_as_pandas_datetime, sizeof(__pyx_k_dates_as_pandas_datetime), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dates_as_pandas_datetime */ {__pyx_k_df, sizeof(__pyx_k_df), 0, 1, 1}, /* PyObject cname: __pyx_n_u_df */ {__pyx_k_dict, sizeof(__pyx_k_dict), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dict */ {__pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_disable */ {__pyx_k_disable_datetime_conversion, sizeof(__pyx_k_disable_datetime_conversion), 0, 1, 1}, /* PyObject cname: __pyx_n_u_disable_datetime_conversion */ {__pyx_k_div, sizeof(__pyx_k_div), 0, 1, 1}, /* PyObject cname: __pyx_n_u_div */ {__pyx_k_divs, sizeof(__pyx_k_divs), 0, 1, 1}, /* PyObject cname: __pyx_n_u_divs */ {__pyx_k_drop, sizeof(__pyx_k_drop), 0, 1, 1}, /* PyObject cname: __pyx_n_u_drop */ {__pyx_k_dst_path, sizeof(__pyx_k_dst_path), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dst_path */ {__pyx_k_dta, sizeof(__pyx_k_dta), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dta */ {__pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_enable */ {__pyx_k_encoding, sizeof(__pyx_k_encoding), 0, 1, 1}, /* PyObject cname: __pyx_n_u_encoding */ {__pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_enumerate */ {__pyx_k_extra_date_formats, sizeof(__pyx_k_extra_date_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_extra_date_formats */ {__pyx_k_extra_datetime_formats, sizeof(__pyx_k_extra_datetime_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_extra_datetime_formats */ {__pyx_k_extra_time_formats, sizeof(__pyx_k_extra_time_formats), 0, 1, 1}, /* PyObject cname: __pyx_n_u_extra_time_formats */ {__pyx_k_file_extension, sizeof(__pyx_k_file_extension), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_extension */ {__pyx_k_file_format, sizeof(__pyx_k_file_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_format */ {__pyx_k_file_format_version, sizeof(__pyx_k_file_format_version), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_format_version */ {__pyx_k_file_label, sizeof(__pyx_k_file_label), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_label */ {__pyx_k_file_path, sizeof(__pyx_k_file_path), 0, 1, 1}, /* PyObject cname: __pyx_n_u_file_path */ {__pyx_k_filename_path, sizeof(__pyx_k_filename_path), 0, 1, 1}, /* PyObject cname: __pyx_n_u_filename_path */ {__pyx_k_final, sizeof(__pyx_k_final), 0, 1, 1}, /* PyObject cname: __pyx_n_u_final */ {__pyx_k_format, sizeof(__pyx_k_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_format */ {__pyx_k_formats_as_category, sizeof(__pyx_k_formats_as_category), 0, 1, 1}, /* PyObject cname: __pyx_n_u_formats_as_category */ {__pyx_k_formats_as_ordered_category, sizeof(__pyx_k_formats_as_ordered_category), 0, 1, 1}, /* PyObject cname: __pyx_n_u_formats_as_ordered_category */ {__pyx_k_formats_presets, sizeof(__pyx_k_formats_presets), 0, 1, 1}, /* PyObject cname: __pyx_n_u_formats_presets */ {__pyx_k_from_native, sizeof(__pyx_k_from_native), 0, 1, 1}, /* PyObject cname: __pyx_n_u_from_native */ {__pyx_k_func, sizeof(__pyx_k_func), 0, 1, 1}, /* PyObject cname: __pyx_n_u_func */ {__pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_gc */ {__pyx_k_get, sizeof(__pyx_k_get), 0, 1, 1}, /* PyObject cname: __pyx_n_u_get */ {__pyx_k_how, sizeof(__pyx_k_how), 0, 1, 1}, /* PyObject cname: __pyx_n_u_how */ {__pyx_k_implementation, sizeof(__pyx_k_implementation), 0, 1, 1}, /* PyObject cname: __pyx_n_u_implementation */ {__pyx_k_indx, sizeof(__pyx_k_indx), 0, 1, 1}, /* PyObject cname: __pyx_n_u_indx */ {__pyx_k_inf, sizeof(__pyx_k_inf), 0, 1, 1}, /* PyObject cname: __pyx_n_u_inf */ {__pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 1, 1}, /* PyObject cname: __pyx_n_u_initializing */ {__pyx_k_integer, sizeof(__pyx_k_integer), 0, 1, 1}, /* PyObject cname: __pyx_n_u_integer */ {__pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_coroutine */ {__pyx_k_is_pandas, sizeof(__pyx_k_is_pandas), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_pandas */ {__pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_isenabled */ {__pyx_k_ispandas, sizeof(__pyx_k_ispandas), 0, 1, 1}, /* PyObject cname: __pyx_n_u_ispandas */ {__pyx_k_items, sizeof(__pyx_k_items), 0, 1, 1}, /* PyObject cname: __pyx_n_u_items */ {__pyx_k_jobs, sizeof(__pyx_k_jobs), 0, 1, 1}, /* PyObject cname: __pyx_n_u_jobs */ {__pyx_k_key, sizeof(__pyx_k_key), 0, 1, 1}, /* PyObject cname: __pyx_n_u_key */ {__pyx_k_keys, sizeof(__pyx_k_keys), 0, 1, 1}, /* PyObject cname: __pyx_n_u_keys */ {__pyx_k_kwargs, sizeof(__pyx_k_kwargs), 0, 1, 1}, /* PyObject cname: __pyx_n_u_kwargs */ {__pyx_k_limit, sizeof(__pyx_k_limit), 0, 1, 1}, /* PyObject cname: __pyx_n_u_limit */ {__pyx_k_main, sizeof(__pyx_k_main), 0, 1, 1}, /* PyObject cname: __pyx_n_u_main */ {__pyx_k_map, sizeof(__pyx_k_map), 0, 1, 1}, /* PyObject cname: __pyx_n_u_map */ {__pyx_k_max, sizeof(__pyx_k_max), 0, 1, 1}, /* PyObject cname: __pyx_n_u_max */ {__pyx_k_meta, sizeof(__pyx_k_meta), 0, 1, 1}, /* PyObject cname: __pyx_n_u_meta */ {__pyx_k_metadata, sizeof(__pyx_k_metadata), 0, 1, 1}, /* PyObject cname: __pyx_n_u_metadata */ {__pyx_k_metadataonly, sizeof(__pyx_k_metadataonly), 0, 1, 1}, /* PyObject cname: __pyx_n_u_metadataonly */ {__pyx_k_metaonly, sizeof(__pyx_k_metaonly), 0, 1, 1}, /* PyObject cname: __pyx_n_u_metaonly */ {__pyx_k_missing_ranges, sizeof(__pyx_k_missing_ranges), 0, 1, 1}, /* PyObject cname: __pyx_n_u_missing_ranges */ {__pyx_k_missing_user_values, sizeof(__pyx_k_missing_user_values), 0, 1, 1}, /* PyObject cname: __pyx_n_u_missing_user_values */ {__pyx_k_module, sizeof(__pyx_k_module), 0, 1, 1}, /* PyObject cname: __pyx_n_u_module */ {__pyx_k_mp, sizeof(__pyx_k_mp), 0, 1, 1}, /* PyObject cname: __pyx_n_u_mp */ {__pyx_k_multiprocess, sizeof(__pyx_k_multiprocess), 0, 1, 1}, /* PyObject cname: __pyx_n_u_multiprocess */ {__pyx_k_multiprocessing, sizeof(__pyx_k_multiprocessing), 0, 1, 1}, /* PyObject cname: __pyx_n_u_multiprocessing */ {__pyx_k_name, sizeof(__pyx_k_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_name */ {__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_next, sizeof(__pyx_k_next), 0, 1, 1}, /* PyObject cname: __pyx_n_u_next */ {__pyx_k_no_datetime_conversion, sizeof(__pyx_k_no_datetime_conversion), 0, 1, 1}, /* PyObject cname: __pyx_n_u_no_datetime_conversion */ {__pyx_k_note, sizeof(__pyx_k_note), 0, 1, 1}, /* PyObject cname: __pyx_n_u_note */ {__pyx_k_np, sizeof(__pyx_k_np), 0, 1, 1}, /* PyObject cname: __pyx_n_u_np */ {__pyx_k_num_processes, sizeof(__pyx_k_num_processes), 0, 1, 1}, /* PyObject cname: __pyx_n_u_num_processes */ {__pyx_k_num_rows, sizeof(__pyx_k_num_rows), 0, 1, 1}, /* PyObject cname: __pyx_n_u_num_rows */ {__pyx_k_num_rows_must_be_specified_for_r, sizeof(__pyx_k_num_rows_must_be_specified_for_r), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_num_rows_must_be_specified_for_r */ {__pyx_k_number_rows, sizeof(__pyx_k_number_rows), 0, 1, 1}, /* PyObject cname: __pyx_n_u_number_rows */ {__pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 1, 1}, /* PyObject cname: __pyx_n_u_numpy */ {__pyx_k_numrows, sizeof(__pyx_k_numrows), 0, 1, 1}, /* PyObject cname: __pyx_n_u_numrows */ {__pyx_k_nw, sizeof(__pyx_k_nw), 0, 1, 1}, /* PyObject cname: __pyx_n_u_nw */ {__pyx_k_offset, sizeof(__pyx_k_offset), 0, 1, 1}, /* PyObject cname: __pyx_n_u_offset */ {__pyx_k_offsets, sizeof(__pyx_k_offsets), 0, 1, 1}, /* PyObject cname: __pyx_n_u_offsets */ {__pyx_k_output_format, sizeof(__pyx_k_output_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_output_format */ {__pyx_k_pool, sizeof(__pyx_k_pool), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pool */ {__pyx_k_pop, sizeof(__pyx_k_pop), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pop */ {__pyx_k_por, sizeof(__pyx_k_por), 0, 1, 1}, /* PyObject cname: __pyx_n_u_por */ {__pyx_k_prev_div, sizeof(__pyx_k_prev_div), 0, 1, 1}, /* PyObject cname: __pyx_n_u_prev_div */ {__pyx_k_prev_offset, sizeof(__pyx_k_prev_offset), 0, 1, 1}, /* PyObject cname: __pyx_n_u_prev_offset */ {__pyx_k_processes, sizeof(__pyx_k_processes), 0, 1, 1}, /* PyObject cname: __pyx_n_u_processes */ {__pyx_k_pyfunctions, sizeof(__pyx_k_pyfunctions), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pyfunctions */ {__pyx_k_pyreadstat_pyreadstat, sizeof(__pyx_k_pyreadstat_pyreadstat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pyreadstat_pyreadstat */ {__pyx_k_pyreadstat_pyreadstat_pyx, sizeof(__pyx_k_pyreadstat_pyreadstat_pyx), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_pyreadstat_pyreadstat_pyx */ {__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_read_dta, sizeof(__pyx_k_read_dta), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_dta */ {__pyx_k_read_file_in_chunks, sizeof(__pyx_k_read_file_in_chunks), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_file_in_chunks */ {__pyx_k_read_file_multiprocessing, sizeof(__pyx_k_read_file_multiprocessing), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_file_multiprocessing */ {__pyx_k_read_function, sizeof(__pyx_k_read_function), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_function */ {__pyx_k_read_por, sizeof(__pyx_k_read_por), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_por */ {__pyx_k_read_sas7bcat, sizeof(__pyx_k_read_sas7bcat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_sas7bcat */ {__pyx_k_read_sas7bcat_is_not_supported, sizeof(__pyx_k_read_sas7bcat_is_not_supported), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_read_sas7bcat_is_not_supported */ {__pyx_k_read_sas7bcat_not_supported, sizeof(__pyx_k_read_sas7bcat_not_supported), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_read_sas7bcat_not_supported */ {__pyx_k_read_sas7bdat, sizeof(__pyx_k_read_sas7bdat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_sas7bdat */ {__pyx_k_read_sav, sizeof(__pyx_k_read_sav), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_sav */ {__pyx_k_read_xport, sizeof(__pyx_k_read_xport), 0, 1, 1}, /* PyObject cname: __pyx_n_u_read_xport */ {__pyx_k_readstat_parser, sizeof(__pyx_k_readstat_parser), 0, 1, 1}, /* PyObject cname: __pyx_n_u_readstat_parser */ {__pyx_k_reset_index, sizeof(__pyx_k_reset_index), 0, 1, 1}, /* PyObject cname: __pyx_n_u_reset_index */ {__pyx_k_restricted_integer, sizeof(__pyx_k_restricted_integer), 0, 1, 1}, /* PyObject cname: __pyx_n_u_restricted_integer */ {__pyx_k_row_compress, sizeof(__pyx_k_row_compress), 0, 1, 1}, /* PyObject cname: __pyx_n_u_row_compress */ {__pyx_k_row_compression, sizeof(__pyx_k_row_compression), 0, 1, 1}, /* PyObject cname: __pyx_n_u_row_compression */ {__pyx_k_row_limit, sizeof(__pyx_k_row_limit), 0, 1, 1}, /* PyObject cname: __pyx_n_u_row_limit */ {__pyx_k_row_offset, sizeof(__pyx_k_row_offset), 0, 1, 1}, /* PyObject cname: __pyx_n_u_row_offset */ {__pyx_k_sas7bcat, sizeof(__pyx_k_sas7bcat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas7bcat */ {__pyx_k_sas7bdat, sizeof(__pyx_k_sas7bdat), 0, 1, 1}, /* PyObject cname: __pyx_n_u_sas7bdat */ {__pyx_k_sav_zsav, sizeof(__pyx_k_sav_zsav), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_sav_zsav */ {__pyx_k_send, sizeof(__pyx_k_send), 0, 1, 1}, /* PyObject cname: __pyx_n_u_send */ {__pyx_k_set_catalog_to_sas, sizeof(__pyx_k_set_catalog_to_sas), 0, 1, 1}, /* PyObject cname: __pyx_n_u_set_catalog_to_sas */ {__pyx_k_set_name, sizeof(__pyx_k_set_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_set_name */ {__pyx_k_set_value_labels, sizeof(__pyx_k_set_value_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_set_value_labels */ {__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_table_name, sizeof(__pyx_k_table_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_table_name */ {__pyx_k_test, sizeof(__pyx_k_test), 0, 1, 1}, /* PyObject cname: __pyx_n_u_test */ {__pyx_k_throw, sizeof(__pyx_k_throw), 0, 1, 1}, /* PyObject cname: __pyx_n_u_throw */ {__pyx_k_to_native, sizeof(__pyx_k_to_native), 0, 1, 1}, /* PyObject cname: __pyx_n_u_to_native */ {__pyx_k_usecols, sizeof(__pyx_k_usecols), 0, 1, 1}, /* PyObject cname: __pyx_n_u_usecols */ {__pyx_k_user_missing, sizeof(__pyx_k_user_missing), 0, 1, 1}, /* PyObject cname: __pyx_n_u_user_missing */ {__pyx_k_usernan, sizeof(__pyx_k_usernan), 0, 1, 1}, /* PyObject cname: __pyx_n_u_usernan */ {__pyx_k_v2, sizeof(__pyx_k_v2), 0, 1, 1}, /* PyObject cname: __pyx_n_u_v2 */ {__pyx_k_value, sizeof(__pyx_k_value), 0, 1, 1}, /* PyObject cname: __pyx_n_u_value */ {__pyx_k_var_width, sizeof(__pyx_k_var_width), 0, 1, 1}, /* PyObject cname: __pyx_n_u_var_width */ {__pyx_k_variable_alignment, sizeof(__pyx_k_variable_alignment), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_alignment */ {__pyx_k_variable_display_width, sizeof(__pyx_k_variable_display_width), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_display_width */ {__pyx_k_variable_format, sizeof(__pyx_k_variable_format), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_format */ {__pyx_k_variable_measure, sizeof(__pyx_k_variable_measure), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_measure */ {__pyx_k_variable_value_labels, sizeof(__pyx_k_variable_value_labels), 0, 1, 1}, /* PyObject cname: __pyx_n_u_variable_value_labels */ {__pyx_k_version, sizeof(__pyx_k_version), 0, 1, 1}, /* PyObject cname: __pyx_n_u_version */ {__pyx_k_vertical, sizeof(__pyx_k_vertical), 0, 1, 1}, /* PyObject cname: __pyx_n_u_vertical */ {__pyx_k_worker, sizeof(__pyx_k_worker), 0, 1, 1}, /* PyObject cname: __pyx_n_u_worker */ {__pyx_k_write_dta, sizeof(__pyx_k_write_dta), 0, 1, 1}, /* PyObject cname: __pyx_n_u_write_dta */ {__pyx_k_write_por, sizeof(__pyx_k_write_por), 0, 1, 1}, /* PyObject cname: __pyx_n_u_write_por */ {__pyx_k_write_sav, sizeof(__pyx_k_write_sav), 0, 1, 1}, /* PyObject cname: __pyx_n_u_write_sav */ {__pyx_k_write_xport, sizeof(__pyx_k_write_xport), 0, 1, 1}, /* PyObject cname: __pyx_n_u_write_xport */ {__pyx_k_x, sizeof(__pyx_k_x), 0, 1, 1}, /* PyObject cname: __pyx_n_u_x */ {__pyx_k_xport, sizeof(__pyx_k_xport), 0, 1, 1}, /* PyObject cname: __pyx_n_u_xport */ {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, 676, __pyx_L1_error) __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 680, __pyx_L1_error) __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_max); if (!__pyx_builtin_max) __PYX_ERR(0, 781, __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/pyreadstat.pyx":23 * import multiprocessing as mp * * import narwhals.stable.v2 as nw # <<<<<<<<<<<<<< * import numpy as np * */ __pyx_mstate_global->__pyx_tuple[0] = 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[0])) __PYX_ERR(0, 23, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]); /* "pyreadstat/pyreadstat.pyx":490 * * * def read_sas7bcat(filename_path, str encoding=None, str output_format=None): # <<<<<<<<<<<<<< * r""" * Read a SAS sas7bcat file. The returning dataframe will be empty. The metadata object will contain a dictionary */ __pyx_mstate_global->__pyx_tuple[1] = PyTuple_Pack(2, Py_None, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[1])) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[1]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[1]); /* "pyreadstat/pyreadstat.pyx":542 * # convenience functions to read in chunks * * def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, # <<<<<<<<<<<<<< * multiprocess=False, num_processes=4, num_rows=None, **kwargs): * """ */ __pyx_mstate_global->__pyx_tuple[2] = PyTuple_Pack(6, ((PyObject*)__pyx_mstate_global->__pyx_int_100000), ((PyObject*)__pyx_mstate_global->__pyx_int_0), ((PyObject*)__pyx_mstate_global->__pyx_int_0), ((PyObject*)Py_False), ((PyObject*)__pyx_mstate_global->__pyx_int_4), Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[2])) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[2]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[2]); /* "pyreadstat/pyreadstat.pyx":713 * # Write API * * def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, # <<<<<<<<<<<<<< * dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, * dict variable_measure=None, dict variable_format=None): */ __pyx_mstate_global->__pyx_tuple[3] = PyTuple_Pack(10, ((PyObject*)__pyx_mstate_global->__pyx_kp_u_), Py_None, ((PyObject*)Py_False), ((PyObject*)Py_False), Py_None, Py_None, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[3])) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[3]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[3]); /* "pyreadstat/pyreadstat.pyx":894 * variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) * * def write_por(df, dst_path, str file_label="", object column_labels=None, dict variable_format=None): # <<<<<<<<<<<<<< * """ * Writes a dataframe to a SPSS POR file. */ __pyx_mstate_global->__pyx_tuple[4] = PyTuple_Pack(3, ((PyObject*)__pyx_mstate_global->__pyx_kp_u_), Py_None, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[4])) __PYX_ERR(0, 894, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[4]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[4]); __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; __pyx_mstate->__pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type; __pyx_mstate->__pyx_umethod_PyDict_Type_pop.method_name = &__pyx_mstate->__pyx_n_u_pop; 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_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_4 = PyLong_FromLong(4); if (unlikely(!__pyx_mstate->__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_mstate->__pyx_int_100000 = PyLong_FromLong(100000L); if (unlikely(!__pyx_mstate->__pyx_int_100000)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } /* #### Code section: init_codeobjects ### */ \ typedef struct { unsigned int argcount : 5; unsigned int num_posonly_args : 1; unsigned int num_kwonly_args : 1; unsigned int nlocals : 5; unsigned int flags : 10; unsigned int first_line : 10; unsigned int line_table_length : 14; } __Pyx_PyCode_New_function_description; /* NewCodeObj.proto */ static PyObject* __Pyx_PyCode_New( const __Pyx_PyCode_New_function_description descr, PyObject * const *varnames, PyObject *filename, PyObject *funcname, const char *line_table, PyObject *tuple_dedup_map ); static int __Pyx_CreateCodeObjects(__pyx_mstatetype *__pyx_mstate) { PyObject* tuple_dedup_map = PyDict_New(); if (unlikely(!tuple_dedup_map)) return -1; { const __Pyx_PyCode_New_function_description descr = {8, 0, 0, 13, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS|CO_GENERATOR), 542, 18}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_read_function, __pyx_mstate->__pyx_n_u_file_path, __pyx_mstate->__pyx_n_u_chunksize, __pyx_mstate->__pyx_n_u_offset, __pyx_mstate->__pyx_n_u_limit, __pyx_mstate->__pyx_n_u_multiprocess, __pyx_mstate->__pyx_n_u_num_processes, __pyx_mstate->__pyx_n_u_num_rows, __pyx_mstate->__pyx_n_u_kwargs, __pyx_mstate->__pyx_n_u__4, __pyx_mstate->__pyx_n_u_meta, __pyx_mstate->__pyx_n_u_numrows, __pyx_mstate->__pyx_n_u_df}; __pyx_mstate_global->__pyx_codeobj_tab[0] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_file_in_chunks, __pyx_k_22DJa_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[0])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {16, 0, 0, 26, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 37, 238}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_filename_path, __pyx_mstate->__pyx_n_u_metadataonly, __pyx_mstate->__pyx_n_u_dates_as_pandas_datetime, __pyx_mstate->__pyx_n_u_catalog_file, __pyx_mstate->__pyx_n_u_formats_as_category, __pyx_mstate->__pyx_n_u_formats_as_ordered_category, __pyx_mstate->__pyx_n_u_encoding, __pyx_mstate->__pyx_n_u_usecols, __pyx_mstate->__pyx_n_u_user_missing, __pyx_mstate->__pyx_n_u_disable_datetime_conversion, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_extra_datetime_formats, __pyx_mstate->__pyx_n_u_extra_date_formats, __pyx_mstate->__pyx_n_u_extra_time_formats, __pyx_mstate->__pyx_n_u_metaonly, __pyx_mstate->__pyx_n_u_dates_as_pandas, __pyx_mstate->__pyx_n_u_usernan, __pyx_mstate->__pyx_n_u_no_datetime_conversion, __pyx_mstate->__pyx_n_u_file_format, __pyx_mstate->__pyx_n_u_file_extension, __pyx_mstate->__pyx_n_u_data_frame, __pyx_mstate->__pyx_n_u_metadata, __pyx_mstate->__pyx_n_u__4, __pyx_mstate->__pyx_n_u_catalog}; __pyx_mstate_global->__pyx_codeobj_tab[1] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_sas7bdat, __pyx_k_55UUV_OObbuuv_55FFXXY_44RRSH_q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[1])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {12, 0, 0, 20, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 139, 169}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_filename_path, __pyx_mstate->__pyx_n_u_metadataonly, __pyx_mstate->__pyx_n_u_dates_as_pandas_datetime, __pyx_mstate->__pyx_n_u_encoding, __pyx_mstate->__pyx_n_u_usecols, __pyx_mstate->__pyx_n_u_disable_datetime_conversion, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_extra_datetime_formats, __pyx_mstate->__pyx_n_u_extra_date_formats, __pyx_mstate->__pyx_n_u_extra_time_formats, __pyx_mstate->__pyx_n_u_metaonly, __pyx_mstate->__pyx_n_u_dates_as_pandas, __pyx_mstate->__pyx_n_u_usernan, __pyx_mstate->__pyx_n_u_no_datetime_conversion, __pyx_mstate->__pyx_n_u_file_format, __pyx_mstate->__pyx_n_u_file_extension, __pyx_mstate->__pyx_n_u_data_frame, __pyx_mstate->__pyx_n_u_metadata}; __pyx_mstate_global->__pyx_codeobj_tab[2] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_xport, __pyx_k_22RRS_EEVVW_IIggh_q_1_q_q_q_6a, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[2])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {16, 0, 0, 24, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 213, 218}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_filename_path, __pyx_mstate->__pyx_n_u_metadataonly, __pyx_mstate->__pyx_n_u_dates_as_pandas_datetime, __pyx_mstate->__pyx_n_u_apply_value_formats, __pyx_mstate->__pyx_n_u_formats_as_category, __pyx_mstate->__pyx_n_u_formats_as_ordered_category, __pyx_mstate->__pyx_n_u_encoding, __pyx_mstate->__pyx_n_u_usecols, __pyx_mstate->__pyx_n_u_user_missing, __pyx_mstate->__pyx_n_u_disable_datetime_conversion, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_extra_datetime_formats, __pyx_mstate->__pyx_n_u_extra_date_formats, __pyx_mstate->__pyx_n_u_extra_time_formats, __pyx_mstate->__pyx_n_u_metaonly, __pyx_mstate->__pyx_n_u_dates_as_pandas, __pyx_mstate->__pyx_n_u_usernan, __pyx_mstate->__pyx_n_u_no_datetime_conversion, __pyx_mstate->__pyx_n_u_file_format, __pyx_mstate->__pyx_n_u_file_extension, __pyx_mstate->__pyx_n_u_data_frame, __pyx_mstate->__pyx_n_u_metadata}; __pyx_mstate_global->__pyx_codeobj_tab[3] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_dta, __pyx_k_00PPQ_JJ_ppq_00AASST_MQ_q_1_q_q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[3])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {16, 0, 0, 24, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 308, 218}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_filename_path, __pyx_mstate->__pyx_n_u_metadataonly, __pyx_mstate->__pyx_n_u_dates_as_pandas_datetime, __pyx_mstate->__pyx_n_u_apply_value_formats, __pyx_mstate->__pyx_n_u_formats_as_category, __pyx_mstate->__pyx_n_u_formats_as_ordered_category, __pyx_mstate->__pyx_n_u_encoding, __pyx_mstate->__pyx_n_u_usecols, __pyx_mstate->__pyx_n_u_user_missing, __pyx_mstate->__pyx_n_u_disable_datetime_conversion, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_extra_datetime_formats, __pyx_mstate->__pyx_n_u_extra_date_formats, __pyx_mstate->__pyx_n_u_extra_time_formats, __pyx_mstate->__pyx_n_u_metaonly, __pyx_mstate->__pyx_n_u_dates_as_pandas, __pyx_mstate->__pyx_n_u_usernan, __pyx_mstate->__pyx_n_u_no_datetime_conversion, __pyx_mstate->__pyx_n_u_file_format, __pyx_mstate->__pyx_n_u_file_extension, __pyx_mstate->__pyx_n_u_data_frame, __pyx_mstate->__pyx_n_u_metadata}; __pyx_mstate_global->__pyx_codeobj_tab[4] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_sav, __pyx_k_00PPQ_JJ_ppq_00AASSkkl_1_q_1_q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[4])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {14, 0, 0, 23, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 403, 201}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_filename_path, __pyx_mstate->__pyx_n_u_metadataonly, __pyx_mstate->__pyx_n_u_dates_as_pandas_datetime, __pyx_mstate->__pyx_n_u_apply_value_formats, __pyx_mstate->__pyx_n_u_formats_as_category, __pyx_mstate->__pyx_n_u_formats_as_ordered_category, __pyx_mstate->__pyx_n_u_usecols, __pyx_mstate->__pyx_n_u_disable_datetime_conversion, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_extra_datetime_formats, __pyx_mstate->__pyx_n_u_extra_date_formats, __pyx_mstate->__pyx_n_u_extra_time_formats, __pyx_mstate->__pyx_n_u_metaonly, __pyx_mstate->__pyx_n_u_dates_as_pandas, __pyx_mstate->__pyx_n_u_usernan, __pyx_mstate->__pyx_n_u_no_datetime_conversion, __pyx_mstate->__pyx_n_u_encoding, __pyx_mstate->__pyx_n_u_file_format, __pyx_mstate->__pyx_n_u_file_extension, __pyx_mstate->__pyx_n_u_data_frame, __pyx_mstate->__pyx_n_u_metadata}; __pyx_mstate_global->__pyx_codeobj_tab[5] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_por, __pyx_k_00PPQ_J_00AASST_MQp_q_1_q_q_q_6, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[5])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {3, 0, 0, 17, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 490, 134}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_filename_path, __pyx_mstate->__pyx_n_u_encoding, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_metaonly, __pyx_mstate->__pyx_n_u_dates_as_pandas, __pyx_mstate->__pyx_n_u_usecols, __pyx_mstate->__pyx_n_u_usernan, __pyx_mstate->__pyx_n_u_no_datetime_conversion, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_extra_datetime_formats, __pyx_mstate->__pyx_n_u_extra_date_formats, __pyx_mstate->__pyx_n_u_extra_time_formats, __pyx_mstate->__pyx_n_u_file_format, __pyx_mstate->__pyx_n_u_file_extension, __pyx_mstate->__pyx_n_u_data_frame, __pyx_mstate->__pyx_n_u_metadata}; __pyx_mstate_global->__pyx_codeobj_tab[6] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_sas7bcat, __pyx_k_4A_q_Q_6a_A_FVV_a_9IMeeppq_99QQ, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[6])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {4, 0, 0, 28, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS), 623, 536}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_read_function, __pyx_mstate->__pyx_n_u_file_path, __pyx_mstate->__pyx_n_u_num_processes, __pyx_mstate->__pyx_n_u_num_rows, __pyx_mstate->__pyx_n_u_kwargs, __pyx_mstate->__pyx_n_u__4, __pyx_mstate->__pyx_n_u_row_offset, __pyx_mstate->__pyx_n_u_row_limit, __pyx_mstate->__pyx_n_u_meta, __pyx_mstate->__pyx_n_u_numrows, __pyx_mstate->__pyx_n_u_final, __pyx_mstate->__pyx_n_u_divs, __pyx_mstate->__pyx_n_u_offsets, __pyx_mstate->__pyx_n_u_prev_offset, __pyx_mstate->__pyx_n_u_prev_div, __pyx_mstate->__pyx_n_u_indx, __pyx_mstate->__pyx_n_u_div, __pyx_mstate->__pyx_n_u_offset, __pyx_mstate->__pyx_n_u_jobs, __pyx_mstate->__pyx_n_u_pool, __pyx_mstate->__pyx_n_u_chunks, __pyx_mstate->__pyx_n_u_output_format, __pyx_mstate->__pyx_n_u_keys, __pyx_mstate->__pyx_n_u_key, __pyx_mstate->__pyx_n_u_ispandas, __pyx_mstate->__pyx_n_u_x, __pyx_mstate->__pyx_n_u_chunksize, __pyx_mstate->__pyx_n_u_chunk}; __pyx_mstate_global->__pyx_codeobj_tab[7] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_read_file_multiprocessing, __pyx_k_88LA_T_iq_S_Yc_iq_t1_1Bj_A_d_1, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[7])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {12, 0, 0, 21, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 713, 248}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_df, __pyx_mstate->__pyx_n_u_dst_path, __pyx_mstate->__pyx_n_u_file_label, __pyx_mstate->__pyx_n_u_column_labels, __pyx_mstate->__pyx_n_u_compress, __pyx_mstate->__pyx_n_u_row_compress, __pyx_mstate->__pyx_n_u_note, __pyx_mstate->__pyx_n_u_variable_value_labels, __pyx_mstate->__pyx_n_u_missing_ranges, __pyx_mstate->__pyx_n_u_variable_display_width, __pyx_mstate->__pyx_n_u_variable_measure, __pyx_mstate->__pyx_n_u_variable_format, __pyx_mstate->__pyx_n_u_file_format_version, __pyx_mstate->__pyx_n_u_var_width, __pyx_mstate->__pyx_n_u_row_compression, __pyx_mstate->__pyx_n_u_table_name, __pyx_mstate->__pyx_n_u_missing_user_values, __pyx_mstate->__pyx_n_u_variable_alignment, __pyx_mstate->__pyx_n_u_formats_presets, __pyx_mstate->__pyx_n_u_col_name, __pyx_mstate->__pyx_n_u_col_format}; __pyx_mstate_global->__pyx_codeobj_tab[8] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_write_sav, __pyx_k_JJZZnno_11K1_A_1_y_A_oQa_q_a_q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[8])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {8, 0, 0, 16, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 788, 192}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_df, __pyx_mstate->__pyx_n_u_dst_path, __pyx_mstate->__pyx_n_u_file_label, __pyx_mstate->__pyx_n_u_column_labels, __pyx_mstate->__pyx_n_u_version, __pyx_mstate->__pyx_n_u_variable_value_labels, __pyx_mstate->__pyx_n_u_missing_user_values, __pyx_mstate->__pyx_n_u_variable_format, __pyx_mstate->__pyx_n_u_file_format_version, __pyx_mstate->__pyx_n_u_note, __pyx_mstate->__pyx_n_u_table_name, __pyx_mstate->__pyx_n_u_missing_ranges, __pyx_mstate->__pyx_n_u_variable_alignment, __pyx_mstate->__pyx_n_u_variable_display_width, __pyx_mstate->__pyx_n_u_variable_measure, __pyx_mstate->__pyx_n_u_row_compression}; __pyx_mstate_global->__pyx_codeobj_tab[9] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_write_dta, __pyx_k_J_LAB_xs_a_A_a_A_a_A_a_T_a_S_a, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[9])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {7, 0, 0, 15, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 850, 107}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_df, __pyx_mstate->__pyx_n_u_dst_path, __pyx_mstate->__pyx_n_u_file_label, __pyx_mstate->__pyx_n_u_column_labels, __pyx_mstate->__pyx_n_u_table_name, __pyx_mstate->__pyx_n_u_file_format_version, __pyx_mstate->__pyx_n_u_variable_format, __pyx_mstate->__pyx_n_u_variable_value_labels, __pyx_mstate->__pyx_n_u_note, __pyx_mstate->__pyx_n_u_missing_ranges, __pyx_mstate->__pyx_n_u_missing_user_values, __pyx_mstate->__pyx_n_u_variable_alignment, __pyx_mstate->__pyx_n_u_variable_display_width, __pyx_mstate->__pyx_n_u_variable_measure, __pyx_mstate->__pyx_n_u_row_compression}; __pyx_mstate_global->__pyx_codeobj_tab[10] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_write_xport, __pyx_k_11LLaab_a_A_q_A_1_q_Qd_A_V_FoUV, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[10])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {5, 0, 0, 15, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 894, 110}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_df, __pyx_mstate->__pyx_n_u_dst_path, __pyx_mstate->__pyx_n_u_file_label, __pyx_mstate->__pyx_n_u_column_labels, __pyx_mstate->__pyx_n_u_variable_format, __pyx_mstate->__pyx_n_u_note, __pyx_mstate->__pyx_n_u_file_format_version, __pyx_mstate->__pyx_n_u_variable_value_labels, __pyx_mstate->__pyx_n_u_missing_ranges, __pyx_mstate->__pyx_n_u_missing_user_values, __pyx_mstate->__pyx_n_u_variable_alignment, __pyx_mstate->__pyx_n_u_variable_display_width, __pyx_mstate->__pyx_n_u_variable_measure, __pyx_mstate->__pyx_n_u_table_name, __pyx_mstate->__pyx_n_u_row_compression}; __pyx_mstate_global->__pyx_codeobj_tab[11] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_pyreadstat_pyreadstat_pyx, __pyx_mstate->__pyx_n_u_write_por, __pyx_k_J_0_1_A_q_A_1_q_Qd_l_V_FoUV_33E, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[11])) goto bad; } Py_DECREF(tuple_dedup_map); return 0; bad: Py_DECREF(tuple_dedup_map); return -1; } /* #### 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) /* CachedMethodType.init */ #if CYTHON_COMPILING_IN_LIMITED_API { PyObject *typesModule=NULL; typesModule = PyImport_ImportModule("types"); if (typesModule) { __pyx_mstate_global->__Pyx_CachedMethodType = PyObject_GetAttrString(typesModule, "MethodType"); Py_DECREF(typesModule); } } // error handling follows #endif 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= 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; } /* TupleAndListFromArray */ #if !CYTHON_COMPILING_IN_CPYTHON && CYTHON_METH_FASTCALL static CYTHON_INLINE PyObject * __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) { PyObject *res; Py_ssize_t i; if (n <= 0) { return __Pyx_NewRef(__pyx_mstate_global->__pyx_empty_tuple); } res = PyTuple_New(n); if (unlikely(res == NULL)) return NULL; for (i = 0; i < n; i++) { if (unlikely(__Pyx_PyTuple_SET_ITEM(res, i, src[i]) < 0)) { Py_DECREF(res); return NULL; } Py_INCREF(src[i]); } return res; } #elif CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { PyObject *v; Py_ssize_t i; for (i = 0; i < length; i++) { v = dest[i] = src[i]; Py_INCREF(v); } } static CYTHON_INLINE PyObject * __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) { PyObject *res; if (n <= 0) { return __Pyx_NewRef(__pyx_mstate_global->__pyx_empty_tuple); } res = PyTuple_New(n); if (unlikely(res == NULL)) return NULL; __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); return res; } static CYTHON_INLINE PyObject * __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) { PyObject *res; if (n <= 0) { return PyList_New(0); } res = PyList_New(n); if (unlikely(res == NULL)) return NULL; __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); return res; } #endif /* 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 } /* fastcall */ #if CYTHON_METH_FASTCALL static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) { Py_ssize_t i, n = __Pyx_PyTuple_GET_SIZE(kwnames); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely(n == -1)) return NULL; #endif for (i = 0; i < n; i++) { PyObject *namei = __Pyx_PyTuple_GET_ITEM(kwnames, i); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(!namei)) return NULL; #endif if (s == namei) return kwvalues[i]; } for (i = 0; i < n; i++) { PyObject *namei = __Pyx_PyTuple_GET_ITEM(kwnames, i); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(!namei)) return NULL; #endif int eq = __Pyx_PyUnicode_Equals(s, namei, Py_EQ); if (unlikely(eq != 0)) { if (unlikely(eq < 0)) return NULL; return kwvalues[i]; } } return NULL; } #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { Py_ssize_t i, nkwargs; PyObject *dict; #if !CYTHON_ASSUME_SAFE_SIZE nkwargs = PyTuple_Size(kwnames); if (unlikely(nkwargs < 0)) return NULL; #else nkwargs = PyTuple_GET_SIZE(kwnames); #endif dict = PyDict_New(); if (unlikely(!dict)) return NULL; for (i=0; irecursion_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 } /* 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; } /* 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); } } /* ParseKeywords */ static int __Pyx_ValidateDuplicatePosArgs( PyObject *kwds, PyObject ** const argnames[], PyObject ** const *first_kw_arg, const char* function_name) { PyObject ** const *name = argnames; while (name != first_kw_arg) { PyObject *key = **name; int found = PyDict_Contains(kwds, key); if (unlikely(found)) { if (found == 1) __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; } name++; } return 0; bad: return -1; } #if CYTHON_USE_UNICODE_INTERNALS static CYTHON_INLINE int __Pyx_UnicodeKeywordsEqual(PyObject *s1, PyObject *s2) { int kind; Py_ssize_t len = PyUnicode_GET_LENGTH(s1); if (len != PyUnicode_GET_LENGTH(s2)) return 0; kind = PyUnicode_KIND(s1); if (kind != PyUnicode_KIND(s2)) return 0; const void *data1 = PyUnicode_DATA(s1); const void *data2 = PyUnicode_DATA(s2); return (memcmp(data1, data2, (size_t) len * (size_t) kind) == 0); } #endif static int __Pyx_MatchKeywordArg_str( PyObject *key, PyObject ** const argnames[], PyObject ** const *first_kw_arg, size_t *index_found, const char *function_name) { PyObject ** const *name; #if CYTHON_USE_UNICODE_INTERNALS Py_hash_t key_hash = ((PyASCIIObject*)key)->hash; if (unlikely(key_hash == -1)) { key_hash = PyObject_Hash(key); if (unlikely(key_hash == -1)) goto bad; } #endif name = first_kw_arg; while (*name) { PyObject *name_str = **name; #if CYTHON_USE_UNICODE_INTERNALS if (key_hash == ((PyASCIIObject*)name_str)->hash && __Pyx_UnicodeKeywordsEqual(name_str, key)) { *index_found = (size_t) (name - argnames); return 1; } #else #if CYTHON_ASSUME_SAFE_SIZE if (PyUnicode_GET_LENGTH(name_str) == PyUnicode_GET_LENGTH(key)) #endif { int cmp = PyUnicode_Compare(name_str, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { *index_found = (size_t) (name - argnames); return 1; } } #endif name++; } name = argnames; while (name != first_kw_arg) { PyObject *name_str = **name; #if CYTHON_USE_UNICODE_INTERNALS if (unlikely(key_hash == ((PyASCIIObject*)name_str)->hash)) { if (__Pyx_UnicodeKeywordsEqual(name_str, key)) goto arg_passed_twice; } #else #if CYTHON_ASSUME_SAFE_SIZE if (PyUnicode_GET_LENGTH(name_str) == PyUnicode_GET_LENGTH(key)) #endif { if (unlikely(name_str == key)) goto arg_passed_twice; int cmp = PyUnicode_Compare(name_str, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; } #endif name++; } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; bad: return -1; } static int __Pyx_MatchKeywordArg_nostr( PyObject *key, PyObject ** const argnames[], PyObject ** const *first_kw_arg, size_t *index_found, const char *function_name) { PyObject ** const *name; if (unlikely(!PyUnicode_Check(key))) goto invalid_keyword_type; name = first_kw_arg; while (*name) { int cmp = PyObject_RichCompareBool(**name, key, Py_EQ); if (cmp == 1) { *index_found = (size_t) (name - argnames); return 1; } if (unlikely(cmp == -1)) goto bad; name++; } name = argnames; while (name != first_kw_arg) { int cmp = PyObject_RichCompareBool(**name, key, Py_EQ); if (unlikely(cmp != 0)) { if (cmp == 1) goto arg_passed_twice; else goto bad; } name++; } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; bad: return -1; } static CYTHON_INLINE int __Pyx_MatchKeywordArg( PyObject *key, PyObject ** const argnames[], PyObject ** const *first_kw_arg, size_t *index_found, const char *function_name) { return likely(PyUnicode_CheckExact(key)) ? __Pyx_MatchKeywordArg_str(key, argnames, first_kw_arg, index_found, function_name) : __Pyx_MatchKeywordArg_nostr(key, argnames, first_kw_arg, index_found, function_name); } static void __Pyx_RejectUnknownKeyword( PyObject *kwds, PyObject ** const argnames[], PyObject ** const *first_kw_arg, const char *function_name) { Py_ssize_t pos = 0; PyObject *key = NULL; __Pyx_BEGIN_CRITICAL_SECTION(kwds); while (PyDict_Next(kwds, &pos, &key, NULL)) { PyObject** const *name = first_kw_arg; while (*name && (**name != key)) name++; if (!*name) { #if CYTHON_AVOID_BORROWED_REFS Py_INCREF(key); #endif size_t index_found = 0; int cmp = __Pyx_MatchKeywordArg(key, argnames, first_kw_arg, &index_found, function_name); if (cmp != 1) { if (cmp == 0) { PyErr_Format(PyExc_TypeError, "%s() got an unexpected keyword argument '%U'", function_name, key); } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(key); #endif break; } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(key); #endif } } __Pyx_END_CRITICAL_SECTION(); assert(PyErr_Occurred()); } static int __Pyx_ParseKeywordDict( PyObject *kwds, PyObject ** const argnames[], PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs) { PyObject** const *name; PyObject** const *first_kw_arg = argnames + num_pos_args; Py_ssize_t extracted = 0; #if !CYTHON_COMPILING_IN_PYPY || defined(PyArg_ValidateKeywordArguments) if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return -1; #endif name = first_kw_arg; while (*name && num_kwargs > extracted) { PyObject * key = **name; PyObject *value; int found = 0; #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000 found = PyDict_GetItemRef(kwds, key, &value); #else value = PyDict_GetItemWithError(kwds, key); if (value) { Py_INCREF(value); found = 1; } else { if (unlikely(PyErr_Occurred())) goto bad; } #endif if (found) { if (unlikely(found < 0)) goto bad; values[name-argnames] = value; extracted++; } name++; } if (num_kwargs > extracted) { if (ignore_unknown_kwargs) { if (unlikely(__Pyx_ValidateDuplicatePosArgs(kwds, argnames, first_kw_arg, function_name) == -1)) goto bad; } else { __Pyx_RejectUnknownKeyword(kwds, argnames, first_kw_arg, function_name); goto bad; } } return 0; bad: return -1; } static int __Pyx_ParseKeywordDictToDict( PyObject *kwds, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject** const *name; PyObject** const *first_kw_arg = argnames + num_pos_args; Py_ssize_t len; #if !CYTHON_COMPILING_IN_PYPY || defined(PyArg_ValidateKeywordArguments) if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return -1; #endif if (PyDict_Update(kwds2, kwds) < 0) goto bad; name = first_kw_arg; while (*name) { PyObject *key = **name; PyObject *value; #if !CYTHON_COMPILING_IN_LIMITED_API && (PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)) int found = PyDict_Pop(kwds2, key, &value); if (found) { if (unlikely(found < 0)) goto bad; values[name-argnames] = value; } #elif __PYX_LIMITED_VERSION_HEX >= 0x030d0000 int found = PyDict_GetItemRef(kwds2, key, &value); if (found) { if (unlikely(found < 0)) goto bad; values[name-argnames] = value; if (unlikely(PyDict_DelItem(kwds2, key) < 0)) goto bad; } #else #if CYTHON_COMPILING_IN_CPYTHON value = _PyDict_Pop(kwds2, key, kwds2); #else value = __Pyx_CallUnboundCMethod2(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_pop, kwds2, key, kwds2); #endif if (value == kwds2) { Py_DECREF(value); } else { if (unlikely(!value)) goto bad; values[name-argnames] = value; } #endif name++; } len = PyDict_Size(kwds2); if (len > 0) { return __Pyx_ValidateDuplicatePosArgs(kwds, argnames, first_kw_arg, function_name); } else if (unlikely(len == -1)) { goto bad; } return 0; bad: return -1; } static int __Pyx_ParseKeywordsTuple( PyObject *kwds, PyObject * const *kwvalues, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs) { PyObject *key = NULL; PyObject** const * name; PyObject** const *first_kw_arg = argnames + num_pos_args; for (Py_ssize_t pos = 0; pos < num_kwargs; pos++) { #if CYTHON_AVOID_BORROWED_REFS key = __Pyx_PySequence_ITEM(kwds, pos); #else key = __Pyx_PyTuple_GET_ITEM(kwds, pos); #endif #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(!key)) goto bad; #endif name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { PyObject *value = kwvalues[pos]; values[name-argnames] = __Pyx_NewRef(value); } else { size_t index_found = 0; int cmp = __Pyx_MatchKeywordArg(key, argnames, first_kw_arg, &index_found, function_name); if (cmp == 1) { PyObject *value = kwvalues[pos]; values[index_found] = __Pyx_NewRef(value); } else { if (unlikely(cmp == -1)) goto bad; if (kwds2) { PyObject *value = kwvalues[pos]; if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else if (!ignore_unknown_kwargs) { goto invalid_keyword; } } } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(key); key = NULL; #endif } return 0; invalid_keyword: PyErr_Format(PyExc_TypeError, "%s() got an unexpected keyword argument '%U'", function_name, key); goto bad; bad: #if CYTHON_AVOID_BORROWED_REFS Py_XDECREF(key); #endif return -1; } static int __Pyx_ParseKeywords( PyObject *kwds, PyObject * const *kwvalues, PyObject ** const argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, Py_ssize_t num_kwargs, const char* function_name, int ignore_unknown_kwargs) { if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds))) return __Pyx_ParseKeywordsTuple(kwds, kwvalues, argnames, kwds2, values, num_pos_args, num_kwargs, function_name, ignore_unknown_kwargs); else if (kwds2) return __Pyx_ParseKeywordDictToDict(kwds, argnames, kwds2, values, num_pos_args, function_name); else return __Pyx_ParseKeywordDict(kwds, argnames, values, num_pos_args, num_kwargs, function_name, ignore_unknown_kwargs); } /* RaiseArgTupleInvalid */ static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } /* ArgTypeTest */ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) { __Pyx_TypeName type_name; __Pyx_TypeName obj_type_name; PyObject *extra_info = __pyx_mstate_global->__pyx_empty_unicode; int from_annotation_subclass = 0; if (unlikely(!type)) { PyErr_SetString(PyExc_SystemError, "Missing type object"); return 0; } else if (!exact) { if (likely(__Pyx_TypeCheck(obj, type))) return 1; } else if (exact == 2) { if (__Pyx_TypeCheck(obj, type)) { from_annotation_subclass = 1; extra_info = __pyx_mstate_global->__pyx_kp_u_Note_that_Cython_is_deliberately; } } type_name = __Pyx_PyType_GetFullyQualifiedName(type); obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj)); PyErr_Format(PyExc_TypeError, "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME ", got " __Pyx_FMT_TYPENAME ")" #if __PYX_LIMITED_VERSION_HEX < 0x030C0000 "%s%U" #endif , name, type_name, obj_type_name #if __PYX_LIMITED_VERSION_HEX < 0x030C0000 , (from_annotation_subclass ? ". " : ""), extra_info #endif ); #if __PYX_LIMITED_VERSION_HEX >= 0x030C0000 if (exact == 2 && from_annotation_subclass) { PyObject *res; PyObject *vargs[2]; vargs[0] = PyErr_GetRaisedException(); vargs[1] = extra_info; res = PyObject_VectorcallMethod(__pyx_mstate_global->__pyx_kp_u_add_note, vargs, 2, NULL); Py_XDECREF(res); PyErr_SetRaisedException(vargs[0]); } #endif __Pyx_DECREF_TypeName(type_name); __Pyx_DECREF_TypeName(obj_type_name); return 0; } /* 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(); } /* PyObjectSetAttrStr */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_setattro)) return tp->tp_setattro(obj, attr_name, value); return PyObject_SetAttr(obj, attr_name, value); } #endif /* 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); } /* 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 /* 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; } /* 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; } /* py_dict_pop */ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) { #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop) PyObject *value; if (PyDict_Pop(d, key, &value) == 0) { if (default_value) { Py_INCREF(default_value); } else { PyErr_SetObject(PyExc_KeyError, key); } value = default_value; } return value; #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 return _PyDict_Pop(d, key, default_value); #else if (default_value) { return __Pyx_CallUnboundCMethod2(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_pop, d, key, default_value); } else { return __Pyx_CallUnboundCMethod1(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_pop, d, key); } #endif } /* 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); } /* 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); } /* PyObjectGetMethod */ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { PyObject *attr; #if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP __Pyx_TypeName type_name; PyTypeObject *tp = Py_TYPE(obj); PyObject *descr; descrgetfunc f = NULL; PyObject **dictptr, *dict; int meth_found = 0; assert (*method == NULL); if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { attr = __Pyx_PyObject_GetAttrStr(obj, name); goto try_unpack; } if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { return 0; } descr = _PyType_Lookup(tp, name); if (likely(descr != NULL)) { Py_INCREF(descr); #if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) #else #ifdef __Pyx_CyFunction_USED if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) #else if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) #endif #endif { meth_found = 1; } else { f = Py_TYPE(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); Py_DECREF(descr); goto try_unpack; } } } dictptr = _PyObject_GetDictPtr(obj); if (dictptr != NULL && (dict = *dictptr) != NULL) { Py_INCREF(dict); attr = __Pyx_PyDict_GetItemStr(dict, name); if (attr != NULL) { Py_INCREF(attr); Py_DECREF(dict); Py_XDECREF(descr); goto try_unpack; } Py_DECREF(dict); } if (meth_found) { *method = descr; return 1; } if (f != NULL) { attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); Py_DECREF(descr); goto try_unpack; } if (likely(descr != NULL)) { *method = descr; return 0; } type_name = __Pyx_PyType_GetFullyQualifiedName(tp); PyErr_Format(PyExc_AttributeError, "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", type_name, name); __Pyx_DECREF_TypeName(type_name); return 0; #else attr = __Pyx_PyObject_GetAttrStr(obj, name); goto try_unpack; #endif try_unpack: #if CYTHON_UNPACK_METHODS if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { PyObject *function = PyMethod_GET_FUNCTION(attr); Py_INCREF(function); Py_DECREF(attr); *method = function; return 1; } #endif *method = attr; return 0; } /* PyObjectCallMethod0 */ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { PyObject *method = NULL, *result = NULL; int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); if (likely(is_method)) { result = __Pyx_PyObject_CallOneArg(method, obj); Py_DECREF(method); return result; } if (unlikely(!method)) goto bad; result = __Pyx_PyObject_CallNoArg(method); Py_DECREF(method); bad: return result; } /* RaiseNoneIterError */ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); } /* UnpackTupleError */ static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { if (t == Py_None) { __Pyx_RaiseNoneNotIterableError(); } else { Py_ssize_t size = __Pyx_PyTuple_GET_SIZE(t); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely(size < 0)) return; #endif if (size < index) { __Pyx_RaiseNeedMoreValuesError(size); } else { __Pyx_RaiseTooManyValuesError(index); } } } /* UnpackTuple2 */ static CYTHON_INLINE int __Pyx_unpack_tuple2( PyObject* tuple, PyObject** value1, PyObject** value2, int is_tuple, int has_known_size, int decref_tuple) { if (likely(is_tuple || PyTuple_Check(tuple))) { Py_ssize_t size; if (has_known_size) { return __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple); } size = __Pyx_PyTuple_GET_SIZE(tuple); if (likely(size == 2)) { return __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple); } if (size >= 0) { __Pyx_UnpackTupleError(tuple, 2); } return -1; } else { return __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple); } } static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { PyObject *value1 = NULL, *value2 = NULL; #if CYTHON_AVOID_BORROWED_REFS || !CYTHON_ASSUME_SAFE_MACROS value1 = __Pyx_PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; value2 = __Pyx_PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; #else value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); #endif if (decref_tuple) { Py_DECREF(tuple); } *pvalue1 = value1; *pvalue2 = value2; return 0; #if CYTHON_AVOID_BORROWED_REFS || !CYTHON_ASSUME_SAFE_MACROS bad: Py_XDECREF(value1); Py_XDECREF(value2); if (decref_tuple) { Py_XDECREF(tuple); } return -1; #endif } static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int has_known_size, int decref_tuple) { Py_ssize_t index; PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; iternextfunc iternext; iter = PyObject_GetIter(tuple); if (unlikely(!iter)) goto bad; if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } iternext = __Pyx_PyObject_GetIterNextFunc(iter); value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; Py_DECREF(iter); *pvalue1 = value1; *pvalue2 = value2; return 0; unpacking_failed: if (!has_known_size && __Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); bad: Py_XDECREF(iter); Py_XDECREF(value1); Py_XDECREF(value2); if (decref_tuple) { Py_XDECREF(tuple); } return -1; } /* dict_iter */ #if CYTHON_COMPILING_IN_PYPY #include #endif static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, Py_ssize_t* p_orig_length, int* p_source_is_dict) { is_dict = is_dict || likely(PyDict_CheckExact(iterable)); *p_source_is_dict = is_dict; if (is_dict) { #if !CYTHON_COMPILING_IN_PYPY *p_orig_length = PyDict_Size(iterable); Py_INCREF(iterable); return iterable; #else static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; PyObject **pp = NULL; if (method_name) { const char *name = PyUnicode_AsUTF8(method_name); if (strcmp(name, "iteritems") == 0) pp = &py_items; else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; else if (strcmp(name, "itervalues") == 0) pp = &py_values; if (pp) { if (!*pp) { *pp = PyUnicode_FromString(name + 4); if (!*pp) return NULL; } method_name = *pp; } } #endif } *p_orig_length = 0; if (method_name) { PyObject* iter; iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); if (!iterable) return NULL; #if !CYTHON_COMPILING_IN_PYPY if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) return iterable; #endif iter = PyObject_GetIter(iterable); Py_DECREF(iterable); return iter; } return PyObject_GetIter(iterable); } #if !CYTHON_COMPILING_IN_PYPY static CYTHON_INLINE int __Pyx_dict_iter_next_source_is_dict( PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, PyObject** pkey, PyObject** pvalue, PyObject** pitem) { PyObject *key, *value; if (unlikely(orig_length != PyDict_Size(iter_obj))) { PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); return -1; } if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { return 0; } if (pitem) { PyObject* tuple = PyTuple_New(2); if (unlikely(!tuple)) { return -1; } Py_INCREF(key); Py_INCREF(value); #if CYTHON_ASSUME_SAFE_MACROS PyTuple_SET_ITEM(tuple, 0, key); PyTuple_SET_ITEM(tuple, 1, value); #else if (unlikely(PyTuple_SetItem(tuple, 0, key) < 0)) { Py_DECREF(value); Py_DECREF(tuple); return -1; } if (unlikely(PyTuple_SetItem(tuple, 1, value) < 0)) { Py_DECREF(tuple); return -1; } #endif *pitem = tuple; } else { if (pkey) { Py_INCREF(key); *pkey = key; } if (pvalue) { Py_INCREF(value); *pvalue = value; } } return 1; } #endif static CYTHON_INLINE int __Pyx_dict_iter_next( PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { PyObject* next_item; #if !CYTHON_COMPILING_IN_PYPY if (source_is_dict) { int result; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_BEGIN_CRITICAL_SECTION(iter_obj); #endif result = __Pyx_dict_iter_next_source_is_dict(iter_obj, orig_length, ppos, pkey, pvalue, pitem); #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_END_CRITICAL_SECTION(); #endif return result; } else if (PyTuple_CheckExact(iter_obj)) { Py_ssize_t pos = *ppos; Py_ssize_t tuple_size = __Pyx_PyTuple_GET_SIZE(iter_obj); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely(tuple_size < 0)) return -1; #endif if (unlikely(pos >= tuple_size)) return 0; *ppos = pos + 1; #if CYTHON_ASSUME_SAFE_MACROS next_item = PyTuple_GET_ITEM(iter_obj, pos); #else next_item = PyTuple_GetItem(iter_obj, pos); if (unlikely(!next_item)) return -1; #endif Py_INCREF(next_item); } else if (PyList_CheckExact(iter_obj)) { Py_ssize_t pos = *ppos; Py_ssize_t list_size = __Pyx_PyList_GET_SIZE(iter_obj); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely(list_size < 0)) return -1; #endif if (unlikely(pos >= list_size)) return 0; *ppos = pos + 1; #if CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS next_item = PyList_GetItemRef(iter_obj, pos); if (unlikely(!next_item)) return -1; #elif CYTHON_ASSUME_SAFE_MACROS next_item = PyList_GET_ITEM(iter_obj, pos); Py_INCREF(next_item); #else next_item = PyList_GetItem(iter_obj, pos); if (unlikely(!next_item)) return -1; Py_INCREF(next_item); #endif } else #endif { next_item = PyIter_Next(iter_obj); if (unlikely(!next_item)) { return __Pyx_IterFinish(); } } if (pitem) { *pitem = next_item; } else if (pkey && pvalue) { if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) return -1; } else if (pkey) { *pkey = next_item; } else { *pvalue = next_item; } return 1; } /* MergeKeywords */ static int __Pyx_MergeKeywords_dict(PyObject *kwdict, PyObject *source_dict) { Py_ssize_t len1, len2; len2 = PyDict_Size(source_dict); if (unlikely(len2 == -1)) return -1; if (len2 == 0) { return 0; } len1 = PyDict_Size(kwdict); if (unlikely(len1 == -1)) return -1; if (len1 > 0) { PyObject *key, *smaller_dict, *larger_dict; Py_ssize_t ppos = 0; int duplicates_found = 0; if (len1 <= len2) { smaller_dict = kwdict; larger_dict = source_dict; } else { smaller_dict = source_dict; larger_dict = kwdict; } __Pyx_BEGIN_CRITICAL_SECTION(smaller_dict); while (PyDict_Next(smaller_dict, &ppos, &key, NULL)) { #if CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS Py_INCREF(key); #endif if (unlikely(PyDict_Contains(larger_dict, key))) { __Pyx_RaiseDoubleKeywordsError("function", key); #if CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS Py_DECREF(key); #endif duplicates_found = 1; break; }; #if CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS Py_DECREF(key); #endif } __Pyx_END_CRITICAL_SECTION(); if (unlikely(duplicates_found)) return -1; } return PyDict_Update(kwdict, source_dict); } static int __Pyx_MergeKeywords_any(PyObject *kwdict, PyObject *source_mapping) { PyObject *iter, *key = NULL, *value = NULL; int source_is_dict, result; Py_ssize_t orig_length, ppos = 0; iter = __Pyx_dict_iterator(source_mapping, 0, __pyx_mstate_global->__pyx_n_u_items, &orig_length, &source_is_dict); if (unlikely(!iter)) { PyObject *args; if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError))) goto bad; PyErr_Clear(); args = PyTuple_Pack(1, source_mapping); if (likely(args)) { PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL); Py_DECREF(args); if (likely(fallback)) { result = __Pyx_MergeKeywords_dict(kwdict, fallback); Py_DECREF(fallback); return result; } } if (unlikely(!iter)) goto bad; } while (1) { result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict); if (unlikely(result < 0)) goto bad; if (!result) break; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API { int inserted = PyDict_SetDefaultRef(kwdict, key, value, NULL); if (unlikely(inserted != 0)) { if (inserted == 1) __Pyx_RaiseDoubleKeywordsError("function", key); result = -1; } } #else if (unlikely(PyDict_Contains(kwdict, key))) { __Pyx_RaiseDoubleKeywordsError("function", key); result = -1; } else { result = PyDict_SetItem(kwdict, key, value); } #endif Py_DECREF(key); Py_DECREF(value); if (unlikely(result < 0)) goto bad; } Py_XDECREF(iter); return 0; bad: Py_XDECREF(iter); return -1; } static CYTHON_INLINE int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) { assert(PyDict_Check(kwdict)); if (likely(PyDict_Check(source_mapping))) { return __Pyx_MergeKeywords_dict(kwdict, source_mapping); } else { return __Pyx_MergeKeywords_any(kwdict, source_mapping); } } /* pybytes_as_double */ static double __Pyx_SlowPyString_AsDouble(PyObject *obj) { PyObject *float_value = PyFloat_FromString(obj); if (likely(float_value)) { double value = __Pyx_PyFloat_AS_DOUBLE(float_value); Py_DECREF(float_value); return value; } return (double)-1; } static const char* __Pyx__PyBytes_AsDouble_Copy(const char* start, char* buffer, Py_ssize_t length) { int last_was_punctuation = 1; int parse_error_found = 0; Py_ssize_t i; for (i=0; i < length; i++) { char chr = start[i]; int is_punctuation = (chr == '_') | (chr == '.') | (chr == 'e') | (chr == 'E'); *buffer = chr; buffer += (chr != '_'); parse_error_found |= last_was_punctuation & is_punctuation; last_was_punctuation = is_punctuation; } parse_error_found |= last_was_punctuation; *buffer = '\0'; return unlikely(parse_error_found) ? NULL : buffer; } static double __Pyx__PyBytes_AsDouble_inf_nan(const char* start, Py_ssize_t length) { int matches = 1; char sign = start[0]; int is_signed = (sign == '+') | (sign == '-'); start += is_signed; length -= is_signed; switch (start[0]) { #ifdef Py_NAN case 'n': case 'N': if (unlikely(length != 3)) goto parse_failure; matches &= (start[1] == 'a' || start[1] == 'A'); matches &= (start[2] == 'n' || start[2] == 'N'); if (unlikely(!matches)) goto parse_failure; return (sign == '-') ? -Py_NAN : Py_NAN; #endif case 'i': case 'I': if (unlikely(length < 3)) goto parse_failure; matches &= (start[1] == 'n' || start[1] == 'N'); matches &= (start[2] == 'f' || start[2] == 'F'); if (likely(length == 3 && matches)) return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL; if (unlikely(length != 8)) goto parse_failure; matches &= (start[3] == 'i' || start[3] == 'I'); matches &= (start[4] == 'n' || start[4] == 'N'); matches &= (start[5] == 'i' || start[5] == 'I'); matches &= (start[6] == 't' || start[6] == 'T'); matches &= (start[7] == 'y' || start[7] == 'Y'); if (unlikely(!matches)) goto parse_failure; return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL; case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; default: goto parse_failure; } return 0.0; parse_failure: return -1.0; } static CYTHON_INLINE int __Pyx__PyBytes_AsDouble_IsSpace(char ch) { return (ch == 0x20) | !((ch < 0x9) | (ch > 0xd)); } CYTHON_UNUSED static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length) { double value; Py_ssize_t i, digits; const char *last = start + length; char *end; while (__Pyx__PyBytes_AsDouble_IsSpace(*start)) start++; while (start < last - 1 && __Pyx__PyBytes_AsDouble_IsSpace(last[-1])) last--; length = last - start; if (unlikely(length <= 0)) goto fallback; value = __Pyx__PyBytes_AsDouble_inf_nan(start, length); if (unlikely(value == -1.0)) goto fallback; if (value != 0.0) return value; digits = 0; for (i=0; i < length; digits += start[i++] != '_'); if (likely(digits == length)) { value = PyOS_string_to_double(start, &end, NULL); } else if (digits < 40) { char number[40]; last = __Pyx__PyBytes_AsDouble_Copy(start, number, length); if (unlikely(!last)) goto fallback; value = PyOS_string_to_double(number, &end, NULL); } else { char *number = (char*) PyMem_Malloc((digits + 1) * sizeof(char)); if (unlikely(!number)) goto fallback; last = __Pyx__PyBytes_AsDouble_Copy(start, number, length); if (unlikely(!last)) { PyMem_Free(number); goto fallback; } value = PyOS_string_to_double(number, &end, NULL); PyMem_Free(number); } if (likely(end == last) || (value == (double)-1 && PyErr_Occurred())) { return value; } fallback: return __Pyx_SlowPyString_AsDouble(obj); } /* PyLongCompare */ static CYTHON_INLINE int __Pyx_PyLong_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace) { CYTHON_MAYBE_UNUSED_VAR(intval); CYTHON_UNUSED_VAR(inplace); if (op1 == op2) { return 1; } #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 0; intval = -intval; } else { if (__Pyx_PyLong_IsNeg(op1)) return 0; } 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_EQ)); } /* 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 /* 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 /* 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 } /* 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 /* 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; } /* 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)); } /* 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 /* 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 /* 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_items */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) { return __Pyx_CallUnboundCMethod0(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_items, d); } /* py_dict_keys */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d) { return __Pyx_CallUnboundCMethod0(&__pyx_mstate_global->__pyx_umethod_PyDict_Type_keys, d); } /* 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 /* 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; } /* CallTypeTraverse */ #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000) #else static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg) { #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03090000 if (__Pyx_get_runtime_version() < 0x03090000) return 0; #endif if (!always_call) { PyTypeObject *base = __Pyx_PyObject_GetSlot(o, tp_base, PyTypeObject*); unsigned long flags = PyType_GetFlags(base); if (flags & Py_TPFLAGS_HEAPTYPE) { return 0; } } Py_VISIT((PyObject*)Py_TYPE(o)); return 0; } #endif /* LimitedApiGetTypeDict */ #if CYTHON_COMPILING_IN_LIMITED_API static Py_ssize_t __Pyx_GetTypeDictOffset(void) { PyObject *tp_dictoffset_o; Py_ssize_t tp_dictoffset; tp_dictoffset_o = PyObject_GetAttrString((PyObject*)(&PyType_Type), "__dictoffset__"); if (unlikely(!tp_dictoffset_o)) return -1; tp_dictoffset = PyLong_AsSsize_t(tp_dictoffset_o); Py_DECREF(tp_dictoffset_o); if (unlikely(tp_dictoffset == 0)) { PyErr_SetString( PyExc_TypeError, "'type' doesn't have a dictoffset"); return -1; } else if (unlikely(tp_dictoffset < 0)) { PyErr_SetString( PyExc_TypeError, "'type' has an unexpected negative dictoffset. " "Please report this as Cython bug"); return -1; } return tp_dictoffset; } static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp) { static Py_ssize_t tp_dictoffset = 0; if (unlikely(tp_dictoffset == 0)) { tp_dictoffset = __Pyx_GetTypeDictOffset(); if (unlikely(tp_dictoffset == -1 && PyErr_Occurred())) { tp_dictoffset = 0; // try again next time? return NULL; } } return *(PyObject**)((char*)tp + tp_dictoffset); } #endif /* SetItemOnTypeDict */ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v) { int result; PyObject *tp_dict; #if CYTHON_COMPILING_IN_LIMITED_API tp_dict = __Pyx_GetTypeDict(tp); if (unlikely(!tp_dict)) return -1; #else tp_dict = tp->tp_dict; #endif result = PyDict_SetItem(tp_dict, k, v); if (likely(!result)) { PyType_Modified(tp); if (unlikely(PyObject_HasAttr(v, __pyx_mstate_global->__pyx_n_u_set_name))) { PyObject *setNameResult = PyObject_CallMethodObjArgs(v, __pyx_mstate_global->__pyx_n_u_set_name, (PyObject *) tp, k, NULL); if (!setNameResult) return -1; Py_DECREF(setNameResult); } } return result; } /* FixUpExtensionType */ static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { #if __PYX_LIMITED_VERSION_HEX > 0x030900B1 CYTHON_UNUSED_VAR(spec); CYTHON_UNUSED_VAR(type); CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict); #else const PyType_Slot *slot = spec->slots; int changed = 0; #if !CYTHON_COMPILING_IN_LIMITED_API while (slot && slot->slot && slot->slot != Py_tp_members) slot++; if (slot && slot->slot == Py_tp_members) { #if !CYTHON_COMPILING_IN_CPYTHON const #endif // !CYTHON_COMPILING_IN_CPYTHON) PyMemberDef *memb = (PyMemberDef*) slot->pfunc; while (memb && memb->name) { if (memb->name[0] == '_' && memb->name[1] == '_') { if (strcmp(memb->name, "__weaklistoffset__") == 0) { assert(memb->type == T_PYSSIZET); assert(memb->flags == READONLY); type->tp_weaklistoffset = memb->offset; changed = 1; } else if (strcmp(memb->name, "__dictoffset__") == 0) { assert(memb->type == T_PYSSIZET); assert(memb->flags == READONLY); type->tp_dictoffset = memb->offset; changed = 1; } #if CYTHON_METH_FASTCALL else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { assert(memb->type == T_PYSSIZET); assert(memb->flags == READONLY); #if PY_VERSION_HEX >= 0x030800b4 type->tp_vectorcall_offset = memb->offset; #else type->tp_print = (printfunc) memb->offset; #endif changed = 1; } #endif // CYTHON_METH_FASTCALL else if (strcmp(memb->name, "__module__") == 0) { PyObject *descr; assert(memb->type == T_OBJECT); assert(memb->flags == 0 || memb->flags == READONLY); descr = PyDescr_NewMember(type, memb); if (unlikely(!descr)) return -1; int set_item_result = PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr); Py_DECREF(descr); if (unlikely(set_item_result < 0)) { return -1; } changed = 1; } } memb++; } } #endif // !CYTHON_COMPILING_IN_LIMITED_API slot = spec->slots; while (slot && slot->slot && slot->slot != Py_tp_getset) slot++; if (slot && slot->slot == Py_tp_getset) { PyGetSetDef *getset = (PyGetSetDef*) slot->pfunc; while (getset && getset->name) { if (getset->name[0] == '_' && getset->name[1] == '_' && strcmp(getset->name, "__module__") == 0) { PyObject *descr = PyDescr_NewGetSet(type, getset); if (unlikely(!descr)) return -1; #if CYTHON_COMPILING_IN_LIMITED_API PyObject *pyname = PyUnicode_FromString(getset->name); if (unlikely(!pyname)) { Py_DECREF(descr); return -1; } int set_item_result = __Pyx_SetItemOnTypeDict(type, pyname, descr); Py_DECREF(pyname); #else CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict); int set_item_result = PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr); #endif Py_DECREF(descr); if (unlikely(set_item_result < 0)) { return -1; } changed = 1; } ++getset; } } if (changed) PyType_Modified(type); #endif // PY_VERSION_HEX > 0x030900B1 return 0; } /* ValidateBasesTuple */ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { Py_ssize_t i, n; #if CYTHON_ASSUME_SAFE_SIZE n = PyTuple_GET_SIZE(bases); #else n = PyTuple_Size(bases); if (unlikely(n < 0)) return -1; #endif for (i = 1; i < n; i++) { PyTypeObject *b; #if CYTHON_AVOID_BORROWED_REFS PyObject *b0 = PySequence_GetItem(bases, i); if (!b0) return -1; #elif CYTHON_ASSUME_SAFE_MACROS PyObject *b0 = PyTuple_GET_ITEM(bases, i); #else PyObject *b0 = PyTuple_GetItem(bases, i); if (!b0) return -1; #endif b = (PyTypeObject*) b0; if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) { __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b); PyErr_Format(PyExc_TypeError, "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); __Pyx_DECREF_TypeName(b_name); #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(b0); #endif return -1; } if (dictoffset == 0) { Py_ssize_t b_dictoffset = 0; #if CYTHON_USE_TYPE_SLOTS b_dictoffset = b->tp_dictoffset; #else PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); if (!py_b_dictoffset) goto dictoffset_return; b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); Py_DECREF(py_b_dictoffset); if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; #endif if (b_dictoffset) { { __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b); PyErr_Format(PyExc_TypeError, "extension type '%.200s' has no __dict__ slot, " "but base type '" __Pyx_FMT_TYPENAME "' has: " "either add 'cdef dict __dict__' to the extension type " "or add '__slots__ = [...]' to the base type", type_name, b_name); __Pyx_DECREF_TypeName(b_name); } #if !CYTHON_USE_TYPE_SLOTS dictoffset_return: #endif #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(b0); #endif return -1; } } #if CYTHON_AVOID_BORROWED_REFS Py_DECREF(b0); #endif } return 0; } #endif /* PyType_Ready */ CYTHON_UNUSED static int __Pyx_PyType_HasMultipleInheritance(PyTypeObject *t) { while (t) { PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); if (bases) { return 1; } t = __Pyx_PyType_GetSlot(t, tp_base, PyTypeObject*); } return 0; } static int __Pyx_PyType_Ready(PyTypeObject *t) { #if CYTHON_USE_TYPE_SPECS || !CYTHON_COMPILING_IN_CPYTHON || defined(PYSTON_MAJOR_VERSION) (void)__Pyx_PyObject_CallMethod0; #if CYTHON_USE_TYPE_SPECS (void)__Pyx_validate_bases_tuple; #endif return PyType_Ready(t); #else int r; if (!__Pyx_PyType_HasMultipleInheritance(t)) { return PyType_Ready(t); } PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) return -1; #if !defined(PYSTON_MAJOR_VERSION) { int gc_was_enabled; #if PY_VERSION_HEX >= 0x030A00b1 gc_was_enabled = PyGC_Disable(); (void)__Pyx_PyObject_CallMethod0; #else PyObject *ret, *py_status; PyObject *gc = NULL; #if (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) &&\ !CYTHON_COMPILING_IN_GRAAL gc = PyImport_GetModule(__pyx_mstate_global->__pyx_kp_u_gc); #endif if (unlikely(!gc)) gc = PyImport_Import(__pyx_mstate_global->__pyx_kp_u_gc); if (unlikely(!gc)) return -1; py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_mstate_global->__pyx_kp_u_isenabled); if (unlikely(!py_status)) { Py_DECREF(gc); return -1; } gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); Py_DECREF(py_status); if (gc_was_enabled > 0) { ret = __Pyx_PyObject_CallMethod0(gc, __pyx_mstate_global->__pyx_kp_u_disable); if (unlikely(!ret)) { Py_DECREF(gc); return -1; } Py_DECREF(ret); } else if (unlikely(gc_was_enabled == -1)) { Py_DECREF(gc); return -1; } #endif t->tp_flags |= Py_TPFLAGS_HEAPTYPE; #if PY_VERSION_HEX >= 0x030A0000 t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; #endif #else (void)__Pyx_PyObject_CallMethod0; #endif r = PyType_Ready(t); #if !defined(PYSTON_MAJOR_VERSION) t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; #if PY_VERSION_HEX >= 0x030A00b1 if (gc_was_enabled) PyGC_Enable(); #else if (gc_was_enabled) { PyObject *tp, *v, *tb; PyErr_Fetch(&tp, &v, &tb); ret = __Pyx_PyObject_CallMethod0(gc, __pyx_mstate_global->__pyx_kp_u_enable); if (likely(ret || r == -1)) { Py_XDECREF(ret); PyErr_Restore(tp, v, tb); } else { Py_XDECREF(tp); Py_XDECREF(v); Py_XDECREF(tb); r = -1; } } Py_DECREF(gc); #endif } #endif return r; #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__pyx_kp_u__2); 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; } /* FetchSharedCythonModule */ static PyObject *__Pyx_FetchSharedCythonABIModule(void) { return __Pyx_PyImport_AddModuleRef(__PYX_ABI_MODULE_NAME); } /* dict_setdefault */ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type) { PyObject* value; CYTHON_MAYBE_UNUSED_VAR(is_safe_type); #if CYTHON_COMPILING_IN_LIMITED_API value = PyObject_CallMethod(d, "setdefault", "OO", key, default_value); #elif PY_VERSION_HEX >= 0x030d0000 PyDict_SetDefaultRef(d, key, default_value, &value); #else value = PyDict_SetDefault(d, key, default_value); if (unlikely(!value)) return NULL; Py_INCREF(value); #endif return value; } /* FetchCommonType */ #if __PYX_LIMITED_VERSION_HEX < 0x030C0000 static PyObject* __Pyx_PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases) { PyObject *result = __Pyx_PyType_FromModuleAndSpec(module, spec, bases); if (result && metaclass) { PyObject *old_tp = (PyObject*)Py_TYPE(result); Py_INCREF((PyObject*)metaclass); #if __PYX_LIMITED_VERSION_HEX >= 0x03090000 Py_SET_TYPE(result, metaclass); #else result->ob_type = metaclass; #endif Py_DECREF(old_tp); } return result; } #else #define __Pyx_PyType_FromMetaclass(me, mo, s, b) PyType_FromMetaclass(me, mo, s, b) #endif static int __Pyx_VerifyCachedType(PyObject *cached_type, const char *name, Py_ssize_t expected_basicsize) { Py_ssize_t basicsize; if (!PyType_Check(cached_type)) { PyErr_Format(PyExc_TypeError, "Shared Cython type %.200s is not a type object", name); return -1; } if (expected_basicsize == 0) { return 0; // size is inherited, nothing useful to check } #if CYTHON_COMPILING_IN_LIMITED_API PyObject *py_basicsize; py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); if (unlikely(!py_basicsize)) return -1; basicsize = PyLong_AsSsize_t(py_basicsize); Py_DECREF(py_basicsize); py_basicsize = NULL; if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) return -1; #else basicsize = ((PyTypeObject*) cached_type)->tp_basicsize; #endif if (basicsize != expected_basicsize) { PyErr_Format(PyExc_TypeError, "Shared Cython type %.200s has the wrong size, try recompiling", name); return -1; } return 0; } static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases) { PyObject *abi_module = NULL, *cached_type = NULL, *abi_module_dict, *new_cached_type, *py_object_name; int get_item_ref_result; const char* object_name = strrchr(spec->name, '.'); object_name = object_name ? object_name+1 : spec->name; py_object_name = PyUnicode_FromString(object_name); if (!py_object_name) return NULL; abi_module = __Pyx_FetchSharedCythonABIModule(); if (!abi_module) goto done; abi_module_dict = PyModule_GetDict(abi_module); if (!abi_module_dict) goto done; get_item_ref_result = __Pyx_PyDict_GetItemRef(abi_module_dict, py_object_name, &cached_type); if (get_item_ref_result == 1) { if (__Pyx_VerifyCachedType( cached_type, object_name, spec->basicsize) < 0) { goto bad; } goto done; } else if (unlikely(get_item_ref_result == -1)) { goto bad; } CYTHON_UNUSED_VAR(module); cached_type = __Pyx_PyType_FromMetaclass(metaclass, abi_module, spec, bases); if (unlikely(!cached_type)) goto bad; if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; new_cached_type = __Pyx_PyDict_SetDefault(abi_module_dict, py_object_name, cached_type, 1); if (unlikely(new_cached_type != cached_type)) { if (unlikely(!new_cached_type)) goto bad; Py_DECREF(cached_type); cached_type = new_cached_type; if (__Pyx_VerifyCachedType( cached_type, object_name, spec->basicsize) < 0) { goto bad; } goto done; } else { Py_DECREF(new_cached_type); } done: Py_XDECREF(abi_module); Py_DECREF(py_object_name); assert(cached_type == NULL || PyType_Check(cached_type)); return (PyTypeObject *) cached_type; bad: Py_XDECREF(cached_type); cached_type = NULL; goto done; } /* CommonTypesMetaclass */ PyObject* __pyx_CommonTypesMetaclass_get_module(CYTHON_UNUSED PyObject *self, CYTHON_UNUSED void* context) { return PyUnicode_FromString(__PYX_ABI_MODULE_NAME); } static PyGetSetDef __pyx_CommonTypesMetaclass_getset[] = { {"__module__", __pyx_CommonTypesMetaclass_get_module, NULL, NULL, NULL}, {0, 0, 0, 0, 0} }; static PyType_Slot __pyx_CommonTypesMetaclass_slots[] = { {Py_tp_getset, (void *)__pyx_CommonTypesMetaclass_getset}, {0, 0} }; static PyType_Spec __pyx_CommonTypesMetaclass_spec = { __PYX_TYPE_MODULE_PREFIX "_common_types_metatype", 0, 0, #if PY_VERSION_HEX >= 0x030A0000 Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION | #endif Py_TPFLAGS_DEFAULT, __pyx_CommonTypesMetaclass_slots }; static int __pyx_CommonTypesMetaclass_init(PyObject *module) { __pyx_mstatetype *mstate = __Pyx_PyModule_GetState(module); PyObject *bases = PyTuple_Pack(1, &PyType_Type); if (unlikely(!bases)) { return -1; } mstate->__pyx_CommonTypesMetaclassType = __Pyx_FetchCommonTypeFromSpec(NULL, module, &__pyx_CommonTypesMetaclass_spec, bases); if (unlikely(mstate->__pyx_CommonTypesMetaclassType == NULL)) { return -1; } return 0; } /* PyMethodNew */ #if CYTHON_COMPILING_IN_LIMITED_API static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { PyObject *result; CYTHON_UNUSED_VAR(typ); if (!self) return __Pyx_NewRef(func); #if __PYX_LIMITED_VERSION_HEX >= 0x030C0000 { PyObject *args[] = {func, self}; result = PyObject_Vectorcall(__pyx_mstate_global->__Pyx_CachedMethodType, args, 2, NULL); } #else result = PyObject_CallFunctionObjArgs(__pyx_mstate_global->__Pyx_CachedMethodType, func, self, NULL); #endif return result; } #else static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { CYTHON_UNUSED_VAR(typ); if (!self) return __Pyx_NewRef(func); return PyMethod_New(func, self); } #endif /* PyVectorcallFastCallDict */ #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) { PyObject *res = NULL; PyObject *kwnames; PyObject **newargs; PyObject **kwvalues; Py_ssize_t i, pos; size_t j; PyObject *key, *value; unsigned long keys_are_strings; #if !CYTHON_ASSUME_SAFE_SIZE Py_ssize_t nkw = PyDict_Size(kw); if (unlikely(nkw == -1)) return NULL; #else Py_ssize_t nkw = PyDict_GET_SIZE(kw); #endif newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); if (unlikely(newargs == NULL)) { PyErr_NoMemory(); return NULL; } for (j = 0; j < nargs; j++) newargs[j] = args[j]; kwnames = PyTuple_New(nkw); if (unlikely(kwnames == NULL)) { PyMem_Free(newargs); return NULL; } kwvalues = newargs + nargs; pos = i = 0; keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; while (PyDict_Next(kw, &pos, &key, &value)) { keys_are_strings &= #if CYTHON_COMPILING_IN_LIMITED_API PyType_GetFlags(Py_TYPE(key)); #else Py_TYPE(key)->tp_flags; #endif Py_INCREF(key); Py_INCREF(value); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely(PyTuple_SetItem(kwnames, i, key) < 0)) goto cleanup; #else PyTuple_SET_ITEM(kwnames, i, key); #endif kwvalues[i] = value; i++; } if (unlikely(!keys_are_strings)) { PyErr_SetString(PyExc_TypeError, "keywords must be strings"); goto cleanup; } res = vc(func, newargs, nargs, kwnames); cleanup: Py_DECREF(kwnames); for (i = 0; i < nkw; i++) Py_DECREF(kwvalues[i]); PyMem_Free(newargs); return res; } static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) { Py_ssize_t kw_size = likely(kw == NULL) ? 0 : #if !CYTHON_ASSUME_SAFE_SIZE PyDict_Size(kw); #else PyDict_GET_SIZE(kw); #endif if (kw_size == 0) { return vc(func, args, nargs, NULL); } #if !CYTHON_ASSUME_SAFE_SIZE else if (unlikely(kw_size == -1)) { return NULL; } #endif return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); } #endif /* CythonFunctionShared */ #if CYTHON_COMPILING_IN_LIMITED_API static CYTHON_INLINE int __Pyx__IsSameCyOrCFunctionNoMethod(PyObject *func, void (*cfunc)(void)) { if (__Pyx_CyFunction_Check(func)) { return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; } else if (PyCFunction_Check(func)) { return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; } return 0; } static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void (*cfunc)(void)) { if ((PyObject*)Py_TYPE(func) == __pyx_mstate_global->__Pyx_CachedMethodType) { int result; PyObject *newFunc = PyObject_GetAttr(func, __pyx_mstate_global->__pyx_n_u_func); if (unlikely(!newFunc)) { PyErr_Clear(); // It's only an optimization, so don't throw an error return 0; } result = __Pyx__IsSameCyOrCFunctionNoMethod(newFunc, cfunc); Py_DECREF(newFunc); return result; } return __Pyx__IsSameCyOrCFunctionNoMethod(func, cfunc); } #else static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void (*cfunc)(void)) { if (PyMethod_Check(func)) { func = PyMethod_GET_FUNCTION(func); } return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; } #endif static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API __Pyx_Py_XDECREF_SET( __Pyx_CyFunction_GetClassObj(f), ((classobj) ? __Pyx_NewRef(classobj) : NULL)); #else __Pyx_Py_XDECREF_SET( ((PyCMethodObject *) (f))->mm_class, (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); #endif } static PyObject * __Pyx_CyFunction_get_doc_locked(__pyx_CyFunctionObject *op) { if (unlikely(op->func_doc == NULL)) { #if CYTHON_COMPILING_IN_LIMITED_API op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); if (unlikely(!op->func_doc)) return NULL; #else if (((PyCFunctionObject*)op)->m_ml->ml_doc) { op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); if (unlikely(op->func_doc == NULL)) return NULL; } else { Py_INCREF(Py_None); return Py_None; } #endif } Py_INCREF(op->func_doc); return op->func_doc; } static PyObject * __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) { PyObject *result; CYTHON_UNUSED_VAR(closure); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_doc_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (value == NULL) { value = Py_None; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_doc, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_name_locked(__pyx_CyFunctionObject *op) { if (unlikely(op->func_name == NULL)) { #if CYTHON_COMPILING_IN_LIMITED_API op->func_name = PyObject_GetAttrString(op->func, "__name__"); #else op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); #endif if (unlikely(op->func_name == NULL)) return NULL; } Py_INCREF(op->func_name); return op->func_name; } static PyObject * __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) { PyObject *result = NULL; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_name_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL || !PyUnicode_Check(value))) { PyErr_SetString(PyExc_TypeError, "__name__ must be set to a string object"); return -1; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_name, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); PyObject *result; __Pyx_BEGIN_CRITICAL_SECTION(op); Py_INCREF(op->func_qualname); result = op->func_qualname; __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL || !PyUnicode_Check(value))) { PyErr_SetString(PyExc_TypeError, "__qualname__ must be set to a string object"); return -1; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_qualname, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_dict_locked(__pyx_CyFunctionObject *op) { if (unlikely(op->func_dict == NULL)) { op->func_dict = PyDict_New(); if (unlikely(op->func_dict == NULL)) return NULL; } Py_INCREF(op->func_dict); return op->func_dict; } static PyObject * __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); PyObject *result; __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_dict_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL)) { PyErr_SetString(PyExc_TypeError, "function's dictionary may not be deleted"); return -1; } if (unlikely(!PyDict_Check(value))) { PyErr_SetString(PyExc_TypeError, "setting function's dictionary to a non-dict"); return -1; } Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_dict, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); Py_INCREF(op->func_globals); return op->func_globals; } static PyObject * __Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(op); CYTHON_UNUSED_VAR(context); Py_INCREF(Py_None); return Py_None; } static PyObject * __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) { PyObject* result = (op->func_code) ? op->func_code : Py_None; CYTHON_UNUSED_VAR(context); Py_INCREF(result); return result; } static int __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { int result = 0; PyObject *res = op->defaults_getter((PyObject *) op); if (unlikely(!res)) return -1; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS op->defaults_tuple = PyTuple_GET_ITEM(res, 0); Py_INCREF(op->defaults_tuple); op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); Py_INCREF(op->defaults_kwdict); #else op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); if (unlikely(!op->defaults_tuple)) result = -1; else { op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); if (unlikely(!op->defaults_kwdict)) result = -1; } #endif Py_DECREF(res); return result; } static int __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); if (!value) { value = Py_None; } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { PyErr_SetString(PyExc_TypeError, "__defaults__ must be set to a tuple object"); return -1; } PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " "currently affect the values used in function calls", 1); Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_defaults_locked(__pyx_CyFunctionObject *op) { PyObject* result = op->defaults_tuple; if (unlikely(!result)) { if (op->defaults_getter) { if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; result = op->defaults_tuple; } else { result = Py_None; } } Py_INCREF(result); return result; } static PyObject * __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { PyObject* result = NULL; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_defaults_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); if (!value) { value = Py_None; } else if (unlikely(value != Py_None && !PyDict_Check(value))) { PyErr_SetString(PyExc_TypeError, "__kwdefaults__ must be set to a dict object"); return -1; } PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " "currently affect the values used in function calls", 1); Py_INCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_kwdefaults_locked(__pyx_CyFunctionObject *op) { PyObject* result = op->defaults_kwdict; if (unlikely(!result)) { if (op->defaults_getter) { if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; result = op->defaults_kwdict; } else { result = Py_None; } } Py_INCREF(result); return result; } static PyObject * __Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { PyObject* result; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_kwdefaults_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static int __Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); if (!value || value == Py_None) { value = NULL; } else if (unlikely(!PyDict_Check(value))) { PyErr_SetString(PyExc_TypeError, "__annotations__ must be set to a dict object"); return -1; } Py_XINCREF(value); __Pyx_BEGIN_CRITICAL_SECTION(op); __Pyx_Py_XDECREF_SET(op->func_annotations, value); __Pyx_END_CRITICAL_SECTION(); return 0; } static PyObject * __Pyx_CyFunction_get_annotations_locked(__pyx_CyFunctionObject *op) { PyObject* result = op->func_annotations; if (unlikely(!result)) { result = PyDict_New(); if (unlikely(!result)) return NULL; op->func_annotations = result; } Py_INCREF(result); return result; } static PyObject * __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { PyObject *result; CYTHON_UNUSED_VAR(context); __Pyx_BEGIN_CRITICAL_SECTION(op); result = __Pyx_CyFunction_get_annotations_locked(op); __Pyx_END_CRITICAL_SECTION(); return result; } static PyObject * __Pyx_CyFunction_get_is_coroutine_value(__pyx_CyFunctionObject *op) { int is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; if (is_coroutine) { PyObject *is_coroutine_value, *module, *fromlist, *marker = __pyx_mstate_global->__pyx_n_u_is_coroutine; fromlist = PyList_New(1); if (unlikely(!fromlist)) return NULL; Py_INCREF(marker); #if CYTHON_ASSUME_SAFE_MACROS PyList_SET_ITEM(fromlist, 0, marker); #else if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { Py_DECREF(marker); Py_DECREF(fromlist); return NULL; } #endif module = PyImport_ImportModuleLevelObject(__pyx_mstate_global->__pyx_n_u_asyncio_coroutines, NULL, NULL, fromlist, 0); Py_DECREF(fromlist); if (unlikely(!module)) goto ignore; is_coroutine_value = __Pyx_PyObject_GetAttrStr(module, marker); Py_DECREF(module); if (likely(is_coroutine_value)) { return is_coroutine_value; } ignore: PyErr_Clear(); } return __Pyx_PyBool_FromLong(is_coroutine); } static PyObject * __Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { PyObject *result; CYTHON_UNUSED_VAR(context); if (op->func_is_coroutine) { return __Pyx_NewRef(op->func_is_coroutine); } result = __Pyx_CyFunction_get_is_coroutine_value(op); if (unlikely(!result)) return NULL; __Pyx_BEGIN_CRITICAL_SECTION(op); if (op->func_is_coroutine) { Py_DECREF(result); result = __Pyx_NewRef(op->func_is_coroutine); } else { op->func_is_coroutine = __Pyx_NewRef(result); } __Pyx_END_CRITICAL_SECTION(); return result; } static void __Pyx_CyFunction_raise_argument_count_error(__pyx_CyFunctionObject *func, const char* message, Py_ssize_t size) { #if CYTHON_COMPILING_IN_LIMITED_API PyObject *py_name = __Pyx_CyFunction_get_name(func, NULL); if (!py_name) return; PyErr_Format(PyExc_TypeError, "%.200S() %s (%" CYTHON_FORMAT_SSIZE_T "d given)", py_name, message, size); Py_DECREF(py_name); #else const char* name = ((PyCFunctionObject*)func)->m_ml->ml_name; PyErr_Format(PyExc_TypeError, "%.200s() %s (%" CYTHON_FORMAT_SSIZE_T "d given)", name, message, size); #endif } static void __Pyx_CyFunction_raise_type_error(__pyx_CyFunctionObject *func, const char* message) { #if CYTHON_COMPILING_IN_LIMITED_API PyObject *py_name = __Pyx_CyFunction_get_name(func, NULL); if (!py_name) return; PyErr_Format(PyExc_TypeError, "%.200S() %s", py_name, message); Py_DECREF(py_name); #else const char* name = ((PyCFunctionObject*)func)->m_ml->ml_name; PyErr_Format(PyExc_TypeError, "%.200s() %s", name, message); #endif } #if CYTHON_COMPILING_IN_LIMITED_API static PyObject * __Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { CYTHON_UNUSED_VAR(context); return PyObject_GetAttrString(op->func, "__module__"); } static int __Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { CYTHON_UNUSED_VAR(context); return PyObject_SetAttrString(op->func, "__module__", value); } #endif static PyGetSetDef __pyx_CyFunction_getsets[] = { {"func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, {"__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, {"func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, {"__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, {"__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, {"func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, {"__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, {"func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, {"__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, {"func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, {"__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, {"func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, {"__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, {"func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, {"__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, {"__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, {"__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, {"_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, #if CYTHON_COMPILING_IN_LIMITED_API {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, #endif {0, 0, 0, 0, 0} }; static PyMemberDef __pyx_CyFunction_members[] = { #if !CYTHON_COMPILING_IN_LIMITED_API {"__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, #endif {"__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, #if CYTHON_METH_FASTCALL #if CYTHON_BACKPORT_VECTORCALL || CYTHON_COMPILING_IN_LIMITED_API {"__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, #else {"__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, #endif #if CYTHON_COMPILING_IN_LIMITED_API {"__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, #else {"__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, #endif #endif {0, 0, 0, 0, 0} }; static PyObject * __Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) { PyObject *result = NULL; CYTHON_UNUSED_VAR(args); __Pyx_BEGIN_CRITICAL_SECTION(m); Py_INCREF(m->func_qualname); result = m->func_qualname; __Pyx_END_CRITICAL_SECTION(); return result; } static PyMethodDef __pyx_CyFunction_methods[] = { {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, {0, 0, 0, 0} }; #if CYTHON_COMPILING_IN_LIMITED_API #define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) #else #define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) #endif static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { #if !CYTHON_COMPILING_IN_LIMITED_API PyCFunctionObject *cf = (PyCFunctionObject*) op; #endif if (unlikely(op == NULL)) return NULL; #if CYTHON_COMPILING_IN_LIMITED_API op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); if (unlikely(!op->func)) return NULL; #endif op->flags = flags; __Pyx_CyFunction_weakreflist(op) = NULL; #if !CYTHON_COMPILING_IN_LIMITED_API cf->m_ml = ml; cf->m_self = (PyObject *) op; #endif Py_XINCREF(closure); op->func_closure = closure; #if !CYTHON_COMPILING_IN_LIMITED_API Py_XINCREF(module); cf->m_module = module; #endif op->func_dict = NULL; op->func_name = NULL; Py_INCREF(qualname); op->func_qualname = qualname; op->func_doc = NULL; #if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API op->func_classobj = NULL; #else ((PyCMethodObject*)op)->mm_class = NULL; #endif op->func_globals = globals; Py_INCREF(op->func_globals); Py_XINCREF(code); op->func_code = code; op->defaults = NULL; op->defaults_tuple = NULL; op->defaults_kwdict = NULL; op->defaults_getter = NULL; op->func_annotations = NULL; op->func_is_coroutine = NULL; #if CYTHON_METH_FASTCALL switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { case METH_NOARGS: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; break; case METH_O: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; break; case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; break; case METH_FASTCALL | METH_KEYWORDS: __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; break; case METH_VARARGS | METH_KEYWORDS: __Pyx_CyFunction_func_vectorcall(op) = NULL; break; default: PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); Py_DECREF(op); return NULL; } #endif return (PyObject *) op; } static int __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) { Py_CLEAR(m->func_closure); #if CYTHON_COMPILING_IN_LIMITED_API Py_CLEAR(m->func); #else Py_CLEAR(((PyCFunctionObject*)m)->m_module); #endif Py_CLEAR(m->func_dict); Py_CLEAR(m->func_name); Py_CLEAR(m->func_qualname); Py_CLEAR(m->func_doc); Py_CLEAR(m->func_globals); Py_CLEAR(m->func_code); #if !CYTHON_COMPILING_IN_LIMITED_API #if PY_VERSION_HEX < 0x030900B1 Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); #else { PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; ((PyCMethodObject *) (m))->mm_class = NULL; Py_XDECREF(cls); } #endif #endif Py_CLEAR(m->defaults_tuple); Py_CLEAR(m->defaults_kwdict); Py_CLEAR(m->func_annotations); Py_CLEAR(m->func_is_coroutine); Py_CLEAR(m->defaults); return 0; } static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) { if (__Pyx_CyFunction_weakreflist(m) != NULL) PyObject_ClearWeakRefs((PyObject *) m); __Pyx_CyFunction_clear(m); __Pyx_PyHeapTypeObject_GC_Del(m); } static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) { PyObject_GC_UnTrack(m); __Pyx__CyFunction_dealloc(m); } static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) { { int e = __Pyx_call_type_traverse((PyObject*)m, 1, visit, arg); if (e) return e; } Py_VISIT(m->func_closure); #if CYTHON_COMPILING_IN_LIMITED_API Py_VISIT(m->func); #else Py_VISIT(((PyCFunctionObject*)m)->m_module); #endif Py_VISIT(m->func_dict); __Pyx_VISIT_CONST(m->func_name); __Pyx_VISIT_CONST(m->func_qualname); Py_VISIT(m->func_doc); Py_VISIT(m->func_globals); __Pyx_VISIT_CONST(m->func_code); #if !CYTHON_COMPILING_IN_LIMITED_API Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); #endif Py_VISIT(m->defaults_tuple); Py_VISIT(m->defaults_kwdict); Py_VISIT(m->func_is_coroutine); Py_VISIT(m->defaults); return 0; } static PyObject* __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) { PyObject *repr; __Pyx_BEGIN_CRITICAL_SECTION(op); repr = PyUnicode_FromFormat("", op->func_qualname, (void *)op); __Pyx_END_CRITICAL_SECTION(); return repr; } static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { #if CYTHON_COMPILING_IN_LIMITED_API PyObject *f = ((__pyx_CyFunctionObject*)func)->func; PyCFunction meth; int flags; meth = PyCFunction_GetFunction(f); if (unlikely(!meth)) return NULL; flags = PyCFunction_GetFlags(f); if (unlikely(flags < 0)) return NULL; #else PyCFunctionObject* f = (PyCFunctionObject*)func; PyCFunction meth = f->m_ml->ml_meth; int flags = f->m_ml->ml_flags; #endif Py_ssize_t size; switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { case METH_VARARGS: if (likely(kw == NULL || PyDict_Size(kw) == 0)) return (*meth)(self, arg); break; case METH_VARARGS | METH_KEYWORDS: return (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, arg, kw); case METH_NOARGS: if (likely(kw == NULL || PyDict_Size(kw) == 0)) { #if CYTHON_ASSUME_SAFE_SIZE size = PyTuple_GET_SIZE(arg); #else size = PyTuple_Size(arg); if (unlikely(size < 0)) return NULL; #endif if (likely(size == 0)) return (*meth)(self, NULL); __Pyx_CyFunction_raise_argument_count_error( (__pyx_CyFunctionObject*)func, "takes no arguments", size); return NULL; } break; case METH_O: if (likely(kw == NULL || PyDict_Size(kw) == 0)) { #if CYTHON_ASSUME_SAFE_SIZE size = PyTuple_GET_SIZE(arg); #else size = PyTuple_Size(arg); if (unlikely(size < 0)) return NULL; #endif if (likely(size == 1)) { PyObject *result, *arg0; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS arg0 = PyTuple_GET_ITEM(arg, 0); #else arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; #endif result = (*meth)(self, arg0); #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) Py_DECREF(arg0); #endif return result; } __Pyx_CyFunction_raise_argument_count_error( (__pyx_CyFunctionObject*)func, "takes exactly one argument", size); return NULL; } break; default: PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); return NULL; } __Pyx_CyFunction_raise_type_error( (__pyx_CyFunctionObject*)func, "takes no keyword arguments"); return NULL; } static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *self, *result; #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)func)->m_self; #endif result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); return result; } static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { PyObject *result; __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); if (vc) { #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); #else (void) &__Pyx_PyVectorcall_FastCallDict; return PyVectorcall_Call(func, args, kw); #endif } #endif if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { Py_ssize_t argc; PyObject *new_args; PyObject *self; #if CYTHON_ASSUME_SAFE_SIZE argc = PyTuple_GET_SIZE(args); #else argc = PyTuple_Size(args); if (unlikely(argc < 0)) return NULL; #endif new_args = PyTuple_GetSlice(args, 1, argc); if (unlikely(!new_args)) return NULL; self = PyTuple_GetItem(args, 0); if (unlikely(!self)) { Py_DECREF(new_args); PyErr_Format(PyExc_TypeError, "unbound method %.200S() needs an argument", cyfunc->func_qualname); return NULL; } result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); Py_DECREF(new_args); } else { result = __Pyx_CyFunction_Call(func, args, kw); } return result; } #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL) static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) { int ret = 0; if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { if (unlikely(nargs < 1)) { __Pyx_CyFunction_raise_type_error( cyfunc, "needs an argument"); return -1; } ret = 1; } if (unlikely(kwnames) && unlikely(__Pyx_PyTuple_GET_SIZE(kwnames))) { __Pyx_CyFunction_raise_type_error( cyfunc, "takes no keyword arguments"); return -1; } return ret; } static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } if (unlikely(nargs != 0)) { __Pyx_CyFunction_raise_argument_count_error( cyfunc, "takes no arguments", nargs); return NULL; } return meth(self, NULL); } static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } if (unlikely(nargs != 1)) { __Pyx_CyFunction_raise_argument_count_error( cyfunc, "takes exactly one argument", nargs); return NULL; } return meth(self, args[0]); } static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))meth)(self, args, nargs, kwnames); } static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) { __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); #if CYTHON_BACKPORT_VECTORCALL Py_ssize_t nargs = (Py_ssize_t)nargsf; #else Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); #endif PyObject *self; #if CYTHON_COMPILING_IN_LIMITED_API PyCFunction meth = PyCFunction_GetFunction(cyfunc->func); if (unlikely(!meth)) return NULL; #else PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth; #endif switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { case 1: self = args[0]; args += 1; nargs -= 1; break; case 0: #if CYTHON_COMPILING_IN_LIMITED_API self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)cyfunc)->func); if (unlikely(!self) && PyErr_Occurred()) return NULL; #else self = ((PyCFunctionObject*)cyfunc)->m_self; #endif break; default: return NULL; } return ((__Pyx_PyCMethod)(void(*)(void))meth)(self, cls, args, (size_t)nargs, kwnames); } #endif static PyType_Slot __pyx_CyFunctionType_slots[] = { {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, {Py_tp_methods, (void *)__pyx_CyFunction_methods}, {Py_tp_members, (void *)__pyx_CyFunction_members}, {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, {0, 0}, }; static PyType_Spec __pyx_CyFunctionType_spec = { __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", sizeof(__pyx_CyFunctionObject), 0, #ifdef Py_TPFLAGS_METHOD_DESCRIPTOR Py_TPFLAGS_METHOD_DESCRIPTOR | #endif #if CYTHON_METH_FASTCALL #if defined(Py_TPFLAGS_HAVE_VECTORCALL) Py_TPFLAGS_HAVE_VECTORCALL | #elif defined(_Py_TPFLAGS_HAVE_VECTORCALL) _Py_TPFLAGS_HAVE_VECTORCALL | #endif #endif // CYTHON_METH_FASTCALL #if PY_VERSION_HEX >= 0x030A0000 Py_TPFLAGS_IMMUTABLETYPE | #endif Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, __pyx_CyFunctionType_slots }; static int __pyx_CyFunction_init(PyObject *module) { __pyx_mstatetype *mstate = __Pyx_PyModule_GetState(module); mstate->__pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec( mstate->__pyx_CommonTypesMetaclassType, module, &__pyx_CyFunctionType_spec, NULL); if (unlikely(mstate->__pyx_CyFunctionType == NULL)) { return -1; } return 0; } static CYTHON_INLINE PyObject *__Pyx_CyFunction_InitDefaults(PyObject *func, PyTypeObject *defaults_type) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults = PyObject_CallObject((PyObject*)defaults_type, NULL); // _PyObject_New(defaults_type); if (unlikely(!m->defaults)) return NULL; return m->defaults; } static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults_tuple = tuple; Py_INCREF(tuple); } static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults_kwdict = dict; Py_INCREF(dict); } static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->func_annotations = dict; Py_INCREF(dict); } /* CythonFunction */ static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { PyObject *op = __Pyx_CyFunction_Init( PyObject_GC_New(__pyx_CyFunctionObject, __pyx_mstate_global->__pyx_CyFunctionType), ml, flags, qualname, closure, module, globals, code ); if (likely(op)) { PyObject_GC_Track(op); } return op; } /* 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;\ } /* 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 } } /* 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 } } /* 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__3); } 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__Pyx_GetBuiltinNext_LimitedAPI_cache)) __pyx_mstate_global->__Pyx_GetBuiltinNext_LimitedAPI_cache = __Pyx_GetBuiltinName(__pyx_mstate_global->__pyx_n_u_next); return __pyx_mstate_global->__Pyx_GetBuiltinNext_LimitedAPI_cache; } #endif static CYTHON_INLINE PyObject *__Pyx_PyIter_Next_Plain(PyObject *iterator) { #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000 PyObject *result; PyObject *next = __Pyx_GetBuiltinNext_LimitedAPI(); if (unlikely(!next)) return NULL; result = PyObject_CallFunctionObjArgs(next, iterator, NULL); return result; #else (void)__Pyx_GetBuiltinName; // only for early limited API iternextfunc iternext = __Pyx_PyObject_GetIterNextFunc(iterator); assert(iternext); return iternext(iterator); #endif } /* PyObjectCallMethod1 */ #if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000) static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); Py_DECREF(method); return result; } #endif static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { #if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000 PyObject *args[2] = {obj, arg}; (void) __Pyx_PyObject_GetMethod; (void) __Pyx_PyObject_CallOneArg; (void) __Pyx_PyObject_Call2Args; return PyObject_VectorcallMethod(method_name, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); #else PyObject *method = NULL, *result; int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); if (likely(is_method)) { result = __Pyx_PyObject_Call2Args(method, obj, arg); Py_DECREF(method); return result; } if (unlikely(!method)) return NULL; return __Pyx__PyObject_CallMethod1(method, arg); #endif } /* ReturnWithStopIteration */ static void __Pyx__ReturnWithStopIteration(PyObject* value, int async); static CYTHON_INLINE void __Pyx_ReturnWithStopIteration(PyObject* value, int async, int iternext) { if (value == Py_None) { if (async || !iternext) PyErr_SetNone(async ? PyExc_StopAsyncIteration : PyExc_StopIteration); return; } __Pyx__ReturnWithStopIteration(value, async); } static void __Pyx__ReturnWithStopIteration(PyObject* value, int async) { #if CYTHON_COMPILING_IN_CPYTHON __Pyx_PyThreadState_declare #endif PyObject *exc; PyObject *exc_type = async ? PyExc_StopAsyncIteration : PyExc_StopIteration; #if CYTHON_COMPILING_IN_CPYTHON if ((PY_VERSION_HEX >= (0x030C00A6)) || unlikely(PyTuple_Check(value) || PyExceptionInstance_Check(value))) { if (PY_VERSION_HEX >= (0x030e00A1)) { exc = __Pyx_PyObject_CallOneArg(exc_type, value); } else { PyObject *args_tuple = PyTuple_New(1); if (unlikely(!args_tuple)) return; Py_INCREF(value); PyTuple_SET_ITEM(args_tuple, 0, value); exc = PyObject_Call(exc_type, args_tuple, NULL); Py_DECREF(args_tuple); } if (unlikely(!exc)) return; } else { Py_INCREF(value); exc = value; } #if CYTHON_FAST_THREAD_STATE __Pyx_PyThreadState_assign #if CYTHON_USE_EXC_INFO_STACK if (!__pyx_tstate->exc_info->exc_value) #else if (!__pyx_tstate->exc_type) #endif { Py_INCREF(exc_type); __Pyx_ErrRestore(exc_type, exc, NULL); return; } #endif #else exc = __Pyx_PyObject_CallOneArg(exc_type, value); if (unlikely(!exc)) return; #endif PyErr_SetObject(exc_type, exc); Py_DECREF(exc); } /* CoroutineBase */ #if !CYTHON_COMPILING_IN_LIMITED_API #include #if PY_VERSION_HEX >= 0x030b00a6 && !defined(PYPY_VERSION) #ifndef Py_BUILD_CORE #define Py_BUILD_CORE 1 #endif #include "internal/pycore_frame.h" #endif #endif // CYTHON_COMPILING_IN_LIMITED_API static CYTHON_INLINE void __Pyx_Coroutine_Undelegate(__pyx_CoroutineObject *gen) { #if CYTHON_USE_AM_SEND gen->yieldfrom_am_send = NULL; #endif Py_CLEAR(gen->yieldfrom); } static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *__pyx_tstate, PyObject **pvalue) { PyObject *et, *ev, *tb; PyObject *value = NULL; CYTHON_UNUSED_VAR(__pyx_tstate); __Pyx_ErrFetch(&et, &ev, &tb); if (!et) { Py_XDECREF(tb); Py_XDECREF(ev); Py_INCREF(Py_None); *pvalue = Py_None; return 0; } if (likely(et == PyExc_StopIteration)) { if (!ev) { Py_INCREF(Py_None); value = Py_None; } else if (likely(__Pyx_IS_TYPE(ev, (PyTypeObject*)PyExc_StopIteration))) { #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL value = PyObject_GetAttr(ev, __pyx_mstate_global->__pyx_n_u_value); if (unlikely(!value)) goto limited_api_failure; #else value = ((PyStopIterationObject *)ev)->value; Py_INCREF(value); #endif Py_DECREF(ev); } else if (unlikely(PyTuple_Check(ev))) { Py_ssize_t tuple_size = __Pyx_PyTuple_GET_SIZE(ev); #if !CYTHON_ASSUME_SAFE_SIZE if (unlikely(tuple_size < 0)) { Py_XDECREF(tb); Py_DECREF(ev); Py_DECREF(et); return -1; } #endif if (tuple_size >= 1) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS value = PyTuple_GET_ITEM(ev, 0); Py_INCREF(value); #elif CYTHON_ASSUME_SAFE_MACROS value = PySequence_ITEM(ev, 0); #else value = PySequence_GetItem(ev, 0); if (!value) goto limited_api_failure; #endif } else { Py_INCREF(Py_None); value = Py_None; } Py_DECREF(ev); } else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) { value = ev; } if (likely(value)) { Py_XDECREF(tb); Py_DECREF(et); *pvalue = value; return 0; } } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) { __Pyx_ErrRestore(et, ev, tb); return -1; } PyErr_NormalizeException(&et, &ev, &tb); if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) { __Pyx_ErrRestore(et, ev, tb); return -1; } Py_XDECREF(tb); Py_DECREF(et); #if CYTHON_COMPILING_IN_LIMITED_API value = PyObject_GetAttr(ev, __pyx_mstate_global->__pyx_n_u_value); #else value = ((PyStopIterationObject *)ev)->value; Py_INCREF(value); #endif Py_DECREF(ev); #if CYTHON_COMPILING_IN_LIMITED_API if (unlikely(!value)) return -1; #endif *pvalue = value; return 0; #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL || !CYTHON_ASSUME_SAFE_MACROS limited_api_failure: Py_XDECREF(et); Py_XDECREF(tb); Py_XDECREF(ev); return -1; #endif } static CYTHON_INLINE __Pyx_PySendResult __Pyx_Coroutine_status_from_result(PyObject **retval) { if (*retval) { return PYGEN_NEXT; } else if (likely(__Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, retval) == 0)) { return PYGEN_RETURN; } else { return PYGEN_ERROR; } } static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) { #if PY_VERSION_HEX >= 0x030B00a4 Py_CLEAR(exc_state->exc_value); #else PyObject *t, *v, *tb; t = exc_state->exc_type; v = exc_state->exc_value; tb = exc_state->exc_traceback; exc_state->exc_type = NULL; exc_state->exc_value = NULL; exc_state->exc_traceback = NULL; Py_XDECREF(t); Py_XDECREF(v); Py_XDECREF(tb); #endif } #define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL) static void __Pyx__Coroutine_AlreadyRunningError(__pyx_CoroutineObject *gen) { const char *msg; CYTHON_MAYBE_UNUSED_VAR(gen); if ((0)) { #ifdef __Pyx_Coroutine_USED } else if (__Pyx_Coroutine_Check((PyObject*)gen)) { msg = "coroutine already executing"; #endif #ifdef __Pyx_AsyncGen_USED } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) { msg = "async generator already executing"; #endif } else { msg = "generator already executing"; } PyErr_SetString(PyExc_ValueError, msg); } static void __Pyx_Coroutine_AlreadyTerminatedError(PyObject *gen, PyObject *value, int closing) { CYTHON_MAYBE_UNUSED_VAR(gen); CYTHON_MAYBE_UNUSED_VAR(closing); #ifdef __Pyx_Coroutine_USED if (!closing && __Pyx_Coroutine_Check(gen)) { PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine"); } else #endif if (value) { #ifdef __Pyx_AsyncGen_USED if (__Pyx_AsyncGen_CheckExact(gen)) PyErr_SetNone(PyExc_StopAsyncIteration); else #endif PyErr_SetNone(PyExc_StopIteration); } } static __Pyx_PySendResult __Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, PyObject **result, int closing) { __Pyx_PyThreadState_declare PyThreadState *tstate; __Pyx_ExcInfoStruct *exc_state; PyObject *retval; assert(__Pyx_Coroutine_get_is_running(self)); // Callers should ensure is_running if (unlikely(self->resume_label == -1)) { __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing); return PYGEN_ERROR; } #if CYTHON_FAST_THREAD_STATE __Pyx_PyThreadState_assign tstate = __pyx_tstate; #else tstate = __Pyx_PyThreadState_Current; #endif exc_state = &self->gi_exc_state; if (exc_state->exc_value) { #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY #else PyObject *exc_tb; #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON exc_tb = PyException_GetTraceback(exc_state->exc_value); #elif PY_VERSION_HEX >= 0x030B00a4 exc_tb = ((PyBaseExceptionObject*) exc_state->exc_value)->traceback; #else exc_tb = exc_state->exc_traceback; #endif if (exc_tb) { PyTracebackObject *tb = (PyTracebackObject *) exc_tb; PyFrameObject *f = tb->tb_frame; assert(f->f_back == NULL); #if PY_VERSION_HEX >= 0x030B00A1 f->f_back = PyThreadState_GetFrame(tstate); #else Py_XINCREF(tstate->frame); f->f_back = tstate->frame; #endif #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON Py_DECREF(exc_tb); #endif } #endif } #if CYTHON_USE_EXC_INFO_STACK exc_state->previous_item = tstate->exc_info; tstate->exc_info = exc_state; #else if (exc_state->exc_type) { __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback); } else { __Pyx_Coroutine_ExceptionClear(exc_state); __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback); } #endif retval = self->body(self, tstate, value); #if CYTHON_USE_EXC_INFO_STACK exc_state = &self->gi_exc_state; tstate->exc_info = exc_state->previous_item; exc_state->previous_item = NULL; __Pyx_Coroutine_ResetFrameBackpointer(exc_state); #endif *result = retval; if (self->resume_label == -1) { return likely(retval) ? PYGEN_RETURN : PYGEN_ERROR; } return PYGEN_NEXT; } static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) { #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API CYTHON_UNUSED_VAR(exc_state); #else PyObject *exc_tb; #if PY_VERSION_HEX >= 0x030B00a4 if (!exc_state->exc_value) return; exc_tb = PyException_GetTraceback(exc_state->exc_value); #else exc_tb = exc_state->exc_traceback; #endif if (likely(exc_tb)) { PyTracebackObject *tb = (PyTracebackObject *) exc_tb; PyFrameObject *f = tb->tb_frame; Py_CLEAR(f->f_back); #if PY_VERSION_HEX >= 0x030B00a4 Py_DECREF(exc_tb); #endif } #endif } #define __Pyx_Coroutine_MethodReturnFromResult(gen, result, retval, iternext)\ ((result) == PYGEN_NEXT ? (retval) : __Pyx__Coroutine_MethodReturnFromResult(gen, result, retval, iternext)) static PyObject * __Pyx__Coroutine_MethodReturnFromResult(PyObject* gen, __Pyx_PySendResult result, PyObject *retval, int iternext) { CYTHON_MAYBE_UNUSED_VAR(gen); if (likely(result == PYGEN_RETURN)) { int is_async = 0; #ifdef __Pyx_AsyncGen_USED is_async = __Pyx_AsyncGen_CheckExact(gen); #endif __Pyx_ReturnWithStopIteration(retval, is_async, iternext); Py_XDECREF(retval); } return NULL; } #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) { #if PY_VERSION_HEX <= 0x030A00A1 return _PyGen_Send(gen, arg); #else PyObject *result; if (PyIter_Send((PyObject*)gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) { if (PyAsyncGen_CheckExact(gen)) { assert(result == Py_None); PyErr_SetNone(PyExc_StopAsyncIteration); } else if (result == Py_None) { PyErr_SetNone(PyExc_StopIteration); } else { #if PY_VERSION_HEX < 0x030d00A1 _PyGen_SetStopIterationValue(result); #else if (!PyTuple_Check(result) && !PyExceptionInstance_Check(result)) { PyErr_SetObject(PyExc_StopIteration, result); } else { PyObject *exc = __Pyx_PyObject_CallOneArg(PyExc_StopIteration, result); if (likely(exc != NULL)) { PyErr_SetObject(PyExc_StopIteration, exc); Py_DECREF(exc); } } #endif } Py_DECREF(result); result = NULL; } return result; #endif } #endif static CYTHON_INLINE __Pyx_PySendResult __Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen, PyObject** retval) { __Pyx_PySendResult result; PyObject *val = NULL; assert(__Pyx_Coroutine_get_is_running(gen)); __Pyx_Coroutine_Undelegate(gen); __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val); result = __Pyx_Coroutine_SendEx(gen, val, retval, 0); Py_XDECREF(val); return result; } #if CYTHON_USE_AM_SEND static __Pyx_PySendResult __Pyx_Coroutine_SendToDelegate(__pyx_CoroutineObject *gen, __Pyx_pyiter_sendfunc gen_am_send, PyObject *value, PyObject **retval) { PyObject *ret = NULL; __Pyx_PySendResult delegate_result, result; assert(__Pyx_Coroutine_get_is_running(gen)); delegate_result = gen_am_send(gen->yieldfrom, value, &ret); if (delegate_result == PYGEN_NEXT) { assert (ret != NULL); *retval = ret; return PYGEN_NEXT; } assert (delegate_result != PYGEN_ERROR || ret == NULL); __Pyx_Coroutine_Undelegate(gen); result = __Pyx_Coroutine_SendEx(gen, ret, retval, 0); Py_XDECREF(ret); return result; } #endif static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) { PyObject *retval = NULL; __Pyx_PySendResult result = __Pyx_Coroutine_AmSend(self, value, &retval); return __Pyx_Coroutine_MethodReturnFromResult(self, result, retval, 0); } static __Pyx_PySendResult __Pyx_Coroutine_AmSend(PyObject *self, PyObject *value, PyObject **retval) { __Pyx_PySendResult result; __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; if (unlikely(__Pyx_Coroutine_test_and_set_is_running(gen))) { *retval = __Pyx_Coroutine_AlreadyRunningError(gen); return PYGEN_ERROR; } #if CYTHON_USE_AM_SEND if (gen->yieldfrom_am_send) { result = __Pyx_Coroutine_SendToDelegate(gen, gen->yieldfrom_am_send, value, retval); } else #endif if (gen->yieldfrom) { PyObject *yf = gen->yieldfrom; PyObject *ret; #if !CYTHON_USE_AM_SEND #ifdef __Pyx_Generator_USED if (__Pyx_Generator_CheckExact(yf)) { ret = __Pyx_Coroutine_Send(yf, value); } else #endif #ifdef __Pyx_Coroutine_USED if (__Pyx_Coroutine_Check(yf)) { ret = __Pyx_Coroutine_Send(yf, value); } else #endif #ifdef __Pyx_AsyncGen_USED if (__pyx_PyAsyncGenASend_CheckExact(yf)) { ret = __Pyx_async_gen_asend_send(yf, value); } else #endif #if CYTHON_COMPILING_IN_CPYTHON if (PyGen_CheckExact(yf)) { ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); } else if (PyCoro_CheckExact(yf)) { ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); } else #endif #endif { #if !CYTHON_COMPILING_IN_LIMITED_API || __PYX_LIMITED_VERSION_HEX >= 0x03080000 if (value == Py_None && PyIter_Check(yf)) ret = __Pyx_PyIter_Next_Plain(yf); else #endif ret = __Pyx_PyObject_CallMethod1(yf, __pyx_mstate_global->__pyx_n_u_send, value); } if (likely(ret)) { __Pyx_Coroutine_unset_is_running(gen); *retval = ret; return PYGEN_NEXT; } result = __Pyx_Coroutine_FinishDelegation(gen, retval); } else { result = __Pyx_Coroutine_SendEx(gen, value, retval, 0); } __Pyx_Coroutine_unset_is_running(gen); return result; } static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { __Pyx_PySendResult result; PyObject *retval = NULL; CYTHON_UNUSED_VAR(gen); assert(__Pyx_Coroutine_get_is_running(gen)); #ifdef __Pyx_Generator_USED if (__Pyx_Generator_CheckExact(yf)) { result = __Pyx_Coroutine_Close(yf, &retval); } else #endif #ifdef __Pyx_Coroutine_USED if (__Pyx_Coroutine_Check(yf)) { result = __Pyx_Coroutine_Close(yf, &retval); } else if (__Pyx_CoroutineAwait_CheckExact(yf)) { result = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf); } else #endif #ifdef __Pyx_AsyncGen_USED if (__pyx_PyAsyncGenASend_CheckExact(yf)) { retval = __Pyx_async_gen_asend_close(yf, NULL); result = PYGEN_RETURN; } else if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) { retval = __Pyx_async_gen_athrow_close(yf, NULL); result = PYGEN_RETURN; } else #endif { PyObject *meth; result = PYGEN_RETURN; meth = __Pyx_PyObject_GetAttrStrNoError(yf, __pyx_mstate_global->__pyx_n_u_close); if (unlikely(!meth)) { if (unlikely(PyErr_Occurred())) { PyErr_WriteUnraisable(yf); } } else { retval = __Pyx_PyObject_CallNoArg(meth); Py_DECREF(meth); if (unlikely(!retval)) { result = PYGEN_ERROR; } } } Py_XDECREF(retval); return result == PYGEN_ERROR ? -1 : 0; } static PyObject *__Pyx_Generator_Next(PyObject *self) { __Pyx_PySendResult result; PyObject *retval = NULL; __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; if (unlikely(__Pyx_Coroutine_test_and_set_is_running(gen))) { return __Pyx_Coroutine_AlreadyRunningError(gen); } #if CYTHON_USE_AM_SEND if (gen->yieldfrom_am_send) { result = __Pyx_Coroutine_SendToDelegate(gen, gen->yieldfrom_am_send, Py_None, &retval); } else #endif if (gen->yieldfrom) { PyObject *yf = gen->yieldfrom; PyObject *ret; #ifdef __Pyx_Generator_USED if (__Pyx_Generator_CheckExact(yf)) { ret = __Pyx_Generator_Next(yf); } else #endif #ifdef __Pyx_Coroutine_USED if (__Pyx_Coroutine_CheckExact(yf)) { ret = __Pyx_Coroutine_Send(yf, Py_None); } else #endif #if CYTHON_COMPILING_IN_CPYTHON && (PY_VERSION_HEX < 0x030A00A3 || !CYTHON_USE_AM_SEND) if (PyGen_CheckExact(yf)) { ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL); } else #endif ret = __Pyx_PyIter_Next_Plain(yf); if (likely(ret)) { __Pyx_Coroutine_unset_is_running(gen); return ret; } result = __Pyx_Coroutine_FinishDelegation(gen, &retval); } else { result = __Pyx_Coroutine_SendEx(gen, Py_None, &retval, 0); } __Pyx_Coroutine_unset_is_running(gen); return __Pyx_Coroutine_MethodReturnFromResult(self, result, retval, 1); } static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, PyObject *arg) { PyObject *retval = NULL; __Pyx_PySendResult result; CYTHON_UNUSED_VAR(arg); result = __Pyx_Coroutine_Close(self, &retval); if (unlikely(result == PYGEN_ERROR)) return NULL; Py_XDECREF(retval); Py_RETURN_NONE; } static __Pyx_PySendResult __Pyx_Coroutine_Close(PyObject *self, PyObject **retval) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; __Pyx_PySendResult result; PyObject *yf; int err = 0; if (unlikely(__Pyx_Coroutine_test_and_set_is_running(gen))) { *retval = __Pyx_Coroutine_AlreadyRunningError(gen); return PYGEN_ERROR; } yf = gen->yieldfrom; if (yf) { Py_INCREF(yf); err = __Pyx_Coroutine_CloseIter(gen, yf); __Pyx_Coroutine_Undelegate(gen); Py_DECREF(yf); } if (err == 0) PyErr_SetNone(PyExc_GeneratorExit); result = __Pyx_Coroutine_SendEx(gen, NULL, retval, 1); if (result == PYGEN_ERROR) { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_Coroutine_unset_is_running(gen); if (!__Pyx_PyErr_Occurred()) { return PYGEN_RETURN; } else if (likely(__Pyx_PyErr_ExceptionMatches2(PyExc_GeneratorExit, PyExc_StopIteration))) { __Pyx_PyErr_Clear(); return PYGEN_RETURN; } return PYGEN_ERROR; } else if (likely(result == PYGEN_RETURN && *retval == Py_None)) { __Pyx_Coroutine_unset_is_running(gen); return PYGEN_RETURN; } else { const char *msg; Py_DECREF(*retval); *retval = NULL; if ((0)) { #ifdef __Pyx_Coroutine_USED } else if (__Pyx_Coroutine_Check(self)) { msg = "coroutine ignored GeneratorExit"; #endif #ifdef __Pyx_AsyncGen_USED } else if (__Pyx_AsyncGen_CheckExact(self)) { msg = "async generator ignored GeneratorExit"; #endif } else { msg = "generator ignored GeneratorExit"; } PyErr_SetString(PyExc_RuntimeError, msg); __Pyx_Coroutine_unset_is_running(gen); return PYGEN_ERROR; } } static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb, PyObject *args, int close_on_genexit) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; PyObject *yf; if (unlikely(__Pyx_Coroutine_test_and_set_is_running(gen))) return __Pyx_Coroutine_AlreadyRunningError(gen); yf = gen->yieldfrom; if (yf) { __Pyx_PySendResult result; PyObject *ret; Py_INCREF(yf); if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) { int err = __Pyx_Coroutine_CloseIter(gen, yf); Py_DECREF(yf); __Pyx_Coroutine_Undelegate(gen); if (err < 0) goto propagate_exception; goto throw_here; } if (0 #ifdef __Pyx_Generator_USED || __Pyx_Generator_CheckExact(yf) #endif #ifdef __Pyx_Coroutine_USED || __Pyx_Coroutine_Check(yf) #endif ) { ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit); #ifdef __Pyx_Coroutine_USED } else if (__Pyx_CoroutineAwait_CheckExact(yf)) { ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit); #endif } else { PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(yf, __pyx_mstate_global->__pyx_n_u_throw); if (unlikely(!meth)) { Py_DECREF(yf); if (unlikely(PyErr_Occurred())) { __Pyx_Coroutine_unset_is_running(gen); return NULL; } __Pyx_Coroutine_Undelegate(gen); goto throw_here; } if (likely(args)) { ret = __Pyx_PyObject_Call(meth, args, NULL); } else { PyObject *cargs[4] = {NULL, typ, val, tb}; ret = __Pyx_PyObject_FastCall(meth, cargs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); } Py_DECREF(meth); } Py_DECREF(yf); if (ret) { __Pyx_Coroutine_unset_is_running(gen); return ret; } result = __Pyx_Coroutine_FinishDelegation(gen, &ret); __Pyx_Coroutine_unset_is_running(gen); return __Pyx_Coroutine_MethodReturnFromResult(self, result, ret, 0); } throw_here: __Pyx_Raise(typ, val, tb, NULL); propagate_exception: { PyObject *retval = NULL; __Pyx_PySendResult result = __Pyx_Coroutine_SendEx(gen, NULL, &retval, 0); __Pyx_Coroutine_unset_is_running(gen); return __Pyx_Coroutine_MethodReturnFromResult(self, result, retval, 0); } } static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { PyObject *typ; PyObject *val = NULL; PyObject *tb = NULL; if (unlikely(!PyArg_UnpackTuple(args, "throw", 1, 3, &typ, &val, &tb))) return NULL; return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1); } static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) { #if PY_VERSION_HEX >= 0x030B00a4 Py_VISIT(exc_state->exc_value); #else Py_VISIT(exc_state->exc_type); Py_VISIT(exc_state->exc_value); Py_VISIT(exc_state->exc_traceback); #endif return 0; } static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) { { int e = __Pyx_call_type_traverse((PyObject*)gen, 1, visit, arg); if (e) return e; } Py_VISIT(gen->closure); Py_VISIT(gen->classobj); Py_VISIT(gen->yieldfrom); return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg); } static int __Pyx_Coroutine_clear(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; Py_CLEAR(gen->closure); Py_CLEAR(gen->classobj); __Pyx_Coroutine_Undelegate(gen); __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state); #ifdef __Pyx_AsyncGen_USED if (__Pyx_AsyncGen_CheckExact(self)) { Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer); } #endif Py_CLEAR(gen->gi_code); Py_CLEAR(gen->gi_frame); Py_CLEAR(gen->gi_name); Py_CLEAR(gen->gi_qualname); Py_CLEAR(gen->gi_modulename); return 0; } static void __Pyx_Coroutine_dealloc(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; PyObject_GC_UnTrack(gen); if (gen->gi_weakreflist != NULL) PyObject_ClearWeakRefs(self); if (gen->resume_label >= 0) { PyObject_GC_Track(self); #if CYTHON_USE_TP_FINALIZE if (unlikely(PyObject_CallFinalizerFromDealloc(self))) #else { destructor del = __Pyx_PyObject_GetSlot(gen, tp_del, destructor); if (del) del(self); } if (unlikely(Py_REFCNT(self) > 0)) #endif { return; } PyObject_GC_UnTrack(self); } #ifdef __Pyx_AsyncGen_USED if (__Pyx_AsyncGen_CheckExact(self)) { /* We have to handle this case for asynchronous generators right here, because this code has to be between UNTRACK and GC_Del. */ Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer); } #endif __Pyx_Coroutine_clear(self); __Pyx_PyHeapTypeObject_GC_Del(gen); } #if CYTHON_USE_TP_FINALIZE static void __Pyx_Coroutine_del(PyObject *self) { PyObject *error_type, *error_value, *error_traceback; __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; __Pyx_PyThreadState_declare if (gen->resume_label < 0) { return; } __Pyx_PyThreadState_assign __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); #ifdef __Pyx_AsyncGen_USED if (__Pyx_AsyncGen_CheckExact(self)) { __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self; PyObject *finalizer = agen->ag_finalizer; if (finalizer && !agen->ag_closed) { PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self); if (unlikely(!res)) { PyErr_WriteUnraisable(self); } else { Py_DECREF(res); } __Pyx_ErrRestore(error_type, error_value, error_traceback); return; } } #endif if (unlikely(gen->resume_label == 0 && !error_value)) { #ifdef __Pyx_Coroutine_USED #ifdef __Pyx_Generator_USED if (!__Pyx_Generator_CheckExact(self)) #endif { PyObject_GC_UnTrack(self); if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0)) PyErr_WriteUnraisable(self); PyObject_GC_Track(self); } #endif } else { PyObject *retval = NULL; __Pyx_PySendResult result = __Pyx_Coroutine_Close(self, &retval); if (result == PYGEN_ERROR) { PyErr_WriteUnraisable(self); } else { Py_XDECREF(retval); } } __Pyx_ErrRestore(error_type, error_value, error_traceback); } #endif static PyObject * __Pyx_Coroutine_get_name(__pyx_CoroutineObject *self, void *context) { PyObject *name = self->gi_name; CYTHON_UNUSED_VAR(context); if (unlikely(!name)) name = Py_None; Py_INCREF(name); return name; } static int __Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL || !PyUnicode_Check(value))) { PyErr_SetString(PyExc_TypeError, "__name__ must be set to a string object"); return -1; } Py_INCREF(value); __Pyx_Py_XDECREF_SET(self->gi_name, value); return 0; } static PyObject * __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self, void *context) { PyObject *name = self->gi_qualname; CYTHON_UNUSED_VAR(context); if (unlikely(!name)) name = Py_None; Py_INCREF(name); return name; } static int __Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, void *context) { CYTHON_UNUSED_VAR(context); if (unlikely(value == NULL || !PyUnicode_Check(value))) { PyErr_SetString(PyExc_TypeError, "__qualname__ must be set to a string object"); return -1; } Py_INCREF(value); __Pyx_Py_XDECREF_SET(self->gi_qualname, value); return 0; } static PyObject * __Pyx__Coroutine_get_frame(__pyx_CoroutineObject *self) { #if !CYTHON_COMPILING_IN_LIMITED_API PyObject *frame; #if PY_VERSION_HEX >= 0x030d0000 Py_BEGIN_CRITICAL_SECTION(self); #endif frame = self->gi_frame; if (!frame) { if (unlikely(!self->gi_code)) { Py_RETURN_NONE; } PyObject *globals = PyDict_New(); if (unlikely(!globals)) return NULL; frame = (PyObject *) PyFrame_New( PyThreadState_Get(), /*PyThreadState *tstate,*/ (PyCodeObject*) self->gi_code, /*PyCodeObject *code,*/ globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); Py_DECREF(globals); if (unlikely(!frame)) return NULL; if (unlikely(self->gi_frame)) { Py_DECREF(frame); frame = self->gi_frame; } else { self->gi_frame = frame; } } Py_INCREF(frame); #if PY_VERSION_HEX >= 0x030d0000 Py_END_CRITICAL_SECTION(); #endif return frame; #else CYTHON_UNUSED_VAR(self); Py_RETURN_NONE; #endif } static PyObject * __Pyx_Coroutine_get_frame(__pyx_CoroutineObject *self, void *context) { CYTHON_UNUSED_VAR(context); PyObject *frame = self->gi_frame; if (frame) return __Pyx_NewRef(frame); return __Pyx__Coroutine_get_frame(self); } static __pyx_CoroutineObject *__Pyx__Coroutine_New( PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, PyObject *name, PyObject *qualname, PyObject *module_name) { __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type); if (unlikely(!gen)) return NULL; return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name); } static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, PyObject *name, PyObject *qualname, PyObject *module_name) { gen->body = body; gen->closure = closure; Py_XINCREF(closure); gen->is_running = 0; gen->resume_label = 0; gen->classobj = NULL; gen->yieldfrom = NULL; gen->yieldfrom_am_send = NULL; #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_LIMITED_API gen->gi_exc_state.exc_value = NULL; #else gen->gi_exc_state.exc_type = NULL; gen->gi_exc_state.exc_value = NULL; gen->gi_exc_state.exc_traceback = NULL; #endif #if CYTHON_USE_EXC_INFO_STACK gen->gi_exc_state.previous_item = NULL; #endif gen->gi_weakreflist = NULL; Py_XINCREF(qualname); gen->gi_qualname = qualname; Py_XINCREF(name); gen->gi_name = name; Py_XINCREF(module_name); gen->gi_modulename = module_name; Py_XINCREF(code); gen->gi_code = code; gen->gi_frame = NULL; PyObject_GC_Track(gen); return gen; } static char __Pyx_Coroutine_test_and_set_is_running(__pyx_CoroutineObject *gen) { char result; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_BEGIN_CRITICAL_SECTION(gen); #endif result = gen->is_running; gen->is_running = 1; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_END_CRITICAL_SECTION(); #endif return result; } static void __Pyx_Coroutine_unset_is_running(__pyx_CoroutineObject *gen) { #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_BEGIN_CRITICAL_SECTION(gen); #endif assert(gen->is_running); gen->is_running = 0; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_END_CRITICAL_SECTION(); #endif } static char __Pyx_Coroutine_get_is_running(__pyx_CoroutineObject *gen) { char result; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_BEGIN_CRITICAL_SECTION(gen); #endif result = gen->is_running; #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API Py_END_CRITICAL_SECTION(); #endif return result; } static PyObject *__Pyx_Coroutine_get_is_running_getter(PyObject *gen, void *closure) { CYTHON_UNUSED_VAR(closure); char result = __Pyx_Coroutine_get_is_running((__pyx_CoroutineObject*)gen); if (result) Py_RETURN_TRUE; else Py_RETURN_FALSE; } #if __PYX_HAS_PY_AM_SEND == 2 static void __Pyx_SetBackportTypeAmSend(PyTypeObject *type, __Pyx_PyAsyncMethodsStruct *static_amsend_methods, __Pyx_pyiter_sendfunc am_send) { Py_ssize_t ptr_offset = (char*)(type->tp_as_async) - (char*)type; if (ptr_offset < 0 || ptr_offset > type->tp_basicsize) { return; } memcpy((void*)static_amsend_methods, (void*)(type->tp_as_async), sizeof(*type->tp_as_async)); static_amsend_methods->am_send = am_send; type->tp_as_async = __Pyx_SlotTpAsAsync(static_amsend_methods); } #endif static PyObject *__Pyx_Coroutine_fail_reduce_ex(PyObject *self, PyObject *arg) { CYTHON_UNUSED_VAR(arg); __Pyx_TypeName self_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE((PyObject*)self)); PyErr_Format(PyExc_TypeError, "cannot pickle '" __Pyx_FMT_TYPENAME "' object", self_type_name); __Pyx_DECREF_TypeName(self_type_name); return NULL; } /* Generator */ static PyMethodDef __pyx_Generator_methods[] = { {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")}, {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")}, {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS, PyDoc_STR("close() -> raise GeneratorExit inside generator.")}, {"__reduce_ex__", (PyCFunction) __Pyx_Coroutine_fail_reduce_ex, METH_O, 0}, {"__reduce__", (PyCFunction) __Pyx_Coroutine_fail_reduce_ex, METH_NOARGS, 0}, {0, 0, 0, 0} }; static PyMemberDef __pyx_Generator_memberlist[] = { {"gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY, PyDoc_STR("object being iterated by 'yield from', or None")}, {"gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL}, {"__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), 0, 0}, {"__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CoroutineObject, gi_weakreflist), READONLY, 0}, {0, 0, 0, 0, 0} }; static PyGetSetDef __pyx_Generator_getsets[] = { {"__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name, PyDoc_STR("name of the generator"), 0}, {"__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname, PyDoc_STR("qualified name of the generator"), 0}, {"gi_frame", (getter)__Pyx_Coroutine_get_frame, NULL, PyDoc_STR("Frame of the generator"), 0}, {"gi_running", __Pyx_Coroutine_get_is_running_getter, NULL, NULL, NULL}, {0, 0, 0, 0, 0} }; static PyType_Slot __pyx_GeneratorType_slots[] = { {Py_tp_dealloc, (void *)__Pyx_Coroutine_dealloc}, {Py_tp_traverse, (void *)__Pyx_Coroutine_traverse}, {Py_tp_iter, (void *)PyObject_SelfIter}, {Py_tp_iternext, (void *)__Pyx_Generator_Next}, {Py_tp_methods, (void *)__pyx_Generator_methods}, {Py_tp_members, (void *)__pyx_Generator_memberlist}, {Py_tp_getset, (void *)__pyx_Generator_getsets}, {Py_tp_getattro, (void *) PyObject_GenericGetAttr}, #if CYTHON_USE_TP_FINALIZE {Py_tp_finalize, (void *)__Pyx_Coroutine_del}, #endif #if __PYX_HAS_PY_AM_SEND == 1 {Py_am_send, (void *)__Pyx_Coroutine_AmSend}, #endif {0, 0}, }; static PyType_Spec __pyx_GeneratorType_spec = { __PYX_TYPE_MODULE_PREFIX "generator", sizeof(__pyx_CoroutineObject), 0, #if PY_VERSION_HEX >= 0x030A0000 Py_TPFLAGS_IMMUTABLETYPE | #endif Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE | __Pyx_TPFLAGS_HAVE_AM_SEND, __pyx_GeneratorType_slots }; #if __PYX_HAS_PY_AM_SEND == 2 static __Pyx_PyAsyncMethodsStruct __pyx_Generator_as_async; #endif static int __pyx_Generator_init(PyObject *module) { __pyx_mstatetype *mstate = __Pyx_PyModule_GetState(module); mstate->__pyx_GeneratorType = __Pyx_FetchCommonTypeFromSpec( mstate->__pyx_CommonTypesMetaclassType, module, &__pyx_GeneratorType_spec, NULL); if (unlikely(!mstate->__pyx_GeneratorType)) { return -1; } #if __PYX_HAS_PY_AM_SEND == 2 __Pyx_SetBackportTypeAmSend(mstate->__pyx_GeneratorType, &__pyx_Generator_as_async, &__Pyx_Coroutine_AmSend); #endif return 0; } static PyObject *__Pyx_Generator_GetInlinedResult(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; PyObject *retval = NULL; if (unlikely(__Pyx_Coroutine_test_and_set_is_running(gen))) { return __Pyx_Coroutine_AlreadyRunningError(gen); } __Pyx_PySendResult result = __Pyx_Coroutine_SendEx(gen, Py_None, &retval, 0); __Pyx_Coroutine_unset_is_running(gen); (void) result; assert (result == PYGEN_RETURN || result == PYGEN_ERROR); assert ((result == PYGEN_RETURN && retval != NULL) || (result == PYGEN_ERROR && retval == NULL)); return retval; } /* 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); } } /* 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 /* NewCodeObj */ #if CYTHON_COMPILING_IN_LIMITED_API static PyObject* __Pyx__PyCode_New(int a, int p, int k, int l, int s, int f, PyObject *code, PyObject *c, PyObject* n, PyObject *v, PyObject *fv, PyObject *cell, PyObject* fn, PyObject *name, int fline, PyObject *lnos) { PyObject *exception_table = NULL; PyObject *types_module=NULL, *code_type=NULL, *result=NULL; #if __PYX_LIMITED_VERSION_HEX < 0x030b0000 PyObject *version_info; PyObject *py_minor_version = NULL; #endif long minor_version = 0; PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); #if __PYX_LIMITED_VERSION_HEX >= 0x030b0000 minor_version = 11; #else if (!(version_info = PySys_GetObject("version_info"))) goto end; if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; minor_version = PyLong_AsLong(py_minor_version); Py_DECREF(py_minor_version); if (minor_version == -1 && PyErr_Occurred()) goto end; #endif if (!(types_module = PyImport_ImportModule("types"))) goto end; if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; if (minor_version <= 7) { (void)p; result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOOO", a, k, l, s, f, code, c, n, v, fn, name, fline, lnos, fv, cell); } else if (minor_version <= 10) { result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOOO", a,p, k, l, s, f, code, c, n, v, fn, name, fline, lnos, fv, cell); } else { if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOOOO", a,p, k, l, s, f, code, c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); } end: Py_XDECREF(code_type); Py_XDECREF(exception_table); Py_XDECREF(types_module); if (type) { PyErr_Restore(type, value, traceback); } return result; } #elif PY_VERSION_HEX >= 0x030B0000 static PyCodeObject* __Pyx__PyCode_New(int a, int p, int k, int l, int s, int f, PyObject *code, PyObject *c, PyObject* n, PyObject *v, PyObject *fv, PyObject *cell, PyObject* fn, PyObject *name, int fline, PyObject *lnos) { PyCodeObject *result; result = #if PY_VERSION_HEX >= 0x030C0000 PyUnstable_Code_NewWithPosOnlyArgs #else PyCode_NewWithPosOnlyArgs #endif (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, __pyx_mstate_global->__pyx_empty_bytes); return result; } #elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY #define __Pyx__PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #else #define __Pyx__PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #endif static PyObject* __Pyx_PyCode_New( const __Pyx_PyCode_New_function_description descr, PyObject * const *varnames, PyObject *filename, PyObject *funcname, const char *line_table, PyObject *tuple_dedup_map ) { PyObject *code_obj = NULL, *varnames_tuple_dedup = NULL, *code_bytes = NULL, *line_table_bytes = NULL; Py_ssize_t var_count = (Py_ssize_t) descr.nlocals; PyObject *varnames_tuple = PyTuple_New(var_count); if (unlikely(!varnames_tuple)) return NULL; for (Py_ssize_t i=0; i < var_count; i++) { Py_INCREF(varnames[i]); if (__Pyx_PyTuple_SET_ITEM(varnames_tuple, i, varnames[i]) != (0)) goto done; } #if CYTHON_COMPILING_IN_LIMITED_API varnames_tuple_dedup = PyDict_GetItem(tuple_dedup_map, varnames_tuple); if (!varnames_tuple_dedup) { if (unlikely(PyDict_SetItem(tuple_dedup_map, varnames_tuple, varnames_tuple) < 0)) goto done; varnames_tuple_dedup = varnames_tuple; } #else varnames_tuple_dedup = PyDict_SetDefault(tuple_dedup_map, varnames_tuple, varnames_tuple); if (unlikely(!varnames_tuple_dedup)) goto done; #endif #if CYTHON_AVOID_BORROWED_REFS Py_INCREF(varnames_tuple_dedup); #endif if (__PYX_LIMITED_VERSION_HEX >= (0x030b0000) && line_table != NULL && !CYTHON_COMPILING_IN_GRAAL) { line_table_bytes = PyBytes_FromStringAndSize(line_table, descr.line_table_length); if (unlikely(!line_table_bytes)) goto done; Py_ssize_t code_len = (descr.line_table_length * 2 + 4) & ~3; code_bytes = PyBytes_FromStringAndSize(NULL, code_len); if (unlikely(!code_bytes)) goto done; char* c_code_bytes = PyBytes_AsString(code_bytes); if (unlikely(!c_code_bytes)) goto done; memset(c_code_bytes, 0, (size_t) code_len); } code_obj = (PyObject*) __Pyx__PyCode_New( (int) descr.argcount, (int) descr.num_posonly_args, (int) descr.num_kwonly_args, (int) descr.nlocals, 0, (int) descr.flags, code_bytes ? code_bytes : __pyx_mstate_global->__pyx_empty_bytes, __pyx_mstate_global->__pyx_empty_tuple, __pyx_mstate_global->__pyx_empty_tuple, varnames_tuple_dedup, __pyx_mstate_global->__pyx_empty_tuple, __pyx_mstate_global->__pyx_empty_tuple, filename, funcname, (int) descr.first_line, (__PYX_LIMITED_VERSION_HEX >= (0x030b0000) && line_table_bytes) ? line_table_bytes : __pyx_mstate_global->__pyx_empty_bytes ); done: Py_XDECREF(code_bytes); Py_XDECREF(line_table_bytes); #if CYTHON_AVOID_BORROWED_REFS Py_XDECREF(varnames_tuple_dedup); #endif Py_DECREF(varnames_tuple); return code_obj; } /* 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 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 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 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 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 // 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 (; readmodule) { write->id = read->id; write->module = read->module; ++write; } } data->count = write - data->table; for (; writeid = 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; icount; ++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_boundid = (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 */ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316780.0 pyreadstat-1.3.3/pyreadstat/pyreadstat.pxd0000644000076500000240000000145714646232654017336 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769172854.0 pyreadstat-1.3.3/pyreadstat/pyreadstat.pyx0000644000076500000240000013757515134667566017405 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# ## if want to profile: # cython: profile=True import multiprocessing as mp import narwhals.stable.v2 as nw import numpy as np from _readstat_parser cimport py_file_format, py_file_extension, run_conversion from _readstat_parser import PyreadstatError from _readstat_writer cimport run_write cimport _readstat_parser, _readstat_writer from worker import worker from pyfunctions import set_value_labels, set_catalog_to_sas # Public interface # Parsing functions def read_sas7bdat(filename_path, metadataonly=False, dates_as_pandas_datetime=False, catalog_file=None, formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): r""" Read a SAS sas7bdat file. It accepts the path to a sas7bcat. Parameters ---------- filename_path : str, bytes, Path-like object or file-like object path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded. metadataonly : bool, optional by default False. IF true, no data will be read but only metadata, so that you can get all elements in the metadata object. The data frame will be set with the correct column names but no data. dates_as_pandas_datetime : bool, optional by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas. catalog_file : str, optional path to a sas7bcat file. By default is None. If not None, will parse the catalog file and replace the values by the formats in the catalog, if any appropiate is found. If this is not the behavior you are looking for, Use read_sas7bcat to parse the catalog independently of the sas7bdat and set_catalog_to_sas to apply the resulting format into sas7bdat files. formats_as_category : bool, optional Will take effect only if the catalog_file was specified. If True the variables whose values were replaced by the formats will be transformed into categories. formats_as_ordered_category : bool, optional defaults to False. If True the variables having formats will be transformed into ordered categories/enums. it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of the value of formats_as_category. encoding : str, optional Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an iconv-compatible name usecols : list, optional a list with column names to read from the file. Only those columns will be imported. Case sensitive! user_missing : bool, optional by default False, in this case user defined missing values are delivered as nan. If true, the missing values will be deliver as is, and an extra piece of information will be set in the metadata (missing_user_values) to be able to interpret those values as missing. disable_datetime_conversion : bool, optional if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns will remain as numbers. In order to convert them later to an appropiate python object, the user can use the information about the original variable format stored in the metadata object in original_variable_types. Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates beyond that will rise an Overflow error in pyreadstat). row_limit : int, optional maximum number of rows to read. The default is 0 meaning unlimited. row_offset : int, optional start reading rows after this offset. By default 0, meaning start with the first row not skipping anything. output_format : str, optional one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a dataframe is avoided. extra_datetime_formats: list of str, optional formats to be parsed as python datetime objects extra_date_formats: list of str, optional formats to be parsed as python date objects extra_time_formats: list of str, optional formats to be parsed as python time objects Returns ------- data_frame : dataframe or dict a dataframe or dict with the data. metadata object with metadata. The members variables_value_labels will be empty unless a valid catalog file is supplied. Look at the documentation for more information. """ cdef bint metaonly = 0 if metadataonly: metaonly = 1 cdef bint dates_as_pandas = 0 if dates_as_pandas_datetime: dates_as_pandas = 1 cdef bint usernan = 0 if user_missing: usernan = 1 cdef bint no_datetime_conversion = 0 if disable_datetime_conversion: no_datetime_conversion = 1 cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BDAT data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) metadata.file_format = "sas7bdat" if catalog_file: _ , catalog = read_sas7bcat(catalog_file, encoding=encoding) data_frame, metadata = set_catalog_to_sas(data_frame, metadata, catalog, formats_as_category=formats_as_category, formats_as_ordered_category=formats_as_ordered_category) return data_frame, metadata def read_xport(filename_path, metadataonly=False, dates_as_pandas_datetime=False, str encoding=None, list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): r""" Read a SAS xport file. Parameters ---------- filename_path : str, bytes, Path-like object or file-like object path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded. metadataonly : bool, optional by default False. IF true, no data will be read but only metadata, so that you can get all elements in the metadata object. The data frame will be set with the correct column names but no data. dates_as_pandas_datetime : bool, optional by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas. encoding : str, optional Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an iconv-compatible name usecols : list, optional a list with column names to read from the file. Only those columns will be imported. Case sensitive! disable_datetime_conversion : bool, optional if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns will remain as numbers. In order to convert them later to an appropiate python object, the user can use the information about the original variable format stored in the metadata object in original_variable_types. Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates beyond that will rise an Overflow error in pyreadstat). row_limit : int, optional maximum number of rows to read. The default is 0 meaning unlimited. row_offset : int, optional start reading rows after this offset. By default 0, meaning start with the first row not skipping anything. output_format : str, optional one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a dataframe is avoided. extra_datetime_formats: list of str, optional formats to be parsed as python datetime objects extra_date_formats: list of str, optional formats to be parsed as python date objects extra_time_formats: list of str, optional formats to be parsed as python time objects Returns ------- data_frame : dataframe or dict a dataframe or dict with the data. metadata : object with metadata. Look at the documentation for more information. """ cdef bint metaonly = 0 if metadataonly: metaonly = 1 cdef bint dates_as_pandas = 0 if dates_as_pandas_datetime: dates_as_pandas = 1 cdef bint usernan = 0 cdef bint no_datetime_conversion = 0 if disable_datetime_conversion: no_datetime_conversion = 1 cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_XPORT data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) metadata.file_format = "xport" return data_frame, metadata def read_dta(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): r""" Read a STATA dta file Parameters ---------- filename_path : str, bytes, Path-like object or file-like object path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded. metadataonly : bool, optional by default False. IF true, no data will be read but only metadata, so that you can get all elements in the metadata object. The data frame will be set with the correct column names but no data. dates_as_pandas_datetime : bool, optional by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas. apply_value_formats : bool, optional by default False. If true it will change values in the dataframe for they value labels in the metadata, if any appropiate are found. formats_as_category : bool, optional by default True. Takes effect only if apply_value_formats is True. If True, variables with values changed for their formatted version will be transformed into categories. formats_as_ordered_category : bool, optional defaults to False. If True the variables having formats will be transformed into ordered categories/enum. it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of the value of formats_as_category. encoding : str, optional Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an iconv-compatible name usecols : list, optional a list with column names to read from the file. Only those columns will be imported. Case sensitive! user_missing : bool, optional by default False, in this case user defined missing values are delivered as nan. If true, the missing values will be deliver as is, and an extra piece of information will be set in the metadata (missing_user_values) to be able to interpret those values as missing. disable_datetime_conversion : bool, optional if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns will remain as numbers. In order to convert them later to an appropiate python object, the user can use the information about the original variable format stored in the metadata object in original_variable_types. Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates beyond that will rise an Overflow error in pyreadstat). row_limit : int, optional maximum number of rows to read. The default is 0 meaning unlimited. row_offset : int, optional start reading rows after this offset. By default 0, meaning start with the first row not skipping anything. output_format : str, optional one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a dataframe is avoided. extra_datetime_formats: list of str, optional formats to be parsed as python datetime objects extra_date_formats: list of str, optional formats to be parsed as python date objects extra_time_formats: list of str, optional formats to be parsed as python time objects Returns ------- data_frame : dataframe or dict a dataframe or dict with the data. metadata : object with metadata. Look at the documentation for more information. """ cdef bint metaonly = 0 if metadataonly: metaonly = 1 cdef bint dates_as_pandas = 0 if dates_as_pandas_datetime: dates_as_pandas = 1 cdef bint usernan = 0 if user_missing: usernan = 1 cdef bint no_datetime_conversion = 0 if disable_datetime_conversion: no_datetime_conversion = 1 cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_STATA cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_DTA data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) metadata.file_format = "dta" if apply_value_formats: data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, formats_as_ordered_category=formats_as_ordered_category) return data_frame, metadata def read_sav(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, formats_as_category=True, formats_as_ordered_category=False, str encoding=None, list usecols=None, user_missing=False, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): r""" Read a SPSS sav or zsav (compressed) files Parameters ---------- filename_path : str, bytes, Path-like object or file-like object path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded. metadataonly : bool, optional by default False. IF true, no data will be read but only metadata, so that you can get all elements in the metadata object. The data frame will be set with the correct column names but no data. dates_as_pandas_datetime : bool, optional by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas. apply_value_formats : bool, optional by default False. If true it will change values in the dataframe for they value labels in the metadata, if any appropiate are found. formats_as_category : bool, optional by default True. Takes effect only if apply_value_formats is True. If True, variables with values changed for their formatted version will be transformed into categories. formats_as_ordered_category : bool, optional defaults to False. If True the variables having formats will be transformed into ordered categories/enum. it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of the value of formats_as_category. encoding : str, optional Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an iconv-compatible name usecols : list, optional a list with column names to read from the file. Only those columns will be imported. Case sensitive! user_missing : bool, optional by default False, in this case user defined missing values are delivered as nan. If true, the missing values will be deliver as is, and an extra piece of information will be set in the metadata (missing_ranges) to be able to interpret those values as missing. disable_datetime_conversion : bool, optional if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns will remain as numbers. In order to convert them later to an appropiate python object, the user can use the information about the original variable format stored in the metadata object in original_variable_types. Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates beyond that will rise an Overflow error in pyreadstat). row_limit : int, optional maximum number of rows to read. The default is 0 meaning unlimited. row_offset : int, optional start reading rows after this offset. By default 0, meaning start with the first row not skipping anything. output_format : str, optional one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a dataframe is avoided. extra_datetime_formats: list of str, optional formats to be parsed as python datetime objects extra_date_formats: list of str, optional formats to be parsed as python date objects extra_time_formats: list of str, optional formats to be parsed as python time objects Returns ------- data_frame : dataframe or dict a dataframe or dict with the data. metadata : object with metadata. Look at the documentation for more information. """ cdef bint metaonly = 0 if metadataonly: metaonly = 1 cdef bint dates_as_pandas = 0 if dates_as_pandas_datetime: dates_as_pandas = 1 cdef bint usernan = 0 if user_missing: usernan = 1 cdef bint no_datetime_conversion = 0 if disable_datetime_conversion: no_datetime_conversion = 1 cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAV data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) metadata.file_format = "sav/zsav" if apply_value_formats: data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category, formats_as_ordered_category=formats_as_ordered_category) return data_frame, metadata def read_por(filename_path, metadataonly=False, dates_as_pandas_datetime=False, apply_value_formats=False, formats_as_category=True, formats_as_ordered_category=False, list usecols=None, disable_datetime_conversion=False, int row_limit=0, int row_offset=0, str output_format=None, list extra_datetime_formats=None, list extra_date_formats=None, list extra_time_formats=None): r""" Read a SPSS por file. Files are assumed to be UTF-8 encoded, the encoding cannot be set to other. Parameters ---------- filename_path : str, bytes, Path-like object or file-like object path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded. metadataonly : bool, optional by default False. IF true, no data will be read but only metadata, so that you can get all elements in the metadata object. The data frame will be set with the correct column names but no data. Notice that number_rows will be None as por files do not have the number of rows recorded in the file metadata. dates_as_pandas_datetime : bool, optional by default False. If true dates will be transformed to pandas datetime64 instead of date, effective only for pandas. apply_value_formats : bool, optional by default False. If true it will change values in the dataframe for they value labels in the metadata, if any appropiate are found. formats_as_category : bool, optional by default True. Takes effect only if apply_value_formats is True. If True, variables with values changed for their formatted version will be transformed into categories. formats_as_ordered_category : bool, optional defaults to False. If True the variables having formats will be transformed into ordered categories/enum. it has precedence over formats_as_category, meaning if this is True, it will take effect irrespective of the value of formats_as_category. usecols : list, optional a list with column names to read from the file. Only those columns will be imported. Case sensitive! disable_datetime_conversion : bool, optional if True pyreadstat will not attempt to convert dates, datetimes and times to python objects but those columns will remain as numbers. In order to convert them later to an appropiate python object, the user can use the information about the original variable format stored in the metadata object in original_variable_types. Disabling datetime conversion speeds up reading files. In addition it helps to overcome situations where there are datetimes that are beyond the limits of python datetime (which is limited to year 10,000, dates beyond that will rise an Overflow error in pyreadstat). row_limit : int, optional maximum number of rows to read. The default is 0 meaning unlimited. row_offset : int, optional start reading rows after this offset. By default 0, meaning start with the first row not skipping anything. output_format : str, optional one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned, the user can then convert it to her preferred data format. Using dict is faster as the other types as the conversion to a dataframe is avoided. extra_datetime_formats: list of str, optional formats to be parsed as python datetime objects extra_date_formats: list of str, optional formats to be parsed as python date objects extra_time_formats: list of str, optional formats to be parsed as python time objects Returns ------- data_frame : dataframe or dict a dataframe or dict with the data. metadata : object with metadata. Look at the documentation for more information. """ cdef bint metaonly = 0 if metadataonly: metaonly = 1 cdef bint dates_as_pandas = 0 if dates_as_pandas_datetime: dates_as_pandas = 1 cdef bint usernan = 0 cdef bint no_datetime_conversion = 0 if disable_datetime_conversion: no_datetime_conversion = 1 cdef str encoding = None cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SPSS cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_POR data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) metadata.file_format = "por" if apply_value_formats: data_frame = set_value_labels(data_frame, metadata, formats_as_category=formats_as_category) return data_frame, metadata def read_sas7bcat(filename_path, str encoding=None, str output_format=None): r""" Read a SAS sas7bcat file. The returning dataframe will be empty. The metadata object will contain a dictionary value_labels that contains the formats. When parsing the sas7bdat file, in the metadata, the dictionary variable_to_label contains a map from variable name to the formats. In order to apply the catalog to the sas7bdat file use set_catalog_to_sas or pass the catalog file as an argument to read_sas7bdat directly. SAS catalog files are difficult ones, some of them can be read only in specific SAS version, may contain strange encodings etc. Therefore it may be that many catalog files are not readable from this application. Parameters ---------- filename_path : str, bytes, Path-like object or file-like object path to the file or file-like object. In python 2.7 the string is assumed to be utf-8 encoded. encoding : str, optional Defaults to None. If set, the system will use the defined encoding instead of guessing it. It has to be an iconv-compatible name output_format : str, optional one of 'pandas' (default), 'polars' or 'dict'. If 'dict' a dictionary with numpy arrays as values will be returned. Notice that for this function the resulting object is always empty, this is done for consistency with other functions but has no impact on performance. Returns ------- data_frame : dataframe or dict a dataframe with the data (no data in this case, so will be always empty). metadata : object with metadata. The member value_labels is the one that contains the formats. Look at the documentation for more information. """ cdef bint metaonly = 1 cdef bint dates_as_pandas = 0 cdef list usecols = None cdef bint usernan = 0 cdef bint no_datetime_conversion = 0 cdef long row_limit=0 cdef long row_offset=0 cdef list extra_datetime_formats=None cdef list extra_date_formats=None cdef list extra_time_formats=None cdef py_file_format file_format = _readstat_parser.FILE_FORMAT_SAS cdef py_file_extension file_extension = _readstat_parser.FILE_EXT_SAS7BCAT data_frame, metadata = run_conversion(filename_path, file_format, file_extension, encoding, metaonly, dates_as_pandas, usecols, usernan, no_datetime_conversion, row_limit, row_offset, output_format, extra_datetime_formats, extra_date_formats, extra_time_formats) metadata.file_format = "sas7bcat" return data_frame, metadata # convenience functions to read in chunks def read_file_in_chunks(read_function, file_path, chunksize=100000, offset=0, limit=0, multiprocess=False, num_processes=4, num_rows=None, **kwargs): """ Returns a generator that will allow to read a file in chunks. If using multiprocessing, for Xport, Por and some defective sav files where the number of rows in the dataset canot be obtained from the metadata, the parameter num_rows must be set to a number equal or larger than the number of rows in the dataset. That information must be obtained by the user before running this function. Parameters ---------- read_function : pyreadstat function a pyreadstat reading function file_path : string path to the file to be read chunksize : integer, optional size of the chunks to read offset : integer, optional start reading the file after certain number of rows limit : integer, optional stop reading the file after certain number of rows, will be added to offset multiprocess: bool, optional use multiprocessing to read each chunk? num_processes: integer, optional in case multiprocess is true, how many workers/processes to spawn? num_rows: integer, optional number of rows in the dataset. If using multiprocessing it is obligatory for files where the number of rows cannot be obtained from the medatata, such as por and some defective xport and sav files. The user must obtain this value by reading the file without multiprocessing first or any other means. A number larger than the actual number of rows will work as well. Discarded if the number of rows can be obtained from the metadata or not using multiprocessing. kwargs : dict, optional any other keyword argument to pass to the read_function. row_limit and row_offset will be discarded if present. Yields ------- data_frame : dataframe a dataframe with the data metadata : object with metadata. Look at the documentation for more information. it : generator A generator that reads the file in chunks. """ if read_function == read_sas7bcat: raise Exception("read_sas7bcat not supported") if "row_offset" in kwargs: _ = kwargs.pop("row_offset") if "row_limit" in kwargs: _ = kwargs.pop("row_limit") if "num_processes" in kwargs: _ = kwargs.pop("num_processes") _, meta = read_function(file_path, metadataonly=True) numrows = meta.number_rows if numrows: if not limit: limit = numrows else: limit = min(offset+limit, numrows) else: if limit: limit = offset + limit df = [0] while len(df): if limit and (offset >= limit): break if multiprocess: df, meta = read_file_multiprocessing(read_function, file_path, num_processes=num_processes, row_offset=offset, row_limit=chunksize, num_rows=num_rows, **kwargs) else: df, meta = read_function(file_path, row_offset=offset, row_limit=chunksize, **kwargs) if len(df): yield df, meta offset += chunksize def read_file_multiprocessing(read_function, file_path, num_processes=None, num_rows=None, **kwargs): """ Reads a file in parallel using multiprocessing. For Xport, Por and some defective sav files where the number of rows in the dataset canot be obtained from the metadata, the parameter num_rows must be set to a number equal or larger than the number of rows in the dataset. That information must be obtained by the user before running this function. Parameters ---------- read_function : pyreadstat function a pyreadstat reading function file_path : string path to the file to be read num_processes : integer, optional number of processes to spawn, by default the min 4 and the max cores on the computer num_rows: integer, optional number of rows in the dataset. Obligatory for files where the number of rows cannot be obtained from the medatata, such as por and some defective xport and sav files. The user must obtain this value by reading the file without multiprocessing first or any other means. A number larger than the actual number of rows will work as well. Discarded if the number of rows can be obtained from the metadata. kwargs : dict, optional any other keyword argument to pass to the read_function. Returns ------- data_frame : dataframe a dataframe with the data metadata : object with metadata. Look at the documentation for more information. """ if read_function in (read_sas7bcat,): raise Exception("read_sas7bcat is not supported") if read_function == read_por and num_rows is None: raise Exception("num_rows must be specified for read_por to be a number equal or larger than the number of rows in the dataset.") if not num_processes: # let's be conservative with the number of workers num_processes = min(mp.cpu_count(), 4) _ = kwargs.pop('metadataonly', None) row_offset = kwargs.pop("row_offset", 0) row_limit = kwargs.pop("row_limit", float('inf')) _, meta = read_function(file_path, metadataonly=True, **kwargs) numrows = meta.number_rows if numrows is None: if num_rows is None: raise Exception("The number of rows of the file cannot be determined from the file's metadata. If you still want to proceed, please set num_rows to a number equal or larger than the number of rows of your data") numrows = num_rows elif numrows == 0: final, meta = read_function(file_path, **kwargs) numrows = min(max(numrows - row_offset, 0), row_limit) divs = [numrows // num_processes + (1 if x < numrows % num_processes else 0) for x in range (num_processes)] offsets = list() prev_offset = row_offset prev_div = 0 for indx, div in enumerate(divs): offset = prev_offset + prev_div prev_offset = offset prev_div = div offsets.append((offset, div)) jobs = [(read_function, file_path, offset, chunksize, kwargs) for offset, chunksize in offsets] pool = mp.Pool(processes=num_processes) try: chunks = pool.map(worker, jobs) except: raise finally: pool.close() output_format = kwargs.get("output_format") if output_format == 'dict': keys = chunks[0].keys() final = dict() for key in keys: final[key] = np.concatenate([chunk[key] for chunk in chunks]) else: #final = pd.concat(chunks, axis=0, ignore_index=True) chunks = [nw.from_native(x) for x in chunks] final = nw.concat(chunks, how='vertical') ispandas = False if final.implementation.is_pandas(): ispandas = True final = final.to_native() if ispandas: final = final.reset_index(drop=True) return final, meta # Write API def write_sav(df, dst_path, str file_label="", object column_labels=None, compress=False, row_compress=False, object note=None, dict variable_value_labels=None, dict missing_ranges=None, dict variable_display_width=None, dict variable_measure=None, dict variable_format=None): """ Writes a dataframe to a SPSS sav or zsav file. Parameters ---------- df : dataframe dataframe to write to sav or zsav dst_path : str or pathlib.Path full path to the result sav or zsav file file_label : str, optional a label for the file column_labels : list or dict, optional labels for columns (variables), if list must be the same length as the number of columns. Variables with no labels must be represented by None. If dict values must be variable names and values variable labels. In such case there is no need to include all variables; labels for non existent variables will be ignored with no warning or error. compress : boolean, optional if true a zsav will be written, by default False, a sav is written row_compress : boolean, optional if true it applies row compression, by default False, compress and row_compress cannot be both true at the same time note : str or list of str, optional a note or list of notes to add to the file variable_value_labels : dict, optional value labels, a dictionary with key variable name and value a dictionary with key values and values labels. Variable names must match variable names in the dataframe otherwise will be ignored. Value types must match the type of the column in the dataframe. missing_ranges : dict, optional user defined missing values. Must be a dictionary with keys as variable names matching variable names in the dataframe. The values must be a list. Each element in that list can either be either a discrete numeric or string value (max 3 per variable) or a dictionary with keys 'hi' and 'lo' to indicate the upper and lower range for numeric values (max 1 range value + 1 discrete value per variable). hi and lo may also be the same value in which case it will be interpreted as a discrete missing value. For this to be effective, values in the dataframe must be the same as reported here and not NaN. variable_display_width : dict, optional set the display width for variables. Must be a dictonary with keys being variable names and values being integers. variable_measure: dict, optional sets the measure type for a variable. Must be a dictionary with keys being variable names and values being strings one of "nominal", "ordinal", "scale" or "unknown" (default). variable_format: dict, optional sets the format of a variable. Must be a dictionary with keys being the variable names and values being strings defining the format. See README, setting variable formats section, for more information. """ cdef int file_format_version = 2 cdef str var_width cdef bint row_compression = 0 if compress and row_compress: raise PyreadstatError("compress and row_compress cannot be both True") if compress: file_format_version = 3 if row_compress: row_compression = 1 cdef table_name = "" cdef dict missing_user_values = None cdef dict variable_alignment = None # formats formats_presets = {'restricted_integer':'N{var_width}', 'integer':'F{var_width}.0'} if variable_format: for col_name, col_format in variable_format.items(): if col_format in formats_presets.keys() and col_name in df.columns: var_width = str(len(str(max(df[col_name])))) variable_format[col_name] = formats_presets[col_format].format(var_width=var_width) run_write(df, dst_path, _readstat_writer.FILE_FORMAT_SAV, file_label, column_labels, file_format_version, note, table_name, variable_value_labels, missing_ranges, missing_user_values, variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) def write_dta(df, dst_path, str file_label="", object column_labels=None, int version=15, dict variable_value_labels=None, dict missing_user_values=None, dict variable_format=None): """ Writes a dataframe to a STATA dta file Parameters ---------- df : dataframe dataframe to write to sav or zsav dst_path : str or pathlib.Path full path to the result dta file file_label : str, optional a label for the file column_labels : list or dict, optional labels for columns (variables), if list must be the same length as the number of columns. Variables with no labels must be represented by None. If dict values must be variable names and values variable labels. In such case there is no need to include all variables; labels for non existent variables will be ignored with no warning or error. version : int, optional dta file version, supported from 8 to 15, default is 15 variable_value_labels : dict, optional value labels, a dictionary with key variable name and value a dictionary with key values and values labels. Variable names must match variable names in the dataframe otherwise will be ignored. Value types must match the type of the column in the dataframe. missing_user_values : dict, optional user defined missing values for numeric variables. Must be a dictionary with keys being variable names and values being a list of missing values. Missing values must be a single character between a and z. variable_format: dict, optional sets the format of a variable. Must be a dictionary with keys being the variable names and values being strings defining the format. See README, setting variable formats section, for more information. """ if version == 15: file_format_version = 119 elif version == 14: file_format_version = 118 elif version == 13: file_format_version = 117 elif version == 12: file_format_version = 115 elif version in {10, 11}: file_format_version = 114 elif version in {8, 9}: file_format_version = 113 else: raise Exception("Version not supported") cdef str note = "" cdef str table_name = "" cdef dict missing_ranges = None cdef dict variable_alignment = None cdef dict variable_display_width = None cdef dict variable_measure = None #cdef dict variable_format = None cdef bint row_compression = 0 run_write(df, dst_path, _readstat_writer.FILE_FORMAT_DTA, file_label, column_labels, file_format_version, note, table_name, variable_value_labels, missing_ranges, missing_user_values, variable_alignment, variable_display_width, variable_measure, variable_format, row_compression) def write_xport(df, dst_path, str file_label="", object column_labels=None, str table_name=None, int file_format_version = 8, dict variable_format=None): """ Writes a dataframe to a SAS Xport (xpt) file. If no table_name is specified the dataset has by default the name DATASET (take it into account if reading the file from SAS.) Versions 5 and 8 are supported, default is 8. Parameters ---------- df : dataframe dataframe to write to xport dst_path : str or pathlib.Path full path to the result xport file file_label : str, optional a label for the file column_labels : list or dict, optional labels for columns (variables), if list must be the same length as the number of columns. Variables with no labels must be represented by None. If dict values must be variable names and values variable labels. In such case there is no need to include all variables; labels for non existent variables will be ignored with no warning or error. table_name : str, optional name of the dataset, by default DATASET file_format_version : int, optional XPORT file version, either 8 or 5, default is 8 variable_format: dict, optional sets the format of a variable. Must be a dictionary with keys being the variable names and values being strings defining the format. See README, setting variable formats section, for more information. """ cdef dict variable_value_labels = None cdef str note = "" cdef dict missing_ranges = None cdef dict missing_user_values = None cdef dict variable_alignment = None cdef dict variable_display_width = None cdef dict variable_measure = None #cdef dict variable_format = None cdef bint row_compression = 0 run_write(df, dst_path, _readstat_writer.FILE_FORMAT_XPORT, file_label, column_labels, file_format_version, note, table_name, variable_value_labels, missing_ranges,missing_user_values, variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) def write_por(df, dst_path, str file_label="", object column_labels=None, dict variable_format=None): """ Writes a dataframe to a SPSS POR file. Parameters ---------- df : dataframe data frame to write to por dst_path : str or pathlib.Path full path to the result por file file_label : str, optional a label for the file column_labels : list or dict, optional labels for columns (variables), if list must be the same length as the number of columns. Variables with no labels must be represented by None. If dict values must be variable names and values variable labels. In such case there is no need to include all variables; labels for non existent variables will be ignored with no warning or error. variable_format: dict, optional sets the format of a variable. Must be a dictionary with keys being the variable names and values being strings defining the format. See README, setting variable formats section, for more information. """ # atm version 5 and 8 are supported by readstat but only 5 can be later be read by SAS cdef str note=None cdef int file_format_version = 0 cdef dict variable_value_labels=None cdef dict missing_ranges = None cdef dict missing_user_values = None cdef dict variable_alignment = None cdef dict variable_display_width = None cdef dict variable_measure = None cdef str table_name = "" #cdef dict variable_format = None cdef bint row_compression = 0 run_write(df, dst_path, _readstat_writer.FILE_FORMAT_POR, file_label, column_labels, file_format_version, note, table_name, variable_value_labels, missing_ranges,missing_user_values, variable_alignment,variable_display_width, variable_measure, variable_format, row_compression) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769156913.0 pyreadstat-1.3.3/pyreadstat/readstat_api.pxd0000644000076500000240000003725715134630461017614 0ustar00dialout# cython: c_string_type=unicode, c_string_encoding=utf8, language_level=2 # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# """ These are C definitions coming from the readstat API (readstat.h) plus some dependecies of that to the C standard library """ cdef extern from "": ctypedef long off_t cdef extern from "" nogil: # 7.18.1 Integer types # 7.18.1.1 Exact-width integer types ctypedef signed char int8_t ctypedef signed short int16_t ctypedef signed int int32_t ctypedef signed long int64_t ctypedef unsigned char uint8_t #cdef extern from "conditional_includes.h": # int close(int fd) # ssize_t write(int fd, const void *buf, size_t nbyte) cdef extern from "readstat.h": ctypedef enum: READSTAT_HANDLER_OK, READSTAT_HANDLER_ABORT, READSTAT_HANDLER_SKIP_VARIABLE ctypedef struct readstat_variable_t: int index ctypedef struct readstat_label_set_t: pass ctypedef struct readstat_metadata_t: pass ctypedef struct mr_set_t: char type char *name char *label int is_dichotomy int counted_value char **subvariables int num_subvars ctypedef enum readstat_io_flags_t: READSTAT_SEEK_SET, READSTAT_SEEK_CUR, READSTAT_SEEK_END ctypedef enum readstat_error_t: READSTAT_OK, READSTAT_ERROR_OPEN = 1, READSTAT_ERROR_READ, READSTAT_ERROR_MALLOC, READSTAT_ERROR_USER_ABORT, READSTAT_ERROR_PARSE, READSTAT_ERROR_UNSUPPORTED_COMPRESSION, READSTAT_ERROR_UNSUPPORTED_CHARSET, READSTAT_ERROR_COLUMN_COUNT_MISMATCH, READSTAT_ERROR_ROW_COUNT_MISMATCH, READSTAT_ERROR_ROW_WIDTH_MISMATCH, READSTAT_ERROR_BAD_FORMAT_STRING, READSTAT_ERROR_VALUE_TYPE_MISMATCH, READSTAT_ERROR_WRITE, READSTAT_ERROR_WRITER_NOT_INITIALIZED, READSTAT_ERROR_SEEK, READSTAT_ERROR_CONVERT, READSTAT_ERROR_CONVERT_BAD_STRING, READSTAT_ERROR_CONVERT_SHORT_STRING, READSTAT_ERROR_CONVERT_LONG_STRING, READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE, READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE, READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG, READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED, READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION, READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER, READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER, READSTAT_ERROR_NAME_IS_RESERVED_WORD, READSTAT_ERROR_NAME_IS_TOO_LONG, READSTAT_ERROR_BAD_TIMESTAMP, READSTAT_ERROR_BAD_FREQUENCY_WEIGHT, READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS, READSTAT_ERROR_NOTE_IS_TOO_LONG, READSTAT_ERROR_STRING_REFS_NOT_SUPPORTED, READSTAT_ERROR_STRING_REF_IS_REQUIRED, READSTAT_ERROR_ROW_IS_TOO_WIDE_FOR_PAGE ctypedef enum readstat_type_t: READSTAT_TYPE_STRING, READSTAT_TYPE_INT8, READSTAT_TYPE_INT16, READSTAT_TYPE_INT32, READSTAT_TYPE_FLOAT, READSTAT_TYPE_DOUBLE, READSTAT_TYPE_STRING_REF ctypedef struct readstat_value_t: pass ctypedef struct readstat_parser_t: pass ctypedef enum readstat_measure_t: READSTAT_MEASURE_UNKNOWN, READSTAT_MEASURE_NOMINAL = 1, READSTAT_MEASURE_ORDINAL, READSTAT_MEASURE_SCALE ctypedef enum readstat_alignment_t: READSTAT_ALIGNMENT_UNKNOWN, READSTAT_ALIGNMENT_LEFT = 1, READSTAT_ALIGNMENT_CENTER, READSTAT_ALIGNMENT_RIGHT ctypedef enum readstat_compress_t: READSTAT_COMPRESS_NONE, READSTAT_COMPRESS_ROWS, READSTAT_COMPRESS_BINARY ctypedef off_t readstat_off_t cdef readstat_parser_t *readstat_parser_init() cdef void readstat_parser_free(readstat_parser_t *parser) ctypedef int (*readstat_open_handler)(const char *path, void *io_ctx); ctypedef int (*readstat_close_handler)(void *io_ctx); ctypedef readstat_off_t (*readstat_seek_handler)(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx); ctypedef ssize_t (*readstat_read_handler)(void *buf, size_t nbyte, void *io_ctx); ctypedef int (*readstat_metadata_handler)(readstat_metadata_t *metadata, void *ctx); ctypedef int (*readstat_variable_handler)(int index, readstat_variable_t *variable, char *val_labels, void *ctx); ctypedef int (*readstat_value_handler)(int obs_index, readstat_variable_t *variable, readstat_value_t value, void *ctx); ctypedef int (*readstat_value_label_handler)(const char *val_labels, readstat_value_t value, const char *label, void *ctx); ctypedef int (*readstat_note_handler)(int note_index, const char *note, void *ctx); cdef readstat_error_t readstat_set_open_handler(readstat_parser_t *parser, readstat_open_handler open_handler); cdef readstat_error_t readstat_set_close_handler(readstat_parser_t *parser, readstat_close_handler close_handler); cdef readstat_error_t readstat_set_seek_handler(readstat_parser_t *parser, readstat_seek_handler seek_handler); cdef readstat_error_t readstat_set_read_handler(readstat_parser_t *parser, readstat_read_handler read_handler); cdef readstat_error_t readstat_set_io_ctx(readstat_parser_t *parser, void *io_ctx); cdef readstat_error_t readstat_set_metadata_handler(readstat_parser_t *parser, readstat_metadata_handler metadata_handler); cdef readstat_error_t readstat_set_note_handler(readstat_parser_t *parser, readstat_note_handler note_handler); cdef readstat_error_t readstat_set_variable_handler(readstat_parser_t *parser, readstat_variable_handler variable_handler) cdef readstat_error_t readstat_set_value_handler(readstat_parser_t *parser, readstat_value_handler value_handler); cdef readstat_error_t readstat_set_value_label_handler(readstat_parser_t *parser, readstat_value_label_handler value_label_handler); cdef readstat_error_t readstat_set_file_character_encoding(readstat_parser_t *parser, const char *encoding); cdef int readstat_get_row_count(readstat_metadata_t *metadata); cdef int readstat_get_var_count(readstat_metadata_t *metadata); cdef char *readstat_get_file_label(readstat_metadata_t *metadata); cdef size_t readstat_get_multiple_response_sets_length(readstat_metadata_t *metadata); cdef mr_set_t *readstat_get_multiple_response_sets(readstat_metadata_t *metadata); cdef char *readstat_get_file_encoding(readstat_metadata_t *metadata); cdef char *readstat_get_table_name(readstat_metadata_t *metadata); cdef int readstat_get_creation_time(readstat_metadata_t *metadata); cdef int readstat_get_modified_time(readstat_metadata_t *metadata); cdef int readstat_variable_get_index_after_skipping(readstat_variable_t *variable) cdef char *readstat_variable_get_name(readstat_variable_t *variable) cdef char *readstat_variable_get_label(readstat_variable_t *variable) cdef char *readstat_variable_get_format(readstat_variable_t *variable) cdef readstat_type_t readstat_variable_get_type(const readstat_variable_t *variable); cdef readstat_measure_t readstat_variable_get_measure(const readstat_variable_t *variable); cdef readstat_alignment_t readstat_variable_get_alignment(const readstat_variable_t *variable) cdef int readstat_variable_get_display_width(const readstat_variable_t *variable); cdef size_t readstat_variable_get_storage_width(const readstat_variable_t *variable) cdef int readstat_value_is_missing(readstat_value_t value, readstat_variable_t *variable); cdef int readstat_value_is_system_missing(readstat_value_t value); cdef int readstat_value_is_tagged_missing(readstat_value_t value); cdef int readstat_value_is_defined_missing(readstat_value_t value, readstat_variable_t *variable); cdef char readstat_value_tag(readstat_value_t value); cdef int readstat_variable_get_missing_ranges_count(const readstat_variable_t *variable); cdef readstat_value_t readstat_variable_get_missing_range_lo(const readstat_variable_t *variable, int i); cdef readstat_value_t readstat_variable_get_missing_range_hi(const readstat_variable_t *variable, int i); cdef readstat_type_t readstat_value_type(readstat_value_t value); cdef readstat_error_t readstat_set_row_limit(readstat_parser_t *parser, long row_limit); cdef readstat_error_t readstat_set_row_offset(readstat_parser_t *parser, long row_offset); cdef readstat_error_t readstat_parse_dta(readstat_parser_t *parser, const char *path, void *user_ctx); cdef readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, void *user_ctx); cdef readstat_error_t readstat_parse_por(readstat_parser_t *parser, const char *path, void *user_ctx); cdef readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx); cdef readstat_error_t readstat_parse_sas7bcat(readstat_parser_t *parser, const char *path, void *user_ctx); cdef readstat_error_t readstat_parse_xport(readstat_parser_t *parser, const char *path, void *user_ctx); char *readstat_string_value(readstat_value_t value); char readstat_int8_value(readstat_value_t value); int16_t readstat_int16_value(readstat_value_t value); int32_t readstat_int32_value(readstat_value_t value); float readstat_float_value(readstat_value_t value); double readstat_double_value(readstat_value_t value); char *readstat_error_message(readstat_error_t error_code); # Write API ctypedef struct readstat_writer_t ctypedef ssize_t (*readstat_data_writer)(const void *data, size_t len, void *ctx) ctypedef struct readstat_string_ref_t cdef readstat_writer_t *readstat_writer_init() cdef readstat_error_t readstat_set_data_writer(readstat_writer_t *writer, readstat_data_writer data_writer) cdef readstat_label_set_t *readstat_add_label_set(readstat_writer_t *writer, readstat_type_t type, const char *name); cdef void readstat_label_double_value(readstat_label_set_t *label_set, double value, const char *label); cdef void readstat_label_int32_value(readstat_label_set_t *label_set, int32_t value, const char *label); cdef void readstat_label_string_value(readstat_label_set_t *label_set, const char *value, const char *label); cdef void readstat_label_tagged_value(readstat_label_set_t *label_set, char tag, const char *label); cdef readstat_error_t readstat_writer_set_file_label(readstat_writer_t *writer, const char *file_label); cdef readstat_error_t readstat_writer_set_file_format_version(readstat_writer_t *writer, uint8_t file_format_version) cdef readstat_error_t readstat_writer_set_compression(readstat_writer_t *writer, readstat_compress_t compression) cdef void readstat_add_note(readstat_writer_t *writer, const char *note); cdef readstat_variable_t *readstat_add_variable(readstat_writer_t *writer, const char *name, readstat_type_t type, size_t storage_width) cdef void readstat_variable_set_label(readstat_variable_t *variable, const char *label) cdef void readstat_variable_set_format(readstat_variable_t *variable, const char *format); cdef void readstat_variable_set_label_set(readstat_variable_t *variable, readstat_label_set_t *label_set); cdef void readstat_variable_set_measure(readstat_variable_t *variable, readstat_measure_t measure); cdef void readstat_variable_set_alignment(readstat_variable_t *variable, readstat_alignment_t alignment); cdef void readstat_variable_set_display_width(readstat_variable_t *variable, int display_width); cdef readstat_error_t readstat_variable_add_missing_double_value(readstat_variable_t *variable, double value); cdef readstat_error_t readstat_variable_add_missing_double_range(readstat_variable_t *variable, double lo, double hi); cdef readstat_error_t readstat_variable_add_missing_string_value(readstat_variable_t *variable, const char *value); cdef readstat_error_t readstat_variable_add_missing_string_range(readstat_variable_t *variable, const char *lo, const char *hi); cdef readstat_error_t readstat_writer_set_table_name(readstat_writer_t *writer, const char *table_name) cdef readstat_variable_t *readstat_get_variable(readstat_writer_t *writer, int index) cdef readstat_error_t readstat_begin_writing_dta(readstat_writer_t *writer, void *user_ctx, long row_count); cdef readstat_error_t readstat_begin_writing_por(readstat_writer_t *writer, void *user_ctx, long row_count); cdef readstat_error_t readstat_begin_writing_sas7bcat(readstat_writer_t *writer, void *user_ctx); cdef readstat_error_t readstat_begin_writing_sas7bdat(readstat_writer_t *writer, void *user_ctx, long row_count); cdef readstat_error_t readstat_begin_writing_sav(readstat_writer_t *writer, void *user_ctx, long row_count); cdef readstat_error_t readstat_begin_writing_xport(readstat_writer_t *writer, void *user_ctx, long row_count); cdef readstat_error_t readstat_validate_metadata(readstat_writer_t *writer) cdef readstat_error_t readstat_validate_variable(readstat_writer_t *writer, const readstat_variable_t *variable) cdef readstat_error_t readstat_begin_row(readstat_writer_t *writer); cdef readstat_error_t readstat_insert_int8_value(readstat_writer_t *writer, const readstat_variable_t *variable, int8_t value); cdef readstat_error_t readstat_insert_int16_value(readstat_writer_t *writer, const readstat_variable_t *variable, int16_t value); cdef readstat_error_t readstat_insert_int32_value(readstat_writer_t *writer, const readstat_variable_t *variable, int32_t value); cdef readstat_error_t readstat_insert_float_value(readstat_writer_t *writer, const readstat_variable_t *variable, float value); cdef readstat_error_t readstat_insert_double_value(readstat_writer_t *writer, const readstat_variable_t *variable, double value); cdef readstat_error_t readstat_insert_string_value(readstat_writer_t *writer, const readstat_variable_t *variable, const char *value); cdef readstat_error_t readstat_insert_missing_value(readstat_writer_t *writer, const readstat_variable_t *variable); cdef readstat_error_t readstat_insert_tagged_missing_value(readstat_writer_t *writer, const readstat_variable_t *variable, char tag); # String refs are used for creating a READSTAT_TYPE_STRING_REF column, # which is only supported in Stata. String references can be shared # across columns, and inserted with readstat_insert_string_ref(). cdef readstat_error_t readstat_insert_string_ref(readstat_writer_t *writer, const readstat_variable_t *variable, readstat_string_ref_t *ref); cdef readstat_string_ref_t *readstat_add_string_ref(readstat_writer_t *writer, const char *string); cdef readstat_string_ref_t *readstat_get_string_ref(readstat_writer_t *writer, int index); cdef readstat_error_t readstat_end_row(readstat_writer_t *writer); cdef readstat_error_t readstat_end_writing(readstat_writer_t *writer); cdef void readstat_writer_free(readstat_writer_t *writer); cdef extern from "readstat_io_unistd.h": cdef struct unistd_io_ctx_t "unistd_io_ctx_s": int fd ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316780.0 pyreadstat-1.3.3/pyreadstat/worker.py0000644000076500000240000000171414646232654016320 0ustar00dialout # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# """ Functions to work with multiprocessing """ def worker(inpt): read_function, path, row_offset, row_limit, kwargs = inpt df, meta = read_function(path, row_offset=row_offset, row_limit=row_limit, **kwargs) return df ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/pyreadstat.egg-info/0000755000076500000240000000000015134706453016120 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180458.0 pyreadstat-1.3.3/pyreadstat.egg-info/PKG-INFO0000644000076500000240000000234015134706452017213 0ustar00dialoutMetadata-Version: 2.4 Name: pyreadstat Version: 1.3.3 Summary: Reads and Writes SAS, SPSS and Stata files into/from pandas and polars data frames. Home-page: https://github.com/Roche/pyreadstat Download-URL: https://github.com/Roche/pyreadstat/dist Author: Otto Fajardo Author-email: pleasecontactviagithub@notvalid.com License: Apache-2.0 Classifier: Programming Language :: Python Classifier: Programming Language :: Cython Classifier: Programming Language :: C Classifier: Intended Audience :: Science/Research Classifier: Topic :: Scientific/Engineering Classifier: Environment :: Console Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: narwhals>=2.10.1 Requires-Dist: numpy Dynamic: author Dynamic: author-email Dynamic: classifier Dynamic: description Dynamic: description-content-type Dynamic: download-url Dynamic: home-page Dynamic: license Dynamic: license-file Dynamic: requires-dist Dynamic: summary A Python package to read and write SAS (sas7bdat, sas7bcat, xport/xpt), SPSS (sav, zsav, por) and Stata (dta) files into/from pandas and polars data frames. It is a wrapper around the C library readstat.
Please visit out project home page for more information:
https://github.com/Roche/pyreadstat ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180458.0 pyreadstat-1.3.3/pyreadstat.egg-info/SOURCES.txt0000644000076500000240000000756215134706452020015 0ustar00dialoutLICENSE MANIFEST.in README.md pyproject.toml setup.py ./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 pyreadstat/__init__.py pyreadstat/_readstat_parser.c pyreadstat/_readstat_parser.pxd pyreadstat/_readstat_parser.pyx pyreadstat/_readstat_writer.c pyreadstat/_readstat_writer.pxd pyreadstat/_readstat_writer.pyx pyreadstat/_readstat_writer_pandas.pyx pyreadstat/conditional_includes.h pyreadstat/pyfunctions.py pyreadstat/pyreadstat.c pyreadstat/pyreadstat.pxd pyreadstat/pyreadstat.pyx pyreadstat/readstat_api.pxd pyreadstat/worker.py pyreadstat.egg-info/PKG-INFO pyreadstat.egg-info/SOURCES.txt pyreadstat.egg-info/dependency_links.txt pyreadstat.egg-info/requires.txt pyreadstat.egg-info/top_level.txt src/CKHashTable.c src/CKHashTable.h src/readstat.h src/readstat_bits.c src/readstat_bits.h src/readstat_convert.c src/readstat_convert.h src/readstat_error.c src/readstat_iconv.h src/readstat_io_unistd.c src/readstat_io_unistd.h src/readstat_malloc.c src/readstat_malloc.h src/readstat_metadata.c src/readstat_parser.c src/readstat_strings.h src/readstat_value.c src/readstat_variable.c src/readstat_writer.c src/readstat_writer.h src/sas/ieee.c src/sas/ieee.h src/sas/readstat_sas.c src/sas/readstat_sas.h 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_sas_rle.h src/sas/readstat_xport.c src/sas/readstat_xport.h src/sas/readstat_xport_parse_format.c src/sas/readstat_xport_parse_format.h src/sas/readstat_xport_read.c src/sas/readstat_xport_write.c src/spss/readstat_por.c src/spss/readstat_por.h src/spss/readstat_por_parse.c src/spss/readstat_por_parse.h src/spss/readstat_por_read.c src/spss/readstat_por_write.c src/spss/readstat_sav.c src/spss/readstat_sav.h src/spss/readstat_sav_compress.c src/spss/readstat_sav_compress.h src/spss/readstat_sav_parse.c src/spss/readstat_sav_parse.h src/spss/readstat_sav_parse_mr_name.c src/spss/readstat_sav_parse_mr_name.h src/spss/readstat_sav_parse_timestamp.c src/spss/readstat_sav_parse_timestamp.h src/spss/readstat_sav_read.c src/spss/readstat_sav_write.c src/spss/readstat_spss.c src/spss/readstat_spss.h src/spss/readstat_spss_parse.c src/spss/readstat_spss_parse.h src/spss/readstat_zsav_compress.c src/spss/readstat_zsav_compress.h src/spss/readstat_zsav_read.c src/spss/readstat_zsav_read.h src/spss/readstat_zsav_write.c src/spss/readstat_zsav_write.h src/stata/readstat_dta.c src/stata/readstat_dta.h src/stata/readstat_dta_parse_timestamp.c src/stata/readstat_dta_parse_timestamp.h src/stata/readstat_dta_read.c src/stata/readstat_dta_write.c tests/test_basic.py tests/test_http_integration.py tests/test_narwhalified.py tests/test_version.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180458.0 pyreadstat-1.3.3/pyreadstat.egg-info/dependency_links.txt0000644000076500000240000000000115134706452022165 0ustar00dialout ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180458.0 pyreadstat-1.3.3/pyreadstat.egg-info/requires.txt0000644000076500000240000000002715134706452020516 0ustar00dialoutnarwhals>=2.10.1 numpy ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180458.0 pyreadstat-1.3.3/pyreadstat.egg-info/top_level.txt0000644000076500000240000000001315134706452020643 0ustar00dialoutpyreadstat ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/setup.cfg0000644000076500000240000000004615134706453014067 0ustar00dialout[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1767630273.0 pyreadstat-1.3.3/setup.py0000644000076500000240000001563515126762701013771 0ustar00dialout# ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# import setuptools from distutils.core import setup, Extension import os import sys import Cython from Cython.Build import cythonize PY_MAJOR_VERSION = sys.version_info[0] PY_MINOR_VERSION = sys.version_info[1] if PY_MAJOR_VERSION < 3 and os.name == 'nt': raise Exception("Python 2 is not supported on Windows.") cyver = int(Cython.__version__.split(".")[0]) if cyver < 3: msg = "Cython version 3 or newer required" raise Exception(msg) ext = '.pyx' dir_path = os.path.dirname(os.path.realpath(__file__)) source_dir_root = "src" python_dir = sys.exec_prefix # Get a list of C source files and C source directories but omitting certain things omitted_sources = [ "mod_xlsx.c", "mod_csv_reader.c", "readstat.c"] omitted_source_dirs = ["src/test", "src/bin", "src/fuzz"] sources = list() for dirname, _ , filenames in os.walk(source_dir_root): if dirname not in omitted_source_dirs: for filename in filenames: if filename.endswith("c") and filename not in omitted_sources: cursource = os.path.join(".", dirname, filename) sources.append(cursource) source_dirs = [dirname for dirname, _, _ in os.walk(source_dir_root) if dirname not in omitted_source_dirs] def is_ubuntu(): """ Checks if the current operating system is Ubuntu. This function is safe to run on any OS. It returns False if not on Linux or if the distribution is not Ubuntu. """ if not sys.platform.startswith('linux'): return False try: with open('/etc/os-release', 'r', encoding='utf-8') as f: for line in f: if line.strip().startswith('ID='): # The value might have quotes, which we strip distro_id = line.split('=', 1)[1].strip().strip('"\'') if distro_id == 'ubuntu': return True except FileNotFoundError: # If /etc/os-release doesn't exist, it's not a standard modern Linux. return False return False def is_python_lt_14(): if PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION < 14: return True return False data_files = [] libraries = [] include_dirs = [source_dir_root] + source_dirs + ["pyreadstat", "."] library_dirs = [] # Windows # On Windows we have two possible setups: the user has included the static libraries in win_libs/64bit # Or the user is going to use the Conda forge versions of those. See the windows compilation document # for more details if os.name == 'nt': is64bit = sys.maxsize > 2 ** 32 # The user included the compiled static libraries if os.path.isfile("win_libs/64bit/libiconv-static.lib") and os.path.isfile("win_libs/64bit/libz-static.lib"): libraries.extend(["libiconv-static", "libz-static"]) include_dirs.append("win_libs/64bit") library_dirs.append("win_libs/64bit") # conda forge libraries else: libraries.extend(["iconv", "zlib"]) include_dirs.append(os.path.join(python_dir, "Library", "include")) library_dirs.append(os.path.join(python_dir, "Library", "bin")) library_dirs.append(os.path.join(python_dir, "Library", "lib")) else: libraries.extend(["m", "z"]) _platform = sys.platform # Mac and ubuntu: iconv needs to be linked statically if _platform.lower().startswith("darwin") or (is_ubuntu() and is_python_lt_14()): libraries.append("iconv") # Extensions sources.sort() extensions = [Extension("pyreadstat.pyreadstat", sources=["pyreadstat/pyreadstat" + ext] + sources, # this dot here is important for cython to find the pxd files include_dirs =include_dirs, libraries=libraries, library_dirs=library_dirs, extra_compile_args=["-Ireadstat", "-DHAVE_ZLIB=1"] ), Extension("pyreadstat._readstat_parser", sources=["pyreadstat/_readstat_parser" + ext] + sources, include_dirs = include_dirs, library_dirs=library_dirs, libraries=libraries, extra_compile_args=["-Ireadstat", "-DHAVE_ZLIB=1"]), Extension("pyreadstat._readstat_writer", sources=["pyreadstat/_readstat_writer" + ext] + sources, include_dirs=include_dirs,# + [numpy.get_include()], library_dirs=library_dirs, libraries=libraries, extra_compile_args=["-Ireadstat", "-DHAVE_ZLIB=1"]) ] # By setting this compiler directive, cython will # embed signature information in docstrings. Sphinx then knows how to extract # and use those signatures. for e in extensions: e.cython_directives = {"embedsignature": True} # let's use cython with force so that it always recompiles in case # somebody is switching between python 2 and 3 extensions = cythonize(extensions, compile_time_env={'PY_MAJOR_VERSION':PY_MAJOR_VERSION}, force=True) long_description = """ A Python package to read and write SAS (sas7bdat, sas7bcat, xport/xpt), SPSS (sav, zsav, por) and Stata (dta) files into/from pandas and polars data frames. It is a wrapper around the C library readstat.
Please visit out project home page for more information:
https://github.com/Roche/pyreadstat""" short_description = "Reads and Writes SAS, SPSS and Stata files into/from pandas and polars data frames." setup( name='pyreadstat', version='1.3.3', description=short_description, author="Otto Fajardo", author_email="pleasecontactviagithub@notvalid.com", url="https://github.com/Roche/pyreadstat", download_url="https://github.com/Roche/pyreadstat/dist", long_description=long_description, long_description_content_type="text/markdown", classifiers=[ "Programming Language :: Python", "Programming Language :: Cython", "Programming Language :: C", "Intended Audience :: Science/Research", "Topic :: Scientific/Engineering", "Environment :: Console", ], ext_modules=extensions, packages=["pyreadstat"], data_files=data_files, install_requires=['narwhals>=2.10.1', 'numpy'], license="Apache-2.0", ) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/src/0000755000076500000240000000000015134706453013035 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/CKHashTable.c0000644000076500000240000002132214674240614015252 0ustar00dialout// CKHashTable - A simple hash table // Copyright 2010-2020 Evan Miller (see LICENSE) #include "CKHashTable.h" /* SipHash reference C implementation Copyright (c) 2012 Jean-Philippe Aumasson Copyright (c) 2012 Daniel J. Bernstein To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . */ #include #include #include typedef uint64_t u64; typedef uint32_t u32; typedef uint8_t u8; #define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) ) #define U32TO8_LE(p, v) \ (p)[0] = (u8)((v) ); (p)[1] = (u8)((v) >> 8); \ (p)[2] = (u8)((v) >> 16); (p)[3] = (u8)((v) >> 24); #define U64TO8_LE(p, v) \ U32TO8_LE((p), (u32)((v) )); \ U32TO8_LE((p) + 4, (u32)((v) >> 32)); #define U8TO64_LE(p) \ (((u64)((p)[0]) ) | \ ((u64)((p)[1]) << 8) | \ ((u64)((p)[2]) << 16) | \ ((u64)((p)[3]) << 24) | \ ((u64)((p)[4]) << 32) | \ ((u64)((p)[5]) << 40) | \ ((u64)((p)[6]) << 48) | \ ((u64)((p)[7]) << 56)) #define SIPROUND \ do { \ v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \ v2 += v3; v3=ROTL(v3,16); v3 ^= v2; \ v0 += v3; v3=ROTL(v3,21); v3 ^= v0; \ v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \ } while(0) /* SipHash-1-2 */ static int siphash( unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k ) { /* "somepseudorandomlygeneratedbytes" */ u64 v0 = 0x736f6d6570736575ULL; u64 v1 = 0x646f72616e646f6dULL; u64 v2 = 0x6c7967656e657261ULL; u64 v3 = 0x7465646279746573ULL; u64 b; u64 k0 = U8TO64_LE( k ); u64 k1 = U8TO64_LE( k + 8 ); u64 m; const u8 *end = in + inlen - ( inlen % sizeof( u64 ) ); const int left = inlen & 7; b = ( ( u64 )inlen ) << 56; v3 ^= k1; v2 ^= k0; v1 ^= k1; v0 ^= k0; for ( ; in != end; in += 8 ) { m = U8TO64_LE( in ); v3 ^= m; SIPROUND; v0 ^= m; } switch( left ) { case 7: b |= ( ( u64 )in[ 6] ) << 48; case 6: b |= ( ( u64 )in[ 5] ) << 40; case 5: b |= ( ( u64 )in[ 4] ) << 32; case 4: b |= ( ( u64 )in[ 3] ) << 24; case 3: b |= ( ( u64 )in[ 2] ) << 16; case 2: b |= ( ( u64 )in[ 1] ) << 8; case 1: b |= ( ( u64 )in[ 0] ); break; case 0: break; } v3 ^= b; SIPROUND; v0 ^= b; v2 ^= 0xff; SIPROUND; SIPROUND; b = v0 ^ v1 ^ v2 ^ v3; U64TO8_LE( out, b ); return 0; } static uint64_t ck_hash_str(const char *str, size_t keylen) { uint64_t hash; unsigned char k[16] = { 0 }; siphash((unsigned char *)&hash, (const unsigned char *)str, keylen, k); return hash; } const void *ck_float_hash_lookup(float key, ck_hash_table_t *table) { return ck_str_n_hash_lookup((const char *)&key, sizeof(float), table); } int ck_float_hash_insert(float key, const void *value, ck_hash_table_t *table) { return ck_str_n_hash_insert((const char *)&key, sizeof(float), value, table); } const void *ck_double_hash_lookup(double key, ck_hash_table_t *table) { return ck_str_n_hash_lookup((const char *)&key, sizeof(double), table); } int ck_double_hash_insert(double key, const void *value, ck_hash_table_t *table) { return ck_str_n_hash_insert((const char *)&key, sizeof(double), value, table); } const void *ck_str_hash_lookup(const char *key, ck_hash_table_t *table) { size_t keylen = strlen(key); return ck_str_n_hash_lookup(key, keylen, table); } const void *ck_str_n_hash_lookup(const char *key, size_t keylen, ck_hash_table_t *table) { if (table->count == 0) return NULL; if (keylen == 0) return NULL; uint64_t hash_key = ck_hash_str(key, keylen); hash_key %= table->capacity; uint64_t end = hash_key; do { char *this_key = &table->keys[table->entries[hash_key].key_offset]; size_t this_keylen = table->entries[hash_key].key_length; if (this_keylen == 0) return NULL; if (this_keylen == keylen && memcmp(this_key, key, keylen) == 0) { return table->entries[hash_key].value; } hash_key++; hash_key %= table->capacity; } while (hash_key != end); return NULL; } int ck_str_hash_insert(const char *key, const void *value, ck_hash_table_t *table) { size_t keylen = strlen(key); return ck_str_n_hash_insert(key, keylen, value, table); } static int ck_hash_insert_nocopy(off_t key_offset, size_t keylen, uint64_t hash_key, const void *value, ck_hash_table_t *table) { if (table->capacity == 0) return 0; hash_key %= table->capacity; uint64_t end = (hash_key + table->capacity - 1) % table->capacity; while (hash_key != end) { ck_hash_entry_t *entry = &table->entries[hash_key]; if (table->entries[hash_key].key_length == 0) { table->count++; entry->key_offset = key_offset; entry->key_length = keylen; entry->value = value; return 1; } else if (entry->key_length == keylen && entry->key_offset == key_offset) { entry->value = value; return 1; } hash_key++; hash_key %= table->capacity; } return 0; } int ck_str_n_hash_insert(const char *key, size_t keylen, const void *value, ck_hash_table_t *table) { if (table->capacity == 0) return 0; if (keylen == 0) return 0; if (table->count >= 0.75 * table->capacity) { if (ck_hash_table_grow(table) == -1) { return 0; } } uint64_t hash_key = ck_hash_str(key, keylen); hash_key %= table->capacity; uint64_t end = hash_key; do { ck_hash_entry_t *entry = &table->entries[hash_key]; char *this_key = &table->keys[entry->key_offset]; if (entry->key_length == 0) { table->count++; while (table->keys_used + keylen > table->keys_capacity) { table->keys_capacity *= 2; table->keys = realloc(table->keys, table->keys_capacity); } memcpy(table->keys + table->keys_used, key, keylen); entry->key_offset = table->keys_used; entry->key_length = keylen; table->keys_used += keylen; entry->value = value; return 1; } else if (entry->key_length == keylen && memcmp(this_key, key, keylen) == 0) { table->entries[hash_key].value = value; return 1; } hash_key++; hash_key %= table->capacity; } while (hash_key != end); return 0; } ck_hash_table_t *ck_hash_table_init(size_t num_entries, size_t mean_key_length) { ck_hash_table_t *table; if ((table = malloc(sizeof(ck_hash_table_t))) == NULL) return NULL; if ((table->keys = malloc(num_entries * mean_key_length)) == NULL) { free(table); return NULL; } table->keys_capacity = num_entries * mean_key_length; num_entries *= 2; if ((table->entries = malloc(num_entries * sizeof(ck_hash_entry_t))) == NULL) { free(table->keys); free(table); return NULL; } table->capacity = num_entries; ck_hash_table_wipe(table); return table; } void ck_hash_table_free(ck_hash_table_t *table) { free(table->entries); if (table->keys) free(table->keys); free(table); } void ck_hash_table_wipe(ck_hash_table_t *table) { table->keys_used = 0; table->count = 0; memset(table->entries, 0, table->capacity * sizeof(ck_hash_entry_t)); } int ck_hash_table_grow(ck_hash_table_t *table) { ck_hash_entry_t *old_entries = table->entries; uint64_t old_capacity = table->capacity; uint64_t new_capacity = 2 * table->capacity; if ((table->entries = calloc(new_capacity, sizeof(ck_hash_entry_t))) == NULL) { return -1; } table->capacity = new_capacity; table->count = 0; for (int i=0; ikeys[old_entries[i].key_offset]; uint64_t hash_key = ck_hash_str(this_key, old_entries[i].key_length); if (!ck_hash_insert_nocopy(old_entries[i].key_offset, old_entries[i].key_length, hash_key, old_entries[i].value, table)) return -1; } } free(old_entries); return 0; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/CKHashTable.h0000644000076500000240000000246014674240614015261 0ustar00dialout// CKHashTable - A simple hash table // Copyright 2010-2020 Evan Miller (see LICENSE) #include #include typedef struct ck_hash_entry_s { off_t key_offset; size_t key_length; const void *value; } ck_hash_entry_t; typedef struct ck_hash_table_s { size_t capacity; size_t count; ck_hash_entry_t *entries; char *keys; size_t keys_used; size_t keys_capacity; } ck_hash_table_t; int ck_str_hash_insert(const char *key, const void *value, ck_hash_table_t *table); const void *ck_str_hash_lookup(const char *key, ck_hash_table_t *table); int ck_str_n_hash_insert(const char *key, size_t keylen, const void *value, ck_hash_table_t *table); const void *ck_str_n_hash_lookup(const char *key, size_t keylen, ck_hash_table_t *table); int ck_float_hash_insert(float key, const void *value, ck_hash_table_t *table); const void *ck_float_hash_lookup(float key, ck_hash_table_t *table); int ck_double_hash_insert(double key, const void *value, ck_hash_table_t *table); const void *ck_double_hash_lookup(double key, ck_hash_table_t *table); ck_hash_table_t *ck_hash_table_init(size_t num_entries, size_t mean_key_length); void ck_hash_table_wipe(ck_hash_table_t *table); int ck_hash_table_grow(ck_hash_table_t *table); void ck_hash_table_free(ck_hash_table_t *table); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748268530.0 pyreadstat-1.3.3/src/readstat.h0000644000076500000240000007113715015072762015023 0ustar00dialout// // readstat.h - API and internal data structures for ReadStat // // Copyright Evan Miller and ReadStat authors (see LICENSE) // #ifndef INCLUDE_READSTAT_H #define INCLUDE_READSTAT_H #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include enum { READSTAT_HANDLER_OK, READSTAT_HANDLER_ABORT, READSTAT_HANDLER_SKIP_VARIABLE }; typedef enum readstat_type_e { READSTAT_TYPE_STRING, READSTAT_TYPE_INT8, READSTAT_TYPE_INT16, READSTAT_TYPE_INT32, READSTAT_TYPE_FLOAT, READSTAT_TYPE_DOUBLE, READSTAT_TYPE_STRING_REF } readstat_type_t; typedef enum readstat_type_class_e { READSTAT_TYPE_CLASS_STRING, READSTAT_TYPE_CLASS_NUMERIC } readstat_type_class_t; typedef enum readstat_measure_e { READSTAT_MEASURE_UNKNOWN, READSTAT_MEASURE_NOMINAL = 1, READSTAT_MEASURE_ORDINAL, READSTAT_MEASURE_SCALE } readstat_measure_t; typedef enum readstat_alignment_e { READSTAT_ALIGNMENT_UNKNOWN, READSTAT_ALIGNMENT_LEFT = 1, READSTAT_ALIGNMENT_CENTER, READSTAT_ALIGNMENT_RIGHT } readstat_alignment_t; typedef enum readstat_compress_e { READSTAT_COMPRESS_NONE, READSTAT_COMPRESS_ROWS, READSTAT_COMPRESS_BINARY } readstat_compress_t; typedef enum readstat_endian_e { READSTAT_ENDIAN_NONE, READSTAT_ENDIAN_LITTLE, READSTAT_ENDIAN_BIG } readstat_endian_t; typedef enum readstat_error_e { READSTAT_OK, READSTAT_ERROR_OPEN = 1, READSTAT_ERROR_READ, READSTAT_ERROR_MALLOC, READSTAT_ERROR_USER_ABORT, READSTAT_ERROR_PARSE, READSTAT_ERROR_UNSUPPORTED_COMPRESSION, READSTAT_ERROR_UNSUPPORTED_CHARSET, READSTAT_ERROR_COLUMN_COUNT_MISMATCH, READSTAT_ERROR_ROW_COUNT_MISMATCH, READSTAT_ERROR_ROW_WIDTH_MISMATCH, READSTAT_ERROR_BAD_FORMAT_STRING, READSTAT_ERROR_VALUE_TYPE_MISMATCH, READSTAT_ERROR_WRITE, READSTAT_ERROR_WRITER_NOT_INITIALIZED, READSTAT_ERROR_SEEK, READSTAT_ERROR_CONVERT, READSTAT_ERROR_CONVERT_BAD_STRING, READSTAT_ERROR_CONVERT_SHORT_STRING, READSTAT_ERROR_CONVERT_LONG_STRING, READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE, READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE, READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG, READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED, READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION, READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER, READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER, READSTAT_ERROR_NAME_IS_RESERVED_WORD, READSTAT_ERROR_NAME_IS_TOO_LONG, READSTAT_ERROR_BAD_TIMESTAMP_STRING, READSTAT_ERROR_BAD_FREQUENCY_WEIGHT, READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS, READSTAT_ERROR_NOTE_IS_TOO_LONG, READSTAT_ERROR_STRING_REFS_NOT_SUPPORTED, READSTAT_ERROR_STRING_REF_IS_REQUIRED, READSTAT_ERROR_ROW_IS_TOO_WIDE_FOR_PAGE, READSTAT_ERROR_TOO_FEW_COLUMNS, READSTAT_ERROR_TOO_MANY_COLUMNS, READSTAT_ERROR_NAME_IS_ZERO_LENGTH, READSTAT_ERROR_BAD_TIMESTAMP_VALUE, READSTAT_ERROR_BAD_MR_STRING } readstat_error_t; const char *readstat_error_message(readstat_error_t error_code); typedef struct mr_set_s { char type; char *name; char *label; int is_dichotomy; int counted_value; char **subvariables; int num_subvars; } mr_set_t; typedef struct readstat_metadata_s { int64_t row_count; int64_t var_count; time_t creation_time; time_t modified_time; int64_t file_format_version; readstat_compress_t compression; readstat_endian_t endianness; const char *table_name; const char *file_label; const char *file_encoding; unsigned int is64bit:1; size_t multiple_response_sets_length; mr_set_t *mr_sets; } readstat_metadata_t; /* If the row count is unknown (e.g. it's an XPORT or POR file, or an SAV * file created with non-conforming software), then readstat_get_row_count * returns -1. */ int readstat_get_row_count(readstat_metadata_t *metadata); int readstat_get_var_count(readstat_metadata_t *metadata); time_t readstat_get_creation_time(readstat_metadata_t *metadata); time_t readstat_get_modified_time(readstat_metadata_t *metadata); int readstat_get_file_format_version(readstat_metadata_t *metadata); int readstat_get_file_format_is_64bit(readstat_metadata_t *metadata); readstat_compress_t readstat_get_compression(readstat_metadata_t *metadata); readstat_endian_t readstat_get_endianness(readstat_metadata_t *metadata); const char *readstat_get_table_name(readstat_metadata_t *metadata); const char *readstat_get_file_label(readstat_metadata_t *metadata); const char *readstat_get_file_encoding(readstat_metadata_t *metadata); const mr_set_t *readstat_get_multiple_response_sets(readstat_metadata_t *metadata); size_t readstat_get_multiple_response_sets_length(readstat_metadata_t *metadata); typedef struct readstat_value_s { union { float float_value; double double_value; int8_t i8_value; int16_t i16_value; int32_t i32_value; const char *string_value; } v; readstat_type_t type; char tag; unsigned int is_system_missing:1; unsigned int is_tagged_missing:1; } readstat_value_t; /* Internal data structures */ typedef struct readstat_value_label_s { double double_key; int32_t int32_key; char tag; char *string_key; size_t string_key_len; char *label; size_t label_len; } readstat_value_label_t; typedef struct readstat_label_set_s { readstat_type_t type; char name[256]; readstat_value_label_t *value_labels; long value_labels_count; long value_labels_capacity; void *variables; long variables_count; long variables_capacity; } readstat_label_set_t; typedef struct readstat_missingness_s { readstat_value_t missing_ranges[32]; long missing_ranges_count; } readstat_missingness_t; typedef struct readstat_variable_s { readstat_type_t type; int index; char name[300]; char format[256]; char label[1024]; readstat_label_set_t *label_set; off_t offset; size_t storage_width; size_t user_width; readstat_missingness_t missingness; readstat_measure_t measure; readstat_alignment_t alignment; int display_width; int decimals; int skip; int index_after_skipping; } readstat_variable_t; typedef struct readstat_schema_entry_s { uint32_t row; uint32_t col; uint32_t len; int skip; readstat_variable_t variable; char labelset[32]; char decimal_separator; } readstat_schema_entry_t; typedef struct readstat_schema_s { char filename[255]; uint32_t rows_per_observation; uint32_t cols_per_observation; int first_line; int entry_count; char field_delimiter; readstat_schema_entry_t *entries; } readstat_schema_t; /* Value accessors */ readstat_type_t readstat_value_type(readstat_value_t value); readstat_type_class_t readstat_value_type_class(readstat_value_t value); /* Values can be missing in one of three ways: * 1. "System missing", delivered to value handlers as NaN. Occurs in all file * types. The most common kind of missing value. * 2. Tagged missing, also delivered as NaN, but with a single character tag * accessible via readstat_value_tag(). The tag might be 'a', 'b', etc, * corresponding to Stata's .a, .b, values etc. Occurs only in Stata and * SAS files. * 3. Defined missing. The value is a real number but is to be treated as * missing according to the variable's missingness rules (such as "value < 0 || * value == 999"). Occurs only in SPSS files. access the rules via: * * readstat_variable_get_missing_ranges_count() * readstat_variable_get_missing_range_lo() * readstat_variable_get_missing_range_hi() * * Note that "ranges" include individual values where lo == hi. * * readstat_value_is_missing() is equivalent to: * * (readstat_value_is_system_missing() * || readstat_value_is_tagged_missing() * || readstat_value_is_defined_missing()) */ int readstat_value_is_missing(readstat_value_t value, readstat_variable_t *variable); int readstat_value_is_system_missing(readstat_value_t value); int readstat_value_is_tagged_missing(readstat_value_t value); int readstat_value_is_defined_missing(readstat_value_t value, readstat_variable_t *variable); char readstat_value_tag(readstat_value_t value); char readstat_int8_value(readstat_value_t value); int16_t readstat_int16_value(readstat_value_t value); int32_t readstat_int32_value(readstat_value_t value); float readstat_float_value(readstat_value_t value); double readstat_double_value(readstat_value_t value); const char *readstat_string_value(readstat_value_t value); readstat_type_class_t readstat_type_class(readstat_type_t type); /* Accessor methods for use inside variable handlers */ int readstat_variable_get_index(const readstat_variable_t *variable); int readstat_variable_get_index_after_skipping(const readstat_variable_t *variable); const char *readstat_variable_get_name(const readstat_variable_t *variable); const char *readstat_variable_get_label(const readstat_variable_t *variable); const char *readstat_variable_get_format(const readstat_variable_t *variable); readstat_type_t readstat_variable_get_type(const readstat_variable_t *variable); readstat_type_class_t readstat_variable_get_type_class(const readstat_variable_t *variable); size_t readstat_variable_get_storage_width(const readstat_variable_t *variable); int readstat_variable_get_display_width(const readstat_variable_t *variable); readstat_measure_t readstat_variable_get_measure(const readstat_variable_t *variable); readstat_alignment_t readstat_variable_get_alignment(const readstat_variable_t *variable); int readstat_variable_get_missing_ranges_count(const readstat_variable_t *variable); readstat_value_t readstat_variable_get_missing_range_lo(const readstat_variable_t *variable, int i); readstat_value_t readstat_variable_get_missing_range_hi(const readstat_variable_t *variable, int i); /* Callbacks should return 0 (aka READSTAT_HANDLER_OK) on success and 1 (aka READSTAT_HANDLER_ABORT) to abort. */ /* If the variable handler returns READSTAT_HANDLER_SKIP_VARIABLE, the value handler will not be called on * the associated variable. (Note that subsequent variables will retain their original index values.) */ typedef int (*readstat_metadata_handler)(readstat_metadata_t *metadata, void *ctx); typedef int (*readstat_note_handler)(int note_index, const char *note, void *ctx); typedef int (*readstat_variable_handler)(int index, readstat_variable_t *variable, const char *val_labels, void *ctx); typedef int (*readstat_fweight_handler)(readstat_variable_t *variable, void *ctx); typedef int (*readstat_value_handler)(int obs_index, readstat_variable_t *variable, readstat_value_t value, void *ctx); typedef int (*readstat_value_label_handler)(const char *val_labels, readstat_value_t value, const char *label, void *ctx); typedef void (*readstat_error_handler)(const char *error_message, void *ctx); typedef int (*readstat_progress_handler)(double progress, void *ctx); #if defined(_MSC_VER) #include typedef SSIZE_T ssize_t; typedef __int64 readstat_off_t; #elif defined _WIN32 || defined __CYGWIN__ typedef _off64_t readstat_off_t; #elif defined _AIX typedef off64_t readstat_off_t; #else typedef off_t readstat_off_t; #endif typedef enum readstat_io_flags_e { READSTAT_SEEK_SET, READSTAT_SEEK_CUR, READSTAT_SEEK_END } readstat_io_flags_t; typedef int (*readstat_open_handler)(const char *path, void *io_ctx); typedef int (*readstat_close_handler)(void *io_ctx); typedef readstat_off_t (*readstat_seek_handler)(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx); typedef ssize_t (*readstat_read_handler)(void *buf, size_t nbyte, void *io_ctx); typedef readstat_error_t (*readstat_update_handler)(long file_size, readstat_progress_handler progress_handler, void *user_ctx, void *io_ctx); typedef struct readstat_io_s { readstat_open_handler open; readstat_close_handler close; readstat_seek_handler seek; readstat_read_handler read; readstat_update_handler update; void *io_ctx; int io_ctx_needs_free; } readstat_io_t; typedef struct readstat_callbacks_s { readstat_metadata_handler metadata; readstat_note_handler note; readstat_variable_handler variable; readstat_fweight_handler fweight; readstat_value_handler value; readstat_value_label_handler value_label; readstat_error_handler error; readstat_progress_handler progress; } readstat_callbacks_t; typedef struct readstat_parser_s { readstat_callbacks_t handlers; readstat_io_t *io; const char *input_encoding; const char *output_encoding; long row_limit; long row_offset; } readstat_parser_t; readstat_parser_t *readstat_parser_init(void); void readstat_parser_free(readstat_parser_t *parser); void readstat_io_free(readstat_io_t *io); readstat_error_t readstat_set_metadata_handler(readstat_parser_t *parser, readstat_metadata_handler metadata_handler); readstat_error_t readstat_set_note_handler(readstat_parser_t *parser, readstat_note_handler note_handler); readstat_error_t readstat_set_variable_handler(readstat_parser_t *parser, readstat_variable_handler variable_handler); readstat_error_t readstat_set_fweight_handler(readstat_parser_t *parser, readstat_fweight_handler fweight_handler); readstat_error_t readstat_set_value_handler(readstat_parser_t *parser, readstat_value_handler value_handler); readstat_error_t readstat_set_value_label_handler(readstat_parser_t *parser, readstat_value_label_handler value_label_handler); readstat_error_t readstat_set_error_handler(readstat_parser_t *parser, readstat_error_handler error_handler); readstat_error_t readstat_set_progress_handler(readstat_parser_t *parser, readstat_progress_handler progress_handler); readstat_error_t readstat_set_open_handler(readstat_parser_t *parser, readstat_open_handler open_handler); readstat_error_t readstat_set_close_handler(readstat_parser_t *parser, readstat_close_handler close_handler); readstat_error_t readstat_set_seek_handler(readstat_parser_t *parser, readstat_seek_handler seek_handler); readstat_error_t readstat_set_read_handler(readstat_parser_t *parser, readstat_read_handler read_handler); readstat_error_t readstat_set_update_handler(readstat_parser_t *parser, readstat_update_handler update_handler); readstat_error_t readstat_set_io_ctx(readstat_parser_t *parser, void *io_ctx); // Usually inferred from the file, but sometimes a manual override is desirable. // In particular, pre-14 Stata uses the system encoding, which is usually Win 1252 // but could be anything. `encoding' should be an iconv-compatible name. readstat_error_t readstat_set_file_character_encoding(readstat_parser_t *parser, const char *encoding); // Defaults to UTF-8. Pass in NULL to disable transliteration. readstat_error_t readstat_set_handler_character_encoding(readstat_parser_t *parser, const char *encoding); readstat_error_t readstat_set_row_limit(readstat_parser_t *parser, long row_limit); readstat_error_t readstat_set_row_offset(readstat_parser_t *parser, long row_offset); /* Parse binary / portable files */ readstat_error_t readstat_parse_dta(readstat_parser_t *parser, const char *path, void *user_ctx); readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, void *user_ctx); readstat_error_t readstat_parse_por(readstat_parser_t *parser, const char *path, void *user_ctx); readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx); readstat_error_t readstat_parse_sas7bcat(readstat_parser_t *parser, const char *path, void *user_ctx); readstat_error_t readstat_parse_xport(readstat_parser_t *parser, const char *path, void *user_ctx); /* Parse a schema file... */ readstat_schema_t *readstat_parse_sas_commands(readstat_parser_t *parser, const char *filepath, void *user_ctx, readstat_error_t *outError); readstat_schema_t *readstat_parse_spss_commands(readstat_parser_t *parser, const char *filepath, void *user_ctx, readstat_error_t *outError); readstat_schema_t *readstat_parse_stata_dictionary(readstat_parser_t *parser, const char *filepath, void *user_ctx, readstat_error_t *outError); /* ... then pass the schema to the plain-text parser ... */ readstat_error_t readstat_parse_txt(readstat_parser_t *parser, const char *filename, readstat_schema_t *schema, void *user_ctx); /* ... and free the schema structure */ void readstat_schema_free(readstat_schema_t *schema); /* Internal module callbacks */ typedef struct readstat_string_ref_s { int64_t first_v; int64_t first_o; size_t len; char data[1]; // Flexible array; using [1] for C++98 compatibility } readstat_string_ref_t; typedef size_t (*readstat_variable_width_callback)(readstat_type_t type, size_t user_width); typedef readstat_error_t (*readstat_variable_ok_callback)(const readstat_variable_t *variable); typedef readstat_error_t (*readstat_write_int8_callback)(void *row_data, const readstat_variable_t *variable, int8_t value); typedef readstat_error_t (*readstat_write_int16_callback)(void *row_data, const readstat_variable_t *variable, int16_t value); typedef readstat_error_t (*readstat_write_int32_callback)(void *row_data, const readstat_variable_t *variable, int32_t value); typedef readstat_error_t (*readstat_write_float_callback)(void *row_data, const readstat_variable_t *variable, float value); typedef readstat_error_t (*readstat_write_double_callback)(void *row_data, const readstat_variable_t *variable, double value); typedef readstat_error_t (*readstat_write_string_callback)(void *row_data, const readstat_variable_t *variable, const char *value); typedef readstat_error_t (*readstat_write_string_ref_callback)(void *row_data, const readstat_variable_t *variable, readstat_string_ref_t *ref); typedef readstat_error_t (*readstat_write_missing_callback)(void *row_data, const readstat_variable_t *variable); typedef readstat_error_t (*readstat_write_tagged_callback)(void *row_data, const readstat_variable_t *variable, char tag); typedef readstat_error_t (*readstat_begin_data_callback)(void *writer); typedef readstat_error_t (*readstat_write_row_callback)(void *writer, void *row_data, size_t row_len); typedef readstat_error_t (*readstat_end_data_callback)(void *writer); typedef void (*readstat_module_ctx_free_callback)(void *module_ctx); typedef readstat_error_t (*readstat_metadata_ok_callback)(void *writer); typedef struct readstat_writer_callbacks_s { readstat_variable_width_callback variable_width; readstat_variable_ok_callback variable_ok; readstat_write_int8_callback write_int8; readstat_write_int16_callback write_int16; readstat_write_int32_callback write_int32; readstat_write_float_callback write_float; readstat_write_double_callback write_double; readstat_write_string_callback write_string; readstat_write_string_ref_callback write_string_ref; readstat_write_missing_callback write_missing_string; readstat_write_missing_callback write_missing_number; readstat_write_tagged_callback write_missing_tagged; readstat_begin_data_callback begin_data; readstat_write_row_callback write_row; readstat_end_data_callback end_data; readstat_module_ctx_free_callback module_ctx_free; readstat_metadata_ok_callback metadata_ok; } readstat_writer_callbacks_t; /* You'll need to define one of these to get going. Should return # bytes written, * or -1 on error, a la write(2) */ typedef ssize_t (*readstat_data_writer)(const void *data, size_t len, void *ctx); typedef struct readstat_writer_s { readstat_data_writer data_writer; size_t bytes_written; long version; int is_64bit; // SAS only readstat_compress_t compression; time_t timestamp; readstat_variable_t **variables; long variables_count; long variables_capacity; readstat_label_set_t **label_sets; long label_sets_count; long label_sets_capacity; char **notes; long notes_count; long notes_capacity; readstat_string_ref_t **string_refs; long string_refs_count; long string_refs_capacity; unsigned char *row; size_t row_len; int row_count; int current_row; char file_label[257]; char table_name[33]; const readstat_variable_t *fweight_variable; readstat_writer_callbacks_t callbacks; readstat_error_handler error_handler; void *module_ctx; void *user_ctx; int initialized; } readstat_writer_t; /* Writer API */ // First call this... readstat_writer_t *readstat_writer_init(void); // Then specify a function that will handle the output bytes... readstat_error_t readstat_set_data_writer(readstat_writer_t *writer, readstat_data_writer data_writer); // Next define your value labels, if any. Create as many named sets as you'd like. readstat_label_set_t *readstat_add_label_set(readstat_writer_t *writer, readstat_type_t type, const char *name); void readstat_label_double_value(readstat_label_set_t *label_set, double value, const char *label); void readstat_label_int32_value(readstat_label_set_t *label_set, int32_t value, const char *label); void readstat_label_string_value(readstat_label_set_t *label_set, const char *value, const char *label); void readstat_label_tagged_value(readstat_label_set_t *label_set, char tag, const char *label); // Now define your variables. Note that `storage_width' is used for: // * READSTAT_TYPE_STRING variables in all formats // * READSTAT_TYPE_DOUBLE variables, but only in the SAS XPORT format (valid values 3-8, defaults to 8) readstat_variable_t *readstat_add_variable(readstat_writer_t *writer, const char *name, readstat_type_t type, size_t storage_width); void readstat_variable_set_label(readstat_variable_t *variable, const char *label); void readstat_variable_set_format(readstat_variable_t *variable, const char *format); void readstat_variable_set_label_set(readstat_variable_t *variable, readstat_label_set_t *label_set); void readstat_variable_set_measure(readstat_variable_t *variable, readstat_measure_t measure); void readstat_variable_set_alignment(readstat_variable_t *variable, readstat_alignment_t alignment); void readstat_variable_set_display_width(readstat_variable_t *variable, int display_width); readstat_error_t readstat_variable_add_missing_double_value(readstat_variable_t *variable, double value); readstat_error_t readstat_variable_add_missing_double_range(readstat_variable_t *variable, double lo, double hi); readstat_error_t readstat_variable_add_missing_string_value(readstat_variable_t *variable, const char *value); readstat_error_t readstat_variable_add_missing_string_range(readstat_variable_t *variable, const char *lo, const char *hi); readstat_variable_t *readstat_get_variable(readstat_writer_t *writer, int index); // "Notes" appear in the file metadata. In SPSS these are stored as // lines in the Document Record; in Stata these are stored using // the "notes" feature. // // Note that the line length in SPSS is 80 characters; ReadStat will // produce a write error if a note is longer than this limit. void readstat_add_note(readstat_writer_t *writer, const char *note); // String refs are used for creating a READSTAT_TYPE_STRING_REF column, // which is only supported in Stata. String references can be shared // across columns, and inserted with readstat_insert_string_ref(). readstat_string_ref_t *readstat_add_string_ref(readstat_writer_t *writer, const char *string); readstat_string_ref_t *readstat_get_string_ref(readstat_writer_t *writer, int index); // Optional metadata readstat_error_t readstat_writer_set_file_label(readstat_writer_t *writer, const char *file_label); readstat_error_t readstat_writer_set_file_timestamp(readstat_writer_t *writer, time_t timestamp); readstat_error_t readstat_writer_set_fweight_variable(readstat_writer_t *writer, const readstat_variable_t *variable); readstat_error_t readstat_writer_set_file_format_version(readstat_writer_t *writer, uint8_t file_format_version); // e.g. 104-119 for DTA; 5 or 8 for SAS Transport. // SAV files support 2 or 3, where 3 is equivalent to setting // readstat_writer_set_compression(READSTAT_COMPRESS_BINARY) readstat_error_t readstat_writer_set_table_name(readstat_writer_t *writer, const char *table_name); // Only used in XPORT files at the moment (defaults to DATASET) readstat_error_t readstat_writer_set_file_format_is_64bit(readstat_writer_t *writer, int is_64bit); // applies only to SAS files; defaults to 1=true readstat_error_t readstat_writer_set_compression(readstat_writer_t *writer, readstat_compress_t compression); // READSTAT_COMPRESS_BINARY is supported only with SAV files (i.e. ZSAV files) // READSTAT_COMPRESS_ROWS is supported only with sas7bdat and SAV files // Optional error handler readstat_error_t readstat_writer_set_error_handler(readstat_writer_t *writer, readstat_error_handler error_handler); // Call one of these at any time before the first invocation of readstat_begin_row readstat_error_t readstat_begin_writing_dta(readstat_writer_t *writer, void *user_ctx, long row_count); readstat_error_t readstat_begin_writing_por(readstat_writer_t *writer, void *user_ctx, long row_count); readstat_error_t readstat_begin_writing_sas7bcat(readstat_writer_t *writer, void *user_ctx); readstat_error_t readstat_begin_writing_sas7bdat(readstat_writer_t *writer, void *user_ctx, long row_count); readstat_error_t readstat_begin_writing_sav(readstat_writer_t *writer, void *user_ctx, long row_count); readstat_error_t readstat_begin_writing_xport(readstat_writer_t *writer, void *user_ctx, long row_count); // Optional, file-specific validation routines, to be called AFTER readstat_begin_writing_XXX readstat_error_t readstat_validate_metadata(readstat_writer_t *writer); readstat_error_t readstat_validate_variable(readstat_writer_t *writer, const readstat_variable_t *variable); // Start a row of data (that is, a case or observation) readstat_error_t readstat_begin_row(readstat_writer_t *writer); // Then call one of these for each variable readstat_error_t readstat_insert_int8_value(readstat_writer_t *writer, const readstat_variable_t *variable, int8_t value); readstat_error_t readstat_insert_int16_value(readstat_writer_t *writer, const readstat_variable_t *variable, int16_t value); readstat_error_t readstat_insert_int32_value(readstat_writer_t *writer, const readstat_variable_t *variable, int32_t value); readstat_error_t readstat_insert_float_value(readstat_writer_t *writer, const readstat_variable_t *variable, float value); readstat_error_t readstat_insert_double_value(readstat_writer_t *writer, const readstat_variable_t *variable, double value); readstat_error_t readstat_insert_string_value(readstat_writer_t *writer, const readstat_variable_t *variable, const char *value); readstat_error_t readstat_insert_string_ref(readstat_writer_t *writer, const readstat_variable_t *variable, readstat_string_ref_t *ref); readstat_error_t readstat_insert_missing_value(readstat_writer_t *writer, const readstat_variable_t *variable); readstat_error_t readstat_insert_tagged_missing_value(readstat_writer_t *writer, const readstat_variable_t *variable, char tag); // Finally, close out the row readstat_error_t readstat_end_row(readstat_writer_t *writer); // Once you've written all the rows, clean up after yourself readstat_error_t readstat_end_writing(readstat_writer_t *writer); void readstat_writer_free(readstat_writer_t *writer); #ifdef __cplusplus } #endif #endif ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_bits.c0000644000076500000240000000317114674240614016033 0ustar00dialout// // readstat_bits.c - Bit-twiddling utility functions // #include #include #include #include "readstat_bits.h" int machine_is_little_endian(void) { int test_byte_order = 1; return ((char *)&test_byte_order)[0]; } char ones_to_twos_complement1(char num) { return num < 0 ? num+1 : num; } int16_t ones_to_twos_complement2(int16_t num) { return num < 0 ? num+1 : num; } int32_t ones_to_twos_complement4(int32_t num) { return num < 0 ? num+1 : num; } char twos_to_ones_complement1(char num) { return num < 0 ? num-1 : num; } int16_t twos_to_ones_complement2(int16_t num) { return num < 0 ? num-1 : num; } int32_t twos_to_ones_complement4(int32_t num) { return num < 0 ? num-1 : num; } uint16_t byteswap2(uint16_t num) { return ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8); } uint32_t byteswap4(uint32_t num) { num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16); return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8); } uint64_t byteswap8(uint64_t num) { num = ((num & 0xFFFFFFFF00000000) >> 32) | ((num & 0x00000000FFFFFFFF) << 32); num = ((num & 0xFFFF0000FFFF0000) >> 16) | ((num & 0x0000FFFF0000FFFF) << 16); return ((num & 0xFF00FF00FF00FF00) >> 8) | ((num & 0x00FF00FF00FF00FF) << 8); } float byteswap_float(float num) { uint32_t answer = 0; memcpy(&answer, &num, 4); answer = byteswap4(answer); memcpy(&num, &answer, 4); return num; } double byteswap_double(double num) { uint64_t answer = 0; memcpy(&answer, &num, 8); answer = byteswap8(answer); memcpy(&num, &answer, 8); return num; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_bits.h0000644000076500000240000000106414674240614016037 0ustar00dialout// // readstat_bit.h - Bit-twiddling utility functions // #define READSTAT_MACHINE_IS_TWOS_COMPLEMENT ((char)0xFF == (char)-1) #undef READSTAT_MACHINE_IS_TWOS_COMPLEMENT #define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0 int machine_is_little_endian(void); char ones_to_twos_complement1(char num); int16_t ones_to_twos_complement2(int16_t num); int32_t ones_to_twos_complement4(int32_t num); uint16_t byteswap2(uint16_t num); uint32_t byteswap4(uint32_t num); uint64_t byteswap8(uint64_t num); float byteswap_float(float num); double byteswap_double(double num); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_convert.c0000644000076500000240000000251214674240614016550 0ustar00dialout #include #include "readstat.h" #include "readstat_iconv.h" #include "readstat_convert.h" readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) { /* strip off spaces from the input because the programs use ASCII space * padding even with non-ASCII encoding. */ while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) { src_len--; } if (dst_len == 0) { return READSTAT_ERROR_CONVERT_LONG_STRING; } else if (converter) { size_t dst_left = dst_len - 1; char *dst_end = dst; size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left); if (status == (size_t)-1) { if (errno == E2BIG) { return READSTAT_ERROR_CONVERT_LONG_STRING; } else if (errno == EILSEQ) { return READSTAT_ERROR_CONVERT_BAD_STRING; } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */ return READSTAT_ERROR_CONVERT; } } dst[dst_len - dst_left - 1] = '\0'; } else if (src_len + 1 > dst_len) { return READSTAT_ERROR_CONVERT_LONG_STRING; } else { memcpy(dst, src, src_len); dst[src_len] = '\0'; } return READSTAT_OK; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_convert.h0000644000076500000240000000016314674240614016555 0ustar00dialout readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/readstat_error.c0000644000076500000240000001234315134704512016216 0ustar00dialout #include "readstat.h" const char *readstat_error_message(readstat_error_t error_code) { if (error_code == READSTAT_OK) return NULL; if (error_code == READSTAT_ERROR_OPEN) return "Unable to open file"; if (error_code == READSTAT_ERROR_READ) return "Unable to read from file"; if (error_code == READSTAT_ERROR_MALLOC) return "Unable to allocate memory"; if (error_code == READSTAT_ERROR_USER_ABORT) return "The parsing was aborted (callback returned non-zero value)"; if (error_code == READSTAT_ERROR_PARSE) return "Invalid file, or file has unsupported features"; if (error_code == READSTAT_ERROR_UNSUPPORTED_COMPRESSION) return "File has unsupported compression scheme"; if (error_code == READSTAT_ERROR_UNSUPPORTED_CHARSET) return "File has an unsupported character set"; if (error_code == READSTAT_ERROR_COLUMN_COUNT_MISMATCH) return "File did not contain the expected number of columns"; if (error_code == READSTAT_ERROR_ROW_COUNT_MISMATCH) return "File did not contain the expected number of rows"; if (error_code == READSTAT_ERROR_ROW_WIDTH_MISMATCH) return "A row in the file was not the expected length"; if (error_code == READSTAT_ERROR_BAD_FORMAT_STRING) return "A provided format string could not be understood"; if (error_code == READSTAT_ERROR_VALUE_TYPE_MISMATCH) return "A provided value was incompatible with the variable's declared type"; if (error_code == READSTAT_ERROR_WRITE) return "Unable to write data"; if (error_code == READSTAT_ERROR_WRITER_NOT_INITIALIZED) return "The writer object was not properly initialized (call and check return value of readstat_begin_writing_XXX)"; if (error_code == READSTAT_ERROR_SEEK) return "Unable to seek within file"; if (error_code == READSTAT_ERROR_CONVERT) return "Unable to convert string to the requested encoding"; if (error_code == READSTAT_ERROR_CONVERT_BAD_STRING) return "Unable to convert string to the requested encoding (invalid byte sequence)"; if (error_code == READSTAT_ERROR_CONVERT_SHORT_STRING) return "Unable to convert string to the requested encoding (incomplete byte sequence)"; if (error_code == READSTAT_ERROR_CONVERT_LONG_STRING) return "Unable to convert string to the requested encoding (output buffer too small)"; if (error_code == READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE) return "A provided numeric value was outside the range of representable values in the specified file format"; if (error_code == READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE) return "A provided tag value was outside the range of allowed values in the specified file format"; if (error_code == READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG) return "A provided string value was longer than the available storage size of the specified column"; if (error_code == READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED) return "The file format does not supported character tags for missing values"; if (error_code == READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION) return "This version of the file format is not supported"; if (error_code == READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER) return "A provided name begins with an illegal character"; if (error_code == READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER) return "A provided name contains an illegal character"; if (error_code == READSTAT_ERROR_NAME_IS_RESERVED_WORD) return "A provided name is a reserved word"; if (error_code == READSTAT_ERROR_NAME_IS_TOO_LONG) return "A provided name is too long for the file format"; if (error_code == READSTAT_ERROR_NAME_IS_ZERO_LENGTH) return "A provided name is blank or empty"; if (error_code == READSTAT_ERROR_BAD_TIMESTAMP_STRING) return "The file's timestamp string is invalid"; if (error_code == READSTAT_ERROR_BAD_FREQUENCY_WEIGHT) return "The provided variable can't be used as a frequency weight"; if (error_code == READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS) return "The number of defined missing values exceeds the format limit"; if (error_code == READSTAT_ERROR_NOTE_IS_TOO_LONG) return "The provided note is too long for the file format"; if (error_code == READSTAT_ERROR_STRING_REFS_NOT_SUPPORTED) return "This version of the file format does not support string references"; if (error_code == READSTAT_ERROR_STRING_REF_IS_REQUIRED) return "The provided value was not a valid string reference"; if (error_code == READSTAT_ERROR_ROW_IS_TOO_WIDE_FOR_PAGE) return "A row of data will not fit into the file format"; if (error_code == READSTAT_ERROR_TOO_FEW_COLUMNS) return "One or more columns must be provided"; if (error_code == READSTAT_ERROR_TOO_MANY_COLUMNS) return "Too many columns for this file format version"; if (error_code == READSTAT_ERROR_BAD_TIMESTAMP_VALUE) return "The provided file timestamp is invalid"; if (error_code == READSTAT_ERROR_BAD_MR_STRING) return "A multi-response set record is invalid"; return "Unknown error"; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_iconv.h0000644000076500000240000000061714674240614016217 0ustar00dialout#include /* ICONV_CONST defined by autotools during configure according * to the current platform. Some people copy-paste the source code, so * provide some fallback logic */ #ifndef ICONV_CONST #define ICONV_CONST #endif typedef ICONV_CONST char ** readstat_iconv_inbuf_t; typedef struct readstat_charset_entry_s { int code; char name[32]; } readstat_charset_entry_t; ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_io_unistd.c0000644000076500000240000000704414674240614017072 0ustar00dialout #include #include #include #if defined _WIN32 # include # include #endif #if !defined(_MSC_VER) # include #else #define open _open #define read _read #define close _close #endif #if defined _WIN32 || defined __CYGWIN__ #define UNISTD_OPEN_OPTIONS O_RDONLY | O_BINARY #elif defined _AIX #define UNISTD_OPEN_OPTIONS O_RDONLY | O_LARGEFILE #else #define UNISTD_OPEN_OPTIONS O_RDONLY #endif #if defined _WIN32 #define lseek _lseeki64 #elif defined _AIX #define lseek lseek64 #endif #include "readstat.h" #include "readstat_io_unistd.h" int open_with_unicode(const char *path, int options) { #if defined _WIN32 const int buffer_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); if(buffer_size <= 0) return -1; wchar_t* wpath = malloc((buffer_size + 1) * sizeof(wchar_t)); const int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, buffer_size); wpath[buffer_size] = 0; if(res <= 0) { free(wpath); return -1; } int fd = _wopen(wpath, options); free(wpath); return fd; #else return open(path, options); #endif } int unistd_open_handler(const char *path, void *io_ctx) { int fd = open_with_unicode(path, UNISTD_OPEN_OPTIONS); ((unistd_io_ctx_t*) io_ctx)->fd = fd; return fd; } int unistd_close_handler(void *io_ctx) { int fd = ((unistd_io_ctx_t*) io_ctx)->fd; if (fd != -1) return close(fd); else return 0; } readstat_off_t unistd_seek_handler(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx) { int flag = 0; switch(whence) { case READSTAT_SEEK_SET: flag = SEEK_SET; break; case READSTAT_SEEK_CUR: flag = SEEK_CUR; break; case READSTAT_SEEK_END: flag = SEEK_END; break; default: return -1; } int fd = ((unistd_io_ctx_t*) io_ctx)->fd; return lseek(fd, offset, flag); } ssize_t unistd_read_handler(void *buf, size_t nbyte, void *io_ctx) { int fd = ((unistd_io_ctx_t*) io_ctx)->fd; ssize_t out = read(fd, buf, nbyte); return out; } readstat_error_t unistd_update_handler(long file_size, readstat_progress_handler progress_handler, void *user_ctx, void *io_ctx) { if (!progress_handler) return READSTAT_OK; int fd = ((unistd_io_ctx_t*) io_ctx)->fd; readstat_off_t current_offset = lseek(fd, 0, SEEK_CUR); if (current_offset == -1) return READSTAT_ERROR_SEEK; if (progress_handler(1.0 * current_offset / file_size, user_ctx)) return READSTAT_ERROR_USER_ABORT; return READSTAT_OK; } readstat_error_t unistd_io_init(readstat_parser_t *parser) { readstat_error_t retval = READSTAT_OK; unistd_io_ctx_t *io_ctx = NULL; if ((retval = readstat_set_open_handler(parser, unistd_open_handler)) != READSTAT_OK) return retval; if ((retval = readstat_set_close_handler(parser, unistd_close_handler)) != READSTAT_OK) return retval; if ((retval = readstat_set_seek_handler(parser, unistd_seek_handler)) != READSTAT_OK) return retval; if ((retval = readstat_set_read_handler(parser, unistd_read_handler)) != READSTAT_OK) return retval; if ((readstat_set_update_handler(parser, unistd_update_handler)) != READSTAT_OK) return retval; io_ctx = calloc(1, sizeof(unistd_io_ctx_t)); io_ctx->fd = -1; retval = readstat_set_io_ctx(parser, (void*) io_ctx); parser->io->io_ctx_needs_free = 1; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_io_unistd.h0000644000076500000240000000103114674240614017065 0ustar00dialout typedef struct unistd_io_ctx_s { int fd; } unistd_io_ctx_t; int unistd_open_handler(const char *path, void *io_ctx); int unistd_close_handler(void *io_ctx); readstat_off_t unistd_seek_handler(readstat_off_t offset, readstat_io_flags_t whence, void *io_ctx); ssize_t unistd_read_handler(void *buf, size_t nbytes, void *io_ctx); readstat_error_t unistd_update_handler(long file_size, readstat_progress_handler progress_handler, void *user_ctx, void *io_ctx); readstat_error_t unistd_io_init(readstat_parser_t *parser); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_malloc.c0000644000076500000240000000174514674240614016346 0ustar00dialout#include #define MAX_MALLOC_SIZE 0x1000000 /* =16 MiB. Needs to be at least 0x3FF00, i.e. the default ~4MB block size used * in compressed SPSS (ZSAV) files. Some SAS installations use 16MiB page sizes * by default, see https://github.com/tidyverse/haven/issues/697. * The purpose here is to prevent massive allocations in the event of a * malformed file or a bug in the library. */ void *readstat_malloc(size_t len) { if (len > MAX_MALLOC_SIZE || len == 0) { return NULL; } return malloc(len); } void *readstat_calloc(size_t count, size_t size) { if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) { return NULL; } if (count == 0 || size == 0) { return NULL; } return calloc(count, size); } void *readstat_realloc(void *ptr, size_t len) { if (len > MAX_MALLOC_SIZE || len == 0) { if (ptr) free(ptr); return NULL; } return realloc(ptr, len); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_malloc.h0000644000076500000240000000020614674240614016342 0ustar00dialout void *readstat_malloc(size_t size); void *readstat_calloc(size_t count, size_t size); void *readstat_realloc(void *ptr, size_t len); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_metadata.c0000644000076500000240000000264614674240614016660 0ustar00dialout#include "readstat.h" int readstat_get_row_count(readstat_metadata_t *metadata) { return metadata->row_count; } int readstat_get_var_count(readstat_metadata_t *metadata) { return metadata->var_count; } time_t readstat_get_creation_time(readstat_metadata_t *metadata) { return metadata->creation_time; } time_t readstat_get_modified_time(readstat_metadata_t *metadata) { return metadata->modified_time; } int readstat_get_file_format_version(readstat_metadata_t *metadata) { return metadata->file_format_version; } int readstat_get_file_format_is_64bit(readstat_metadata_t *metadata) { return metadata->is64bit; } readstat_compress_t readstat_get_compression(readstat_metadata_t *metadata) { return metadata->compression; } readstat_endian_t readstat_get_endianness(readstat_metadata_t *metadata) { return metadata->endianness; } const char *readstat_get_file_label(readstat_metadata_t *metadata) { return metadata->file_label; } const char *readstat_get_file_encoding(readstat_metadata_t *metadata) { return metadata->file_encoding; } const char *readstat_get_table_name(readstat_metadata_t *metadata) { return metadata->table_name; } size_t readstat_get_multiple_response_sets_length(readstat_metadata_t *metadata) { return metadata->multiple_response_sets_length; } const mr_set_t *readstat_get_multiple_response_sets(readstat_metadata_t *metadata) { return metadata->mr_sets; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_parser.c0000644000076500000240000000754514674240614016377 0ustar00dialout #include #include "readstat.h" #include "readstat_io_unistd.h" readstat_parser_t *readstat_parser_init(void) { readstat_parser_t *parser = calloc(1, sizeof(readstat_parser_t)); parser->io = calloc(1, sizeof(readstat_io_t)); if (unistd_io_init(parser) != READSTAT_OK) { readstat_parser_free(parser); return NULL; } parser->output_encoding = "UTF-8"; return parser; } void readstat_parser_free(readstat_parser_t *parser) { if (parser) { if (parser->io) { readstat_set_io_ctx(parser, NULL); free(parser->io); } free(parser); } } readstat_error_t readstat_set_metadata_handler(readstat_parser_t *parser, readstat_metadata_handler metadata_handler) { parser->handlers.metadata = metadata_handler; return READSTAT_OK; } readstat_error_t readstat_set_note_handler(readstat_parser_t *parser, readstat_note_handler note_handler) { parser->handlers.note = note_handler; return READSTAT_OK; } readstat_error_t readstat_set_variable_handler(readstat_parser_t *parser, readstat_variable_handler variable_handler) { parser->handlers.variable = variable_handler; return READSTAT_OK; } readstat_error_t readstat_set_value_handler(readstat_parser_t *parser, readstat_value_handler value_handler) { parser->handlers.value = value_handler; return READSTAT_OK; } readstat_error_t readstat_set_value_label_handler(readstat_parser_t *parser, readstat_value_label_handler label_handler) { parser->handlers.value_label = label_handler; return READSTAT_OK; } readstat_error_t readstat_set_error_handler(readstat_parser_t *parser, readstat_error_handler error_handler) { parser->handlers.error = error_handler; return READSTAT_OK; } readstat_error_t readstat_set_progress_handler(readstat_parser_t *parser, readstat_progress_handler progress_handler) { parser->handlers.progress = progress_handler; return READSTAT_OK; } readstat_error_t readstat_set_fweight_handler(readstat_parser_t *parser, readstat_fweight_handler fweight_handler) { parser->handlers.fweight = fweight_handler; return READSTAT_OK; } readstat_error_t readstat_set_open_handler(readstat_parser_t *parser, readstat_open_handler open_handler) { parser->io->open = open_handler; return READSTAT_OK; } readstat_error_t readstat_set_close_handler(readstat_parser_t *parser, readstat_close_handler close_handler) { parser->io->close = close_handler; return READSTAT_OK; } readstat_error_t readstat_set_seek_handler(readstat_parser_t *parser, readstat_seek_handler seek_handler) { parser->io->seek = seek_handler; return READSTAT_OK; } readstat_error_t readstat_set_read_handler(readstat_parser_t *parser, readstat_read_handler read_handler) { parser->io->read = read_handler; return READSTAT_OK; } readstat_error_t readstat_set_update_handler(readstat_parser_t *parser, readstat_update_handler update_handler) { parser->io->update = update_handler; return READSTAT_OK; } readstat_error_t readstat_set_io_ctx(readstat_parser_t *parser, void *io_ctx) { if (parser->io->io_ctx_needs_free) { free(parser->io->io_ctx); } parser->io->io_ctx = io_ctx; parser->io->io_ctx_needs_free = 0; return READSTAT_OK; } readstat_error_t readstat_set_file_character_encoding(readstat_parser_t *parser, const char *encoding) { parser->input_encoding = encoding; return READSTAT_OK; } readstat_error_t readstat_set_handler_character_encoding(readstat_parser_t *parser, const char *encoding) { parser->output_encoding = encoding; return READSTAT_OK; } readstat_error_t readstat_set_row_limit(readstat_parser_t *parser, long row_limit) { parser->row_limit = row_limit; return READSTAT_OK; } readstat_error_t readstat_set_row_offset(readstat_parser_t *parser, long row_offset) { parser->row_offset = row_offset; return READSTAT_OK; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_strings.h0000644000076500000240000000017314674240614016567 0ustar00dialout#if defined(_MSC_VER) # define strncasecmp _strnicmp # define strcasecmp _stricmp #else # include #endif ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_value.c0000644000076500000240000001270314674240614016207 0ustar00dialout #include "readstat.h" readstat_type_class_t readstat_type_class(readstat_type_t type) { if (type == READSTAT_TYPE_STRING || type == READSTAT_TYPE_STRING_REF) return READSTAT_TYPE_CLASS_STRING; return READSTAT_TYPE_CLASS_NUMERIC; } readstat_type_t readstat_value_type(readstat_value_t value) { return value.type; } readstat_type_class_t readstat_value_type_class(readstat_value_t value) { return readstat_type_class(value.type); } char readstat_value_tag(readstat_value_t value) { return value.tag; } int readstat_value_is_missing(readstat_value_t value, readstat_variable_t *variable) { if (value.is_system_missing || value.is_tagged_missing) return 1; if (variable) return readstat_value_is_defined_missing(value, variable); return 0; } int readstat_value_is_system_missing(readstat_value_t value) { return (value.is_system_missing); } int readstat_value_is_tagged_missing(readstat_value_t value) { return (value.is_tagged_missing); } static int readstat_double_is_defined_missing(double fp_value, readstat_variable_t *variable) { int count = readstat_variable_get_missing_ranges_count(variable); int i; for (i=0; i= lo && fp_value <= hi) { return 1; } } return 0; } static int readstat_string_is_defined_missing(const char *string, readstat_variable_t *variable) { if (string == NULL) return 0; int count = readstat_variable_get_missing_ranges_count(variable); int i; for (i=0; i= 0 && strcmp(string, hi) <= 0) { return 1; } } return 0; } int readstat_value_is_defined_missing(readstat_value_t value, readstat_variable_t *variable) { if (readstat_value_type_class(value) != readstat_variable_get_type_class(variable)) return 0; if (readstat_value_type_class(value) == READSTAT_TYPE_CLASS_STRING) return readstat_string_is_defined_missing(readstat_string_value(value), variable); if (readstat_value_type_class(value) == READSTAT_TYPE_CLASS_NUMERIC) return readstat_double_is_defined_missing(readstat_double_value(value), variable); return 0; } char readstat_int8_value(readstat_value_t value) { if (readstat_value_is_system_missing(value)) return 0; if (value.type == READSTAT_TYPE_DOUBLE) return (char)value.v.double_value; if (value.type == READSTAT_TYPE_FLOAT) return (char)value.v.float_value; if (value.type == READSTAT_TYPE_INT32) return (char)value.v.i32_value; if (value.type == READSTAT_TYPE_INT16) return (char)value.v.i16_value; if (value.type == READSTAT_TYPE_INT8) return value.v.i8_value; return 0; } int16_t readstat_int16_value(readstat_value_t value) { if (readstat_value_is_system_missing(value)) return 0; if (value.type == READSTAT_TYPE_DOUBLE) return (int16_t)value.v.double_value; if (value.type == READSTAT_TYPE_FLOAT) return (int16_t)value.v.float_value; if (value.type == READSTAT_TYPE_INT32) return (int16_t)value.v.i32_value; if (value.type == READSTAT_TYPE_INT16) return value.v.i16_value; if (value.type == READSTAT_TYPE_INT8) return value.v.i8_value; return 0; } int32_t readstat_int32_value(readstat_value_t value) { if (readstat_value_is_system_missing(value)) return 0; if (value.type == READSTAT_TYPE_DOUBLE) return (int32_t)value.v.double_value; if (value.type == READSTAT_TYPE_FLOAT) return (int32_t)value.v.float_value; if (value.type == READSTAT_TYPE_INT32) return value.v.i32_value; if (value.type == READSTAT_TYPE_INT16) return value.v.i16_value; if (value.type == READSTAT_TYPE_INT8) return value.v.i8_value; return 0; } float readstat_float_value(readstat_value_t value) { if (readstat_value_is_system_missing(value)) return NAN; if (value.type == READSTAT_TYPE_DOUBLE) return (float)value.v.double_value; if (value.type == READSTAT_TYPE_FLOAT) return value.v.float_value; if (value.type == READSTAT_TYPE_INT32) return value.v.i32_value; if (value.type == READSTAT_TYPE_INT16) return value.v.i16_value; if (value.type == READSTAT_TYPE_INT8) return value.v.i8_value; return value.v.float_value; } double readstat_double_value(readstat_value_t value) { if (readstat_value_is_system_missing(value)) return NAN; if (value.type == READSTAT_TYPE_DOUBLE) return value.v.double_value; if (value.type == READSTAT_TYPE_FLOAT) return value.v.float_value; if (value.type == READSTAT_TYPE_INT32) return value.v.i32_value; if (value.type == READSTAT_TYPE_INT16) return value.v.i16_value; if (value.type == READSTAT_TYPE_INT8) return value.v.i8_value; return NAN; } const char *readstat_string_value(readstat_value_t value) { if (readstat_value_type(value) == READSTAT_TYPE_STRING) return value.v.string_value; return NULL; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748268530.0 pyreadstat-1.3.3/src/readstat_variable.c0000644000076500000240000001070515015072762016655 0ustar00dialout #include #include "readstat.h" static readstat_value_t make_blank_value(void); static readstat_value_t make_double_value(double dval); static readstat_value_t make_blank_value(void) { readstat_value_t value = { .is_system_missing = 1, .v = { .double_value = NAN }, .type = READSTAT_TYPE_DOUBLE }; return value; } static readstat_value_t make_double_value(double dval) { readstat_value_t value = { .v = { .double_value = dval }, .type = READSTAT_TYPE_DOUBLE }; return value; } static readstat_value_t make_string_value(const char *string) { readstat_value_t value = { .v = { .string_value = string }, .type = READSTAT_TYPE_STRING }; return value; } const char *readstat_variable_get_name(const readstat_variable_t *variable) { if (variable->name[0]) return variable->name; return NULL; } const char *readstat_variable_get_label(const readstat_variable_t *variable) { if (variable->label[0]) return variable->label; return NULL; } const char *readstat_variable_get_format(const readstat_variable_t *variable) { if (variable->format[0]) return variable->format; return NULL; } readstat_type_t readstat_variable_get_type(const readstat_variable_t *variable) { return variable->type; } readstat_type_class_t readstat_variable_get_type_class(const readstat_variable_t *variable) { return readstat_type_class(variable->type); } int readstat_variable_get_index(const readstat_variable_t *variable) { return variable->index; } int readstat_variable_get_index_after_skipping(const readstat_variable_t *variable) { return variable->index_after_skipping; } size_t readstat_variable_get_storage_width(const readstat_variable_t *variable) { return variable->storage_width; } readstat_measure_t readstat_variable_get_measure(const readstat_variable_t *variable) { return variable->measure; } readstat_alignment_t readstat_variable_get_alignment(const readstat_variable_t *variable) { return variable->alignment; } int readstat_variable_get_display_width(const readstat_variable_t *variable) { return variable->display_width; } int readstat_variable_get_missing_ranges_count(const readstat_variable_t *variable) { return variable->missingness.missing_ranges_count; } readstat_value_t readstat_variable_get_missing_range_lo(const readstat_variable_t *variable, int i) { if (i < variable->missingness.missing_ranges_count && 2*i+1 < sizeof(variable->missingness.missing_ranges)/sizeof(variable->missingness.missing_ranges[0])) { return variable->missingness.missing_ranges[2*i]; } return make_blank_value(); } readstat_value_t readstat_variable_get_missing_range_hi(const readstat_variable_t *variable, int i) { if (i < variable->missingness.missing_ranges_count && 2*i+1 < sizeof(variable->missingness.missing_ranges)/sizeof(variable->missingness.missing_ranges[0])) { return variable->missingness.missing_ranges[2*i+1]; } return make_blank_value(); } static readstat_error_t readstat_variable_add_missing_value_range(readstat_variable_t *variable, readstat_value_t lo, readstat_value_t hi) { int i = readstat_variable_get_missing_ranges_count(variable); if (2*i < sizeof(variable->missingness.missing_ranges)/sizeof(variable->missingness.missing_ranges[0])) { variable->missingness.missing_ranges[2*i] = lo; variable->missingness.missing_ranges[2*i+1] = hi; variable->missingness.missing_ranges_count++; return READSTAT_OK; } return READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS; } readstat_error_t readstat_variable_add_missing_double_range(readstat_variable_t *variable, double lo, double hi) { return readstat_variable_add_missing_value_range(variable, make_double_value(lo), make_double_value(hi)); } readstat_error_t readstat_variable_add_missing_double_value(readstat_variable_t *variable, double value) { return readstat_variable_add_missing_value_range(variable, make_double_value(value), make_double_value(value)); } readstat_error_t readstat_variable_add_missing_string_range(readstat_variable_t *variable, const char *lo, const char *hi) { return readstat_variable_add_missing_value_range(variable, make_string_value(lo), make_string_value(hi)); } readstat_error_t readstat_variable_add_missing_string_value(readstat_variable_t *variable, const char *value) { return readstat_variable_add_missing_value_range(variable, make_string_value(value), make_string_value(value)); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748268530.0 pyreadstat-1.3.3/src/readstat_writer.c0000644000076500000240000006070115015072762016405 0ustar00dialout #include #include #include "readstat.h" #include "readstat_writer.h" #define VARIABLES_INITIAL_CAPACITY 50 #define LABEL_SETS_INITIAL_CAPACITY 50 #define NOTES_INITIAL_CAPACITY 50 #define VALUE_LABELS_INITIAL_CAPACITY 10 #define STRING_REFS_INITIAL_CAPACITY 100 #define LABEL_SET_VARIABLES_INITIAL_CAPACITY 2 static readstat_error_t readstat_write_row_default_callback(void *writer_ctx, void *bytes, size_t len) { return readstat_write_bytes((readstat_writer_t *)writer_ctx, bytes, len); } static int readstat_compare_string_refs(const void *elem1, const void *elem2) { readstat_string_ref_t *ref1 = *(readstat_string_ref_t **)elem1; readstat_string_ref_t *ref2 = *(readstat_string_ref_t **)elem2; if (ref1->first_o == ref2->first_o) return ref1->first_v - ref2->first_v; return ref1->first_o - ref2->first_o; } readstat_string_ref_t *readstat_string_ref_init(const char *string) { size_t len = strlen(string) + 1; readstat_string_ref_t *ref = calloc(1, sizeof(readstat_string_ref_t) + len); ref->first_o = -1; ref->first_v = -1; ref->len = len; memcpy(&ref->data[0], string, len); return ref; } readstat_writer_t *readstat_writer_init(void) { readstat_writer_t *writer = calloc(1, sizeof(readstat_writer_t)); writer->variables = calloc(VARIABLES_INITIAL_CAPACITY, sizeof(readstat_variable_t *)); writer->variables_capacity = VARIABLES_INITIAL_CAPACITY; writer->label_sets = calloc(LABEL_SETS_INITIAL_CAPACITY, sizeof(readstat_label_set_t *)); writer->label_sets_capacity = LABEL_SETS_INITIAL_CAPACITY; writer->notes = calloc(NOTES_INITIAL_CAPACITY, sizeof(char *)); writer->notes_capacity = NOTES_INITIAL_CAPACITY; writer->string_refs = calloc(STRING_REFS_INITIAL_CAPACITY, sizeof(readstat_string_ref_t *)); writer->string_refs_capacity = STRING_REFS_INITIAL_CAPACITY; writer->timestamp = time(NULL); writer->is_64bit = 1; writer->callbacks.write_row = &readstat_write_row_default_callback; return writer; } static void readstat_variable_free(readstat_variable_t *variable) { free(variable); } static void readstat_label_set_free(readstat_label_set_t *label_set) { int i; for (i=0; ivalue_labels_count; i++) { readstat_value_label_t *value_label = readstat_get_value_label(label_set, i); if (value_label->label) free(value_label->label); if (value_label->string_key) free(value_label->string_key); } free(label_set->value_labels); free(label_set->variables); free(label_set); } static void readstat_copy_label(readstat_value_label_t *value_label, const char *label) { if (label && strlen(label)) { value_label->label_len = strlen(label); value_label->label = malloc(value_label->label_len); memcpy(value_label->label, label, value_label->label_len); } } static readstat_value_label_t *readstat_add_value_label(readstat_label_set_t *label_set, const char *label) { if (label_set->value_labels_count == label_set->value_labels_capacity) { label_set->value_labels_capacity *= 2; label_set->value_labels = realloc(label_set->value_labels, label_set->value_labels_capacity * sizeof(readstat_value_label_t)); } readstat_value_label_t *new_value_label = &label_set->value_labels[label_set->value_labels_count++]; memset(new_value_label, 0, sizeof(readstat_value_label_t)); readstat_copy_label(new_value_label, label); return new_value_label; } readstat_error_t readstat_validate_variable(readstat_writer_t *writer, const readstat_variable_t *variable) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (writer->callbacks.variable_ok) return writer->callbacks.variable_ok(variable); return READSTAT_OK; } readstat_error_t readstat_validate_metadata(readstat_writer_t *writer) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (writer->callbacks.metadata_ok) return writer->callbacks.metadata_ok(writer); return READSTAT_OK; } static readstat_error_t readstat_begin_writing_data(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; size_t row_len = 0; int i; retval = readstat_validate_metadata(writer); if (retval != READSTAT_OK) goto cleanup; for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); variable->storage_width = writer->callbacks.variable_width(variable->type, variable->user_width); variable->offset = row_len; row_len += variable->storage_width; } if (writer->callbacks.variable_ok) { for (i=0; ivariables_count; i++) { retval = readstat_validate_variable(writer, readstat_get_variable(writer, i)); if (retval != READSTAT_OK) goto cleanup; } } writer->row_len = row_len; writer->row = malloc(writer->row_len); if (writer->callbacks.begin_data) { retval = writer->callbacks.begin_data(writer); } cleanup: return retval; } void readstat_writer_free(readstat_writer_t *writer) { int i; if (writer) { if (writer->callbacks.module_ctx_free && writer->module_ctx) { writer->callbacks.module_ctx_free(writer->module_ctx); } if (writer->variables) { for (i=0; ivariables_count; i++) { readstat_variable_free(writer->variables[i]); } free(writer->variables); } if (writer->label_sets) { for (i=0; ilabel_sets_count; i++) { readstat_label_set_free(writer->label_sets[i]); } free(writer->label_sets); } if (writer->notes) { for (i=0; inotes_count; i++) { free(writer->notes[i]); } free(writer->notes); } if (writer->string_refs) { for (i=0; istring_refs_count; i++) { free(writer->string_refs[i]); } free(writer->string_refs); } if (writer->row) { free(writer->row); } free(writer); } } readstat_error_t readstat_set_data_writer(readstat_writer_t *writer, readstat_data_writer data_writer) { writer->data_writer = data_writer; return READSTAT_OK; } readstat_error_t readstat_write_bytes(readstat_writer_t *writer, const void *bytes, size_t len) { size_t bytes_written = writer->data_writer(bytes, len, writer->user_ctx); if (bytes_written < len) { return READSTAT_ERROR_WRITE; } writer->bytes_written += bytes_written; return READSTAT_OK; } readstat_error_t readstat_write_bytes_as_lines(readstat_writer_t *writer, const void *bytes, size_t len, size_t line_len, const char *line_sep) { size_t line_sep_len = strlen(line_sep); readstat_error_t retval = READSTAT_OK; size_t bytes_written = 0; while (bytes_written < len) { ssize_t bytes_left_in_line = line_len - (writer->bytes_written % (line_len + line_sep_len)); if (len - bytes_written < bytes_left_in_line) { retval = readstat_write_bytes(writer, ((const char *)bytes) + bytes_written, len - bytes_written); bytes_written = len; } else { retval = readstat_write_bytes(writer, ((const char *)bytes) + bytes_written, bytes_left_in_line); bytes_written += bytes_left_in_line; } if (retval != READSTAT_OK) break; if (writer->bytes_written % (line_len + line_sep_len) == line_len) { if ((retval = readstat_write_bytes(writer, line_sep, line_sep_len)) != READSTAT_OK) break; } } return retval; } readstat_error_t readstat_write_line_padding(readstat_writer_t *writer, char pad, size_t line_len, const char *line_sep) { size_t line_sep_len = strlen(line_sep); if (writer->bytes_written % (line_len + line_sep_len) == 0) return READSTAT_OK; readstat_error_t error = READSTAT_OK; ssize_t bytes_left_in_line = line_len - (writer->bytes_written % (line_len + line_sep_len)); char *bytes = malloc(bytes_left_in_line); memset(bytes, pad, bytes_left_in_line); if ((error = readstat_write_bytes(writer, bytes, bytes_left_in_line)) != READSTAT_OK) goto cleanup; if ((error = readstat_write_bytes(writer, line_sep, line_sep_len)) != READSTAT_OK) goto cleanup; cleanup: if (bytes) free(bytes); return READSTAT_OK; } readstat_error_t readstat_write_string(readstat_writer_t *writer, const char *bytes) { return readstat_write_bytes(writer, bytes, strlen(bytes)); } static readstat_error_t readstat_write_repeated_byte(readstat_writer_t *writer, char byte, size_t len) { if (len == 0) return READSTAT_OK; char *zeros = malloc(len); memset(zeros, byte, len); readstat_error_t error = readstat_write_bytes(writer, zeros, len); free(zeros); return error; } readstat_error_t readstat_write_zeros(readstat_writer_t *writer, size_t len) { return readstat_write_repeated_byte(writer, '\0', len); } readstat_error_t readstat_write_spaces(readstat_writer_t *writer, size_t len) { return readstat_write_repeated_byte(writer, ' ', len); } readstat_error_t readstat_write_space_padded_string(readstat_writer_t *writer, const char *string, size_t max_len) { readstat_error_t retval = READSTAT_OK; if (string == NULL || string[0] == '\0') return readstat_write_spaces(writer, max_len); size_t len = strlen(string); if (len > max_len) len = max_len; if ((retval = readstat_write_bytes(writer, string, len)) != READSTAT_OK) return retval; return readstat_write_spaces(writer, max_len - len); } readstat_label_set_t *readstat_add_label_set(readstat_writer_t *writer, readstat_type_t type, const char *name) { if (writer->label_sets_count == writer->label_sets_capacity) { writer->label_sets_capacity *= 2; writer->label_sets = realloc(writer->label_sets, writer->label_sets_capacity * sizeof(readstat_label_set_t *)); } readstat_label_set_t *new_label_set = calloc(1, sizeof(readstat_label_set_t)); writer->label_sets[writer->label_sets_count++] = new_label_set; new_label_set->type = type; snprintf(new_label_set->name, sizeof(new_label_set->name), "%s", name); new_label_set->value_labels = calloc(VALUE_LABELS_INITIAL_CAPACITY, sizeof(readstat_value_label_t)); new_label_set->value_labels_capacity = VALUE_LABELS_INITIAL_CAPACITY; new_label_set->variables = calloc(LABEL_SET_VARIABLES_INITIAL_CAPACITY, sizeof(readstat_variable_t *)); new_label_set->variables_capacity = LABEL_SET_VARIABLES_INITIAL_CAPACITY; return new_label_set; } readstat_label_set_t *readstat_get_label_set(readstat_writer_t *writer, int index) { if (index < writer->label_sets_count) { return writer->label_sets[index]; } return NULL; } void readstat_sort_label_set(readstat_label_set_t *label_set, int (*compare)(const readstat_value_label_t *, const readstat_value_label_t *)) { qsort(label_set->value_labels, label_set->value_labels_count, sizeof(readstat_value_label_t), (int (*)(const void *, const void *))compare); } readstat_value_label_t *readstat_get_value_label(readstat_label_set_t *label_set, int index) { if (index < label_set->value_labels_count) { return &label_set->value_labels[index]; } return NULL; } readstat_variable_t *readstat_get_label_set_variable(readstat_label_set_t *label_set, int index) { if (index < label_set->variables_count) { return ((readstat_variable_t **)label_set->variables)[index]; } return NULL; } void readstat_label_double_value(readstat_label_set_t *label_set, double value, const char *label) { readstat_value_label_t *new_value_label = readstat_add_value_label(label_set, label); new_value_label->double_key = value; new_value_label->int32_key = value; } void readstat_label_int32_value(readstat_label_set_t *label_set, int32_t value, const char *label) { readstat_value_label_t *new_value_label = readstat_add_value_label(label_set, label); new_value_label->double_key = value; new_value_label->int32_key = value; } void readstat_label_string_value(readstat_label_set_t *label_set, const char *value, const char *label) { readstat_value_label_t *new_value_label = readstat_add_value_label(label_set, label); if (value && strlen(value)) { new_value_label->string_key_len = strlen(value); new_value_label->string_key = malloc(new_value_label->string_key_len); memcpy(new_value_label->string_key, value, new_value_label->string_key_len); } } void readstat_label_tagged_value(readstat_label_set_t *label_set, char tag, const char *label) { readstat_value_label_t *new_value_label = readstat_add_value_label(label_set, label); new_value_label->tag = tag; } readstat_variable_t *readstat_add_variable(readstat_writer_t *writer, const char *name, readstat_type_t type, size_t width) { if (writer->variables_count == writer->variables_capacity) { writer->variables_capacity *= 2; writer->variables = realloc(writer->variables, writer->variables_capacity * sizeof(readstat_variable_t *)); } readstat_variable_t *new_variable = calloc(1, sizeof(readstat_variable_t)); new_variable->index = writer->variables_count++; writer->variables[new_variable->index] = new_variable; new_variable->user_width = width; new_variable->type = type; if (readstat_variable_get_type_class(new_variable) == READSTAT_TYPE_CLASS_STRING) { new_variable->alignment = READSTAT_ALIGNMENT_LEFT; } else { new_variable->alignment = READSTAT_ALIGNMENT_RIGHT; } new_variable->measure = READSTAT_MEASURE_UNKNOWN; if (name) { snprintf(new_variable->name, sizeof(new_variable->name), "%s", name); } return new_variable; } static void readstat_append_string_ref(readstat_writer_t *writer, readstat_string_ref_t *ref) { if (writer->string_refs_count == writer->string_refs_capacity) { writer->string_refs_capacity *= 2; writer->string_refs = realloc(writer->string_refs, writer->string_refs_capacity * sizeof(readstat_string_ref_t *)); } writer->string_refs[writer->string_refs_count++] = ref; } readstat_string_ref_t *readstat_add_string_ref(readstat_writer_t *writer, const char *string) { readstat_string_ref_t *ref = readstat_string_ref_init(string); readstat_append_string_ref(writer, ref); return ref; } void readstat_add_note(readstat_writer_t *writer, const char *note) { if (writer->notes_count == writer->notes_capacity) { writer->notes_capacity *= 2; writer->notes = realloc(writer->notes, writer->notes_capacity * sizeof(const char *)); } char *note_copy = malloc(strlen(note) + 1); strcpy(note_copy, note); writer->notes[writer->notes_count++] = note_copy; } void readstat_variable_set_label(readstat_variable_t *variable, const char *label) { if (label) { snprintf(variable->label, sizeof(variable->label), "%s", label); } else { memset(variable->label, '\0', sizeof(variable->label)); } } void readstat_variable_set_format(readstat_variable_t *variable, const char *format) { if (format) { snprintf(variable->format, sizeof(variable->format), "%s", format); } else { memset(variable->format, '\0', sizeof(variable->format)); } } void readstat_variable_set_measure(readstat_variable_t *variable, readstat_measure_t measure) { variable->measure = measure; } void readstat_variable_set_alignment(readstat_variable_t *variable, readstat_alignment_t alignment) { variable->alignment = alignment; } void readstat_variable_set_display_width(readstat_variable_t *variable, int display_width) { variable->display_width = display_width; } void readstat_variable_set_label_set(readstat_variable_t *variable, readstat_label_set_t *label_set) { variable->label_set = label_set; if (label_set) { if (label_set->variables_count == label_set->variables_capacity) { label_set->variables_capacity *= 2; label_set->variables = realloc(label_set->variables, label_set->variables_capacity * sizeof(readstat_variable_t *)); } ((readstat_variable_t **)label_set->variables)[label_set->variables_count++] = variable; } } readstat_variable_t *readstat_get_variable(readstat_writer_t *writer, int index) { if (index < writer->variables_count) { return writer->variables[index]; } return NULL; } readstat_string_ref_t *readstat_get_string_ref(readstat_writer_t *writer, int index) { if (index < writer->string_refs_count) { return writer->string_refs[index]; } return NULL; } readstat_error_t readstat_writer_set_file_label(readstat_writer_t *writer, const char *file_label) { snprintf(writer->file_label, sizeof(writer->file_label), "%s", file_label); return READSTAT_OK; } readstat_error_t readstat_writer_set_file_timestamp(readstat_writer_t *writer, time_t timestamp) { writer->timestamp = timestamp; return READSTAT_OK; } readstat_error_t readstat_writer_set_table_name(readstat_writer_t *writer, const char *table_name) { snprintf(writer->table_name, sizeof(writer->table_name), "%s", table_name); return READSTAT_OK; } readstat_error_t readstat_writer_set_fweight_variable(readstat_writer_t *writer, const readstat_variable_t *variable) { if (readstat_variable_get_type_class(variable) == READSTAT_TYPE_CLASS_STRING) return READSTAT_ERROR_BAD_FREQUENCY_WEIGHT; writer->fweight_variable = variable; return READSTAT_OK; } readstat_error_t readstat_writer_set_file_format_version(readstat_writer_t *writer, uint8_t version) { writer->version = version; return READSTAT_OK; } readstat_error_t readstat_writer_set_file_format_is_64bit(readstat_writer_t *writer, int is_64bit) { writer->is_64bit = is_64bit; return READSTAT_OK; } readstat_error_t readstat_writer_set_compression(readstat_writer_t *writer, readstat_compress_t compression) { writer->compression = compression; return READSTAT_OK; } readstat_error_t readstat_writer_set_error_handler(readstat_writer_t *writer, readstat_error_handler error_handler) { writer->error_handler = error_handler; return READSTAT_OK; } readstat_error_t readstat_begin_writing_file(readstat_writer_t *writer, void *user_ctx, long row_count) { writer->row_count = row_count; writer->user_ctx = user_ctx; writer->initialized = 1; return readstat_validate_metadata(writer); } readstat_error_t readstat_begin_row(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (writer->current_row == 0) retval = readstat_begin_writing_data(writer); memset(writer->row, '\0', writer->row_len); return retval; } // Then call one of these for each variable readstat_error_t readstat_insert_int8_value(readstat_writer_t *writer, const readstat_variable_t *variable, int8_t value) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_INT8) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; return writer->callbacks.write_int8(&writer->row[variable->offset], variable, value); } readstat_error_t readstat_insert_int16_value(readstat_writer_t *writer, const readstat_variable_t *variable, int16_t value) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_INT16) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; return writer->callbacks.write_int16(&writer->row[variable->offset], variable, value); } readstat_error_t readstat_insert_int32_value(readstat_writer_t *writer, const readstat_variable_t *variable, int32_t value) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_INT32) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; return writer->callbacks.write_int32(&writer->row[variable->offset], variable, value); } readstat_error_t readstat_insert_float_value(readstat_writer_t *writer, const readstat_variable_t *variable, float value) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_FLOAT) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; return writer->callbacks.write_float(&writer->row[variable->offset], variable, value); } readstat_error_t readstat_insert_double_value(readstat_writer_t *writer, const readstat_variable_t *variable, double value) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_DOUBLE) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; return writer->callbacks.write_double(&writer->row[variable->offset], variable, value); } readstat_error_t readstat_insert_string_value(readstat_writer_t *writer, const readstat_variable_t *variable, const char *value) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_STRING) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; return writer->callbacks.write_string(&writer->row[variable->offset], variable, value); } readstat_error_t readstat_insert_string_ref(readstat_writer_t *writer, const readstat_variable_t *variable, readstat_string_ref_t *ref) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type != READSTAT_TYPE_STRING_REF) return READSTAT_ERROR_VALUE_TYPE_MISMATCH; if (!writer->callbacks.write_string_ref) return READSTAT_ERROR_STRING_REFS_NOT_SUPPORTED; if (ref && ref->first_o == -1 && ref->first_v == -1) { ref->first_o = writer->current_row + 1; ref->first_v = variable->index + 1; } return writer->callbacks.write_string_ref(&writer->row[variable->offset], variable, ref); } readstat_error_t readstat_insert_missing_value(readstat_writer_t *writer, const readstat_variable_t *variable) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (variable->type == READSTAT_TYPE_STRING) { return writer->callbacks.write_missing_string(&writer->row[variable->offset], variable); } if (variable->type == READSTAT_TYPE_STRING_REF) { return readstat_insert_string_ref(writer, variable, NULL); } return writer->callbacks.write_missing_number(&writer->row[variable->offset], variable); } readstat_error_t readstat_insert_tagged_missing_value(readstat_writer_t *writer, const readstat_variable_t *variable, char tag) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (!writer->callbacks.write_missing_tagged) { /* Write out a missing number but return an error */ writer->callbacks.write_missing_number(&writer->row[variable->offset], variable); return READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED; } return writer->callbacks.write_missing_tagged(&writer->row[variable->offset], variable, tag); } readstat_error_t readstat_end_row(readstat_writer_t *writer) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; readstat_error_t error = writer->callbacks.write_row(writer, writer->row, writer->row_len); if (error == READSTAT_OK) writer->current_row++; return error; } readstat_error_t readstat_end_writing(readstat_writer_t *writer) { if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; if (writer->current_row != writer->row_count) return READSTAT_ERROR_ROW_COUNT_MISMATCH; if (writer->row_count == 0) { readstat_error_t retval = readstat_begin_writing_data(writer); if (retval != READSTAT_OK) return retval; } /* Sort if out of order */ int i; for (i=1; istring_refs_count; i++) { if (readstat_compare_string_refs(&writer->string_refs[i-1], &writer->string_refs[i]) > 0) { qsort(writer->string_refs, writer->string_refs_count, sizeof(readstat_string_ref_t *), &readstat_compare_string_refs); break; } } if (!writer->callbacks.end_data) return READSTAT_OK; return writer->callbacks.end_data(writer); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/readstat_writer.h0000644000076500000240000000256614674240614016422 0ustar00dialout #define READSTAT_PRODUCT_NAME "ReadStat" #define READSTAT_PRODUCT_URL "https://github.com/WizardMac/ReadStat" readstat_error_t readstat_begin_writing_file(readstat_writer_t *writer, void *user_ctx, long row_count); readstat_error_t readstat_write_bytes(readstat_writer_t *writer, const void *bytes, size_t len); readstat_error_t readstat_write_bytes_as_lines(readstat_writer_t *writer, const void *bytes, size_t len, size_t line_len, const char *line_sep); readstat_error_t readstat_write_line_padding(readstat_writer_t *writer, char pad, size_t line_len, const char *line_sep); readstat_error_t readstat_write_zeros(readstat_writer_t *writer, size_t len); readstat_error_t readstat_write_spaces(readstat_writer_t *writer, size_t len); readstat_error_t readstat_write_string(readstat_writer_t *writer, const char *bytes); readstat_error_t readstat_write_space_padded_string(readstat_writer_t *writer, const char *string, size_t max_len); readstat_value_label_t *readstat_get_value_label(readstat_label_set_t *label_set, int index); readstat_label_set_t *readstat_get_label_set(readstat_writer_t *writer, int index); readstat_variable_t *readstat_get_label_set_variable(readstat_label_set_t *label_set, int index); void readstat_sort_label_set(readstat_label_set_t *label_set, int (*compare)(const readstat_value_label_t *, const readstat_value_label_t *)); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/src/sas/0000755000076500000240000000000015134706453013623 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/ieee.c0000644000076500000240000003434714674240614014711 0ustar00dialout#include #include #include "ieee.h" #include "../readstat_bits.h" /* These routines are modified versions of those found in SAS publication TS-140, * "RECORD LAYOUT OF A SAS VERSION 5 OR 6 DATA SET IN SAS TRANSPORT (XPORT) FORMAT" * https://support.sas.com/techsup/technote/ts140.pdf * * Modifications include using stdint.h and supporting infinite IEEE values. */ static void xpt2ieee(unsigned char *xport, unsigned char *ieee); static void ieee2xpt(unsigned char *ieee, unsigned char *xport); #ifndef FLOATREP #define FLOATREP get_native() int get_native(void); #endif void memreverse(void *intp_void, int l) { if (!machine_is_little_endian()) return; int i,j; char save; char *intp = (char *)intp_void; j = l/2; for (i=0;i=0;i--) { temp[7-i] = from[i]; } from = temp; fromtype = CN_TYPE_IEEEB; /* Break intentionally omitted. */ case CN_TYPE_IEEEB : /* Break intentionally omitted. */ case CN_TYPE_XPORT : break; default: return(-1); } if (totype == CN_TYPE_NATIVE) { totype = FLOATREP; } switch(totype) { case CN_TYPE_XPORT : case CN_TYPE_IEEEB : case CN_TYPE_IEEEL : break; default: return(-2); } if (fromtype == totype) { memcpy(to,from,8); return(0); } switch(fromtype) { case CN_TYPE_IEEEB : if (totype == CN_TYPE_XPORT) ieee2xpt(from,to); else memcpy(to,from,8); break; case CN_TYPE_XPORT : xpt2ieee(from,to); break; } if (totype == CN_TYPE_IEEEL) { memcpy(temp,to,8); for (i=7;i>=0;i--) { to[7-i] = temp[i]; } } return(0); } int get_native(void) { static unsigned char float_reps[][8] = { {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00}, {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f} }; static double one = 1.00; int i,j; j = sizeof(float_reps)/8; for (i=0;i>= shift; ieee2 = (xport2 >> shift) | ((xport1 & 0x00000007) << (29 + (3 - shift))); } /* clear the 1 bit to the left of the binary point */ ieee1 &= 0xffefffff; /* set the exponent of the ieee number to be the actual */ /* exponent plus the shift count + 1023. Or this into the */ /* first half of the ieee number. The ibm exponent is excess */ /* 64 but is adjusted by 65 since during conversion to ibm */ /* format the exponent is incremented by 1 and the fraction */ /* bits left 4 positions to the right of the radix point. */ ieee1 |= (((((int32_t)(*temp & 0x7f) - 65) * 4) + shift + 1023) << 20) | (xport1 & 0x80000000); doret: memreverse(&ieee1,sizeof(uint32_t)); memcpy(ieee,&ieee1,sizeof(uint32_t)); memreverse(&ieee2,sizeof(uint32_t)); memcpy(ieee+4,&ieee2,sizeof(uint32_t)); return; } /*-------------------------------------------------------------*/ /* Name: ieee2xpt */ /* Purpose: converts IEEE to transport */ /* Usage: rc = ieee2xpt(to_ieee,p_data); */ /* Notes: this routine is an adaptation of the wzctdbl routine */ /* from the Apollo. */ /*-------------------------------------------------------------*/ void ieee2xpt(unsigned char *ieee, unsigned char *xport) { register int shift; unsigned char misschar; int ieee_exp; uint32_t xport1,xport2; uint32_t ieee1 = 0; uint32_t ieee2 = 0; char ieee8[8]; memcpy(ieee8,ieee,8); /*------get 2 longs for shifting------------------------------*/ memcpy(&ieee1,ieee8,sizeof(uint32_t)); memreverse(&ieee1,sizeof(uint32_t)); memcpy(&ieee2,ieee8+4,sizeof(uint32_t)); memreverse(&ieee2,sizeof(uint32_t)); memset(xport,0,8); /*-----if IEEE value is missing (1st 2 bytes are FFFF)-----*/ if (*ieee8 == (char)0xff && ieee8[1] == (char)0xff) { misschar = ~ieee8[2]; *xport = (misschar == 0xD2) ? 0x6D : misschar; return; } /**************************************************************/ /* Translate IEEE floating point number into IBM format float */ /* */ /* IEEE format: */ /* */ /* 6 5 0 */ /* 3 1 0 */ /* */ /* SEEEEEEEEEEEMMMM ........ MMMM */ /* */ /* Sign bit, 11 bit exponent, 52 fraction. Exponent is excess */ /* 1023. The fraction is multiplied by a power of 2 of the */ /* actual exponent. Normalized floating point numbers are */ /* represented with the binary point immediately to the left */ /* of the fraction with an implied "1" to the left of the */ /* binary point. */ /* */ /* IBM format: */ /* */ /* 6 5 0 */ /* 3 5 0 */ /* */ /* SEEEEEEEMMMM ......... MMMM */ /* */ /* Sign bit, 7 bit exponent, 56 bit fraction. Exponent is */ /* excess 64. The fraction is multiplied by a power of 16 of */ /* of the actual exponent. Normalized floating point numbers */ /* are presented with the radix point immediately to the left */ /* of the high order hex fraction digit. */ /* */ /* How do you translate from local to IBM format? */ /* */ /* The ieee format gives you a number that has a power of 2 */ /* exponent and a fraction of the form "1.". */ /* The first step is to get that "1" bit back into the */ /* fraction. Right shift it down 1 position, set the high */ /* order bit and reduce the binary exponent by 1. Now we have */ /* a fraction that looks like ".1" and it's */ /* ready to be shoved into ibm format. The ibm fraction has 4 */ /* more bits than the ieee, the ieee fraction must therefore */ /* be shifted left 4 positions before moving it in. We must */ /* also correct the fraction bits to account for the loss of 2*/ /* bits when converting from a binary exponent to a hex one */ /* (>> 2). We must shift the fraction left for 0, 1, 2, or 3 */ /* positions to maintain the proper magnitude. Doing */ /* conversion this way would tend to lose bits in the fraction*/ /* which is not desirable or necessary if we cheat a bit. */ /* First of all, we know that we are going to have to shift */ /* the ieee fraction left 4 places to put it in the right */ /* position; we won't do that, we'll just leave it where it is*/ /* and increment the ibm exponent by one, this will have the */ /* same effect and we won't have to do any shifting. Now, */ /* since we have 4 bits in front of the fraction to work with,*/ /* we won't lose any bits. We set the bit to the left of the */ /* fraction which is the implicit "1" in the ieee fraction. We*/ /* then adjust the fraction to account for the loss of bits */ /* when going to a hex exponent. This adjustment will never */ /* involve shifting by more than 3 positions so no bits are */ /* lost. */ /* Get ieee number less the exponent into the first half of */ /* the ibm number */ xport1 = ieee1 & 0x000fffff; /* get the second half of the number into the second half of */ /* the ibm number and see if both halves are 0. If so, ibm is */ /* also 0 and we just return */ if ((!(xport2 = ieee2)) && !ieee1) { ieee_exp = 0; goto doret; } /* get the actual exponent value out of the ieee number. The */ /* ibm fraction is a power of 16 and the ieee fraction a power*/ /* of 2 (16 ** n == 2 ** 4n). Save the low order 2 bits since */ /* they will get lost when we divide the exponent by 4 (right */ /* shift by 2) and we will have to shift the fraction by the */ /* appropriate number of bits to keep the proper magnitude. */ shift = (int) (ieee_exp = (int)(((ieee1 >> 16) & 0x7ff0) >> 4) - 1023) & 3; /* the ieee format has an implied "1" immediately to the left */ /* of the binary point. Show it in here. */ xport1 |= 0x00100000; if (shift) { /* set the first half of the ibm number by shifting it left */ /* the appropriate number of bits and oring in the bits */ /* from the lower half that would have been shifted in (if */ /* we could shift a double). The shift count can never */ /* exceed 3, so all we care about are the high order 3 */ /* bits. We don't want sign extension so make sure it's an */ /* unsigned char. We'll shift either5, 6, or 7 places to */ /* keep 3, 2, or 1 bits. After that, shift the second half */ /* of the number the right number of places. We always get */ /* zero fill on left shifts. */ xport1 = (xport1 << shift) | ((unsigned char) (((ieee2 >> 24) & 0xE0) >> (5 + (3 - shift)))); xport2 <<= shift; } /* Now set the ibm exponent and the sign of the fraction. The */ /* power of 2 ieee exponent must be divided by 4 and made */ /* excess 64 (we add 65 here because of the position of the */ /* fraction bits, essentially 4 positions lower than they */ /* should be so we increment the ibm exponent). */ xport1 |= (((ieee_exp >>2) + 65) | ((ieee1 >> 24) & 0x80)) << 24; /* If the ieee exponent is greater than 248 or less than -260, */ /* then it cannot fit in the ibm exponent field. Send back the */ /* appropriate flag. */ doret: if (ieee_exp < -260) { memset(xport,0x00,8); } else if (ieee_exp > 248) { memset(xport+1,0xFF,7); *xport = 0x7F | ((ieee1 >> 24) & 0x80); } else { memreverse(&xport1,sizeof(uint32_t)); memcpy(xport,&xport1,sizeof(uint32_t)); memreverse(&xport2,sizeof(uint32_t)); memcpy(xport+4,&xport2,sizeof(uint32_t)); } return; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/ieee.h0000644000076500000240000000026214674240614014703 0ustar00dialout#define CN_TYPE_NATIVE 0 #define CN_TYPE_XPORT 1 #define CN_TYPE_IEEEB 2 #define CN_TYPE_IEEEL 3 int cnxptiee(const void *from_bytes, int fromtype, void *to_bytes, int totype); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748268535.0 pyreadstat-1.3.3/src/sas/readstat_sas.c0000644000076500000240000004505615015072767016460 0ustar00dialout #include #include #include #include #include #include #include #include #include "readstat_sas.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_writer.h" #define SAS_FILE_HEADER_SIZE_32BIT 1024 #define SAS_FILE_HEADER_SIZE_64BIT 8192 #define SAS_DEFAULT_PAGE_SIZE 4096 #define SAS_DEFAULT_STRING_ENCODING "WINDOWS-1252" unsigned char sas7bdat_magic_number[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0xea, 0x81, 0x60, 0xb3, 0x14, 0x11, 0xcf, 0xbd, 0x92, 0x08, 0x00, 0x09, 0xc7, 0x31, 0x8c, 0x18, 0x1f, 0x10, 0x11 }; unsigned char sas7bcat_magic_number[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0xea, 0x81, 0x63, 0xb3, 0x14, 0x11, 0xcf, 0xbd, 0x92, 0x08, 0x00, 0x09, 0xc7, 0x31, 0x8c, 0x18, 0x1f, 0x10, 0x11 }; /* This table is cobbled together from extant files and: * https://support.sas.com/documentation/cdl/en/nlsref/61893/HTML/default/viewer.htm#a002607278.htm * https://support.sas.com/documentation/onlinedoc/dfdmstudio/2.6/dmpdmsug/Content/dfU_Encodings_SAS.html * * Discrepancies form the official documentation are noted with a comment. It * appears that in some instances that SAS software uses a newer encoding than * what's listed in the docs. In these cases the encoding used by ReadStat * represents the author's best guess. */ static readstat_charset_entry_t _charset_table[] = { { .code = 0, .name = SAS_DEFAULT_STRING_ENCODING }, { .code = 20, .name = "UTF-8" }, { .code = 28, .name = "US-ASCII" }, { .code = 29, .name = "ISO-8859-1" }, { .code = 30, .name = "ISO-8859-2" }, { .code = 31, .name = "ISO-8859-3" }, { .code = 32, .name = "ISO-8859-4" }, { .code = 33, .name = "ISO-8859-5" }, { .code = 34, .name = "ISO-8859-6" }, { .code = 35, .name = "ISO-8859-7" }, { .code = 36, .name = "ISO-8859-8" }, { .code = 37, .name = "ISO-8859-9" }, { .code = 39, .name = "ISO-8859-11" }, { .code = 40, .name = "ISO-8859-15" }, { .code = 41, .name = "CP437" }, { .code = 42, .name = "CP850" }, { .code = 43, .name = "CP852" }, { .code = 44, .name = "CP857" }, { .code = 45, .name = "CP858" }, { .code = 46, .name = "CP862" }, { .code = 47, .name = "CP864" }, { .code = 48, .name = "CP865" }, { .code = 49, .name = "CP866" }, { .code = 50, .name = "CP869" }, { .code = 51, .name = "CP874" }, { .code = 52, .name = "CP921" }, { .code = 53, .name = "CP922" }, { .code = 54, .name = "CP1129" }, { .code = 55, .name = "CP720" }, { .code = 56, .name = "CP737" }, { .code = 57, .name = "CP775" }, { .code = 58, .name = "CP860" }, { .code = 59, .name = "CP863" }, { .code = 60, .name = "WINDOWS-1250" }, { .code = 61, .name = "WINDOWS-1251" }, { .code = 62, .name = "WINDOWS-1252" }, { .code = 63, .name = "WINDOWS-1253" }, { .code = 64, .name = "WINDOWS-1254" }, { .code = 65, .name = "WINDOWS-1255" }, { .code = 66, .name = "WINDOWS-1256" }, { .code = 67, .name = "WINDOWS-1257" }, { .code = 68, .name = "WINDOWS-1258" }, { .code = 69, .name = "MACROMAN" }, { .code = 70, .name = "MACARABIC" }, { .code = 71, .name = "MACHEBREW" }, { .code = 72, .name = "MACGREEK" }, { .code = 73, .name = "MACTHAI" }, { .code = 75, .name = "MACTURKISH" }, { .code = 76, .name = "MACUKRAINE" }, { .code = 118, .name = "CP950" }, { .code = 119, .name = "EUC-TW" }, { .code = 123, .name = "BIG-5" }, { .code = 125, .name = "GB18030" }, // "euc-cn" in SAS { .code = 126, .name = "WINDOWS-936" }, // "zwin" { .code = 128, .name = "CP1381" }, // "zpce" { .code = 134, .name = "EUC-JP" }, { .code = 136, .name = "CP949" }, { .code = 137, .name = "CP942" }, { .code = 138, .name = "CP932" }, // "shift-jis" in SAS { .code = 140, .name = "EUC-KR" }, { .code = 141, .name = "CP949" }, // "kpce" { .code = 142, .name = "CP949" }, // "kwin" { .code = 163, .name = "MACICELAND" }, { .code = 167, .name = "ISO-2022-JP" }, { .code = 168, .name = "ISO-2022-KR" }, { .code = 169, .name = "ISO-2022-CN" }, { .code = 172, .name = "ISO-2022-CN-EXT" }, { .code = 204, .name = SAS_DEFAULT_STRING_ENCODING }, // "any" in SAS { .code = 205, .name = "GB18030" }, { .code = 227, .name = "ISO-8859-14" }, { .code = 242, .name = "ISO-8859-13" }, { .code = 245, .name = "MACCROATIAN" }, { .code = 246, .name = "MACCYRILLIC" }, { .code = 247, .name = "MACROMANIA" }, { .code = 248, .name = "SHIFT_JISX0213" }, }; static time_t sas_epoch(void) { return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970 } static time_t sas_convert_time(double time, double time_diff, time_t epoch) { time -= time_diff; time += epoch; if (isnan(time)) return 0; if (time > (double)LONG_MAX) return LONG_MAX; if (time < (double)LONG_MIN) return LONG_MIN; return time; } uint64_t sas_read8(const char *data, int bswap) { uint64_t tmp; memcpy(&tmp, data, 8); return bswap ? byteswap8(tmp) : tmp; } uint32_t sas_read4(const char *data, int bswap) { uint32_t tmp; memcpy(&tmp, data, 4); return bswap ? byteswap4(tmp) : tmp; } uint16_t sas_read2(const char *data, int bswap) { uint16_t tmp; memcpy(&tmp, data, 2); return bswap ? byteswap2(tmp) : tmp; } size_t sas_subheader_remainder(size_t len, size_t signature_len) { return len - (4+2*signature_len); } readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, readstat_error_handler error_handler, void *user_ctx) { sas_header_start_t header_start; sas_header_end_t header_end; int retval = READSTAT_OK; char error_buf[1024]; time_t epoch = sas_epoch(); if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 && memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) { hinfo->pad1 = 4; } if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) { hinfo->u64 = 1; } int bswap = 0; if (header_start.endian == SAS_ENDIAN_BIG) { bswap = machine_is_little_endian(); hinfo->little_endian = 0; } else if (header_start.endian == SAS_ENDIAN_LITTLE) { bswap = !machine_is_little_endian(); hinfo->little_endian = 1; } else { retval = READSTAT_ERROR_PARSE; goto cleanup; } int i; for (i=0; iencoding = _charset_table[i].name; break; } } if (hinfo->encoding == NULL) { if (error_handler) { snprintf(error_buf, sizeof(error_buf), "Unsupported character set code: %d", header_start.encoding); error_handler(error_buf, user_ctx); } retval = READSTAT_ERROR_UNSUPPORTED_CHARSET; goto cleanup; } memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name)); if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } double creation_time, modification_time, creation_time_diff, modification_time_diff; if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (bswap) creation_time = byteswap_double(creation_time); if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (bswap) modification_time = byteswap_double(modification_time); if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (bswap) creation_time_diff = byteswap_double(creation_time_diff); if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (bswap) modification_time_diff = byteswap_double(modification_time_diff); hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch); hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch); uint32_t header_size, page_size; if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } hinfo->header_size = bswap ? byteswap4(header_size) : header_size; hinfo->page_size = bswap ? byteswap4(page_size) : page_size; if (hinfo->header_size < 1024 || hinfo->page_size < 1024) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (hinfo->u64) { hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT; hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT; } else { hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT; hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT; } if (hinfo->u64) { uint64_t page_count; if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } hinfo->page_count = bswap ? byteswap8(page_count) : page_count; } else { uint32_t page_count; if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } hinfo->page_count = bswap ? byteswap4(page_count) : page_count; } if (hinfo->page_count > (1<<24)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; if (error_handler) { snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek forward by %d", 8); error_handler(error_buf, user_ctx); } goto cleanup; } if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } char major, revision_tag; int minor, revision; if (sscanf(header_end.release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (major >= '1' && major <= '9') { hinfo->major_version = major - '0'; } else if (major == 'V') { // It appears that SAS Visual Forecaster reports the major version as "V" // Treat it as version 9 for all intents and purposes hinfo->major_version = 9; } else { retval = READSTAT_ERROR_PARSE; goto cleanup; } // revision_tag is usually M, but J has been observed in the wild (not created with SAS?) if (revision_tag != 'M' && revision_tag != 'J') { retval = READSTAT_ERROR_PARSE; goto cleanup; } hinfo->minor_version = minor; hinfo->revision = revision; if ((major == '8' || major == '9') && minor == 0 && revision == 0) { /* A bit of a hack, but most SAS installations are running a minor update */ hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER; } else { hinfo->vendor = READSTAT_VENDOR_SAS; } if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; if (error_handler) { snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek to position %" PRId64, hinfo->header_size); error_handler(error_buf, user_ctx); } goto cleanup; } cleanup: return retval; } readstat_error_t sas_write_header(readstat_writer_t *writer, sas_header_info_t *hinfo, sas_header_start_t header_start) { readstat_error_t retval = READSTAT_OK; time_t epoch = sas_epoch(); memset(header_start.table_name, ' ', sizeof(header_start.table_name)); size_t table_name_len = strlen(writer->table_name); if (table_name_len > sizeof(header_start.table_name)) table_name_len = sizeof(header_start.table_name); if (table_name_len) { memcpy(header_start.table_name, writer->table_name, table_name_len); } else { memcpy(header_start.table_name, "DATASET", sizeof("DATASET")-1); } retval = readstat_write_bytes(writer, &header_start, sizeof(sas_header_start_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_zeros(writer, hinfo->pad1); if (retval != READSTAT_OK) goto cleanup; double creation_time = hinfo->creation_time - epoch; retval = readstat_write_bytes(writer, &creation_time, sizeof(double)); if (retval != READSTAT_OK) goto cleanup; double modification_time = hinfo->modification_time - epoch; retval = readstat_write_bytes(writer, &modification_time, sizeof(double)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_zeros(writer, 16); if (retval != READSTAT_OK) goto cleanup; uint32_t header_size = hinfo->header_size; uint32_t page_size = hinfo->page_size; retval = readstat_write_bytes(writer, &header_size, sizeof(uint32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &page_size, sizeof(uint32_t)); if (retval != READSTAT_OK) goto cleanup; if (hinfo->u64) { uint64_t page_count = hinfo->page_count; retval = readstat_write_bytes(writer, &page_count, sizeof(uint64_t)); } else { uint32_t page_count = hinfo->page_count; retval = readstat_write_bytes(writer, &page_count, sizeof(uint32_t)); } if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_zeros(writer, 8); if (retval != READSTAT_OK) goto cleanup; sas_header_end_t header_end = { .host = "9.0401M6Linux" }; char release[sizeof(header_end.release)+1] = { 0 }; snprintf(release, sizeof(release), "%1d.%04dM0", (unsigned int)writer->version % 10, 101); memcpy(header_end.release, release, sizeof(header_end.release)); retval = readstat_write_bytes(writer, &header_end, sizeof(sas_header_end_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_zeros(writer, hinfo->header_size-writer->bytes_written); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } sas_header_info_t *sas_header_info_init(readstat_writer_t *writer, int is_64bit) { sas_header_info_t *hinfo = calloc(1, sizeof(sas_header_info_t)); hinfo->creation_time = writer->timestamp; hinfo->modification_time = writer->timestamp; hinfo->page_size = SAS_DEFAULT_PAGE_SIZE; hinfo->u64 = !!is_64bit; if (hinfo->u64) { hinfo->header_size = SAS_FILE_HEADER_SIZE_64BIT; hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT; hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT; } else { hinfo->header_size = SAS_FILE_HEADER_SIZE_32BIT; hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT; hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT; } return hinfo; } readstat_error_t sas_fill_page(readstat_writer_t *writer, sas_header_info_t *hinfo) { if ((writer->bytes_written - hinfo->header_size) % hinfo->page_size) { size_t num_zeros = (hinfo->page_size - (writer->bytes_written - hinfo->header_size) % hinfo->page_size); return readstat_write_zeros(writer, num_zeros); } return READSTAT_OK; } readstat_error_t sas_validate_name(const char *name, size_t max_len) { int j; for (j=0; name[j]; j++) { if (name[j] != '_' && !(name[j] >= 'a' && name[j] <= 'z') && !(name[j] >= 'A' && name[j] <= 'Z') && !(name[j] >= '0' && name[j] <= '9')) { return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER; } } char first_char = name[0]; if (!first_char) return READSTAT_ERROR_NAME_IS_ZERO_LENGTH; if (first_char != '_' && !(first_char >= 'a' && first_char <= 'z') && !(first_char >= 'A' && first_char <= 'Z')) { return READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER; } if (strcmp(name, "_N_") == 0 || strcmp(name, "_ERROR_") == 0 || strcmp(name, "_NUMERIC_") == 0 || strcmp(name, "_CHARACTER_") == 0 || strcmp(name, "_ALL_") == 0) { return READSTAT_ERROR_NAME_IS_RESERVED_WORD; } if (strlen(name) > max_len) return READSTAT_ERROR_NAME_IS_TOO_LONG; return READSTAT_OK; } readstat_error_t sas_validate_variable(const readstat_variable_t *variable) { return sas_validate_name(readstat_variable_get_name(variable), 32); } readstat_error_t sas_validate_tag(char tag) { if (tag == '_' || (tag >= 'A' && tag <= 'Z')) return READSTAT_OK; return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE; } void sas_assign_tag(readstat_value_t *value, uint8_t tag) { /* We accommodate two tag schemes. In the first, the tag is an ASCII code * given by uint8_t tag above. System missing is represented by an ASCII * period. In the second scheme, (tag-2) is an offset from 'A', except when * tag == 0, in which case it represents an underscore, or tag == 1, in * which case it represents system-missing. */ if (tag == 0) { tag = '_'; } else if (tag >= 2 && tag < 28) { tag = 'A' + (tag - 2); } if (sas_validate_tag(tag) == READSTAT_OK) { value->tag = tag; value->is_tagged_missing = 1; } else { value->tag = 0; value->is_system_missing = 1; } } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_sas.h0000644000076500000240000000773114674240614016461 0ustar00dialout #include "../readstat.h" #include "../readstat_bits.h" #pragma pack(push, 1) typedef struct sas_header_start_s { unsigned char magic[32]; unsigned char a2; unsigned char mystery1[2]; unsigned char a1; unsigned char mystery2[1]; unsigned char endian; unsigned char mystery3[1]; char file_format; unsigned char mystery4[30]; unsigned char encoding; unsigned char mystery5[13]; char file_type[8]; char table_name[32]; unsigned char mystery6[32]; char file_info[8]; } sas_header_start_t; typedef struct sas_header_end_s { char release[8]; char host[16]; char version[16]; char os_vendor[16]; char os_name[16]; char extra[48]; } sas_header_end_t; #pragma pack(pop) typedef struct sas_header_info_s { int little_endian; int u64; int vendor; int major_version; int minor_version; int revision; int pad1; int64_t page_size; int64_t page_header_size; int64_t subheader_pointer_size; int64_t page_count; int64_t header_size; time_t creation_time; time_t modification_time; char table_name[32]; char file_label[256]; char *encoding; } sas_header_info_t; enum { READSTAT_VENDOR_STAT_TRANSFER, READSTAT_VENDOR_SAS }; typedef struct sas_text_ref_s { uint16_t index; uint16_t offset; uint16_t length; } sas_text_ref_t; #define SAS_ENDIAN_BIG 0x00 #define SAS_ENDIAN_LITTLE 0x01 #define SAS_FILE_FORMAT_UNIX '1' #define SAS_FILE_FORMAT_WINDOWS '2' #define SAS_ALIGNMENT_OFFSET_0 0x22 #define SAS_ALIGNMENT_OFFSET_4 0x33 #define SAS_COLUMN_TYPE_NUM 0x01 #define SAS_COLUMN_TYPE_CHR 0x02 #define SAS_SUBHEADER_SIGNATURE_ROW_SIZE 0xF7F7F7F7 #define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE 0xF6F6F6F6 #define SAS_SUBHEADER_SIGNATURE_COUNTS 0xFFFFFC00 #define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT 0xFFFFFBFE #define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK 0xFFFFFFF8 /* Seen in the wild: FA (unknown), F8 (locale?) */ #define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS 0xFFFFFFFC #define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT 0xFFFFFFFD #define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST 0xFFFFFFFE #define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME 0xFFFFFFFF #define SAS_PAGE_TYPE_META 0x0000 #define SAS_PAGE_TYPE_DATA 0x0100 #define SAS_PAGE_TYPE_MIX 0x0200 #define SAS_PAGE_TYPE_AMD 0x0400 #define SAS_PAGE_TYPE_MASK 0x0F00 #define SAS_PAGE_TYPE_META2 0x4000 #define SAS_PAGE_TYPE_COMP 0x9000 #define SAS_SUBHEADER_POINTER_SIZE_32BIT 12 #define SAS_SUBHEADER_POINTER_SIZE_64BIT 24 #define SAS_PAGE_HEADER_SIZE_32BIT 24 #define SAS_PAGE_HEADER_SIZE_64BIT 40 #define SAS_COMPRESSION_NONE 0x00 #define SAS_COMPRESSION_TRUNC 0x01 #define SAS_COMPRESSION_ROW 0x04 #define SAS_COMPRESSION_SIGNATURE_RLE "SASYZCRL" #define SAS_COMPRESSION_SIGNATURE_RDC "SASYZCR2" #define SAS_DEFAULT_FILE_VERSION 9 extern unsigned char sas7bdat_magic_number[32]; extern unsigned char sas7bcat_magic_number[32]; uint64_t sas_read8(const char *data, int bswap); uint32_t sas_read4(const char *data, int bswap); uint16_t sas_read2(const char *data, int bswap); readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *ctx, readstat_error_handler error_handler, void *user_ctx); size_t sas_subheader_remainder(size_t len, size_t signature_len); sas_header_info_t *sas_header_info_init(readstat_writer_t *writer, int is_64bit); readstat_error_t sas_write_header(readstat_writer_t *writer, sas_header_info_t *hinfo, sas_header_start_t header_start); readstat_error_t sas_fill_page(readstat_writer_t *writer, sas_header_info_t *hinfo); readstat_error_t sas_validate_variable(const readstat_variable_t *variable); readstat_error_t sas_validate_name(const char *name, size_t max_len); readstat_error_t sas_validate_tag(char tag); void sas_assign_tag(readstat_value_t *value, uint8_t tag); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748249037.0 pyreadstat-1.3.3/src/sas/readstat_sas7bcat_read.c0000644000076500000240000004274115015024715020360 0ustar00dialout#include #include #include #include #include #include "readstat_sas.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" #define SAS_CATALOG_FIRST_INDEX_PAGE 1 #define SAS_CATALOG_USELESS_PAGES 3 typedef struct sas7bcat_ctx_s { readstat_metadata_handler metadata_handler; readstat_value_label_handler value_label_handler; void *user_ctx; readstat_io_t *io; int u64; int pad1; int bswap; int64_t xlsr_size; int64_t xlsr_offset; int64_t xlsr_O_offset; int64_t page_count; int64_t page_size; int64_t header_size; uint64_t *block_pointers; int block_pointers_used; int block_pointers_capacity; const char *input_encoding; const char *output_encoding; iconv_t converter; } sas7bcat_ctx_t; static void sas7bcat_ctx_free(sas7bcat_ctx_t *ctx) { if (ctx->converter) iconv_close(ctx->converter); if (ctx->block_pointers) free(ctx->block_pointers); free(ctx); } static readstat_error_t sas7bcat_parse_value_labels(const char *value_start, size_t value_labels_len, int label_count_used, int label_count_capacity, const char *name, sas7bcat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i; const char *lbp1 = value_start; uint32_t *value_offset = readstat_calloc(label_count_used, sizeof(uint32_t)); /* Doubles appear to be stored as big-endian, always */ int bswap_doubles = machine_is_little_endian(); int is_string = (name[0] == '$'); char *label = NULL; if (value_offset == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } /* Pass 1 -- find out the offset of the labels */ for (i=0; i value_labels_len || sas_read2(&lbp1[2], ctx->bswap) < 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (ipad1+4] - value_start > value_labels_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } uint32_t label_pos = sas_read4(&lbp1[10+ctx->pad1], ctx->bswap); if (label_pos >= label_count_used) { retval = READSTAT_ERROR_PARSE; goto cleanup; } value_offset[label_pos] = lbp1 - value_start; } lbp1 += 6 + sas_read2(&lbp1[2], ctx->bswap); } const char *lbp2 = lbp1; /* Pass 2 -- parse pairs of values & labels */ for (i=0; i value_labels_len || &lbp2[10] - value_start > value_labels_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } readstat_value_t value = { .type = is_string ? READSTAT_TYPE_STRING : READSTAT_TYPE_DOUBLE }; char string_val[4*16+1]; if (is_string) { size_t value_entry_len = 6 + sas_read2(&lbp1[2], ctx->bswap); retval = readstat_convert(string_val, sizeof(string_val), &lbp1[value_entry_len-16], 16, ctx->converter); if (retval != READSTAT_OK) goto cleanup; value.v.string_value = string_val; } else { uint64_t val = sas_read8(&lbp1[22], bswap_doubles); double dval = NAN; if ((val | 0xFF0000000000) == 0xFFFFFFFFFFFF) { sas_assign_tag(&value, (val >> 40)); } else { memcpy(&dval, &val, 8); if (dval > 0.0) { val = ~val; memcpy(&dval, &val, 8); } else { dval *= -1.0; } } value.v.double_value = dval; } size_t label_len = sas_read2(&lbp2[8], ctx->bswap); if (&lbp2[10] > value_start + value_labels_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } /* Some labels seem to overflow the reported block length, truncate it */ /* (Observed with formats.sasbcat from GSS2021, produced with 9.0401M6X64_SR12R2 */ if (label_len > value_start + value_labels_len - &lbp2[10]) { label_len = value_start + value_labels_len - &lbp2[10]; } if (ctx->value_label_handler) { label = realloc(label, 4 * label_len + 1); retval = readstat_convert(label, 4 * label_len + 1, &lbp2[10], label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; if (ctx->value_label_handler(name, value, label, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } lbp2 += 8 + 2 + label_len + 1; } cleanup: free(label); free(value_offset); return retval; } static readstat_error_t sas7bcat_parse_block(const char *data, size_t data_size, sas7bcat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t pad = 0; uint64_t label_count_capacity = 0; uint64_t label_count_used = 0; int payload_offset = 106; uint16_t flags = 0; char name[4*32+1]; if (data_size < payload_offset) goto cleanup; flags = sas_read2(&data[2], ctx->bswap); pad = (flags & 0x08) ? 4 : 0; // might be 0x10, not sure if (ctx->u64) { label_count_capacity = sas_read8(&data[42+pad], ctx->bswap); label_count_used = sas_read8(&data[50+pad], ctx->bswap); payload_offset += 32; } else { label_count_capacity = sas_read4(&data[38+pad], ctx->bswap); label_count_used = sas_read4(&data[42+pad], ctx->bswap); } if ((retval = readstat_convert(name, sizeof(name), &data[8], 8, ctx->converter)) != READSTAT_OK) goto cleanup; if (pad) { pad += 16; } if (((flags & 0x80) && !ctx->u64) || ((flags & 0x20) && ctx->u64)) { // has long name if (data_size < payload_offset + pad + 32) goto cleanup; retval = readstat_convert(name, sizeof(name), &data[payload_offset+pad], 32, ctx->converter); if (retval != READSTAT_OK) goto cleanup; pad += 32; } if (data_size < payload_offset + pad) goto cleanup; if (label_count_used == 0) goto cleanup; if ((retval = sas7bcat_parse_value_labels(&data[payload_offset+pad], data_size - payload_offset - pad, label_count_used, label_count_capacity, name, ctx)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sas7bcat_augment_index(const char *index, size_t len, sas7bcat_ctx_t *ctx) { const char *xlsr = index; readstat_error_t retval = READSTAT_OK; while (xlsr + ctx->xlsr_size <= index + len) { if (memcmp(xlsr, "XLSR", 4) != 0) // some block pointers seem to have 8 bytes of extra padding xlsr += 8; if (memcmp(xlsr, "XLSR", 4) != 0) break; if (xlsr[ctx->xlsr_O_offset] == 'O') { uint64_t page = 0, pos = 0; if (ctx->u64) { page = sas_read8(&xlsr[8], ctx->bswap); pos = sas_read2(&xlsr[16], ctx->bswap); } else { page = sas_read4(&xlsr[4], ctx->bswap); pos = sas_read2(&xlsr[8], ctx->bswap); } ctx->block_pointers[ctx->block_pointers_used++] = (page << 32) + pos; } if (ctx->block_pointers_used == ctx->block_pointers_capacity) { ctx->block_pointers = readstat_realloc(ctx->block_pointers, (ctx->block_pointers_capacity *= 2) * sizeof(uint64_t)); if (ctx->block_pointers == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } } xlsr += ctx->xlsr_size; } cleanup: return retval; } static int compare_block_pointers(const void *elem1, const void *elem2) { uint64_t v1 = *(const uint64_t *)elem1; uint64_t v2 = *(const uint64_t *)elem2; return v1 - v2; } static void sas7bcat_sort_index(sas7bcat_ctx_t *ctx) { if (ctx->block_pointers_used == 0) return; int i; for (i=1; iblock_pointers_used; i++) { if (ctx->block_pointers[i] < ctx->block_pointers[i-1]) { qsort(ctx->block_pointers, ctx->block_pointers_used, sizeof(uint64_t), &compare_block_pointers); break; } } } static void sas7bcat_uniq_index(sas7bcat_ctx_t *ctx) { if (ctx->block_pointers_used == 0) return; int i; int out_i = 1; for (i=1; iblock_pointers_used; i++) { if (ctx->block_pointers[i] != ctx->block_pointers[i-1]) { if (out_i != i) { ctx->block_pointers[out_i] = ctx->block_pointers[i]; } out_i++; } } ctx->block_pointers_used = out_i; } static int sas7bcat_block_size(int start_page, int start_page_pos, sas7bcat_ctx_t *ctx, readstat_error_t *outError) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; int next_page = start_page; int next_page_pos = start_page_pos; int link_count = 0; int buffer_len = 0; int chain_link_len = 0; char chain_link[32]; int chain_link_header_len = 16; if (ctx->u64) { chain_link_header_len = 32; } // calculate buffer size needed while (next_page > 0 && next_page_pos > 0 && next_page <= ctx->page_count && link_count++ < ctx->page_count) { if (io->seek(ctx->header_size+(next_page-1)*ctx->page_size+next_page_pos, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(chain_link, chain_link_header_len, io->io_ctx) < chain_link_header_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->u64) { next_page = sas_read4(&chain_link[0], ctx->bswap); next_page_pos = sas_read2(&chain_link[8], ctx->bswap); chain_link_len = sas_read2(&chain_link[10], ctx->bswap); } else { next_page = sas_read4(&chain_link[0], ctx->bswap); next_page_pos = sas_read2(&chain_link[4], ctx->bswap); chain_link_len = sas_read2(&chain_link[6], ctx->bswap); } buffer_len += chain_link_len; } cleanup: if (outError) *outError = retval; return retval == READSTAT_OK ? buffer_len : -1; } static readstat_error_t sas7bcat_read_block(char *buffer, size_t buffer_len, int start_page, int start_page_pos, sas7bcat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; int next_page = start_page; int next_page_pos = start_page_pos; int link_count = 0; int chain_link_len = 0; int buffer_offset = 0; char chain_link[32]; int chain_link_header_len = 16; if (ctx->u64) { chain_link_header_len = 32; } while (next_page > 0 && next_page_pos > 0 && next_page <= ctx->page_count && link_count++ < ctx->page_count) { if (io->seek(ctx->header_size+(next_page-1)*ctx->page_size+next_page_pos, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(chain_link, chain_link_header_len, io->io_ctx) < chain_link_header_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->u64) { next_page = sas_read4(&chain_link[0], ctx->bswap); next_page_pos = sas_read2(&chain_link[8], ctx->bswap); chain_link_len = sas_read2(&chain_link[10], ctx->bswap); } else { next_page = sas_read4(&chain_link[0], ctx->bswap); next_page_pos = sas_read2(&chain_link[4], ctx->bswap); chain_link_len = sas_read2(&chain_link[6], ctx->bswap); } if (buffer_offset + chain_link_len > buffer_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (io->read(buffer + buffer_offset, chain_link_len, io->io_ctx) < chain_link_len) { retval = READSTAT_ERROR_READ; goto cleanup; } buffer_offset += chain_link_len; } cleanup: return retval; } readstat_error_t readstat_parse_sas7bcat(readstat_parser_t *parser, const char *path, void *user_ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = parser->io; int64_t i; char *page = NULL; char *buffer = NULL; sas7bcat_ctx_t *ctx = calloc(1, sizeof(sas7bcat_ctx_t)); sas_header_info_t *hinfo = calloc(1, sizeof(sas_header_info_t)); ctx->block_pointers = malloc((ctx->block_pointers_capacity = 200) * sizeof(uint64_t)); ctx->value_label_handler = parser->handlers.value_label; ctx->metadata_handler = parser->handlers.metadata; ctx->input_encoding = parser->input_encoding; ctx->output_encoding = parser->output_encoding; ctx->user_ctx = user_ctx; ctx->io = io; if (io->open(path, io->io_ctx) == -1) { retval = READSTAT_ERROR_OPEN; goto cleanup; } if ((retval = sas_read_header(io, hinfo, parser->handlers.error, user_ctx)) != READSTAT_OK) { goto cleanup; } ctx->u64 = hinfo->u64; ctx->pad1 = hinfo->pad1; ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian; ctx->header_size = hinfo->header_size; ctx->page_count = hinfo->page_count; ctx->page_size = hinfo->page_size; if (ctx->input_encoding == NULL) { ctx->input_encoding = hinfo->encoding; } ctx->xlsr_size = 212 + ctx->pad1; ctx->xlsr_offset = 856 + 2 * ctx->pad1; ctx->xlsr_O_offset = 50 + ctx->pad1; if (ctx->u64) { ctx->xlsr_offset += 144; ctx->xlsr_size += 72; ctx->xlsr_O_offset += 24; } if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) { iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding); if (converter == (iconv_t)-1) { retval = READSTAT_ERROR_UNSUPPORTED_CHARSET; goto cleanup; } ctx->converter = converter; } if (ctx->metadata_handler) { char table_name[4*32+1]; readstat_metadata_t metadata = { .file_encoding = ctx->input_encoding, /* orig encoding? */ .modified_time = hinfo->modification_time, .creation_time = hinfo->creation_time, .file_format_version = hinfo->major_version, .endianness = hinfo->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG, .is64bit = ctx->u64 }; retval = readstat_convert(table_name, sizeof(table_name), hinfo->table_name, sizeof(hinfo->table_name), ctx->converter); if (retval != READSTAT_OK) goto cleanup; metadata.table_name = table_name; if (ctx->metadata_handler(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } if ((page = readstat_malloc(ctx->page_size)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (io->seek(ctx->header_size+SAS_CATALOG_FIRST_INDEX_PAGE*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(page, ctx->page_size, io->io_ctx) < ctx->page_size) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = sas7bcat_augment_index(&page[ctx->xlsr_offset], ctx->page_size - ctx->xlsr_offset, ctx); if (retval != READSTAT_OK) goto cleanup; // Pass 1 -- find the XLSR entries for (i=SAS_CATALOG_USELESS_PAGES; ipage_count; i++) { if (io->seek(ctx->header_size+i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(page, ctx->page_size, io->io_ctx) < ctx->page_size) { retval = READSTAT_ERROR_READ; goto cleanup; } if (memcmp(&page[16], "XLSR", sizeof("XLSR")-1) == 0) { retval = sas7bcat_augment_index(&page[16], ctx->page_size - 16, ctx); if (retval != READSTAT_OK) goto cleanup; } } sas7bcat_sort_index(ctx); sas7bcat_uniq_index(ctx); // Pass 2 -- look up the individual block pointers for (i=0; iblock_pointers_used; i++) { int start_page = ctx->block_pointers[i] >> 32; int start_page_pos = (ctx->block_pointers[i]) & 0xFFFF; int buffer_len = sas7bcat_block_size(start_page, start_page_pos, ctx, &retval); if (buffer_len == -1) { goto cleanup; } else if (buffer_len == 0) { continue; } if ((buffer = readstat_realloc(buffer, buffer_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((retval = sas7bcat_read_block(buffer, buffer_len, start_page, start_page_pos, ctx)) != READSTAT_OK) goto cleanup; if ((retval = sas7bcat_parse_block(buffer, buffer_len, ctx)) != READSTAT_OK) goto cleanup; } cleanup: io->close(io->io_ctx); if (page) free(page); if (buffer) free(buffer); if (ctx) sas7bcat_ctx_free(ctx); if (hinfo) free(hinfo); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748249037.0 pyreadstat-1.3.3/src/sas/readstat_sas7bcat_write.c0000644000076500000240000001537115015024715020576 0ustar00dialout #include #include #include #include #include "../readstat.h" #include "../readstat_writer.h" #include "readstat_sas.h" #include "readstat_sas_rle.h" typedef struct sas7bcat_block_s { size_t len; char data[1]; // Flexible array; use [1] for C++-98 compatibility } sas7bcat_block_t; static sas7bcat_block_t *sas7bcat_block_for_label_set(readstat_label_set_t *r_label_set) { size_t len = 0; size_t name_len = strlen(r_label_set->name); int j; char name[32]; len += 106; if (name_len > 8) { len += 32; // long name if (name_len > 32) { name_len = 32; } } memcpy(&name[0], r_label_set->name, name_len); for (j=0; jvalue_labels_count; j++) { readstat_value_label_t *value_label = readstat_get_value_label(r_label_set, j); len += 30; // Value: 14-byte header + 16-byte padded value len += 8 + 2 + value_label->label_len + 1; } sas7bcat_block_t *block = calloc(1, sizeof(sas7bcat_block_t) + len); block->len = len; off_t begin = 106; int32_t count = r_label_set->value_labels_count; memcpy(&block->data[38], &count, sizeof(int32_t)); memcpy(&block->data[42], &count, sizeof(int32_t)); if (name_len > 8) { int16_t flags = 0x80; memcpy(&block->data[2], &flags, sizeof(int16_t)); memcpy(&block->data[8], name, 8); memset(&block->data[106], ' ', 32); memcpy(&block->data[106], name, name_len); begin += 32; } else { memset(&block->data[8], ' ', 8); memcpy(&block->data[8], name, name_len); } char *lbp1 = &block->data[begin]; char *lbp2 = &block->data[begin+r_label_set->value_labels_count*30]; for (j=0; jvalue_labels_count; j++) { readstat_value_label_t *value_label = readstat_get_value_label(r_label_set, j); int16_t value_entry_len = 24; // size - 6 memcpy(&lbp1[2], &value_entry_len, sizeof(int16_t)); int32_t index = j; memcpy(&lbp1[10], &index, sizeof(int32_t)); if (r_label_set->type == READSTAT_TYPE_STRING) { size_t string_len = value_label->string_key_len; if (string_len > 16) string_len = 16; memset(&lbp1[14], ' ', 16); memcpy(&lbp1[14], value_label->string_key, string_len); } else { uint64_t big_endian_value; double double_value = value_label->double_key; if (double_value >= 0.0) { double_value *= -1.0; memcpy(&big_endian_value, &double_value, sizeof(double)); } else { memcpy(&big_endian_value, &double_value, sizeof(double)); big_endian_value = ~big_endian_value; } if (machine_is_little_endian()) { big_endian_value = byteswap8(big_endian_value); } memcpy(&lbp1[22], &big_endian_value, sizeof(uint64_t)); } int16_t label_len = value_label->label_len; memcpy(&lbp2[8], &label_len, sizeof(int16_t)); memcpy(&lbp2[10], value_label->label, label_len); lbp1 += 6 + value_entry_len; lbp2 += 8 + 2 + value_label->label_len + 1; } return block; } static readstat_error_t sas7bcat_emit_header(readstat_writer_t *writer, sas_header_info_t *hinfo) { sas_header_start_t header_start = { .a2 = hinfo->u64 ? SAS_ALIGNMENT_OFFSET_4 : SAS_ALIGNMENT_OFFSET_0, .a1 = SAS_ALIGNMENT_OFFSET_0, .endian = machine_is_little_endian() ? SAS_ENDIAN_LITTLE : SAS_ENDIAN_BIG, .file_format = SAS_FILE_FORMAT_UNIX, .encoding = 20, /* UTF-8 */ .file_type = "SAS FILE", .file_info = "CATALOG " }; memcpy(&header_start.magic, sas7bcat_magic_number, sizeof(header_start.magic)); return sas_write_header(writer, hinfo, header_start); } static readstat_error_t sas7bcat_begin_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t retval = READSTAT_OK; int i; sas_header_info_t *hinfo = sas_header_info_init(writer, 0); sas7bcat_block_t **blocks = malloc(writer->label_sets_count * sizeof(sas7bcat_block_t)); char *page = malloc(hinfo->page_size); for (i=0; ilabel_sets_count; i++) { blocks[i] = sas7bcat_block_for_label_set(writer->label_sets[i]); } hinfo->page_count = 4; // Header retval = sas7bcat_emit_header(writer, hinfo); if (retval != READSTAT_OK) goto cleanup; // Page 0 retval = readstat_write_zeros(writer, hinfo->page_size); if (retval != READSTAT_OK) goto cleanup; memset(page, '\0', hinfo->page_size); // Page 1 char *xlsr = &page[856]; int32_t block_idx = 4; int16_t block_off = 16; for (i=0; ilabel_sets_count; i++) { if (xlsr + 212 > page + hinfo->page_size) break; memcpy(&xlsr[0], "XLSR", 4); memcpy(&xlsr[4], &block_idx, sizeof(int32_t)); memcpy(&xlsr[8], &block_off, sizeof(int16_t)); xlsr[50] = 'O'; block_off += blocks[i]->len; xlsr += 212; } retval = readstat_write_bytes(writer, page, hinfo->page_size); if (retval != READSTAT_OK) goto cleanup; // Page 2 retval = readstat_write_zeros(writer, hinfo->page_size); if (retval != READSTAT_OK) goto cleanup; // Page 3 memset(page, '\0', hinfo->page_size); char block_header[16]; block_off = 16; for (i=0; ilabel_sets_count; i++) { if (block_off + sizeof(block_header) + blocks[i]->len > hinfo->page_size) break; memset(block_header, '\0', sizeof(block_header)); int32_t next_page = 0; int16_t next_off = 0; int16_t block_len = blocks[i]->len; memcpy(&block_header[0], &next_page, sizeof(int32_t)); memcpy(&block_header[4], &next_off, sizeof(int16_t)); memcpy(&block_header[6], &block_len, sizeof(int16_t)); memcpy(&page[block_off], block_header, sizeof(block_header)); block_off += sizeof(block_header); memcpy(&page[block_off], blocks[i]->data, blocks[i]->len); block_off += blocks[i]->len; } retval = readstat_write_bytes(writer, page, hinfo->page_size); if (retval != READSTAT_OK) goto cleanup; cleanup: for (i=0; ilabel_sets_count; i++) { free(blocks[i]); } free(blocks); free(hinfo); free(page); return retval; } readstat_error_t readstat_begin_writing_sas7bcat(readstat_writer_t *writer, void *user_ctx) { if (writer->version == 0) writer->version = SAS_DEFAULT_FILE_VERSION; writer->callbacks.begin_data = &sas7bcat_begin_data; return readstat_begin_writing_file(writer, user_ctx, 0); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/sas/readstat_sas7bdat_read.c0000644000076500000240000013324015134704512020356 0ustar00dialout #include #include #include #include #include #include #include "readstat_sas.h" #include "readstat_sas_rle.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" typedef struct col_info_s { sas_text_ref_t name_ref; sas_text_ref_t format_ref; sas_text_ref_t label_ref; int index; uint64_t offset; uint32_t width; int type; int format_width; int format_digits; } col_info_t; typedef struct subheader_pointer_s { uint64_t offset; uint64_t len; unsigned char compression; unsigned char is_compressed_data; } subheader_pointer_t; typedef struct sas7bdat_ctx_s { readstat_callbacks_t handle; int64_t file_size; int little_endian; int u64; int vendor; void *user_ctx; readstat_io_t *io; int bswap; int did_submit_columns; uint32_t row_length; uint32_t page_row_count; uint32_t parsed_row_count; uint32_t column_count; uint32_t row_limit; uint32_t row_offset; uint64_t header_size; uint64_t page_count; uint64_t page_size; char *page; char *row; uint64_t page_header_size; uint64_t subheader_signature_size; uint64_t subheader_pointer_size; int text_blob_count; size_t *text_blob_lengths; char **text_blobs; int col_names_count; int col_attrs_count; int col_formats_count; size_t max_col_width; char *scratch_buffer; size_t scratch_buffer_len; int col_info_count; col_info_t *col_info; readstat_variable_t **variables; const char *input_encoding; const char *output_encoding; iconv_t converter; time_t ctime; time_t mtime; int version; char table_name[4*32+1]; char file_label[4*256+1]; char error_buf[2048]; unsigned int rdc_compression:1; } sas7bdat_ctx_t; static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) { int i; if (ctx->text_blobs) { for (i=0; itext_blob_count; i++) { free(ctx->text_blobs[i]); } free(ctx->text_blobs); free(ctx->text_blob_lengths); } if (ctx->variables) { for (i=0; icolumn_count; i++) { if (ctx->variables[i]) free(ctx->variables[i]); } free(ctx->variables); } if (ctx->col_info) free(ctx->col_info); if (ctx->scratch_buffer) free(ctx->scratch_buffer); if (ctx->page) free(ctx->page); if (ctx->row) free(ctx->row); if (ctx->converter) iconv_close(ctx->converter); free(ctx); } static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) { readstat_io_t *io = ctx->io; return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx); } static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) { sas_text_ref_t ref; ref.index = sas_read2(&data[0], ctx->bswap); ref.offset = sas_read2(&data[2], ctx->bswap); ref.length = sas_read2(&data[4], ctx->bswap); return ref; } static readstat_error_t sas7bdat_copy_text_ref(char *out_buffer, size_t out_buffer_len, sas_text_ref_t text_ref, sas7bdat_ctx_t *ctx) { if (text_ref.index >= ctx->text_blob_count) return READSTAT_ERROR_PARSE; if (text_ref.length == 0) { out_buffer[0] = '\0'; return READSTAT_OK; } char *blob = ctx->text_blobs[text_ref.index]; if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index]) return READSTAT_ERROR_PARSE; return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length, ctx->converter); } static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t signature_len = ctx->subheader_signature_size; uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap); char *blob = NULL; if (remainder != sas_subheader_remainder(len, signature_len)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->text_blob_count++; ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *)); ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths, ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0])); if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((blob = readstat_malloc(len-signature_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memcpy(blob, subheader+signature_len, len-signature_len); ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len; ctx->text_blobs[ctx->text_blob_count-1] = blob; cleanup: return retval; } static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) { if (ctx->col_info_count < count) { size_t old_count = ctx->col_info_count; ctx->col_info_count = count; ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t)); if (ctx->col_info == NULL) { return READSTAT_ERROR_MALLOC; } memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t)); } return READSTAT_OK; } static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { uint64_t col_count; readstat_error_t retval = READSTAT_OK; if (ctx->column_count || ctx->did_submit_columns) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (len < (ctx->u64 ? 16 : 8)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (ctx->u64) { col_count = sas_read8(&subheader[8], ctx->bswap); } else { col_count = sas_read4(&subheader[4], ctx->bswap); } ctx->column_count = col_count; retval = sas7bdat_realloc_col_info(ctx, ctx->column_count); cleanup: return retval; } static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; uint64_t total_row_count; uint64_t row_length, page_row_count; if (len < (ctx->u64 ? 250: 190)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (ctx->u64) { row_length = sas_read8(&subheader[40], ctx->bswap); total_row_count = sas_read8(&subheader[48], ctx->bswap); page_row_count = sas_read8(&subheader[120], ctx->bswap); } else { row_length = sas_read4(&subheader[20], ctx->bswap); total_row_count = sas_read4(&subheader[24], ctx->bswap); page_row_count = sas_read4(&subheader[60], ctx->bswap); } sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx); if (file_label_ref.length) { if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label), file_label_ref, ctx)) != READSTAT_OK) { goto cleanup; } } sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx); if (compression_ref.length) { char compression[9]; if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression), compression_ref, ctx)) != READSTAT_OK) { goto cleanup; } ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0); } ctx->row_length = row_length; ctx->row = readstat_realloc(ctx->row, ctx->row_length); if (ctx->row == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } ctx->page_row_count = page_row_count; uint64_t total_row_count_after_skipping = total_row_count; if (total_row_count > ctx->row_offset) { total_row_count_after_skipping -= ctx->row_offset; } else { total_row_count_after_skipping = 0; ctx->row_offset = total_row_count; } if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit) ctx->row_limit = total_row_count_after_skipping; cleanup: return retval; } static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t signature_len = ctx->subheader_signature_size; int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8; int i; const char *cnp = &subheader[signature_len+8]; uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap); if (remainder != sas_subheader_remainder(len, signature_len)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->col_names_count += cmax; if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK) goto cleanup; for (i=ctx->col_names_count-cmax; icol_names_count; i++) { ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx); cnp += 8; } cleanup: return retval; } static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t signature_len = ctx->subheader_signature_size; int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12; int i; const char *cap = &subheader[signature_len+8]; uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap); if (remainder != sas_subheader_remainder(len, signature_len)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->col_attrs_count += cmax; if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK) goto cleanup; for (i=ctx->col_attrs_count-cmax; icol_attrs_count; i++) { if (ctx->u64) { ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap); } else { ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap); } readstat_off_t off=4; if (ctx->u64) off=8; ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap); if (ctx->col_info[i].width > ctx->max_col_width) ctx->max_col_width = ctx->col_info[i].width; if (cap[off+6] == SAS_COLUMN_TYPE_NUM) { ctx->col_info[i].type = READSTAT_TYPE_DOUBLE; } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) { ctx->col_info[i].type = READSTAT_TYPE_STRING; } else { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->col_info[i].index = i; cap += off+8; } cleanup: return retval; } static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if (len < (ctx->u64 ? 58 : 46)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->col_formats_count++; if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK) goto cleanup; if (ctx->u64) { ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[24], ctx->bswap); ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[26], ctx->bswap); } ctx->col_info[ctx->col_formats_count-1].format_ref = sas7bdat_parse_text_ref( ctx->u64 ? &subheader[46] : &subheader[34], ctx); ctx->col_info[ctx->col_formats_count-1].label_ref = sas7bdat_parse_text_ref( ctx->u64 ? &subheader[52] : &subheader[40], ctx); cleanup: return retval; } static readstat_error_t sas7bdat_handle_data_value(readstat_variable_t *variable, col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int cb_retval = 0; readstat_value_t value; memset(&value, 0, sizeof(readstat_value_t)); value.type = col_info->type; if (col_info->type == READSTAT_TYPE_STRING) { retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len, col_data, col_info->width, ctx->converter); if (retval != READSTAT_OK) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Error converting string (row=%u, col=%u) to specified encoding: %.*s", ctx->parsed_row_count+1, col_info->index+1, col_info->width, col_data); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } value.v.string_value = ctx->scratch_buffer; } else if (col_info->type == READSTAT_TYPE_DOUBLE) { uint64_t val = 0; double dval = NAN; if (ctx->little_endian) { int k; for (k=0; kwidth; k++) { val = (val << 8) | (unsigned char)col_data[col_info->width-1-k]; } } else { int k; for (k=0; kwidth; k++) { val = (val << 8) | (unsigned char)col_data[k]; } } val <<= (8-col_info->width)*8; memcpy(&dval, &val, 8); if (isnan(dval)) { value.v.double_value = NAN; sas_assign_tag(&value, ~((val >> 40) & 0xFF)); } else { value.v.double_value = dval; } } cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx); if (cb_retval != READSTAT_HANDLER_OK) retval = READSTAT_ERROR_USER_ABORT; cleanup: return retval; } static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) { if (ctx->parsed_row_count == ctx->row_limit) return READSTAT_OK; if (ctx->row_offset) { ctx->row_offset--; return READSTAT_OK; } readstat_error_t retval = READSTAT_OK; int j; if (ctx->handle.value) { ctx->scratch_buffer_len = 4*ctx->max_col_width+1; ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len); if (ctx->scratch_buffer == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } for (j=0; jcolumn_count; j++) { col_info_t *col_info = &ctx->col_info[j]; readstat_variable_t *variable = ctx->variables[j]; if (variable->skip) continue; if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) { retval = READSTAT_ERROR_PARSE; goto cleanup; } retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx); if (retval != READSTAT_OK) { goto cleanup; } } } ctx->parsed_row_count++; cleanup: return retval; } static readstat_error_t sas7bdat_parse_rows(const char *data, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i; size_t row_offset=0; for (i=0; ipage_row_count && ctx->parsed_row_count < ctx->row_limit; i++) { if (row_offset + ctx->row_length > len) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK) goto cleanup; row_offset += ctx->row_length; } cleanup: return retval; } static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; const unsigned char *input = (const unsigned char *)subheader; char *buffer = malloc(ctx->row_length); char *output = buffer; while (input + 2 <= (const unsigned char *)subheader + len) { int i; unsigned short prefix = (input[0] << 8) + input[1]; input += 2; for (i=0; i<16; i++) { if ((prefix & (1 << (15 - i))) == 0) { if (input + 1 > (const unsigned char *)subheader + len) { break; } if (output + 1 > buffer + ctx->row_length) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } *output++ = *input++; continue; } if (input + 2 > (const unsigned char *)subheader + len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } unsigned char marker_byte = *input++; unsigned char next_byte = *input++; size_t insert_len = 0, copy_len = 0; unsigned char insert_byte = 0x00; size_t back_offset = 0; if (marker_byte <= 0x0F) { insert_len = 3 + marker_byte; insert_byte = next_byte; } else if ((marker_byte >> 4) == 1) { if (input + 1 > (const unsigned char *)subheader + len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16; insert_byte = *input++; } else if ((marker_byte >> 4) == 2) { if (input + 1 > (const unsigned char *)subheader + len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } copy_len = 16 + (*input++); back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16; } else { copy_len = (marker_byte >> 4); back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16; } if (insert_len) { if (output + insert_len > buffer + ctx->row_length) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } memset(output, insert_byte, insert_len); output += insert_len; } else if (copy_len) { if (output - buffer < back_offset || copy_len > back_offset) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (output + copy_len > buffer + ctx->row_length) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } memcpy(output, output - back_offset, copy_len); output += copy_len; } } } if (output - buffer != ctx->row_length) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } retval = sas7bdat_parse_single_row(buffer, ctx); cleanup: free(buffer); return retval; } static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { if (ctx->row_limit == ctx->parsed_row_count) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; ssize_t bytes_decompressed = 0; bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len); if (bytes_decompressed != ctx->row_length) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)", ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } retval = sas7bdat_parse_single_row(ctx->row, ctx); cleanup: return retval; } static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { if (ctx->rdc_compression) return sas7bdat_parse_subheader_rdc(subheader, len, ctx); return sas7bdat_parse_subheader_rle(subheader, len, ctx); } static readstat_error_t sas7bdat_parse_subheader(uint32_t signature, const char *subheader, size_t len, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if (len < 2 + ctx->subheader_signature_size) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) { retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx); } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) { retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx); } else if (signature == SAS_SUBHEADER_SIGNATURE_COUNTS) { /* void */ } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT) { retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx); } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_NAME) { retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx); } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS) { retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx); } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT) { retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx); } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_LIST) { /* void */ } else if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) { /* void */ } else { retval = READSTAT_ERROR_PARSE; } cleanup: return retval; } static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) { if (col_info->type == READSTAT_TYPE_DOUBLE) { if (col_info->width > 8 || col_info->width < 3) { return READSTAT_ERROR_PARSE; } } if (col_info->type == READSTAT_TYPE_STRING) { if (col_info->width > INT16_MAX) { return READSTAT_ERROR_PARSE; } } return READSTAT_OK; } static readstat_variable_t *sas7bdat_init_variable(sas7bdat_ctx_t *ctx, int i, int index_after_skipping, readstat_error_t *out_retval) { readstat_error_t retval = READSTAT_OK; readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t)); variable->index = i; variable->index_after_skipping = index_after_skipping; variable->type = ctx->col_info[i].type; variable->storage_width = ctx->col_info[i].width; if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_copy_text_ref(variable->format, sizeof(variable->format), ctx->col_info[i].format_ref, ctx)) != READSTAT_OK) { goto cleanup; } size_t len = strlen(variable->format); if (len && ctx->col_info[i].format_width) { len += snprintf(variable->format + len, sizeof(variable->format) - len, "%d", ctx->col_info[i].format_width); } if (len && ctx->col_info[i].format_digits) { len += snprintf(variable->format + len, sizeof(variable->format) - len, ".%d", ctx->col_info[i].format_digits); } if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) { goto cleanup; } cleanup: if (retval != READSTAT_OK) { if (out_retval) *out_retval = retval; if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)", i, variable->name, variable->format, variable->label); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } } free(variable); return NULL; } return variable; } static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) { readstat_error_t retval = READSTAT_OK; if (ctx->handle.metadata) { readstat_metadata_t metadata = { .row_count = ctx->row_limit, .var_count = ctx->column_count, .table_name = ctx->table_name, .file_label = ctx->file_label, .file_encoding = ctx->input_encoding, /* orig encoding? */ .creation_time = ctx->ctime, .modified_time = ctx->mtime, .file_format_version = ctx->version, .compression = READSTAT_COMPRESS_NONE, .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG, .is64bit = ctx->u64 }; if (compressed) { if (ctx->rdc_compression) { metadata.compression = READSTAT_COMPRESS_BINARY; } else { metadata.compression = READSTAT_COMPRESS_ROWS; } } if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } if (ctx->column_count == 0) goto cleanup; if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } int i; int index_after_skipping = 0; for (i=0; icolumn_count; i++) { ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval); if (ctx->variables[i] == NULL) break; int cb_retval = READSTAT_HANDLER_OK; if (ctx->handle.variable) { cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx); } if (cb_retval == READSTAT_HANDLER_ABORT) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) { ctx->variables[i]->skip = 1; } else { index_after_skipping++; } } cleanup: return retval; } static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) { readstat_error_t retval = READSTAT_OK; if (!ctx->did_submit_columns) { if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) { goto cleanup; } ctx->did_submit_columns = 1; } cleanup: return retval; } static int sas7bdat_signature_is_recognized(uint32_t signature) { return (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE || signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE || signature == SAS_SUBHEADER_SIGNATURE_COUNTS || signature == SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT || (signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK); } static readstat_error_t sas7bdat_parse_subheader_pointer(const char *shp, size_t shp_size, subheader_pointer_t *info, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if (ctx->u64) { if (shp_size <= 17) { retval = READSTAT_ERROR_PARSE; goto cleanup; } info->offset = sas_read8(&shp[0], ctx->bswap); info->len = sas_read8(&shp[8], ctx->bswap); info->compression = shp[16]; info->is_compressed_data = shp[17]; } else { if (shp_size <= 9) { retval = READSTAT_ERROR_PARSE; goto cleanup; } info->offset = sas_read4(&shp[0], ctx->bswap); info->len = sas_read4(&shp[4], ctx->bswap); info->compression = shp[8]; info->is_compressed_data = shp[9]; } cleanup: return retval; } static readstat_error_t sas7bdat_validate_subheader_pointer(subheader_pointer_t *shp_info, size_t page_size, uint16_t subheader_count, sas7bdat_ctx_t *ctx) { if (shp_info->offset > page_size) return READSTAT_ERROR_PARSE; if (shp_info->len > page_size) return READSTAT_ERROR_PARSE; if (shp_info->offset + shp_info->len > page_size) return READSTAT_ERROR_PARSE; if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size) return READSTAT_ERROR_PARSE; if (shp_info->compression == SAS_COMPRESSION_NONE) { if (shp_info->len < ctx->subheader_signature_size) return READSTAT_ERROR_PARSE; if (shp_info->offset + ctx->subheader_signature_size > page_size) return READSTAT_ERROR_PARSE; } return READSTAT_OK; } /* First, extract column text */ static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap); int i; const char *shp = &page[ctx->page_header_size]; int lshp = ctx->subheader_pointer_size; if (ctx->page_header_size + subheader_count*lshp > page_size) { retval = READSTAT_ERROR_PARSE; goto cleanup; } for (i=0; isubheader_signature_size; if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) { goto cleanup; } if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) { if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) { goto cleanup; } if (shp_info.compression == SAS_COMPRESSION_NONE) { signature = sas_read4(page + shp_info.offset, ctx->bswap); if (!ctx->little_endian && signature == -1 && signature_len == 8) { signature = sas_read4(page + shp_info.offset + 4, ctx->bswap); } if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT) { if ((retval = sas7bdat_parse_subheader(signature, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) { goto cleanup; } } } else if (shp_info.compression == SAS_COMPRESSION_ROW) { /* void */ } else { retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION; goto cleanup; } } shp += lshp; } cleanup: return retval; } static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) { uint16_t page_type; readstat_error_t retval = READSTAT_OK; page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap); const char *data = NULL; if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) { ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap); data = &page[ctx->page_header_size]; } else if (!(page_type & SAS_PAGE_TYPE_COMP)) { uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap); int i; const char *shp = &page[ctx->page_header_size]; int lshp = ctx->subheader_pointer_size; if (ctx->page_header_size + subheader_count*lshp > page_size) { retval = READSTAT_ERROR_PARSE; goto cleanup; } for (i=0; i 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) { if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) { goto cleanup; } if (shp_info.compression == SAS_COMPRESSION_NONE) { signature = sas_read4(page + shp_info.offset, ctx->bswap); if (!ctx->little_endian && signature == -1 && ctx->u64) { signature = sas_read4(page + shp_info.offset + 4, ctx->bswap); } if (shp_info.is_compressed_data && !sas7bdat_signature_is_recognized(signature)) { if (shp_info.len != ctx->row_length) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) { goto cleanup; } } else { if (signature != SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT) { if ((retval = sas7bdat_parse_subheader(signature, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) { goto cleanup; } } } } else if (shp_info.compression == SAS_COMPRESSION_ROW) { if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) { goto cleanup; } } else { retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION; goto cleanup; } } shp += lshp; } if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) { /* HACK - this is supposed to obey 8-byte boundaries but * some files created by Stat/Transfer don't. So verify that the * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that * the file is not from Stat/Transfer) before skipping it */ if ((shp-page)%8 == 4 && shp + 4 <= page + page_size && (*(uint32_t *)shp == 0x00000000 || *(uint32_t *)shp == 0x20202020 || ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) { data = shp + 4; } else { data = shp; } } } if (data) { if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) { goto cleanup; } if (ctx->handle.value) { retval = sas7bdat_parse_rows(data, page + page_size - data, ctx); } } cleanup: return retval; } static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; int64_t i; /* look for META and MIX pages at beginning... */ for (i=0; ipage_count; i++) { if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")", ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } readstat_off_t off = 0; if (ctx->u64) off = 16; size_t head_len = off + 16 + 2; size_t tail_len = ctx->page_size - head_len; if (io->read(ctx->page, head_len, io->io_ctx) < head_len) { retval = READSTAT_ERROR_READ; goto cleanup; } uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap); if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) break; if ((page_type & SAS_PAGE_TYPE_COMP)) continue; if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) { if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) { int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx); snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, i, pos - ctx->page_size, pos-1); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } } cleanup: if (outLastExaminedPage) *outLastExaminedPage = i; return retval; } static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; uint64_t i; uint64_t amd_page_count = 0; /* ...then AMD pages at the end */ for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) { if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")", ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } readstat_off_t off = 0; if (ctx->u64) off = 16; size_t head_len = off + 16 + 2; size_t tail_len = ctx->page_size - head_len; if (io->read(ctx->page, head_len, io->io_ctx) < head_len) { retval = READSTAT_ERROR_READ; goto cleanup; } uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap); if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) { /* Usually AMD pages are at the end but sometimes data pages appear after them */ if (amd_page_count > 0) break; continue; } if ((page_type & SAS_PAGE_TYPE_COMP)) continue; if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) { if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) { int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx); snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, i, pos - ctx->page_size, pos-1); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } amd_page_count++; } cleanup: return retval; } static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; int64_t i; for (i=0; ipage_count; i++) { if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) { goto cleanup; } if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) { if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) { int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx); snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, i, pos - ctx->page_size, pos-1); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } if (ctx->parsed_row_count == ctx->row_limit) break; } cleanup: return retval; } readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) { int64_t last_examined_page_pass1 = 0; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = parser->io; sas7bdat_ctx_t *ctx = calloc(1, sizeof(sas7bdat_ctx_t)); sas_header_info_t *hinfo = calloc(1, sizeof(sas_header_info_t)); ctx->handle = parser->handlers; ctx->input_encoding = parser->input_encoding; ctx->output_encoding = parser->output_encoding; ctx->user_ctx = user_ctx; ctx->io = parser->io; ctx->row_limit = parser->row_limit; if (parser->row_offset > 0) ctx->row_offset = parser->row_offset; if (io->open(path, io->io_ctx) == -1) { retval = READSTAT_ERROR_OPEN; goto cleanup; } if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) { retval = READSTAT_ERROR_SEEK; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file"); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file"); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) { goto cleanup; } ctx->u64 = hinfo->u64; ctx->little_endian = hinfo->little_endian; ctx->vendor = hinfo->vendor; ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian; ctx->header_size = hinfo->header_size; ctx->page_count = hinfo->page_count; ctx->page_size = hinfo->page_size; ctx->page_header_size = hinfo->page_header_size; ctx->subheader_pointer_size = hinfo->subheader_pointer_size; ctx->subheader_signature_size = ctx->u64 ? 8 : 4; ctx->ctime = hinfo->creation_time; ctx->mtime = hinfo->modification_time; ctx->version = hinfo->major_version; if (ctx->input_encoding == NULL) { ctx->input_encoding = hinfo->encoding; } if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) { iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding); if (converter == (iconv_t)-1) { retval = READSTAT_ERROR_UNSUPPORTED_CHARSET; goto cleanup; } ctx->converter = converter; } if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name), hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) { goto cleanup; } if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, ctx->header_size); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) { goto cleanup; } if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) { goto cleanup; } if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) { retval = READSTAT_ERROR_ROW_COUNT_MISMATCH; if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d", ctx->row_limit, ctx->parsed_row_count); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } goto cleanup; } if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) { goto cleanup; } cleanup: io->close(io->io_ctx); if (retval == READSTAT_ERROR_OPEN || retval == READSTAT_ERROR_READ || retval == READSTAT_ERROR_SEEK) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", readstat_error_message(retval), retval, strerror(errno), errno); ctx->handle.error(ctx->error_buf, user_ctx); } } if (ctx) sas7bdat_ctx_free(ctx); if (hinfo) free(hinfo); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_sas7bdat_write.c0000644000076500000240000007475614674240614020623 0ustar00dialout #include #include #include #include #include "../readstat.h" #include "../readstat_writer.h" #include "readstat_sas.h" #include "readstat_sas_rle.h" typedef struct sas7bdat_subheader_s { uint32_t signature; char *data; size_t len; int is_row_data; int is_row_data_compressed; } sas7bdat_subheader_t; typedef struct sas7bdat_subheader_array_s { int64_t count; int64_t capacity; sas7bdat_subheader_t **subheaders; } sas7bdat_subheader_array_t; typedef struct sas7bdat_column_text_s { char *data; size_t capacity; size_t used; int64_t index; } sas7bdat_column_text_t; typedef struct sas7bdat_column_text_array_s { int64_t count; sas7bdat_column_text_t **column_texts; } sas7bdat_column_text_array_t; typedef struct sas7bdat_write_ctx_s { sas_header_info_t *hinfo; sas7bdat_subheader_array_t *sarray; } sas7bdat_write_ctx_t; static size_t sas7bdat_variable_width(readstat_type_t type, size_t user_width); static int32_t sas7bdat_count_meta_pages(readstat_writer_t *writer) { sas7bdat_write_ctx_t *ctx = (sas7bdat_write_ctx_t *)writer->module_ctx; sas_header_info_t *hinfo = ctx->hinfo; sas7bdat_subheader_array_t *sarray = ctx->sarray; int i; int pages = 1; size_t bytes_left = hinfo->page_size - hinfo->page_header_size; size_t shp_ptr_size = hinfo->subheader_pointer_size; for (i=sarray->count-1; i>=0; i--) { sas7bdat_subheader_t *subheader = sarray->subheaders[i]; if (subheader->len + shp_ptr_size > bytes_left) { bytes_left = hinfo->page_size - hinfo->page_header_size; pages++; } bytes_left -= (subheader->len + shp_ptr_size); } return pages; } static size_t sas7bdat_row_length(readstat_writer_t *writer) { int i; size_t len = 0; for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); len += sas7bdat_variable_width(readstat_variable_get_type(variable), readstat_variable_get_storage_width(variable)); } return len; } static int32_t sas7bdat_rows_per_page(readstat_writer_t *writer, sas_header_info_t *hinfo) { size_t row_length = sas7bdat_row_length(writer); return (hinfo->page_size - hinfo->page_header_size) / row_length; } static int32_t sas7bdat_count_data_pages(readstat_writer_t *writer, sas_header_info_t *hinfo) { if (writer->compression == READSTAT_COMPRESS_ROWS) return 0; int32_t rows_per_page = sas7bdat_rows_per_page(writer, hinfo); return (writer->row_count + (rows_per_page - 1)) / rows_per_page; } static sas7bdat_column_text_t *sas7bdat_column_text_init(int64_t index, size_t len) { sas7bdat_column_text_t *column_text = calloc(1, sizeof(sas7bdat_column_text_t)); column_text->data = malloc(len); column_text->capacity = len; column_text->index = index; return column_text; } static void sas7bdat_column_text_free(sas7bdat_column_text_t *column_text) { free(column_text->data); free(column_text); } static void sas7bdat_column_text_array_free(sas7bdat_column_text_array_t *column_text_array) { int i; for (i=0; icount; i++) { sas7bdat_column_text_free(column_text_array->column_texts[i]); } free(column_text_array->column_texts); free(column_text_array); } static sas_text_ref_t sas7bdat_make_text_ref(sas7bdat_column_text_array_t *column_text_array, const char *string) { size_t len = strlen(string); size_t padded_len = (len + 3) / 4 * 4; sas7bdat_column_text_t *column_text = column_text_array->column_texts[ column_text_array->count-1]; if (column_text->used + padded_len > column_text->capacity) { column_text_array->count++; column_text_array->column_texts = realloc(column_text_array->column_texts, sizeof(sas7bdat_column_text_t *) * column_text_array->count); column_text = sas7bdat_column_text_init(column_text_array->count-1, column_text->capacity); column_text_array->column_texts[column_text_array->count-1] = column_text; } sas_text_ref_t text_ref = { .index = column_text->index, .offset = column_text->used + 28, .length = len }; strncpy(&column_text->data[column_text->used], string, padded_len); column_text->used += padded_len; return text_ref; } static readstat_error_t sas7bdat_emit_header(readstat_writer_t *writer, sas_header_info_t *hinfo) { sas_header_start_t header_start = { .a2 = hinfo->u64 ? SAS_ALIGNMENT_OFFSET_4 : SAS_ALIGNMENT_OFFSET_0, .a1 = SAS_ALIGNMENT_OFFSET_0, .endian = machine_is_little_endian() ? SAS_ENDIAN_LITTLE : SAS_ENDIAN_BIG, .file_format = SAS_FILE_FORMAT_UNIX, .encoding = 20, /* UTF-8 */ .file_type = "SAS FILE", .file_info = "DATA " }; memcpy(&header_start.magic, sas7bdat_magic_number, sizeof(header_start.magic)); return sas_write_header(writer, hinfo, header_start); } static sas7bdat_subheader_t *sas7bdat_subheader_init(uint32_t signature, size_t len) { sas7bdat_subheader_t *subheader = calloc(1, sizeof(sas7bdat_subheader_t)); subheader->signature = signature; subheader->len = len; subheader->data = calloc(1, len); return subheader; } static sas7bdat_subheader_t *sas7bdat_row_size_subheader_init(readstat_writer_t *writer, sas_header_info_t *hinfo, sas7bdat_column_text_array_t *column_text_array) { sas7bdat_subheader_t *subheader = sas7bdat_subheader_init( SAS_SUBHEADER_SIGNATURE_ROW_SIZE, hinfo->u64 ? 808 : 480); if (hinfo->u64) { int64_t row_length = sas7bdat_row_length(writer); int64_t row_count = writer->row_count; int64_t ncfl1 = writer->variables_count; int64_t page_size = hinfo->page_size; memcpy(&subheader->data[40], &row_length, sizeof(int64_t)); memcpy(&subheader->data[48], &row_count, sizeof(int64_t)); memcpy(&subheader->data[72], &ncfl1, sizeof(int64_t)); memcpy(&subheader->data[104], &page_size, sizeof(int64_t)); memset(&subheader->data[128], 0xFF, 16); } else { int32_t row_length = sas7bdat_row_length(writer); int32_t row_count = writer->row_count; int32_t ncfl1 = writer->variables_count; int32_t page_size = hinfo->page_size; memcpy(&subheader->data[20], &row_length, sizeof(int32_t)); memcpy(&subheader->data[24], &row_count, sizeof(int32_t)); memcpy(&subheader->data[36], &ncfl1, sizeof(int32_t)); memcpy(&subheader->data[52], &page_size, sizeof(int32_t)); memset(&subheader->data[64], 0xFF, 8); } sas_text_ref_t text_ref = { 0 }; if (writer->file_label[0]) { text_ref = sas7bdat_make_text_ref(column_text_array, writer->file_label); memcpy(&subheader->data[subheader->len-130], &text_ref, sizeof(sas_text_ref_t)); } if (writer->compression == READSTAT_COMPRESS_ROWS) { text_ref = sas7bdat_make_text_ref(column_text_array, SAS_COMPRESSION_SIGNATURE_RLE); memcpy(&subheader->data[subheader->len-118], &text_ref, sizeof(sas_text_ref_t)); } return subheader; } static sas7bdat_subheader_t *sas7bdat_col_size_subheader_init(readstat_writer_t *writer, sas_header_info_t *hinfo) { sas7bdat_subheader_t *subheader = sas7bdat_subheader_init( SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE, hinfo->u64 ? 24 : 12); if (hinfo->u64) { int64_t col_count = writer->variables_count; memcpy(&subheader->data[8], &col_count, sizeof(int64_t)); } else { int32_t col_count = writer->variables_count; memcpy(&subheader->data[4], &col_count, sizeof(int32_t)); } return subheader; } static size_t sas7bdat_col_name_subheader_length(readstat_writer_t *writer, sas_header_info_t *hinfo) { return (hinfo->u64 ? 28+8*writer->variables_count : 20+8*writer->variables_count); } static sas7bdat_subheader_t *sas7bdat_col_name_subheader_init(readstat_writer_t *writer, sas_header_info_t *hinfo, sas7bdat_column_text_array_t *column_text_array) { size_t len = sas7bdat_col_name_subheader_length(writer, hinfo); size_t signature_len = hinfo->u64 ? 8 : 4; uint16_t remainder = sas_subheader_remainder(len, signature_len); sas7bdat_subheader_t *subheader = sas7bdat_subheader_init( SAS_SUBHEADER_SIGNATURE_COLUMN_NAME, len); memcpy(&subheader->data[signature_len], &remainder, sizeof(uint16_t)); int i; char *ptrs = &subheader->data[signature_len+8]; for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); const char *name = readstat_variable_get_name(variable); sas_text_ref_t text_ref = sas7bdat_make_text_ref(column_text_array, name); memcpy(ptrs, &text_ref, sizeof(sas_text_ref_t)); ptrs += 8; } return subheader; } static size_t sas7bdat_col_attrs_subheader_length(readstat_writer_t *writer, sas_header_info_t *hinfo) { return (hinfo->u64 ? 28+16*writer->variables_count : 20+12*writer->variables_count); } static sas7bdat_subheader_t *sas7bdat_col_attrs_subheader_init(readstat_writer_t *writer, sas_header_info_t *hinfo) { size_t len = sas7bdat_col_attrs_subheader_length(writer, hinfo); size_t signature_len = hinfo->u64 ? 8 : 4; uint16_t remainder = sas_subheader_remainder(len, signature_len); sas7bdat_subheader_t *subheader = sas7bdat_subheader_init( SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS, len); memcpy(&subheader->data[signature_len], &remainder, sizeof(uint16_t)); char *ptrs = &subheader->data[signature_len+8]; uint64_t offset = 0; int i; for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); const char *name = readstat_variable_get_name(variable); readstat_type_t type = readstat_variable_get_type(variable); uint16_t name_length_flag = strlen(name) <= 8 ? 4 : 2048; uint32_t width = 0; if (hinfo->u64) { memcpy(&ptrs[0], &offset, sizeof(uint64_t)); ptrs += sizeof(uint64_t); } else { uint32_t offset32 = offset; memcpy(&ptrs[0], &offset32, sizeof(uint32_t)); ptrs += sizeof(uint32_t); } if (type == READSTAT_TYPE_STRING) { ptrs[6] = SAS_COLUMN_TYPE_CHR; width = readstat_variable_get_storage_width(variable); } else { ptrs[6] = SAS_COLUMN_TYPE_NUM; width = 8; } memcpy(&ptrs[0], &width, sizeof(uint32_t)); memcpy(&ptrs[4], &name_length_flag, sizeof(uint16_t)); offset += width; ptrs += 8; } return subheader; } static sas7bdat_subheader_t *sas7bdat_col_format_subheader_init(readstat_variable_t *variable, sas_header_info_t *hinfo, sas7bdat_column_text_array_t *column_text_array) { sas7bdat_subheader_t *subheader = sas7bdat_subheader_init( SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT, hinfo->u64 ? 64 : 52); const char *format = readstat_variable_get_format(variable); const char *label = readstat_variable_get_label(variable); off_t format_offset = hinfo->u64 ? 46 : 34; off_t label_offset = hinfo->u64 ? 52 : 40; if (format) { sas_text_ref_t text_ref = sas7bdat_make_text_ref(column_text_array, format); memcpy(&subheader->data[format_offset+0], &text_ref.index, sizeof(uint16_t)); memcpy(&subheader->data[format_offset+2], &text_ref.offset, sizeof(uint16_t)); memcpy(&subheader->data[format_offset+4], &text_ref.length, sizeof(uint16_t)); } if (label) { sas_text_ref_t text_ref = sas7bdat_make_text_ref(column_text_array, label); memcpy(&subheader->data[label_offset+0], &text_ref.index, sizeof(uint16_t)); memcpy(&subheader->data[label_offset+2], &text_ref.offset, sizeof(uint16_t)); memcpy(&subheader->data[label_offset+4], &text_ref.length, sizeof(uint16_t)); } return subheader; } static size_t sas7bdat_col_text_subheader_length(sas_header_info_t *hinfo, sas7bdat_column_text_t *column_text) { size_t signature_len = hinfo->u64 ? 8 : 4; size_t text_len = column_text ? column_text->used : 0; return signature_len + 28 + text_len; } static sas7bdat_subheader_t *sas7bdat_col_text_subheader_init(readstat_writer_t *writer, sas_header_info_t *hinfo, sas7bdat_column_text_t *column_text) { size_t signature_len = hinfo->u64 ? 8 : 4; size_t len = sas7bdat_col_text_subheader_length(hinfo, column_text); sas7bdat_subheader_t *subheader = sas7bdat_subheader_init( SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT, len); uint16_t used = sas_subheader_remainder(len, signature_len); memcpy(&subheader->data[signature_len], &used, sizeof(uint16_t)); memset(&subheader->data[signature_len+12], ' ', 8); memcpy(&subheader->data[signature_len+28], column_text->data, column_text->used); return subheader; } static sas7bdat_subheader_array_t *sas7bdat_subheader_array_init(readstat_writer_t *writer, sas_header_info_t *hinfo) { sas7bdat_column_text_array_t *column_text_array = calloc(1, sizeof(sas7bdat_column_text_array_t)); column_text_array->count = 1; column_text_array->column_texts = malloc(sizeof(sas7bdat_column_text_t *)); column_text_array->column_texts[0] = sas7bdat_column_text_init(0, hinfo->page_size - hinfo->page_header_size - hinfo->subheader_pointer_size - sas7bdat_col_text_subheader_length(hinfo, NULL)); sas7bdat_subheader_array_t *sarray = calloc(1, sizeof(sas7bdat_subheader_array_t)); sarray->count = 4+writer->variables_count; sarray->subheaders = calloc(sarray->count, sizeof(sas7bdat_subheader_t *)); long idx = 0; int i; sas7bdat_subheader_t *col_name_subheader = NULL; sas7bdat_subheader_t *col_attrs_subheader = NULL; sas7bdat_subheader_t **col_format_subheaders = NULL; col_name_subheader = sas7bdat_col_name_subheader_init(writer, hinfo, column_text_array); col_attrs_subheader = sas7bdat_col_attrs_subheader_init(writer, hinfo); sarray->subheaders[idx++] = sas7bdat_row_size_subheader_init(writer, hinfo, column_text_array); sarray->subheaders[idx++] = sas7bdat_col_size_subheader_init(writer, hinfo); col_format_subheaders = calloc(writer->variables_count, sizeof(sas7bdat_subheader_t *)); for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); col_format_subheaders[i] = sas7bdat_col_format_subheader_init(variable, hinfo, column_text_array); } sarray->count += column_text_array->count; sarray->subheaders = realloc(sarray->subheaders, sarray->count * sizeof(sas7bdat_subheader_t *)); for (i=0; icount; i++) { sarray->subheaders[idx++] = sas7bdat_col_text_subheader_init(writer, hinfo, column_text_array->column_texts[i]); } sas7bdat_column_text_array_free(column_text_array); sarray->subheaders[idx++] = col_name_subheader; sarray->subheaders[idx++] = col_attrs_subheader; for (i=0; ivariables_count; i++) { sarray->subheaders[idx++] = col_format_subheaders[i]; } free(col_format_subheaders); sarray->capacity = sarray->count; if (writer->compression == READSTAT_COMPRESS_ROWS) { sarray->capacity = (sarray->count + writer->row_count); sarray->subheaders = realloc(sarray->subheaders, sarray->capacity * sizeof(sas7bdat_subheader_t *)); } return sarray; } static void sas7bdat_subheader_free(sas7bdat_subheader_t *subheader) { if (!subheader) return; if (subheader->data) free(subheader->data); free(subheader); } static void sas7bdat_subheader_array_free(sas7bdat_subheader_array_t *sarray) { int i; for (i=0; icount; i++) { sas7bdat_subheader_free(sarray->subheaders[i]); } free(sarray->subheaders); free(sarray); } static int sas7bdat_subheader_type(uint32_t signature) { return (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT || signature == SAS_SUBHEADER_SIGNATURE_COLUMN_NAME || signature == SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS || signature == SAS_SUBHEADER_SIGNATURE_COLUMN_LIST); } static readstat_error_t sas7bdat_emit_meta_pages(readstat_writer_t *writer) { sas7bdat_write_ctx_t *ctx = (sas7bdat_write_ctx_t *)writer->module_ctx; sas_header_info_t *hinfo = ctx->hinfo; sas7bdat_subheader_array_t *sarray = ctx->sarray; readstat_error_t retval = READSTAT_OK; int16_t page_type = SAS_PAGE_TYPE_META; char *page = malloc(hinfo->page_size); int64_t shp_written = 0; while (sarray->count > shp_written) { memset(page, 0, hinfo->page_size); int16_t shp_count = 0; size_t shp_data_offset = hinfo->page_size; size_t shp_ptr_offset = hinfo->page_header_size; size_t shp_ptr_size = hinfo->subheader_pointer_size; memcpy(&page[hinfo->page_header_size-8], &page_type, sizeof(int16_t)); if (sarray->subheaders[shp_written]->len + shp_ptr_size > shp_data_offset - shp_ptr_offset) { retval = READSTAT_ERROR_ROW_IS_TOO_WIDE_FOR_PAGE; goto cleanup; } while (sarray->count > shp_written && sarray->subheaders[shp_written]->len + shp_ptr_size <= shp_data_offset - shp_ptr_offset) { sas7bdat_subheader_t *subheader = sarray->subheaders[shp_written]; uint32_t signature32 = subheader->signature; /* copy ptr */ if (hinfo->u64) { uint64_t offset = shp_data_offset - subheader->len; uint64_t len = subheader->len; memcpy(&page[shp_ptr_offset], &offset, sizeof(uint64_t)); memcpy(&page[shp_ptr_offset+8], &len, sizeof(uint64_t)); if (subheader->is_row_data) { if (subheader->is_row_data_compressed) { page[shp_ptr_offset+16] = SAS_COMPRESSION_ROW; } else { page[shp_ptr_offset+16] = SAS_COMPRESSION_NONE; } page[shp_ptr_offset+17] = 1; } else { page[shp_ptr_offset+17] = sas7bdat_subheader_type(subheader->signature); if (signature32 >= 0xFF000000) { int64_t signature64 = (int32_t)signature32; memcpy(&subheader->data[0], &signature64, sizeof(int64_t)); } else { memcpy(&subheader->data[0], &signature32, sizeof(int32_t)); } } } else { uint32_t offset = shp_data_offset - subheader->len; uint32_t len = subheader->len; memcpy(&page[shp_ptr_offset], &offset, sizeof(uint32_t)); memcpy(&page[shp_ptr_offset+4], &len, sizeof(uint32_t)); if (subheader->is_row_data) { if (subheader->is_row_data_compressed) { page[shp_ptr_offset+8] = SAS_COMPRESSION_ROW; } else { page[shp_ptr_offset+8] = SAS_COMPRESSION_NONE; } page[shp_ptr_offset+9] = 1; } else { page[shp_ptr_offset+9] = sas7bdat_subheader_type(subheader->signature); memcpy(&subheader->data[0], &signature32, sizeof(int32_t)); } } shp_ptr_offset += shp_ptr_size; /* copy data */ shp_data_offset -= subheader->len; memcpy(&page[shp_data_offset], subheader->data, subheader->len); shp_written++; shp_count++; } if (hinfo->u64) { memcpy(&page[34], &shp_count, sizeof(int16_t)); memcpy(&page[36], &shp_count, sizeof(int16_t)); } else { memcpy(&page[18], &shp_count, sizeof(int16_t)); memcpy(&page[20], &shp_count, sizeof(int16_t)); } retval = readstat_write_bytes(writer, page, hinfo->page_size); if (retval != READSTAT_OK) goto cleanup; } cleanup: free(page); return retval; } static int sas7bdat_page_is_too_small(readstat_writer_t *writer, sas_header_info_t *hinfo, size_t row_length) { size_t page_length = hinfo->page_size - hinfo->page_header_size; if (writer->compression == READSTAT_COMPRESS_NONE && page_length < row_length) return 1; if (writer->compression == READSTAT_COMPRESS_ROWS && page_length < row_length + hinfo->subheader_pointer_size) return 1; if (page_length < sas7bdat_col_name_subheader_length(writer, hinfo) + hinfo->subheader_pointer_size) return 1; if (page_length < sas7bdat_col_attrs_subheader_length(writer, hinfo) + hinfo->subheader_pointer_size) return 1; return 0; } static sas7bdat_write_ctx_t *sas7bdat_write_ctx_init(readstat_writer_t *writer) { sas7bdat_write_ctx_t *ctx = calloc(1, sizeof(sas7bdat_write_ctx_t)); sas_header_info_t *hinfo = sas_header_info_init(writer, writer->is_64bit); size_t row_length = sas7bdat_row_length(writer); while (sas7bdat_page_is_too_small(writer, hinfo, row_length)) { hinfo->page_size <<= 1; } ctx->hinfo = hinfo; ctx->sarray = sas7bdat_subheader_array_init(writer, hinfo); return ctx; } static void sas7bdat_write_ctx_free(sas7bdat_write_ctx_t *ctx) { free(ctx->hinfo); sas7bdat_subheader_array_free(ctx->sarray); free(ctx); } static readstat_error_t sas7bdat_emit_header_and_meta_pages(readstat_writer_t *writer) { sas7bdat_write_ctx_t *ctx = (sas7bdat_write_ctx_t *)writer->module_ctx; readstat_error_t retval = READSTAT_OK; if (sas7bdat_row_length(writer) == 0) { retval = READSTAT_ERROR_TOO_FEW_COLUMNS; goto cleanup; } if (writer->compression == READSTAT_COMPRESS_NONE && sas7bdat_rows_per_page(writer, ctx->hinfo) == 0) { retval = READSTAT_ERROR_ROW_IS_TOO_WIDE_FOR_PAGE; goto cleanup; } ctx->hinfo->page_count = sas7bdat_count_meta_pages(writer) + sas7bdat_count_data_pages(writer, ctx->hinfo); retval = sas7bdat_emit_header(writer, ctx->hinfo); if (retval != READSTAT_OK) goto cleanup; retval = sas7bdat_emit_meta_pages(writer); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sas7bdat_begin_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t retval = READSTAT_OK; writer->module_ctx = sas7bdat_write_ctx_init(writer); if (writer->compression == READSTAT_COMPRESS_NONE) { retval = sas7bdat_emit_header_and_meta_pages(writer); if (retval != READSTAT_OK) goto cleanup; } cleanup: if (retval != READSTAT_OK) { if (writer->module_ctx) { sas7bdat_write_ctx_free(writer->module_ctx); writer->module_ctx = NULL; } } return retval; } static readstat_error_t sas7bdat_end_data(void *writer_ctx) { readstat_error_t retval = READSTAT_OK; readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; sas7bdat_write_ctx_t *ctx = (sas7bdat_write_ctx_t *)writer->module_ctx; if (writer->compression == READSTAT_COMPRESS_ROWS) { retval = sas7bdat_emit_header_and_meta_pages(writer); } else { retval = sas_fill_page(writer, ctx->hinfo); } return retval; } static void sas7bdat_module_ctx_free(void *module_ctx) { sas7bdat_write_ctx_free(module_ctx); } static readstat_error_t sas7bdat_write_double(void *row, const readstat_variable_t *var, double value) { memcpy(row, &value, sizeof(double)); return READSTAT_OK; } static readstat_error_t sas7bdat_write_float(void *row, const readstat_variable_t *var, float value) { return sas7bdat_write_double(row, var, value); } static readstat_error_t sas7bdat_write_int32(void *row, const readstat_variable_t *var, int32_t value) { return sas7bdat_write_double(row, var, value); } static readstat_error_t sas7bdat_write_int16(void *row, const readstat_variable_t *var, int16_t value) { return sas7bdat_write_double(row, var, value); } static readstat_error_t sas7bdat_write_int8(void *row, const readstat_variable_t *var, int8_t value) { return sas7bdat_write_double(row, var, value); } static readstat_error_t sas7bdat_write_missing_tagged_raw(void *row, const readstat_variable_t *var, char tag) { union { double dval; char chars[8]; } nan_value; nan_value.dval = NAN; nan_value.chars[machine_is_little_endian() ? 5 : 2] = ~tag; return sas7bdat_write_double(row, var, nan_value.dval); } static readstat_error_t sas7bdat_write_missing_tagged(void *row, const readstat_variable_t *var, char tag) { readstat_error_t error = sas_validate_tag(tag); if (error == READSTAT_OK) return sas7bdat_write_missing_tagged_raw(row, var, tag); return error; } static readstat_error_t sas7bdat_write_missing_numeric(void *row, const readstat_variable_t *var) { return sas7bdat_write_missing_tagged_raw(row, var, '.'); } static readstat_error_t sas7bdat_write_string(void *row, const readstat_variable_t *var, const char *value) { size_t max_len = readstat_variable_get_storage_width(var); if (value == NULL || value[0] == '\0') { memset(row, '\0', max_len); } else { size_t value_len = strlen(value); if (value_len > max_len) return READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG; strncpy((char *)row, value, max_len); } return READSTAT_OK; } static readstat_error_t sas7bdat_write_missing_string(void *row, const readstat_variable_t *var) { return sas7bdat_write_string(row, var, NULL); } static size_t sas7bdat_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) { return user_width; } return 8; } static readstat_error_t sas7bdat_write_row_uncompressed(readstat_writer_t *writer, sas7bdat_write_ctx_t *ctx, void *bytes, size_t len) { readstat_error_t retval = READSTAT_OK; sas_header_info_t *hinfo = ctx->hinfo; int32_t rows_per_page = sas7bdat_rows_per_page(writer, hinfo); if (writer->current_row % rows_per_page == 0) { retval = sas_fill_page(writer, ctx->hinfo); if (retval != READSTAT_OK) goto cleanup; int16_t page_type = SAS_PAGE_TYPE_DATA; int16_t page_row_count = (writer->row_count - writer->current_row < rows_per_page ? writer->row_count - writer->current_row : rows_per_page); char *header = calloc(hinfo->page_header_size, 1); memcpy(&header[hinfo->page_header_size-6], &page_row_count, sizeof(int16_t)); memcpy(&header[hinfo->page_header_size-8], &page_type, sizeof(int16_t)); retval = readstat_write_bytes(writer, header, hinfo->page_header_size); free(header); if (retval != READSTAT_OK) goto cleanup; } retval = readstat_write_bytes(writer, bytes, len); cleanup: return retval; } /* We don't actually write compressed data out at this point; the file header * requires a page count, so instead we collect the compressed subheaders in * memory and write the entire file at the end, once the page count can be * determined. */ static readstat_error_t sas7bdat_write_row_compressed(readstat_writer_t *writer, sas7bdat_write_ctx_t *ctx, void *bytes, size_t len) { readstat_error_t retval = READSTAT_OK; size_t compressed_len = sas_rle_compressed_len(bytes, len); sas7bdat_subheader_t *subheader = NULL; if (compressed_len < len) { subheader = sas7bdat_subheader_init(0, compressed_len); subheader->is_row_data = 1; subheader->is_row_data_compressed = 1; size_t actual_len = sas_rle_compress(subheader->data, subheader->len, bytes, len); if (actual_len != compressed_len) { retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH; goto cleanup; } } else { subheader = sas7bdat_subheader_init(0, len); subheader->is_row_data = 1; memcpy(subheader->data, bytes, len); } ctx->sarray->subheaders[ctx->sarray->count++] = subheader; cleanup: if (retval != READSTAT_OK) sas7bdat_subheader_free(subheader); return retval; } static readstat_error_t sas7bdat_write_row(void *writer_ctx, void *bytes, size_t len) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; sas7bdat_write_ctx_t *ctx = (sas7bdat_write_ctx_t *)writer->module_ctx; readstat_error_t retval = READSTAT_OK; if (writer->compression == READSTAT_COMPRESS_NONE) { retval = sas7bdat_write_row_uncompressed(writer, ctx, bytes, len); } else if (writer->compression == READSTAT_COMPRESS_ROWS) { retval = sas7bdat_write_row_compressed(writer, ctx, bytes, len); } return retval; } static readstat_error_t sas7bdat_metadata_ok(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; if (writer->compression != READSTAT_COMPRESS_NONE && writer->compression != READSTAT_COMPRESS_ROWS) return READSTAT_ERROR_UNSUPPORTED_COMPRESSION; return READSTAT_OK; } readstat_error_t readstat_begin_writing_sas7bdat(readstat_writer_t *writer, void *user_ctx, long row_count) { if (writer->version == 0) writer->version = SAS_DEFAULT_FILE_VERSION; writer->callbacks.metadata_ok = &sas7bdat_metadata_ok; writer->callbacks.write_int8 = &sas7bdat_write_int8; writer->callbacks.write_int16 = &sas7bdat_write_int16; writer->callbacks.write_int32 = &sas7bdat_write_int32; writer->callbacks.write_float = &sas7bdat_write_float; writer->callbacks.write_double = &sas7bdat_write_double; writer->callbacks.write_string = &sas7bdat_write_string; writer->callbacks.write_missing_string = &sas7bdat_write_missing_string; writer->callbacks.write_missing_number = &sas7bdat_write_missing_numeric; writer->callbacks.write_missing_tagged = &sas7bdat_write_missing_tagged; writer->callbacks.variable_width = &sas7bdat_variable_width; writer->callbacks.variable_ok = &sas_validate_variable; writer->callbacks.begin_data = &sas7bdat_begin_data; writer->callbacks.end_data = &sas7bdat_end_data; writer->callbacks.module_ctx_free = &sas7bdat_module_ctx_free; writer->callbacks.write_row = &sas7bdat_write_row; return readstat_begin_writing_file(writer, user_ctx, row_count); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_sas_rle.c0000644000076500000240000002370114674240614017311 0ustar00dialout #include #include #include #if defined(_MSC_VER) #include typedef SSIZE_T ssize_t; #endif #include "readstat_sas_rle.h" #define SAS_RLE_COMMAND_COPY64 0 #define SAS_RLE_COMMAND_COPY64_PLUS_4096 1 #define SAS_RLE_COMMAND_COPY96 2 #define SAS_RLE_COMMAND_INSERT_BYTE18 4 #define SAS_RLE_COMMAND_INSERT_AT17 5 #define SAS_RLE_COMMAND_INSERT_BLANK17 6 #define SAS_RLE_COMMAND_INSERT_ZERO17 7 #define SAS_RLE_COMMAND_COPY1 8 #define SAS_RLE_COMMAND_COPY17 9 #define SAS_RLE_COMMAND_COPY33 10 #define SAS_RLE_COMMAND_COPY49 11 #define SAS_RLE_COMMAND_INSERT_BYTE3 12 #define SAS_RLE_COMMAND_INSERT_AT2 13 #define SAS_RLE_COMMAND_INSERT_BLANK2 14 #define SAS_RLE_COMMAND_INSERT_ZERO2 15 #define MAX_INSERT_RUN 4112 // 4095 + 17 #define MAX_COPY_RUN 4159 // 4095 + 64 static size_t command_lengths[16] = { [SAS_RLE_COMMAND_COPY64] = 1, [SAS_RLE_COMMAND_COPY64_PLUS_4096] = 1, [SAS_RLE_COMMAND_INSERT_BYTE18] = 2, [SAS_RLE_COMMAND_INSERT_AT17] = 1, [SAS_RLE_COMMAND_INSERT_BLANK17] = 1, [SAS_RLE_COMMAND_INSERT_ZERO17] = 1, [SAS_RLE_COMMAND_INSERT_BYTE3] = 1 }; ssize_t sas_rle_decompressed_len(const void *input_buf, size_t input_len) { return sas_rle_decompress(NULL, 0, input_buf, input_len); } ssize_t sas_rle_decompress(void *output_buf, size_t output_len, const void *input_buf, size_t input_len) { unsigned char *buffer = (unsigned char *)output_buf; unsigned char *output = buffer; size_t output_written = 0; const unsigned char *input = (const unsigned char *)input_buf; while (input < (const unsigned char *)input_buf + input_len) { unsigned char control = *input++; unsigned char command = (control & 0xF0) >> 4; unsigned char length = (control & 0x0F); int copy_len = 0; int insert_len = 0; unsigned char insert_byte = '\0'; if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) { return -1; } switch (command) { case SAS_RLE_COMMAND_COPY64: copy_len = (*input++) + 64 + length * 256; break; case SAS_RLE_COMMAND_COPY64_PLUS_4096: copy_len = (*input++) + 64 + length * 256 + 4096; break; case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break; case SAS_RLE_COMMAND_INSERT_BYTE18: insert_len = (*input++) + 18 + length * 256; insert_byte = *input++; break; case SAS_RLE_COMMAND_INSERT_AT17: insert_len = (*input++) + 17 + length * 256; insert_byte = '@'; break; case SAS_RLE_COMMAND_INSERT_BLANK17: insert_len = (*input++) + 17 + length * 256; insert_byte = ' '; break; case SAS_RLE_COMMAND_INSERT_ZERO17: insert_len = (*input++) + 17 + length * 256; insert_byte = '\0'; break; case SAS_RLE_COMMAND_COPY1: copy_len = length + 1; break; case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break; case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break; case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break; case SAS_RLE_COMMAND_INSERT_BYTE3: insert_byte = *input++; insert_len = length + 3; break; case SAS_RLE_COMMAND_INSERT_AT2: insert_byte = '@'; insert_len = length + 2; break; case SAS_RLE_COMMAND_INSERT_BLANK2: insert_byte = ' '; insert_len = length + 2; break; case SAS_RLE_COMMAND_INSERT_ZERO2: insert_byte = '\0'; insert_len = length + 2; break; default: /* error out here? */ break; } if (copy_len) { if (output_written + copy_len > output_len) { return -1; } if (input + copy_len > (const unsigned char *)input_buf + input_len) { return -1; } if (output) { memcpy(&output[output_written], input, copy_len); } input += copy_len; output_written += copy_len; } if (insert_len) { if (output_written + insert_len > output_len) { return -1; } if (output) { memset(&output[output_written], insert_byte, insert_len); } output_written += insert_len; } } return output_written; } static size_t sas_rle_measure_copy_run(size_t copy_run) { size_t len = 0; while (copy_run >= MAX_COPY_RUN) { len += 2 + MAX_COPY_RUN; copy_run -= MAX_COPY_RUN; } return len + (copy_run > 64) + (copy_run > 0) + copy_run; } static size_t sas_rle_copy_run(unsigned char *output_buf, size_t offset, const unsigned char *copy, size_t copy_run) { unsigned char *out = output_buf + offset; if (output_buf == NULL) return sas_rle_measure_copy_run(copy_run); while (copy_run >= MAX_COPY_RUN) { *out++ = (SAS_RLE_COMMAND_COPY64 << 4) + 0x0F; *out++ = 0xFF; memcpy(out, copy, MAX_COPY_RUN); out += MAX_COPY_RUN; copy += MAX_COPY_RUN; copy_run -= MAX_COPY_RUN; } if (copy_run > 64) { int length = (copy_run - 64) / 256; unsigned char rem = (copy_run - 64) % 256; *out++ = (SAS_RLE_COMMAND_COPY64 << 4) + (length & 0x0F); *out++ = rem; } else if (copy_run >= 49) { *out++ = (SAS_RLE_COMMAND_COPY49 << 4) + (copy_run - 49); } else if (copy_run >= 33) { *out++ = (SAS_RLE_COMMAND_COPY33 << 4) + (copy_run - 33); } else if (copy_run >= 17) { *out++ = (SAS_RLE_COMMAND_COPY17 << 4) + (copy_run - 17); } else if (copy_run >= 1) { *out++ = (SAS_RLE_COMMAND_COPY1 << 4) + (copy_run - 1); } memcpy(out, copy, copy_run); out += copy_run; return out - (output_buf + offset); } static int sas_rle_is_special_byte(unsigned char last_byte) { return (last_byte == '@' || last_byte == ' ' || last_byte == '\0'); } static size_t sas_rle_measure_insert_run(unsigned char last_byte, size_t insert_run) { if (sas_rle_is_special_byte(last_byte)) return insert_run > 17 ? 2 : 1; return insert_run > 18 ? 3 : 2; } static size_t sas_rle_insert_run(unsigned char *output_buf, size_t offset, unsigned char last_byte, size_t insert_run) { unsigned char *out = output_buf + offset; if (output_buf == NULL) return sas_rle_measure_insert_run(last_byte, insert_run); if (sas_rle_is_special_byte(last_byte)) { if (insert_run > 17) { int length = (insert_run - 17) / 256; unsigned char rem = (insert_run - 17) % 256; if (last_byte == '@') { *out++ = (SAS_RLE_COMMAND_INSERT_AT17 << 4) + (length & 0x0F); } else if (last_byte == ' ') { *out++ = (SAS_RLE_COMMAND_INSERT_BLANK17 << 4) + (length & 0x0F); } else if (last_byte == '\0') { *out++ = (SAS_RLE_COMMAND_INSERT_ZERO17 << 4) + (length & 0x0F); } *out++ = rem; } else if (insert_run >= 2) { if (last_byte == '@') { *out++ = (SAS_RLE_COMMAND_INSERT_AT2 << 4) + (insert_run - 2); } else if (last_byte == ' ') { *out++ = (SAS_RLE_COMMAND_INSERT_BLANK2 << 4) + (insert_run - 2); } else if (last_byte == '\0') { *out++ = (SAS_RLE_COMMAND_INSERT_ZERO2 << 4) + (insert_run - 2); } } } else if (insert_run > 18) { int length = (insert_run - 18) / 256; unsigned char rem = (insert_run - 18) % 256; *out++ = (SAS_RLE_COMMAND_INSERT_BYTE18 << 4) + (length & 0x0F); *out++ = rem; *out++ = last_byte; } else if (insert_run >= 3) { *out++ = (SAS_RLE_COMMAND_INSERT_BYTE3 << 4) + (insert_run - 3); *out++ = last_byte; } return out - (output_buf + offset); } static int sas_rle_is_insert_run(unsigned char last_byte, size_t insert_run) { if (sas_rle_is_special_byte(last_byte)) return (insert_run > 1); return (insert_run > 2); } ssize_t sas_rle_compressed_len(const void *bytes, size_t len) { return sas_rle_compress(NULL, 0, bytes, len); } ssize_t sas_rle_compress(void *output_buf, size_t output_len, const void *input_buf, size_t input_len) { /* TODO bounds check */ const unsigned char *p = (const unsigned char *)input_buf; const unsigned char *pe = p + input_len; const unsigned char *copy = p; unsigned char *out = (unsigned char *)output_buf; size_t insert_run = 0; size_t copy_run = 0; size_t out_written = 0; unsigned char last_byte = 0; while (p < pe) { unsigned char c = *p; if (insert_run == 0) { insert_run = 1; } else if (c == last_byte && insert_run < MAX_INSERT_RUN) { insert_run++; } else { if (sas_rle_is_insert_run(last_byte, insert_run)) { out_written += sas_rle_copy_run(out, out_written, copy, copy_run); out_written += sas_rle_insert_run(out, out_written, last_byte, insert_run); copy_run = 0; copy = p; } else { copy_run += insert_run; } insert_run = 1; } last_byte = c; p++; } if (sas_rle_is_insert_run(last_byte, insert_run)) { out_written += sas_rle_copy_run(out, out_written, copy, copy_run); out_written += sas_rle_insert_run(out, out_written, last_byte, insert_run); } else { out_written += sas_rle_copy_run(out, out_written, copy, copy_run + insert_run); } return out_written; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_sas_rle.h0000644000076500000240000000055614674240614017321 0ustar00dialout ssize_t sas_rle_decompress(void *output_buf, size_t output_len, const void *input_buf, size_t input_len); ssize_t sas_rle_compress(void *output_buf, size_t output_len, const void *input_buf, size_t input_len); ssize_t sas_rle_decompressed_len(const void *input_buf, size_t input_len); ssize_t sas_rle_compressed_len(const void *bytes, size_t len); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_xport.c0000644000076500000240000000147414674240614017040 0ustar00dialout#include #include "readstat_xport.h" #include "../readstat_bits.h" char _xport_months[12][4] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; void xport_namestr_bswap(xport_namestr_t *namestr) { if (!machine_is_little_endian()) return; namestr->ntype = byteswap2(namestr->ntype); namestr->nhfun = byteswap2(namestr->nhfun); namestr->nlng = byteswap2(namestr->nlng); namestr->nvar0 = byteswap2(namestr->nvar0); namestr->nfl = byteswap2(namestr->nfl); namestr->nfd = byteswap2(namestr->nfd); namestr->nfj = byteswap2(namestr->nfj); namestr->nifl = byteswap2(namestr->nifl); namestr->nifd = byteswap2(namestr->nifd); namestr->npos = byteswap4(namestr->npos); namestr->labeln = byteswap2(namestr->labeln); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_xport.h0000644000076500000240000000175714674240614017051 0ustar00dialout typedef struct xport_header_record_s { char name[9]; int num1; int num2; int num3; int num4; int num5; int num6; } xport_header_record_t; extern char _xport_months[12][4]; #pragma pack(push, 1) typedef struct xport_namestr_s { uint16_t ntype; uint16_t nhfun; uint16_t nlng; uint16_t nvar0; char nname[8]; char nlabel[40]; char nform[8]; uint16_t nfl; uint16_t nfd; uint16_t nfj; char nfill[2]; char niform[8]; uint16_t nifl; uint16_t nifd; uint32_t npos; char longname[32]; uint16_t labeln; char rest[18]; } xport_namestr_t; #pragma pack(pop) typedef struct xport_format_s { char name[32]; int width; int decimals; } xport_format_t; #define XPORT_MIN_DOUBLE_SIZE 3 #define XPORT_MAX_DOUBLE_SIZE 8 void xport_namestr_bswap(xport_namestr_t *namestr); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_xport_parse_format.c0000644000076500000240000001406014674240614021575 0ustar00dialout #line 1 "src/sas/readstat_xport_parse_format.rl" #include "../readstat.h" #include "readstat_xport.h" #include "readstat_xport_parse_format.h" #line 10 "src/sas/readstat_xport_parse_format.c" static const char _xport_format_parse_actions[] = { 0, 1, 0, 1, 1, 1, 3, 1, 4, 2, 2, 0, 3, 1, 2, 0 }; static const char _xport_format_parse_key_offsets[] = { 0, 0, 7, 14, 23, 31, 31, 34, 42, 50, 58, 60, 62, 65, 73, 81 }; static const char _xport_format_parse_trans_keys[] = { 95, 48, 57, 65, 90, 97, 122, 95, 48, 57, 65, 90, 97, 122, 36, 46, 95, 48, 57, 65, 90, 97, 122, 46, 95, 48, 57, 65, 90, 97, 122, 46, 48, 57, 46, 95, 48, 57, 65, 90, 97, 122, 46, 95, 48, 57, 65, 90, 97, 122, 46, 95, 48, 57, 65, 90, 97, 122, 48, 57, 48, 57, 46, 48, 57, 46, 95, 48, 57, 65, 90, 97, 122, 46, 95, 48, 57, 65, 90, 97, 122, 46, 95, 48, 57, 65, 90, 97, 122, 0 }; static const char _xport_format_parse_single_lengths[] = { 0, 1, 1, 3, 2, 0, 1, 2, 2, 2, 0, 0, 1, 2, 2, 2 }; static const char _xport_format_parse_range_lengths[] = { 0, 3, 3, 3, 3, 0, 1, 3, 3, 3, 1, 1, 1, 3, 3, 3 }; static const char _xport_format_parse_index_offsets[] = { 0, 0, 5, 10, 17, 23, 24, 27, 33, 39, 45, 47, 49, 52, 58, 64 }; static const char _xport_format_parse_indicies[] = { 2, 0, 2, 2, 1, 4, 3, 4, 4, 1, 5, 6, 8, 7, 8, 8, 1, 9, 11, 10, 11, 11, 1, 1, 12, 13, 1, 9, 0, 14, 0, 0, 1, 12, 2, 15, 2, 2, 1, 9, 2, 14, 2, 2, 1, 16, 1, 17, 1, 18, 19, 1, 6, 3, 20, 3, 3, 1, 18, 4, 21, 4, 4, 1, 6, 4, 20, 4, 4, 1, 0 }; static const char _xport_format_parse_trans_targs[] = { 1, 0, 9, 2, 15, 4, 10, 12, 13, 5, 6, 7, 5, 6, 8, 8, 11, 11, 10, 12, 14, 14 }; static const char _xport_format_parse_trans_actions[] = { 0, 0, 0, 0, 0, 0, 3, 12, 0, 3, 12, 0, 5, 1, 12, 1, 9, 1, 5, 1, 12, 1 }; static const char _xport_format_parse_eof_actions[] = { 0, 0, 0, 3, 3, 0, 5, 3, 5, 3, 0, 7, 5, 3, 5, 3 }; static const int xport_format_parse_start = 3; static const int xport_format_parse_en_main = 3; #line 9 "src/sas/readstat_xport_parse_format.rl" readstat_error_t xport_parse_format(const char *data, size_t len, xport_format_t *fmt, readstat_error_handler error_handler, void *user_ctx) { fmt->name[0] = '\0'; fmt->width = 0; fmt->decimals = 0; readstat_error_t retval = READSTAT_OK; const char *p = data; const char *pe = p + len; const char *eof = pe; int cs; unsigned int temp_val = 0; size_t parsed_len = 0; #line 106 "src/sas/readstat_xport_parse_format.c" { cs = xport_format_parse_start; } #line 111 "src/sas/readstat_xport_parse_format.c" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _xport_format_parse_trans_keys + _xport_format_parse_key_offsets[cs]; _trans = _xport_format_parse_index_offsets[cs]; _klen = _xport_format_parse_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _xport_format_parse_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _xport_format_parse_indicies[_trans]; cs = _xport_format_parse_trans_targs[_trans]; if ( _xport_format_parse_trans_actions[_trans] == 0 ) goto _again; _acts = _xport_format_parse_actions + _xport_format_parse_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 28 "src/sas/readstat_xport_parse_format.rl" { temp_val = 10 * temp_val + ((*p) - '0'); } break; case 1: #line 32 "src/sas/readstat_xport_parse_format.rl" { parsed_len = p - data; if (parsed_len < sizeof(fmt->name)) { memcpy(fmt->name, data, parsed_len); fmt->name[parsed_len] = '\0'; } } break; case 2: #line 40 "src/sas/readstat_xport_parse_format.rl" { temp_val = 0; } break; case 3: #line 47 "src/sas/readstat_xport_parse_format.rl" { fmt->width = temp_val; } break; #line 209 "src/sas/readstat_xport_parse_format.c" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} if ( p == eof ) { const char *__acts = _xport_format_parse_actions + _xport_format_parse_eof_actions[cs]; unsigned int __nacts = (unsigned int) *__acts++; while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 1: #line 32 "src/sas/readstat_xport_parse_format.rl" { parsed_len = p - data; if (parsed_len < sizeof(fmt->name)) { memcpy(fmt->name, data, parsed_len); fmt->name[parsed_len] = '\0'; } } break; case 3: #line 47 "src/sas/readstat_xport_parse_format.rl" { fmt->width = temp_val; } break; case 4: #line 48 "src/sas/readstat_xport_parse_format.rl" { fmt->decimals = temp_val; } break; #line 243 "src/sas/readstat_xport_parse_format.c" } } } _out: {} } #line 54 "src/sas/readstat_xport_parse_format.rl" if (cs < 3|| p != pe || parsed_len + 1 > sizeof(fmt->name)) { char error_buf[1024]; if (error_handler) { snprintf(error_buf, sizeof(error_buf), "Invalid format string (length=%d): %.*s", (int)len, (int)len, data); error_handler(error_buf, user_ctx); } retval = READSTAT_ERROR_BAD_FORMAT_STRING; } (void)xport_format_parse_en_main; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/sas/readstat_xport_parse_format.h0000644000076500000240000000023014674240614021574 0ustar00dialout readstat_error_t xport_parse_format(const char *data, size_t len, xport_format_t *fmt, readstat_error_handler error_handler, void *user_ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748268530.0 pyreadstat-1.3.3/src/sas/readstat_xport_read.c0000644000076500000240000005511715015072762020033 0ustar00dialout#include #include #include #include #include #include #include "../readstat.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" #include "readstat_sas.h" #include "readstat_xport.h" #include "ieee.h" #define LINE_LEN 80 typedef struct xport_ctx_s { readstat_callbacks_t handle; size_t file_size; void *user_ctx; const char *input_encoding; const char *output_encoding; iconv_t converter; readstat_io_t *io; time_t timestamp; int obs_count; int var_count; int row_limit; int row_offset; size_t row_length; int parsed_row_count; char file_label[256*4+1]; char table_name[32*4+1]; readstat_variable_t **variables; int version; } xport_ctx_t; static readstat_error_t xport_update_progress(xport_ctx_t *ctx) { readstat_io_t *io = ctx->io; return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx); } static xport_ctx_t *xport_ctx_init(void) { xport_ctx_t *ctx = calloc(1, sizeof(xport_ctx_t)); return ctx; } static void xport_ctx_free(xport_ctx_t *ctx) { if (ctx->variables) { int i; for (i=0; ivar_count; i++) { if (ctx->variables[i]) free(ctx->variables[i]); } free(ctx->variables); } if (ctx->converter) { iconv_close(ctx->converter); } free(ctx); } static ssize_t read_bytes(xport_ctx_t *ctx, void *dst, size_t dst_len) { readstat_io_t *io = (readstat_io_t *)ctx->io; return io->read(dst, dst_len, io->io_ctx); } static readstat_error_t xport_skip_record(xport_ctx_t *ctx) { readstat_io_t *io = (readstat_io_t *)ctx->io; if (io->seek(LINE_LEN, READSTAT_SEEK_CUR, io->io_ctx) == -1) return READSTAT_ERROR_SEEK; return READSTAT_OK; } static readstat_error_t xport_skip_rest_of_record(xport_ctx_t *ctx) { readstat_io_t *io = (readstat_io_t *)ctx->io; off_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx); if (pos == -1) return READSTAT_ERROR_SEEK; if (pos % LINE_LEN) { if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1) return READSTAT_ERROR_SEEK; } return READSTAT_OK; } static readstat_error_t xport_read_record(xport_ctx_t *ctx, char *record) { ssize_t bytes_read = read_bytes(ctx, record, LINE_LEN); if (bytes_read < LINE_LEN) return READSTAT_ERROR_READ; record[LINE_LEN] = '\0'; return READSTAT_OK; } static readstat_error_t xport_read_header_record(xport_ctx_t *ctx, xport_header_record_t *xrecord) { char line[LINE_LEN+1]; readstat_error_t retval = READSTAT_OK; retval = xport_read_record(ctx, line); if (retval != READSTAT_OK) return retval; memset(xrecord, 0, sizeof(xport_header_record_t)); int matches = sscanf(line, "HEADER RECORD*******%8s HEADER RECORD!!!!!!!" "%05d%05d%05d" "%05d%05d%05d", xrecord->name, &xrecord->num1, &xrecord->num2, &xrecord->num3, &xrecord->num4, &xrecord->num5, &xrecord->num6); if (matches < 2) { return READSTAT_ERROR_PARSE; } return READSTAT_OK; } static readstat_error_t xport_expect_header_record(xport_ctx_t *ctx, const char *v5_name, const char *v8_name) { readstat_error_t retval = READSTAT_OK; xport_header_record_t xrecord; retval = xport_read_header_record(ctx, &xrecord); if (retval != READSTAT_OK) goto cleanup; if (ctx->version == 5 && strcmp(xrecord.name, v5_name) != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } else if (ctx->version == 8 && strcmp(xrecord.name, v8_name) != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } cleanup: return retval; } static readstat_error_t xport_read_table_name_record(xport_ctx_t *ctx) { char line[LINE_LEN+1]; readstat_error_t retval = READSTAT_OK; retval = xport_read_record(ctx, line); if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name), &line[8], ctx->version == 5 ? 8 : 32, ctx->converter); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t xport_read_file_label_record(xport_ctx_t *ctx) { char line[LINE_LEN+1]; readstat_error_t retval = READSTAT_OK; retval = xport_read_record(ctx, line); if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label), &line[32], 40, ctx->converter); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t xport_read_library_record(xport_ctx_t *ctx) { xport_header_record_t xrecord; readstat_error_t retval = xport_read_header_record(ctx, &xrecord); if (retval != READSTAT_OK) goto cleanup; if (strcmp(xrecord.name, "LIBRARY") == 0) { ctx->version = 5; } else if (strcmp(xrecord.name, "LIBV8") == 0) { ctx->version = 8; } else { retval = READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION; goto cleanup; } cleanup: return retval; } static readstat_error_t xport_read_timestamp_record(xport_ctx_t *ctx) { char line[LINE_LEN+1]; readstat_error_t retval = READSTAT_OK; struct tm ts = { .tm_isdst = -1 }; char month[4]; int i; retval = xport_read_record(ctx, line); if (retval != READSTAT_OK) goto cleanup; sscanf(line, "%02d%3s%02d:%02d:%02d:%02d", &ts.tm_mday, month, &ts.tm_year, &ts.tm_hour, &ts.tm_min, &ts.tm_sec); for (i=0; itimestamp = mktime(&ts); cleanup: return retval; } static readstat_error_t xport_read_namestr_header_record(xport_ctx_t *ctx) { xport_header_record_t xrecord; readstat_error_t retval = READSTAT_OK; retval = xport_read_header_record(ctx, &xrecord); if (retval != READSTAT_OK) goto cleanup; if (ctx->version == 5 && strcmp(xrecord.name, "NAMESTR") != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } else if (ctx->version == 8 && strcmp(xrecord.name, "NAMSTV8") != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->var_count = xrecord.num2; ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *)); if (ctx->variables == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (ctx->handle.metadata) { readstat_metadata_t metadata = { .row_count = -1, .var_count = ctx->var_count, .file_label = ctx->file_label, .table_name = ctx->table_name, .creation_time = ctx->timestamp, .modified_time = ctx->timestamp, .file_format_version = ctx->version }; if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } cleanup: return retval; } static readstat_error_t xport_read_obs_header_record(xport_ctx_t *ctx) { return xport_expect_header_record(ctx, "OBS", "OBSV8"); } static readstat_error_t xport_construct_format(char *dst, size_t dst_len, const char *src, size_t src_len, int width, int decimals) { char *format = malloc(4 * src_len + 1); readstat_error_t retval = readstat_convert(format, 4 * src_len + 1, src, src_len, NULL); if (retval != READSTAT_OK) { free(format); return retval; } char *pos = dst; *dst = '\0'; if (format[0]) { pos += snprintf(dst, dst_len, "%s", format); } if (width) { pos += snprintf(pos, dst_len-(pos-dst), "%d", width); } if (decimals) { pos += snprintf(pos, dst_len-(pos-dst), ".%d", decimals); } free(format); return retval; } static readstat_error_t xport_read_labels_v8(xport_ctx_t *ctx, int label_count) { readstat_error_t retval = READSTAT_OK; uint16_t labeldef[3]; char *name = NULL; char *label = NULL; int i; for (i=0; i ctx->var_count || index == 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } name = realloc(name, name_len + 1); label = realloc(label, label_len + 1); readstat_variable_t *variable = ctx->variables[index-1]; if (read_bytes(ctx, name, name_len) != name_len || read_bytes(ctx, label, label_len) != label_len) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = readstat_convert(variable->name, sizeof(variable->name), name, name_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(variable->label, sizeof(variable->label), label, label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; } retval = xport_skip_rest_of_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_obs_header_record(ctx); if (retval != READSTAT_OK) goto cleanup; cleanup: free(name); free(label); return retval; } static readstat_error_t xport_read_labels_v9(xport_ctx_t *ctx, int label_count) { readstat_error_t retval = READSTAT_OK; uint16_t labeldef[5]; int i; char *name = NULL; char *label = NULL; char *format = NULL; char *informat = NULL; for (i=0; i ctx->var_count || index == 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } name = realloc(name, name_len + 1); label = realloc(label, label_len + 1); format = realloc(format, format_len + 1); informat = realloc(informat, informat_len + 1); readstat_variable_t *variable = ctx->variables[index-1]; if (read_bytes(ctx, name, name_len) != name_len || read_bytes(ctx, label, label_len) != label_len || read_bytes(ctx, format, format_len) != format_len || read_bytes(ctx, informat, informat_len) != informat_len) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = readstat_convert(variable->name, sizeof(variable->name), name, name_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(variable->label, sizeof(variable->label), label, label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(variable->format, sizeof(variable->format), format, format_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; } retval = xport_skip_rest_of_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_obs_header_record(ctx); if (retval != READSTAT_OK) goto cleanup; cleanup: free(name); free(format); free(informat); free(label); return retval; } static readstat_error_t xport_read_variables(xport_ctx_t *ctx) { int i; readstat_error_t retval = READSTAT_OK; for (i=0; ivar_count; i++) { xport_namestr_t namestr; ssize_t bytes_read = read_bytes(ctx, &namestr, sizeof(xport_namestr_t)); if (bytes_read < sizeof(xport_namestr_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } xport_namestr_bswap(&namestr); readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t)); variable->index = i; variable->type = namestr.ntype == SAS_COLUMN_TYPE_CHR ? READSTAT_TYPE_STRING : READSTAT_TYPE_DOUBLE; variable->storage_width = namestr.nlng; variable->display_width = namestr.nfl; variable->decimals = namestr.nfd; variable->alignment = namestr.nfj ? READSTAT_ALIGNMENT_RIGHT : READSTAT_ALIGNMENT_LEFT; if (ctx->version == 5) { retval = readstat_convert(variable->name, sizeof(variable->name), namestr.nname, sizeof(namestr.nname), ctx->converter); } else { retval = readstat_convert(variable->name, sizeof(variable->name), namestr.longname, sizeof(namestr.longname), ctx->converter); } if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(variable->label, sizeof(variable->label), namestr.nlabel, sizeof(namestr.nlabel), ctx->converter); if (retval != READSTAT_OK) goto cleanup; retval = xport_construct_format(variable->format, sizeof(variable->format), namestr.nform, sizeof(namestr.nform), variable->display_width, variable->decimals); if (retval != READSTAT_OK) goto cleanup; ctx->variables[i] = variable; } retval = xport_skip_rest_of_record(ctx); if (retval != READSTAT_OK) goto cleanup; if (ctx->version == 5) { retval = xport_read_obs_header_record(ctx); if (retval != READSTAT_OK) goto cleanup; } else { xport_header_record_t xrecord; retval = xport_read_header_record(ctx, &xrecord); if (retval != READSTAT_OK) goto cleanup; if (strcmp(xrecord.name, "OBSV8") == 0) { /* void */ } else if (strcmp(xrecord.name, "LABELV8") == 0) { retval = xport_read_labels_v8(ctx, xrecord.num1); } else if (strcmp(xrecord.name, "LABELV9") == 0) { retval = xport_read_labels_v9(ctx, xrecord.num1); } if (retval != READSTAT_OK) goto cleanup; } ctx->row_length = 0; int index_after_skipping = 0; for (i=0; ivar_count; i++) { readstat_variable_t *variable = ctx->variables[i]; variable->index_after_skipping = index_after_skipping; int cb_retval = READSTAT_HANDLER_OK; if (ctx->handle.variable) { cb_retval = ctx->handle.variable(i, variable, variable->format, ctx->user_ctx); } if (cb_retval == READSTAT_HANDLER_ABORT) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) { variable->skip = 1; } else { index_after_skipping++; } ctx->row_length += variable->storage_width; } cleanup: return retval; } static readstat_error_t xport_process_row(xport_ctx_t *ctx, const char *row, size_t row_length) { readstat_error_t retval = READSTAT_OK; int i; off_t pos = 0; char *string = NULL; for (i=0; ivar_count; i++) { readstat_variable_t *variable = ctx->variables[i]; readstat_value_t value = { .type = variable->type }; if (variable->type == READSTAT_TYPE_STRING) { string = readstat_realloc(string, 4*variable->storage_width+1); if (string == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } retval = readstat_convert(string, 4*variable->storage_width+1, &row[pos], variable->storage_width, ctx->converter); if (retval != READSTAT_OK) goto cleanup; value.v.string_value = string; } else { double dval = NAN; if (variable->storage_width <= XPORT_MAX_DOUBLE_SIZE && variable->storage_width >= XPORT_MIN_DOUBLE_SIZE) { char full_value[8] = { 0 }; if (memcmp(&full_value[1], &row[pos+1], variable->storage_width - 1) == 0 && (row[pos] == '.' || sas_validate_tag(row[pos]) == READSTAT_OK)) { if (row[pos] == '.') { value.is_system_missing = 1; } else { value.tag = row[pos]; value.is_tagged_missing = 1; } } else { memcpy(full_value, &row[pos], variable->storage_width); int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE); if (rc != 0) { retval = READSTAT_ERROR_CONVERT; goto cleanup; } } } value.v.double_value = dval; } pos += variable->storage_width; if (ctx->handle.value && !ctx->variables[i]->skip && !ctx->row_offset) { if (ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } if (ctx->row_offset) { ctx->row_offset--; } else { ctx->parsed_row_count++; } cleanup: free(string); return retval; } static readstat_error_t xport_read_data(xport_ctx_t *ctx) { if (!ctx->row_length) return READSTAT_OK; if (!ctx->handle.value) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; char *row = readstat_malloc(ctx->row_length); char *blank_row = readstat_malloc(ctx->row_length); int num_blank_rows = 0; if (row == NULL || blank_row == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memset(blank_row, ' ', ctx->row_length); while (1) { ssize_t bytes_read = read_bytes(ctx, row, ctx->row_length); if (bytes_read == -1) { retval = READSTAT_ERROR_READ; goto cleanup; } else if (bytes_read < ctx->row_length) { break; } off_t pos = 0; int row_is_blank = 1; for (pos=0; posrow_length; pos++) { if (row[pos] != ' ') { row_is_blank = 0; break; } } if (row_is_blank) { num_blank_rows++; continue; } while (num_blank_rows) { retval = xport_process_row(ctx, blank_row, ctx->row_length); if (retval != READSTAT_OK) goto cleanup; if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit) goto cleanup; num_blank_rows--; } retval = xport_process_row(ctx, row, ctx->row_length); if (retval != READSTAT_OK) goto cleanup; retval = xport_update_progress(ctx); if (retval != READSTAT_OK) goto cleanup; if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit) break; } cleanup: if (row) free(row); if (blank_row) free(blank_row); return retval; } readstat_error_t readstat_parse_xport(readstat_parser_t *parser, const char *path, void *user_ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = parser->io; xport_ctx_t *ctx = xport_ctx_init(); ctx->handle = parser->handlers; ctx->input_encoding = parser->input_encoding; ctx->output_encoding = parser->output_encoding; ctx->user_ctx = user_ctx; ctx->io = io; ctx->row_limit = parser->row_limit; if (parser->row_offset > 0) ctx->row_offset = parser->row_offset; if (io->open(path, io->io_ctx) == -1) { retval = READSTAT_ERROR_OPEN; goto cleanup; } if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) { iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding); if (converter == (iconv_t)-1) { retval = READSTAT_ERROR_UNSUPPORTED_CHARSET; goto cleanup; } ctx->converter = converter; } retval = xport_read_library_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_skip_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_timestamp_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_expect_header_record(ctx, "MEMBER", "MEMBV8"); if (retval != READSTAT_OK) goto cleanup; retval = xport_expect_header_record(ctx, "DSCRPTR", "DSCPTV8"); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_table_name_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_file_label_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_namestr_header_record(ctx); if (retval != READSTAT_OK) goto cleanup; retval = xport_read_variables(ctx); if (retval != READSTAT_OK) goto cleanup; if (ctx->row_length) { retval = xport_read_data(ctx); if (retval != READSTAT_OK) goto cleanup; } cleanup: io->close(io->io_ctx); xport_ctx_free(ctx); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/sas/readstat_xport_write.c0000644000076500000240000004432715134704512020250 0ustar00dialout #include #include #include #include "../readstat.h" #include "../readstat_writer.h" #include "readstat_sas.h" #include "readstat_xport.h" #include "readstat_xport_parse_format.h" #include "ieee.h" #define XPORT_DEFAULT_VERSION 8 #define RECORD_LEN 80 #if defined _MSC_VER #define restrict __restrict #endif static void copypad(char * restrict dst, size_t dst_len, const char * restrict src) { char *dst_end = dst + dst_len; while (dst < dst_end && *src) *dst++ = *src++; while (dst < dst_end) *dst++ = ' '; } static readstat_error_t xport_write_bytes(readstat_writer_t *writer, const void *bytes, size_t len) { return readstat_write_bytes_as_lines(writer, bytes, len, RECORD_LEN, ""); } static readstat_error_t xport_finish_record(readstat_writer_t *writer) { return readstat_write_line_padding(writer, ' ', RECORD_LEN, ""); } static readstat_error_t xport_write_record(readstat_writer_t *writer, const char *record) { size_t len = strlen(record); readstat_error_t retval = READSTAT_OK; retval = xport_write_bytes(writer, record, len); if (retval != READSTAT_OK) goto cleanup; retval = xport_finish_record(writer); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t xport_write_header_record_obsv8(readstat_writer_t *writer, int row_count) { char record[RECORD_LEN+1]; snprintf(record, sizeof(record), "HEADER RECORD*******OBSV8 HEADER RECORD!!!!!!!" "%15d", row_count); return xport_write_record(writer, record); } static readstat_error_t xport_write_header_record_labelv8(readstat_writer_t *writer, xport_header_record_t *xrecord) { char record[RECORD_LEN+1]; snprintf(record, sizeof(record), "HEADER RECORD*******%-8sHEADER RECORD!!!!!!!" "%-5d", xrecord->name, xrecord->num1); return xport_write_record(writer, record); } static readstat_error_t xport_write_header_record(readstat_writer_t *writer, xport_header_record_t *xrecord) { char record[RECORD_LEN+1]; snprintf(record, sizeof(record), "HEADER RECORD*******%-8sHEADER RECORD!!!!!!!" "%05d%05d%05d" "%05d%05d%05d", xrecord->name, xrecord->num1, xrecord->num2, xrecord->num3, xrecord->num4, xrecord->num5, xrecord->num6); return xport_write_record(writer, record); } static size_t xport_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) return user_width; if (user_width >= XPORT_MAX_DOUBLE_SIZE || user_width == 0) return XPORT_MAX_DOUBLE_SIZE; if (user_width <= XPORT_MIN_DOUBLE_SIZE) return XPORT_MIN_DOUBLE_SIZE; return user_width; } static readstat_error_t xport_write_variables(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; int i; long offset = 0; int num_long_labels = 0; int any_has_long_format = 0; for (i=0; ivariables_count; i++) { int needs_long_record = 0; readstat_variable_t *variable = readstat_get_variable(writer, i); size_t width = xport_variable_width(variable->type, variable->user_width); xport_namestr_t namestr = { .nvar0 = i+1, .nlng = width, .npos = offset, .niform = " ", .nform = " " }; if (readstat_variable_get_type_class(variable) == READSTAT_TYPE_CLASS_STRING) { namestr.ntype = SAS_COLUMN_TYPE_CHR; } else { namestr.ntype = SAS_COLUMN_TYPE_NUM; } copypad(namestr.nname, sizeof(namestr.nname), variable->name); copypad(namestr.nlabel, sizeof(namestr.nlabel), variable->label); if (variable->format[0]) { xport_format_t format; retval = xport_parse_format(variable->format, strlen(variable->format), &format, NULL, NULL); if (retval != READSTAT_OK) goto cleanup; copypad(namestr.nform, sizeof(namestr.nform), format.name); namestr.nfl = format.width; namestr.nfd = format.decimals; copypad(namestr.niform, sizeof(namestr.niform), format.name); namestr.nifl = format.width; namestr.nifd = format.decimals; if (strlen(format.name) > 8) { any_has_long_format = 1; needs_long_record = 1; } } else if (variable->display_width) { namestr.nfl = variable->display_width; } namestr.nfj = (variable->alignment == READSTAT_ALIGNMENT_RIGHT); if (writer->version == 8) { copypad(namestr.longname, sizeof(namestr.longname), variable->name); size_t label_len = strlen(variable->label); if (label_len > 40) { needs_long_record = 1; } namestr.labeln = label_len; } if (needs_long_record) { num_long_labels++; } offset += width; xport_namestr_bswap(&namestr); retval = xport_write_bytes(writer, &namestr, sizeof(xport_namestr_t)); if (retval != READSTAT_OK) goto cleanup; } retval = xport_finish_record(writer); if (retval != READSTAT_OK) goto cleanup; if (writer->version == 8 && num_long_labels) { xport_header_record_t header = { .name = "LABELV8", .num1 = num_long_labels }; if (any_has_long_format) { strcpy(header.name, "LABELV9"); } retval = xport_write_header_record_labelv8(writer, &header); if (retval != READSTAT_OK) goto cleanup; for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); size_t label_len = strlen(variable->label); size_t name_len = strlen(variable->name); size_t format_len = strlen(variable->format); int has_long_label = 0; int has_long_format = 0; has_long_label = (label_len > 40); if (variable->format[0]) { xport_format_t format; retval = xport_parse_format(variable->format, strlen(variable->format), &format, NULL, NULL); if (retval != READSTAT_OK) goto cleanup; if (strlen(format.name) > 8) { has_long_format = 1; } } if (has_long_format) { uint16_t labeldef[5] = { i+1, name_len, label_len, format_len, format_len }; if (machine_is_little_endian()) { labeldef[0] = byteswap2(labeldef[0]); labeldef[1] = byteswap2(labeldef[1]); labeldef[2] = byteswap2(labeldef[2]); labeldef[3] = byteswap2(labeldef[3]); labeldef[4] = byteswap2(labeldef[4]); } retval = readstat_write_bytes(writer, labeldef, sizeof(labeldef)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_string(writer, variable->name); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_string(writer, variable->label); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_string(writer, variable->format); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_string(writer, variable->format); if (retval != READSTAT_OK) goto cleanup; } else if (has_long_label) { uint16_t labeldef[3] = { i+1, name_len, label_len }; if (machine_is_little_endian()) { labeldef[0] = byteswap2(labeldef[0]); labeldef[1] = byteswap2(labeldef[1]); labeldef[2] = byteswap2(labeldef[2]); } retval = readstat_write_bytes(writer, labeldef, sizeof(labeldef)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_string(writer, variable->name); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_string(writer, variable->label); if (retval != READSTAT_OK) goto cleanup; } } retval = xport_finish_record(writer); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t xport_write_first_header_record(readstat_writer_t *writer) { xport_header_record_t xrecord = { .name = "LIBRARY" }; if (writer->version == 8) { strcpy(xrecord.name, "LIBV8"); } return xport_write_header_record(writer, &xrecord); } static readstat_error_t xport_write_first_real_header_record(readstat_writer_t *writer, const char *timestamp) { char real_record[RECORD_LEN+1]; snprintf(real_record, sizeof(real_record), "%-8.8s" "%-8.8s" "%-8.8s" "%-8.8s" "%-8.8s" "%-24.24s" "%16.16s", "SAS", "SAS", "SASLIB", "6.06", "bsd4.2", "", timestamp); return xport_write_record(writer, real_record); } static readstat_error_t xport_write_member_header_record(readstat_writer_t *writer) { xport_header_record_t xrecord = { .name = "MEMBER", .num4 = 160, .num6 = 140 }; if (writer->version == 8) { strcpy(xrecord.name, "MEMBV8"); } return xport_write_header_record(writer, &xrecord); } static readstat_error_t xport_write_descriptor_header_record(readstat_writer_t *writer) { xport_header_record_t xrecord = { .name = "DSCRPTR" }; if (writer->version == 8) { strcpy(xrecord.name, "DSCPTV8"); } return xport_write_header_record(writer, &xrecord); } static readstat_error_t xport_write_member_record_v8(readstat_writer_t *writer, char *timestamp) { readstat_error_t retval = READSTAT_OK; char member_header[RECORD_LEN+1]; char *ds_name = "DATASET"; if (writer->table_name[0]) ds_name = writer->table_name; snprintf(member_header, sizeof(member_header), "%-8.8s" "%-32.32s" "%-8.8s" "%-8.8s" "%-8.8s" "%16.16s", "SAS", ds_name, "SASDATA", "6.06", "bsd4.2", timestamp); retval = xport_write_record(writer, member_header); return retval; } static readstat_error_t xport_write_member_record(readstat_writer_t *writer, char *timestamp) { if (writer->version == 8) return xport_write_member_record_v8(writer, timestamp); readstat_error_t retval = READSTAT_OK; char member_header[RECORD_LEN+1]; char *ds_name = "DATASET"; if (writer->table_name[0]) ds_name = writer->table_name; snprintf(member_header, sizeof(member_header), "%-8.8s" "%-8.8s" "%-8.8s" "%-8.8s" "%-8.8s" "%-24.24s" "%16.16s", "SAS", ds_name, "SASDATA", "6.06", "bsd4.2", "", timestamp); retval = xport_write_record(writer, member_header); return retval; } static readstat_error_t xport_write_file_label_record(readstat_writer_t *writer, char *timestamp) { char member_header[RECORD_LEN+1]; snprintf(member_header, sizeof(member_header), "%16.16s" "%16.16s" "%-40.40s" "%-8.8s", timestamp, "", writer->file_label, "" /* dstype? */); return xport_write_record(writer, member_header); } static readstat_error_t xport_write_namestr_header_record(readstat_writer_t *writer) { xport_header_record_t xrecord = { .name = "NAMESTR", .num2 = writer->variables_count }; if (writer->version == 8) { strcpy(xrecord.name, "NAMSTV8"); } return xport_write_header_record(writer, &xrecord); } static readstat_error_t xport_write_obs_header_record(readstat_writer_t *writer) { if (writer->version == 8) { return xport_write_header_record_obsv8(writer, writer->row_count); } xport_header_record_t xrecord = { .name = "OBS" }; return xport_write_header_record(writer, &xrecord); } static readstat_error_t xport_format_timestamp(char *output, size_t output_len, time_t timestamp) { struct tm *ts = localtime(×tamp); if (!ts) return READSTAT_ERROR_BAD_TIMESTAMP_VALUE; snprintf(output, output_len, "%02d%3.3s%02d:%02d:%02d:%02d", (unsigned int)ts->tm_mday % 100, _xport_months[ts->tm_mon], (unsigned int)ts->tm_year % 100, (unsigned int)ts->tm_hour % 100, (unsigned int)ts->tm_min % 100, (unsigned int)ts->tm_sec % 100 ); return READSTAT_OK; } static readstat_error_t xport_begin_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t retval = READSTAT_OK; char timestamp[17]; retval = xport_format_timestamp(timestamp, sizeof(timestamp), writer->timestamp); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_first_header_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_first_real_header_record(writer, timestamp); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_record(writer, timestamp); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_member_header_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_descriptor_header_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_member_record(writer, timestamp); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_file_label_record(writer, timestamp); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_namestr_header_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_variables(writer); if (retval != READSTAT_OK) goto cleanup; retval = xport_write_obs_header_record(writer); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t xport_end_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t retval = READSTAT_OK; retval = xport_finish_record(writer); return retval; } static readstat_error_t xport_write_row(void *writer_ctx, void *row, size_t row_len) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; return xport_write_bytes(writer, row, row_len); } static readstat_error_t xport_write_double(void *row, const readstat_variable_t *var, double value) { char full_value[8]; int rc = cnxptiee(&value, CN_TYPE_NATIVE, full_value, CN_TYPE_XPORT); if (rc) return READSTAT_ERROR_CONVERT; memcpy(row, full_value, var->storage_width); return READSTAT_OK; } static readstat_error_t xport_write_float(void *row, const readstat_variable_t *var, float value) { return xport_write_double(row, var, value); } static readstat_error_t xport_write_int32(void *row, const readstat_variable_t *var, int32_t value) { return xport_write_double(row, var, value); } static readstat_error_t xport_write_int16(void *row, const readstat_variable_t *var, int16_t value) { return xport_write_double(row, var, value); } static readstat_error_t xport_write_int8(void *row, const readstat_variable_t *var, int8_t value) { return xport_write_double(row, var, value); } static readstat_error_t xport_write_string(void *row, const readstat_variable_t *var, const char *string) { memset(row, ' ', var->storage_width); if (string != NULL && string[0]) { size_t value_len = strlen(string); if (value_len > var->storage_width) return READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG; memcpy(row, string, value_len); } return READSTAT_OK; } static readstat_error_t xport_write_missing_numeric(void *row, const readstat_variable_t *var) { char *row_bytes = (char *)row; row_bytes[0] = 0x2e; return READSTAT_OK; } static readstat_error_t xport_write_missing_string(void *row, const readstat_variable_t *var) { return xport_write_string(row, var, NULL); } static readstat_error_t xport_write_missing_tagged(void *row, const readstat_variable_t *var, char tag) { char *row_bytes = (char *)row; readstat_error_t error = sas_validate_tag(tag); if (error == READSTAT_OK) { row_bytes[0] = tag; } return error; } static readstat_error_t xport_metadata_ok(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; if (writer->version != 5 && writer->version != 8) return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION; if (writer->table_name[0]) { if (writer->version == 8) { return sas_validate_name(writer->table_name, 32); } if (writer->version == 5) { return sas_validate_name(writer->table_name, 8); } } return READSTAT_OK; } readstat_error_t readstat_begin_writing_xport(readstat_writer_t *writer, void *user_ctx, long row_count) { if (writer->version == 0) writer->version = XPORT_DEFAULT_VERSION; writer->callbacks.metadata_ok = &xport_metadata_ok; writer->callbacks.write_int8 = &xport_write_int8; writer->callbacks.write_int16 = &xport_write_int16; writer->callbacks.write_int32 = &xport_write_int32; writer->callbacks.write_float = &xport_write_float; writer->callbacks.write_double = &xport_write_double; writer->callbacks.write_string = &xport_write_string; writer->callbacks.write_missing_string = &xport_write_missing_string; writer->callbacks.write_missing_number = &xport_write_missing_numeric; writer->callbacks.write_missing_tagged = &xport_write_missing_tagged; writer->callbacks.variable_width = &xport_variable_width; writer->callbacks.variable_ok = &sas_validate_variable; writer->callbacks.begin_data = &xport_begin_data; writer->callbacks.end_data = &xport_end_data; writer->callbacks.write_row = &xport_write_row; return readstat_begin_writing_file(writer, user_ctx, row_count); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/src/spss/0000755000076500000240000000000015134706453014025 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_por.c0000644000076500000240000001306014674240614016660 0ustar00dialout#include #include #include "../readstat.h" #include "../CKHashTable.h" #include "../readstat_convert.h" #include "readstat_spss.h" #include "readstat_por.h" int8_t por_ascii_lookup[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ', '.', '<', '(', '+', '|', '&', '[', ']', '!', '$', '*', ')', ';', '^', '-', '/', '|', ',', '%', '_', '>', '?', '`', ':', '#', '@', '\'', '=', '"', 0, 0, 0, 0, 0, 0, '~', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{', '}', '\\', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; uint16_t por_unicode_lookup[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ', '.', '<', '(', '+', '|', '&', '[', ']', '!', '$', '*', ')', ';', '^', '-', '/', 0x00A3, ',', '%', '_', '>', '?', 0x2018, ':', 0x00A6, '@', 0x2019, '=', '"', 0x2264, 0x25A1, 0x00B1, 0x25A0, 0x00B0, 0x2020, '~', 0x2013, 0x2514, 0x250C, 0x2265, 0x2070, 0x2071, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079, 0x2518, 0x2510, 0x2260, 0x2014, 0x207D, 0x207E, 0x2E38, '{', '}', '\\', 0x00A2, 0x2022, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; por_ctx_t *por_ctx_init(void) { por_ctx_t *ctx = calloc(1, sizeof(por_ctx_t)); ctx->space = ' '; ctx->base30_precision = 20; ctx->var_dict = ck_hash_table_init(1024, 8); return ctx; } void por_ctx_free(por_ctx_t *ctx) { if (ctx->string_buffer) free(ctx->string_buffer); if (ctx->varinfo) { int i; for (i=0; ivar_count; i++) { if (ctx->varinfo[i].label) free(ctx->varinfo[i].label); } free(ctx->varinfo); } if (ctx->variables) { int i; for (i=0; ivar_count; i++) { if (ctx->variables[i]) free(ctx->variables[i]); } free(ctx->variables); } if (ctx->var_dict) ck_hash_table_free(ctx->var_dict); if (ctx->converter) iconv_close(ctx->converter); free(ctx); } ssize_t por_utf8_encode(const unsigned char *input, size_t input_len, char *output, size_t output_len, uint16_t lookup[256]) { int offset = 0; int i; for (i=0; i output_len) return offset; output[offset++] = codepoint; } else { if (codepoint <= 0x07FF) { if (offset + 2 > output_len) return offset; } else /* if (codepoint <= 0xFFFF) */{ if (offset + 3 > output_len) return offset; } /* TODO - For some reason that replacement character isn't recognized * by some systems, so be prepared to insert an ASCII space instead */ int printed = snprintf(output + offset, output_len - offset, "%lc", codepoint); if (printed > 0) { offset += printed; } else { output[offset++] = ' '; } } } return offset; } ssize_t por_utf8_decode( const char *input, size_t input_len, char *output, size_t output_len, uint8_t *lookup, size_t lookup_len) { int offset = 0; wchar_t codepoint = 0; while (1) { int char_len = 0; if (offset + 1 > output_len) return offset; unsigned char val = *input; if (val >= 0x20 && val < 0x7F) { if (!lookup[val]) return -1; output[offset++] = lookup[val]; input++; } else { int conversions = sscanf(input, "%lc%n", &codepoint, &char_len); if (conversions == 0 || codepoint >= lookup_len || lookup[codepoint] == 0) { return -1; } output[offset++] = lookup[codepoint]; input += char_len; } } return offset; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_por.h0000644000076500000240000000240714674240614016670 0ustar00dialout extern int8_t por_ascii_lookup[256]; extern uint16_t por_unicode_lookup[256]; typedef struct por_ctx_s { readstat_callbacks_t handle; size_t file_size; void *user_ctx; int pos; readstat_io_t *io; char space; long num_spaces; time_t timestamp; long version; char fweight_name[9]; char file_label[21]; uint16_t byte2unicode[256]; size_t base30_precision; iconv_t converter; unsigned char *string_buffer; size_t string_buffer_len; int labels_offset; int obs_count; int var_count; int var_offset; int row_limit; int row_offset; readstat_variable_t **variables; spss_varinfo_t *varinfo; ck_hash_table_t *var_dict; } por_ctx_t; por_ctx_t *por_ctx_init(void); void por_ctx_free(por_ctx_t *ctx); ssize_t por_utf8_encode(const unsigned char *input, size_t input_len, char *output, size_t output_len, uint16_t lookup[256]); ssize_t por_utf8_decode( const char *input, size_t input_len, char *output, size_t output_len, uint8_t *lookup, size_t lookup_len); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_por_parse.c0000644000076500000240000001604014674240614020053 0ustar00dialout#line 1 "src/spss/readstat_por_parse.rl" #include #include "../readstat.h" #include "readstat_por_parse.h" #line 9 "src/spss/readstat_por_parse.c" static const signed char _por_field_parse_actions[] = { 0, 1, 0, 1, 1, 1, 5, 1, 8, 1, 9, 1, 10, 2, 2, 0, 2, 3, 1, 2, 5, 10, 2, 7, 10, 3, 4, 2, 0, 3, 6, 2, 0, 0 }; static const signed char _por_field_parse_key_offsets[] = { 0, 0, 8, 9, 14, 18, 23, 31, 35, 40, 44, 48, 55, 0 }; static const char _por_field_parse_trans_keys[] = { 32, 42, 45, 46, 48, 57, 65, 84, 46, 46, 48, 57, 65, 84, 48, 57, 65, 84, 47, 48, 57, 65, 84, 43, 45, 46, 47, 48, 57, 65, 84, 48, 57, 65, 84, 47, 48, 57, 65, 84, 48, 57, 65, 84, 48, 57, 65, 84, 43, 45, 47, 48, 57, 65, 84, 0 }; static const signed char _por_field_parse_single_lengths[] = { 0, 4, 1, 1, 0, 1, 4, 0, 1, 0, 0, 3, 0, 0 }; static const signed char _por_field_parse_range_lengths[] = { 0, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0 }; static const signed char _por_field_parse_index_offsets[] = { 0, 0, 7, 9, 13, 16, 20, 27, 30, 34, 37, 40, 46, 0 }; static const signed char _por_field_parse_cond_targs[] = { 1, 2, 3, 4, 6, 6, 0, 12, 0, 4, 6, 6, 0, 5, 5, 0, 12, 5, 5, 0, 7, 9, 10, 12, 6, 6, 0, 8, 8, 0, 12, 8, 8, 0, 8, 8, 0, 11, 11, 0, 7, 9, 12, 11, 11, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 }; static const signed char _por_field_parse_cond_actions[] = { 0, 9, 0, 0, 13, 13, 0, 11, 0, 7, 25, 25, 0, 16, 16, 0, 11, 3, 3, 0, 5, 5, 5, 19, 1, 1, 0, 13, 13, 0, 22, 1, 1, 0, 29, 29, 0, 16, 16, 0, 0, 0, 11, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const int por_field_parse_start = 1; static const int por_field_parse_en_main = 1; #line 9 "src/spss/readstat_por_parse.rl" ssize_t readstat_por_parse_double(const char *data, size_t len, double *result, readstat_error_handler error_cb, void *user_ctx) { ssize_t retval = 0; double val = 0.0; double denom = 30.0; double temp_frac = 0.0; double num = 0.0; double exp = 0.0; double temp_val = 0.0; const unsigned char *p = (const unsigned char *)data; const unsigned char *pe = p + len; int cs; int is_negative = 0, exp_is_negative = 0; int success = 0; #line 97 "src/spss/readstat_por_parse.c" { cs = (int)por_field_parse_start; } #line 102 "src/spss/readstat_por_parse.c" { int _klen; unsigned int _trans = 0; const char * _keys; const signed char * _acts; unsigned int _nacts; _resume: {} if ( p == pe ) goto _out; _keys = ( _por_field_parse_trans_keys + (_por_field_parse_key_offsets[cs])); _trans = (unsigned int)_por_field_parse_index_offsets[cs]; _klen = (int)_por_field_parse_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + _klen - 1; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _keys += _klen; _trans += (unsigned int)_klen; break; } _mid = _lower + ((_upper-_lower) >> 1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 1; else if ( ( (*( p))) > (*( _mid)) ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } } _klen = (int)_por_field_parse_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + (_klen<<1) - 2; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _trans += (unsigned int)_klen; break; } _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 2; else if ( ( (*( p))) > (*( _mid + 1)) ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); break; } } } _match: {} cs = (int)_por_field_parse_cond_targs[_trans]; if ( _por_field_parse_cond_actions[_trans] != 0 ) { _acts = ( _por_field_parse_actions + (_por_field_parse_cond_actions[_trans])); _nacts = (unsigned int)(*( _acts)); _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts)) ) { case 0: { { #line 30 "src/spss/readstat_por_parse.rl" if ((( (*( p)))) >= '0' && (( (*( p)))) <= '9') { temp_val = 30 * temp_val + ((( (*( p)))) - '0'); } else if ((( (*( p)))) >= 'A' && (( (*( p)))) <= 'T') { temp_val = 30 * temp_val + (10 + (( (*( p)))) - 'A'); } } #line 184 "src/spss/readstat_por_parse.c" break; } case 1: { { #line 38 "src/spss/readstat_por_parse.rl" if ((( (*( p)))) >= '0' && (( (*( p)))) <= '9') { temp_frac += ((( (*( p)))) - '0') / denom; } else if ((( (*( p)))) >= 'A' && (( (*( p)))) <= 'T') { temp_frac += (10 + (( (*( p)))) - 'A') / denom; } denom *= 30.0; } #line 200 "src/spss/readstat_por_parse.c" break; } case 2: { { #line 47 "src/spss/readstat_por_parse.rl" temp_val = 0; } #line 209 "src/spss/readstat_por_parse.c" break; } case 3: { { #line 49 "src/spss/readstat_por_parse.rl" temp_frac = 0.0; } #line 218 "src/spss/readstat_por_parse.c" break; } case 4: { { #line 53 "src/spss/readstat_por_parse.rl" is_negative = 1; } #line 227 "src/spss/readstat_por_parse.c" break; } case 5: { { #line 53 "src/spss/readstat_por_parse.rl" num = temp_val; } #line 236 "src/spss/readstat_por_parse.c" break; } case 6: { { #line 54 "src/spss/readstat_por_parse.rl" exp_is_negative = 1; } #line 245 "src/spss/readstat_por_parse.c" break; } case 7: { { #line 54 "src/spss/readstat_por_parse.rl" exp = temp_val; } #line 254 "src/spss/readstat_por_parse.c" break; } case 8: { { #line 56 "src/spss/readstat_por_parse.rl" is_negative = 1; } #line 263 "src/spss/readstat_por_parse.c" break; } case 9: { { #line 58 "src/spss/readstat_por_parse.rl" val = NAN; } #line 272 "src/spss/readstat_por_parse.c" break; } case 10: { { #line 60 "src/spss/readstat_por_parse.rl" success = 1; {p += 1; goto _out; } } #line 281 "src/spss/readstat_por_parse.c" break; } } _nacts -= 1; _acts += 1; } } if ( cs != 0 ) { p += 1; goto _resume; } _out: {} } #line 64 "src/spss/readstat_por_parse.rl" if (!isnan(val)) { val = 1.0 * num + temp_frac; if (exp_is_negative) exp *= -1; if (exp) { val *= pow(30.0, exp); } if (is_negative) val *= -1; } if (!success) { retval = -1; if (error_cb) { char error_buf[1024]; snprintf(error_buf, sizeof(error_buf), "Read bytes: %ld String: %.*s Ending state: %d", (long)(p - (const unsigned char *)data), (int)len, data, cs); error_cb(error_buf, user_ctx); } } if (retval == 0) { if (result) *result = val; retval = (p - (const unsigned char *)data); } /* suppress warning */ (void)por_field_parse_en_main; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_por_parse.h0000644000076500000240000000025314674240614020057 0ustar00dialout// // readstat_por_parse.h // ssize_t readstat_por_parse_double(const char *data, size_t len, double *result, readstat_error_handler error_cb, void *user_ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748249037.0 pyreadstat-1.3.3/src/spss/readstat_por_read.c0000644000076500000240000007144215015024715017653 0ustar00dialout// // readstat_por.c // #include #include #include #include #include #include #include #include #include "../readstat.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" #include "../CKHashTable.h" #include "readstat_por_parse.h" #include "readstat_spss.h" #include "readstat_por.h" #define POR_LINE_LENGTH 80 #define POR_LABEL_NAME_PREFIX "labels" #define POR_FORMAT_SHIFT 82 #define MAX_FORMAT_TYPE (POR_FORMAT_SHIFT+SPSS_FORMAT_TYPE_YMDHMS) #define MAX_FORMAT_WIDTH 20000 #define MAX_FORMAT_DECIMALS 100 #define MAX_STRING_LENGTH 20000 #define MAX_VARS 1000000 #define MAX_WIDTH 1000000 #define MAX_LINES 1000000 #define MAX_STRINGS 1000000 #define MAX_LABELS 1000000 static ssize_t read_bytes(por_ctx_t *ctx, void *dst, size_t len); static readstat_error_t read_string(por_ctx_t *ctx, char *data, size_t len); static readstat_error_t por_update_progress(por_ctx_t *ctx) { readstat_io_t *io = ctx->io; return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx); } static ssize_t read_bytes(por_ctx_t *ctx, void *dst, size_t len) { char *dst_pos = (char *)dst; readstat_io_t *io = ctx->io; char byte; while (dst_pos < (char *)dst + len) { if (ctx->num_spaces) { *dst_pos++ = ctx->space; ctx->num_spaces--; continue; } ssize_t bytes_read = io->read(&byte, 1, io->io_ctx); if (bytes_read == 0) { break; } if (bytes_read == -1) { return -1; } if (byte == '\r' || byte == '\n') { if (byte == '\r') { bytes_read = io->read(&byte, 1, io->io_ctx); if (bytes_read == 0 || bytes_read == -1 || byte != '\n') return -1; } ctx->num_spaces = POR_LINE_LENGTH - ctx->pos; ctx->pos = 0; continue; } else if (ctx->pos == POR_LINE_LENGTH) { return -1; } *dst_pos++ = byte; ctx->pos++; } return (int)(dst_pos - (char *)dst); } static uint16_t read_tag(por_ctx_t *ctx) { unsigned char tag; if (read_bytes(ctx, &tag, 1) != 1) { return -1; } return ctx->byte2unicode[tag]; } static readstat_error_t read_double_with_peek(por_ctx_t *ctx, double *out_double, unsigned char peek) { readstat_error_t retval = READSTAT_OK; double value = NAN; unsigned char buffer[100]; char utf8_buffer[300]; char error_buf[1024]; int64_t len = 0; ssize_t bytes_read = 0; buffer[0] = peek; bytes_read = read_bytes(ctx, &buffer[1], 1); if (bytes_read != 1) return READSTAT_ERROR_PARSE; if (ctx->byte2unicode[buffer[0]] == '*' && ctx->byte2unicode[buffer[1]] == '.') { if (out_double) *out_double = NAN; return READSTAT_OK; } int64_t i=2; while (ibyte2unicode[buffer[i-1]] != '/') { bytes_read = read_bytes(ctx, &buffer[i], 1); if (bytes_read != 1) return READSTAT_ERROR_PARSE; i++; } if (i == sizeof(buffer)) { return READSTAT_ERROR_PARSE; } len = por_utf8_encode(buffer, i, utf8_buffer, sizeof(utf8_buffer), ctx->byte2unicode); if (len == -1) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error converting double string (length=%" PRId64 "): %.*s", i, (int)i, buffer); ctx->handle.error(error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_CONVERT; goto cleanup; } bytes_read = readstat_por_parse_double(utf8_buffer, len, &value, ctx->handle.error, ctx->user_ctx); if (bytes_read == -1) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error parsing double string (length=%" PRId64 "): %.*s [%s]", len, (int)len, utf8_buffer, buffer); ctx->handle.error(error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_PARSE; goto cleanup; } cleanup: if (out_double) *out_double = value; return retval; } static readstat_error_t read_double(por_ctx_t *ctx, double *out_double) { unsigned char peek; size_t bytes_read = read_bytes(ctx, &peek, 1); if (bytes_read != 1) return READSTAT_ERROR_PARSE; return read_double_with_peek(ctx, out_double, peek); } static readstat_error_t read_integer_in_range(por_ctx_t *ctx, int min, int max, int *out_integer) { double dval = NAN; readstat_error_t retval = read_double(ctx, &dval); if (retval != READSTAT_OK) return retval; if (isnan(dval) || dval < min || dval > max) return READSTAT_ERROR_PARSE; if (out_integer) *out_integer = (int)dval; return READSTAT_OK; } static readstat_error_t maybe_read_double(por_ctx_t *ctx, double *out_double, int *out_finished) { unsigned char peek; size_t bytes_read = read_bytes(ctx, &peek, 1); if (bytes_read != 1) return READSTAT_ERROR_PARSE; if (ctx->byte2unicode[peek] == 'Z') { if (out_double) *out_double = NAN; if (out_finished) *out_finished = 1; return READSTAT_OK; } if (out_finished) *out_finished = 0; return read_double_with_peek(ctx, out_double, peek); } static readstat_error_t maybe_read_string(por_ctx_t *ctx, char *data, size_t len, int *out_finished) { readstat_error_t retval = READSTAT_OK; double value; int finished = 0; char error_buf[1024]; size_t string_length = 0; retval = maybe_read_double(ctx, &value, &finished); if (retval != READSTAT_OK || finished) { if (out_finished) *out_finished = finished; return retval; } if (value < 0 || value > MAX_STRING_LENGTH || isnan(value)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } string_length = (size_t)value; if (string_length > ctx->string_buffer_len) { ctx->string_buffer_len = string_length; ctx->string_buffer = realloc(ctx->string_buffer, ctx->string_buffer_len); memset(ctx->string_buffer, 0, ctx->string_buffer_len); } if (read_bytes(ctx, ctx->string_buffer, string_length) == -1) { retval = READSTAT_ERROR_READ; goto cleanup; } size_t bytes_encoded = por_utf8_encode(ctx->string_buffer, string_length, data, len - 1, ctx->byte2unicode); if (bytes_encoded == -1) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error converting string: %.*s", (int)string_length, ctx->string_buffer); ctx->handle.error(error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_CONVERT; goto cleanup; } data[bytes_encoded] = '\0'; if (out_finished) *out_finished = 0; cleanup: return retval; } static readstat_error_t read_string(por_ctx_t *ctx, char *data, size_t len) { int finished = 0; readstat_error_t retval = maybe_read_string(ctx, data, len, &finished); if (retval == READSTAT_OK && finished) { return READSTAT_ERROR_PARSE; } return retval; } static readstat_error_t read_variable_count_record(por_ctx_t *ctx) { int value; readstat_error_t retval = READSTAT_OK; if (ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if ((retval = read_integer_in_range(ctx, 0, MAX_VARS, &value)) != READSTAT_OK) { goto cleanup; } ctx->var_count = value; ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *)); ctx->varinfo = readstat_calloc(ctx->var_count, sizeof(spss_varinfo_t)); if (ctx->variables == NULL || ctx->varinfo == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (ctx->handle.metadata) { readstat_metadata_t metadata = { .row_count = -1, .var_count = ctx->var_count, .creation_time = ctx->timestamp, .modified_time = ctx->timestamp, .file_format_version = ctx->version, .file_label = ctx->file_label }; if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } cleanup: return retval; } static readstat_error_t read_precision_record(por_ctx_t *ctx) { int precision = 0; readstat_error_t error = read_integer_in_range(ctx, 0, 100, &precision); if (error == READSTAT_OK) ctx->base30_precision = precision; return error; } static readstat_error_t read_case_weight_record(por_ctx_t *ctx) { return read_string(ctx, ctx->fweight_name, sizeof(ctx->fweight_name)); } static readstat_error_t read_variable_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int value; int i; spss_varinfo_t *varinfo = NULL; spss_format_t *formats[2]; ctx->var_offset++; if (ctx->var_offset == ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo = &ctx->varinfo[ctx->var_offset]; formats[0] = &varinfo->print_format; formats[1] = &varinfo->write_format; varinfo->labels_index = -1; if ((retval = read_integer_in_range(ctx, 0, MAX_WIDTH, &value)) != READSTAT_OK) { goto cleanup; } varinfo->width = value; if (varinfo->width == 0) { varinfo->type = READSTAT_TYPE_DOUBLE; } else { varinfo->type = READSTAT_TYPE_STRING; } if ((retval = read_string(ctx, varinfo->name, sizeof(varinfo->name))) != READSTAT_OK) { goto cleanup; } ck_str_hash_insert(varinfo->name, varinfo, ctx->var_dict); for (i=0; i POR_FORMAT_SHIFT) { // Some files in the wild have their format types shifted by 82 for date/time values // I have no idea why, but see test files linked from: // https://github.com/WizardMac/ReadStat/issues/158 format->type = value - POR_FORMAT_SHIFT; } else { format->type = value; } if ((retval = read_integer_in_range(ctx, 0, MAX_FORMAT_WIDTH, &value)) != READSTAT_OK) { goto cleanup; } format->width = value; if ((retval = read_integer_in_range(ctx, 0, MAX_FORMAT_DECIMALS, &value)) != READSTAT_OK) { goto cleanup; } format->decimal_places = value; } cleanup: return retval; } static readstat_error_t read_missing_value_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; spss_varinfo_t *varinfo = NULL; if (ctx->var_offset < 0 || ctx->var_offset >= ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo = &ctx->varinfo[ctx->var_offset]; if (varinfo->type == READSTAT_TYPE_DOUBLE) { if ((retval = read_double(ctx, &varinfo->missing_double_values[varinfo->n_missing_values])) != READSTAT_OK) { goto cleanup; } } else { if ((retval = read_string(ctx, varinfo->missing_string_values[varinfo->n_missing_values], sizeof(varinfo->missing_string_values[varinfo->n_missing_values]))) != READSTAT_OK) { goto cleanup; } } if (varinfo->n_missing_values > 2) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo->n_missing_values++; cleanup: return retval; } static readstat_error_t read_missing_value_range_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; spss_varinfo_t *varinfo = NULL; if (ctx->var_offset < 0 || ctx->var_offset == ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo = &ctx->varinfo[ctx->var_offset]; varinfo->missing_range = 1; varinfo->n_missing_values = 2; if (varinfo->type == READSTAT_TYPE_DOUBLE) { if ((retval = read_double(ctx, &varinfo->missing_double_values[0])) != READSTAT_OK) { goto cleanup; } if ((retval = read_double(ctx, &varinfo->missing_double_values[1])) != READSTAT_OK) { goto cleanup; } } else { if ((retval = read_string(ctx, varinfo->missing_string_values[0], sizeof(varinfo->missing_string_values[0]))) != READSTAT_OK) { goto cleanup; } if ((retval = read_string(ctx, varinfo->missing_string_values[1], sizeof(varinfo->missing_string_values[1]))) != READSTAT_OK) { goto cleanup; } } cleanup: return retval; } static readstat_error_t read_missing_value_lo_range_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; spss_varinfo_t *varinfo = NULL; if (ctx->var_offset < 0 || ctx->var_offset == ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo = &ctx->varinfo[ctx->var_offset]; varinfo->missing_range = 1; varinfo->n_missing_values = 2; if (varinfo->type == READSTAT_TYPE_DOUBLE) { varinfo->missing_double_values[0] = -HUGE_VAL; if ((retval = read_double(ctx, &varinfo->missing_double_values[1])) != READSTAT_OK) { goto cleanup; } } else { varinfo->missing_string_values[0][0] = '\0'; if ((retval = read_string(ctx, varinfo->missing_string_values[1], sizeof(varinfo->missing_string_values[1]))) != READSTAT_OK) { goto cleanup; } } cleanup: return retval; } static readstat_error_t read_missing_value_hi_range_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; spss_varinfo_t *varinfo = NULL; if (ctx->var_offset < 0 || ctx->var_offset == ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo = &ctx->varinfo[ctx->var_offset]; varinfo->missing_range = 1; varinfo->n_missing_values = 2; if (varinfo->type == READSTAT_TYPE_DOUBLE) { if ((retval = read_double(ctx, &varinfo->missing_double_values[0])) != READSTAT_OK) { goto cleanup; } varinfo->missing_double_values[1] = HUGE_VAL; } else { if ((retval = read_string(ctx, varinfo->missing_string_values[0], sizeof(varinfo->missing_string_values[0]))) != READSTAT_OK) { goto cleanup; } varinfo->missing_string_values[1][0] = '\0'; } cleanup: return retval; } static readstat_error_t read_document_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; char string[256]; int i; int line_count = 0; if ((retval = read_integer_in_range(ctx, 0, MAX_LINES, &line_count)) != READSTAT_OK) { goto cleanup; } for (i=0; ihandle.note) { if (ctx->handle.note(i, string, ctx->user_ctx) != READSTAT_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } cleanup: return retval; } static readstat_error_t read_variable_label_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; char string[256]; spss_varinfo_t *varinfo = NULL; if (ctx->var_offset < 0 || ctx->var_offset == ctx->var_count) { retval = READSTAT_ERROR_PARSE; goto cleanup; } varinfo = &ctx->varinfo[ctx->var_offset]; if ((retval = read_string(ctx, string, sizeof(string))) != READSTAT_OK) { goto cleanup; } varinfo->label = realloc(varinfo->label, 4*strlen(string) + 1); retval = readstat_convert(varinfo->label, 4*strlen(string) + 1, string, strlen(string), ctx->converter); cleanup: return retval; } static readstat_error_t read_value_label_record(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; double dval; int i; char string[256]; int count = 0, label_count = 0; char label_name_buf[256]; char label_buf[256]; snprintf(label_name_buf, sizeof(label_name_buf), POR_LABEL_NAME_PREFIX "%d", ctx->labels_offset); readstat_type_t value_type = READSTAT_TYPE_DOUBLE; if ((retval = read_integer_in_range(ctx, 0, MAX_STRINGS, &count)) != READSTAT_OK) { goto cleanup; } for (i=0; ivar_dict); if (info) { value_type = info->type; info->labels_index = ctx->labels_offset; } } if ((retval = read_integer_in_range(ctx, 0, MAX_LABELS, &label_count)) != READSTAT_OK) { goto cleanup; } for (i=0; ihandle.value_label) { if (ctx->handle.value_label(label_name_buf, value, label_buf, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } ctx->labels_offset++; cleanup: return retval; } static readstat_error_t read_por_file_data(por_ctx_t *ctx) { int i; char input_string[256]; char output_string[4*256+1]; char error_buf[1024]; readstat_error_t rs_retval = READSTAT_OK; if (ctx->var_count == 0) return READSTAT_OK; while (1) { int finished = 0; for (i=0; ivar_count; i++) { spss_varinfo_t *info = &ctx->varinfo[i]; readstat_value_t value = { .type = info->type }; if (info->type == READSTAT_TYPE_STRING) { rs_retval = maybe_read_string(ctx, input_string, sizeof(input_string), &finished); if (rs_retval != READSTAT_OK) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error in %s (row=%d)", info->name, ctx->obs_count+1); ctx->handle.error(error_buf, ctx->user_ctx); } goto cleanup; } else if (finished) { if (i != 0) rs_retval = READSTAT_ERROR_PARSE; goto cleanup; } rs_retval = readstat_convert(output_string, sizeof(output_string), input_string, strlen(input_string), ctx->converter); if (rs_retval != READSTAT_OK) { goto cleanup; } value.v.string_value = output_string; } else if (info->type == READSTAT_TYPE_DOUBLE) { rs_retval = maybe_read_double(ctx, &value.v.double_value, &finished); if (rs_retval != READSTAT_OK) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error in %s (row=%d)", info->name, ctx->obs_count+1); ctx->handle.error(error_buf, ctx->user_ctx); } goto cleanup; } else if (finished) { if (i != 0) rs_retval = READSTAT_ERROR_PARSE; goto cleanup; } value.is_system_missing = isnan(value.v.double_value); } if (ctx->handle.value && !ctx->variables[i]->skip && !ctx->row_offset) { if (ctx->handle.value(ctx->obs_count, ctx->variables[i], value, ctx->user_ctx) != READSTAT_HANDLER_OK) { rs_retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } if (ctx->row_offset) { ctx->row_offset--; } else { ctx->obs_count++; } rs_retval = por_update_progress(ctx); if (rs_retval != READSTAT_OK) break; if (ctx->row_limit > 0 && ctx->obs_count == ctx->row_limit) break; } cleanup: return rs_retval; } readstat_error_t read_version_and_timestamp(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; char string[256]; struct tm timestamp = { .tm_isdst = -1 }; unsigned char version; if (read_bytes(ctx, &version, sizeof(version)) != sizeof(version)) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = read_string(ctx, string, sizeof(string))) != READSTAT_OK) { /* creation date */ goto cleanup; } if (sscanf(string, "%04d%02d%02d", ×tamp.tm_year, ×tamp.tm_mon, ×tamp.tm_mday) != 3) { retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING; goto cleanup; } if ((retval = read_string(ctx, string, sizeof(string))) != READSTAT_OK) { /* creation time */ goto cleanup; } if (sscanf(string, "%02d%02d%02d", ×tamp.tm_hour, ×tamp.tm_min, ×tamp.tm_sec) != 3) { /* optional */ } timestamp.tm_year -= 1900; timestamp.tm_mon--; ctx->timestamp = mktime(×tamp); ctx->version = ctx->byte2unicode[version] - 'A'; cleanup: return retval; } readstat_error_t handle_variables(por_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i; int index_after_skipping = 0; for (i=0; ivar_count; i++) { char label_name_buf[256]; spss_varinfo_t *info = &ctx->varinfo[i]; info->index = i; ctx->variables[i] = spss_init_variable_for_info(info, index_after_skipping, ctx->converter); snprintf(label_name_buf, sizeof(label_name_buf), POR_LABEL_NAME_PREFIX "%d", info->labels_index); int cb_retval = READSTAT_HANDLER_OK; if (ctx->handle.variable) { cb_retval = ctx->handle.variable(i, ctx->variables[i], info->labels_index == -1 ? NULL : label_name_buf, ctx->user_ctx); } if (cb_retval == READSTAT_HANDLER_ABORT) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) { ctx->variables[i]->skip = 1; } else { index_after_skipping++; } } if (ctx->handle.fweight && ctx->fweight_name[0]) { for (i=0; ivar_count; i++) { spss_varinfo_t *info = &ctx->varinfo[i]; if (strcmp(info->name, ctx->fweight_name) == 0) { if (ctx->handle.fweight(ctx->variables[i], ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } break; } } } cleanup: return retval; } readstat_error_t readstat_parse_por(readstat_parser_t *parser, const char *path, void *user_ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = parser->io; unsigned char reverse_lookup[256]; char vanity[5][40]; char error_buf[1024]; por_ctx_t *ctx = por_ctx_init(); ctx->handle = parser->handlers; ctx->user_ctx = user_ctx; ctx->io = io; ctx->row_limit = parser->row_limit; if (parser->row_offset > 0) ctx->row_offset = parser->row_offset; if (parser->output_encoding) { if (strcmp(parser->output_encoding, "UTF-8") != 0) ctx->converter = iconv_open(parser->output_encoding, "UTF-8"); if (ctx->converter == (iconv_t)-1) { ctx->converter = NULL; retval = READSTAT_ERROR_UNSUPPORTED_CHARSET; goto cleanup; } } if (io->open(path, io->io_ctx) == -1) { retval = READSTAT_ERROR_OPEN; goto cleanup; } if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (read_bytes(ctx, vanity, sizeof(vanity)) != sizeof(vanity)) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label), vanity[1] + 20, 20, NULL); if (retval != READSTAT_OK) goto cleanup; if (read_bytes(ctx, reverse_lookup, sizeof(reverse_lookup)) != sizeof(reverse_lookup)) { retval = READSTAT_ERROR_READ; goto cleanup; } ctx->space = reverse_lookup[126]; int i; for (i=0; i<256; i++) { if (por_ascii_lookup[i]) { ctx->byte2unicode[reverse_lookup[i]] = por_ascii_lookup[i]; } else if (por_unicode_lookup[i]) { ctx->byte2unicode[reverse_lookup[i]] = por_unicode_lookup[i]; } } ctx->byte2unicode[reverse_lookup[64]] = por_unicode_lookup[64]; unsigned char check[8]; char tr_check[8]; if (read_bytes(ctx, check, sizeof(check)) != sizeof(check)) { retval = READSTAT_ERROR_READ; goto cleanup; } ssize_t encoded_len; if ((encoded_len = por_utf8_encode(check, sizeof(check), tr_check, sizeof(tr_check), ctx->byte2unicode)) == -1) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error converting check string: %.*s", (int)sizeof(check), check); ctx->handle.error(error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_CONVERT; goto cleanup; } if (strncmp("SPSSPORT", tr_check, encoded_len) != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->var_offset = -1; char string[256]; retval = read_version_and_timestamp(ctx); if (retval != READSTAT_OK) goto cleanup; while (1) { uint16_t tr_tag = read_tag(ctx); switch (tr_tag) { case '1': /* product ID */ case '2': /* author ID */ case '3': /* sub-product ID */ retval = read_string(ctx, string, sizeof(string)); break; case '4': /* variable count */ retval = read_variable_count_record(ctx); break; case '5': /* precision */ retval = read_precision_record(ctx); break; case '6': /* case weight */ retval = read_case_weight_record(ctx); break; case '7': /* variable */ retval = read_variable_record(ctx); break; case '8': /* missing value */ retval = read_missing_value_record(ctx); break; case 'B': /* missing value range */ retval = read_missing_value_range_record(ctx); break; case '9': /* LO THRU x */ retval = read_missing_value_lo_range_record(ctx); break; case 'A': /* x THRU HI */ retval = read_missing_value_hi_range_record(ctx); break; case 'C': /* variable label */ retval = read_variable_label_record(ctx); break; case 'D': /* value label */ retval = read_value_label_record(ctx); break; case 'E': /* document record */ retval = read_document_record(ctx); break; case 'F': /* file data */ if (ctx->var_offset != ctx->var_count - 1) { retval = READSTAT_ERROR_COLUMN_COUNT_MISMATCH; goto cleanup; } retval = handle_variables(ctx); if (retval != READSTAT_OK) goto cleanup; if (ctx->handle.value) { retval = read_por_file_data(ctx); } goto cleanup; default: retval = READSTAT_ERROR_PARSE; goto cleanup; } if (retval != READSTAT_OK) break; } cleanup: io->close(io->io_ctx); por_ctx_free(ctx); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748249037.0 pyreadstat-1.3.3/src/spss/readstat_por_write.c0000644000076500000240000006457215015024715020100 0ustar00dialout #include #include #include #include #include #include "../readstat.h" #include "../CKHashTable.h" #include "../readstat_writer.h" #include "readstat_spss.h" #include "readstat_por.h" #define POR_BASE30_PRECISION 50 typedef struct por_write_ctx_s { unsigned char *unicode2byte; size_t unicode2byte_len; } por_write_ctx_t; static inline char por_encode_base30_digit(uint64_t digit) { if (digit < 10) return '0' + digit; return 'A' + (digit - 10); } static int por_write_base30_integer(char *string, size_t string_len, uint64_t integer) { int start = 0; int end = 0; int offset = 0; while (integer) { string[offset++] = por_encode_base30_digit(integer % 30); integer /= 30; } end = offset; offset--; while (offset > start) { char tmp = string[start]; string[start] = string[offset]; string[offset] = tmp; offset--; start++; } return end; } static readstat_error_t por_finish(readstat_writer_t *writer) { return readstat_write_line_padding(writer, 'Z', 80, "\r\n"); } static readstat_error_t por_write_bytes(readstat_writer_t *writer, const void *bytes, size_t len) { return readstat_write_bytes_as_lines(writer, bytes, len, 80, "\r\n"); } static readstat_error_t por_write_string_n(readstat_writer_t *writer, por_write_ctx_t *ctx, const char *string, size_t input_len) { char error_buf[1024]; readstat_error_t retval = READSTAT_OK; char *por_string = malloc(input_len); ssize_t output_len = por_utf8_decode(string, input_len, por_string, input_len, ctx->unicode2byte, ctx->unicode2byte_len); if (output_len == -1) { if (writer->error_handler) { snprintf(error_buf, sizeof(error_buf), "Error converting string (length=%" PRId64 "): %.*s", (int64_t)input_len, (int)input_len, string); writer->error_handler(error_buf, writer->user_ctx); } retval = READSTAT_ERROR_CONVERT; goto cleanup; } retval = por_write_bytes(writer, por_string, output_len); cleanup: if (por_string) free(por_string); return retval; } static readstat_error_t por_write_tag(readstat_writer_t *writer, por_write_ctx_t *ctx, char tag) { char string[2]; string[0] = tag; string[1] = '\0'; return por_write_string_n(writer, ctx, string, 1); } static ssize_t por_write_double_to_buffer(char *string, size_t buffer_len, double value, long precision) { int offset = 0; if (isnan(value)) { string[offset++] = '*'; string[offset++] = '.'; } else if (isinf(value)) { if (value < 0.0) { string[offset++] = '-'; } string[offset++] = '1'; string[offset++] = '+'; string[offset++] = 'T'; string[offset++] = 'T'; string[offset++] = '/'; } else { long integers_printed = 0; double integer_part; double fraction = modf(fabs(value), &integer_part); int64_t integer = integer_part; int64_t exponent = 0; if (value < 0.0) { string[offset++] = '-'; } if (integer == 0) { string[offset++] = '0'; } else { while (fraction == 0 && integer != 0 && (integer % 30) == 0) { integer /= 30; exponent++; } integers_printed = por_write_base30_integer(&string[offset], buffer_len - offset, integer); offset += integers_printed; } /* should use exponents for efficiency, but this works */ if (fraction) { string[offset++] = '.'; } while (fraction && integers_printed < precision) { fraction = modf(fraction * 30, &integer_part); integer = integer_part; if (integer < 0) { return -1; } else { string[offset++] = por_encode_base30_digit(integer); } integers_printed++; } if (exponent) { string[offset++] = '+'; offset += por_write_base30_integer(&string[offset], buffer_len - offset, exponent); } string[offset++] = '/'; } string[offset] = '\0'; return offset; } static readstat_error_t por_write_double(readstat_writer_t *writer, por_write_ctx_t *ctx, double value) { char error_buf[1024]; char string[256]; ssize_t bytes_written = por_write_double_to_buffer(string, sizeof(string), value, POR_BASE30_PRECISION); if (bytes_written == -1) { if (writer->error_handler) { snprintf(error_buf, sizeof(error_buf), "Unable to encode number: %lf", value); writer->error_handler(error_buf, writer->user_ctx); } return READSTAT_ERROR_WRITE; } return por_write_string_n(writer, ctx, string, bytes_written); } static readstat_error_t por_write_string_field_n(readstat_writer_t *writer, por_write_ctx_t *ctx, const char *string, size_t len) { readstat_error_t error = por_write_double(writer, ctx, len); if (error != READSTAT_OK) return error; return por_write_string_n(writer, ctx, string, len); } static readstat_error_t por_write_string_field(readstat_writer_t *writer, por_write_ctx_t *ctx, const char *string) { return por_write_string_field_n(writer, ctx, string, strlen(string)); } static por_write_ctx_t *por_write_ctx_init(void) { por_write_ctx_t *ctx = calloc(1, sizeof(por_write_ctx_t)); uint16_t max_unicode = 0; int i; for (i=0; i max_unicode) max_unicode = por_unicode_lookup[i]; } ctx->unicode2byte = malloc(max_unicode+1); ctx->unicode2byte_len = max_unicode+1; for (i=0; iunicode2byte[por_unicode_lookup[i]] = por_ascii_lookup[i]; } if (por_ascii_lookup[i]) { ctx->unicode2byte[por_ascii_lookup[i]] = por_ascii_lookup[i]; } } return ctx; } static void por_write_ctx_free(por_write_ctx_t *ctx) { if (ctx->unicode2byte) free(ctx->unicode2byte); free(ctx); } static readstat_error_t por_emit_header(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t file_label_len = strlen(writer->file_label); char vanity[5][40]; memset(vanity, '0', sizeof(vanity)); memset(vanity[1], ' ', sizeof(vanity[1])); memcpy(vanity[1], "ASCII SPSS PORT FILE", 20); memcpy(vanity[1] + 20, writer->file_label, file_label_len > 20 ? 20 : file_label_len); por_write_bytes(writer, vanity, sizeof(vanity)); char lookup[256]; int i; memset(lookup, '0', sizeof(lookup)); for (i=0; itimestamp); if (!timestamp) { retval = READSTAT_ERROR_BAD_TIMESTAMP_VALUE; goto cleanup; } if ((retval = por_write_tag(writer, ctx, 'A')) != READSTAT_OK) goto cleanup; char date[9]; snprintf(date, sizeof(date), "%04d%02d%02d", (unsigned int)(timestamp->tm_year + 1900) % 10000, (unsigned int)(timestamp->tm_mon + 1) % 100, (unsigned int)(timestamp->tm_mday) % 100); if ((retval = por_write_string_field(writer, ctx, date)) != READSTAT_OK) goto cleanup; char time[7]; snprintf(time, sizeof(time), "%02d%02d%02d", (unsigned int)timestamp->tm_hour % 100, (unsigned int)timestamp->tm_min % 100, (unsigned int)timestamp->tm_sec % 100); if ((retval = por_write_string_field(writer, ctx, time)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t por_emit_identification_records(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if ((retval = por_write_tag(writer, ctx, '1')) != READSTAT_OK) goto cleanup; if ((retval = por_write_string_field(writer, ctx, READSTAT_PRODUCT_NAME)) != READSTAT_OK) goto cleanup; if ((retval = por_write_tag(writer, ctx, '3')) != READSTAT_OK) goto cleanup; if ((retval = por_write_string_field(writer, ctx, READSTAT_PRODUCT_URL)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t por_emit_variable_count_record(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if ((retval = por_write_tag(writer, ctx, '4')) != READSTAT_OK) goto cleanup; if ((retval = por_write_double(writer, ctx, writer->variables_count)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t por_emit_precision_record(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if ((retval = por_write_tag(writer, ctx, '5')) != READSTAT_OK) goto cleanup; if ((retval = por_write_double(writer, ctx, POR_BASE30_PRECISION)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t por_emit_case_weight_variable_record(readstat_writer_t *writer, por_write_ctx_t *ctx) { if (!writer->fweight_variable) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; if ((retval = por_write_tag(writer, ctx, '6')) != READSTAT_OK) goto cleanup; if ((retval = por_write_string_field(writer, ctx, readstat_variable_get_name(writer->fweight_variable))) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t por_emit_format(readstat_writer_t *writer, por_write_ctx_t *ctx, spss_format_t *format) { readstat_error_t error = READSTAT_OK; if ((error = por_write_double(writer, ctx, format->type)) != READSTAT_OK) goto cleanup; if ((error = por_write_double(writer, ctx, format->width)) != READSTAT_OK) goto cleanup; if ((error = por_write_double(writer, ctx, format->decimal_places)) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t validate_variable_name(const char *name) { size_t len = strlen(name); if (len < 1 || len > 8) return READSTAT_ERROR_NAME_IS_TOO_LONG; int i; for (i=0; name[i]; i++) { if (name[i] >= 'A' && name[i] <= 'Z') continue; if (name[i] >= '0' && name[i] <= '9') continue; if (name[i] == '@' || name[i] == '#' || name[i] == '$') continue; if (name[i] == '_' || name[i] == '.') continue; return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER; } if (!(name[0] >= 'A' && name[0] <= 'Z') && name[0] != '@') return READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER; return READSTAT_OK; } static readstat_error_t por_emit_variable_label_record(readstat_writer_t *writer, por_write_ctx_t *ctx, readstat_variable_t *r_variable) { const char *label = readstat_variable_get_label(r_variable); readstat_error_t retval = READSTAT_OK; if (!label) return READSTAT_OK; if ((retval = por_write_tag(writer, ctx, 'C')) != READSTAT_OK) goto cleanup; if ((retval = por_write_string_field(writer, ctx, label)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t por_emit_missing_string_values_records(readstat_writer_t *writer, por_write_ctx_t *ctx, readstat_variable_t *r_variable) { readstat_error_t retval = READSTAT_OK; int n_missing_values = 0; int n_missing_ranges = readstat_variable_get_missing_ranges_count(r_variable); /* ranges */ int j; for (j=0; j 3) retval = READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS; cleanup: return retval; } static readstat_error_t por_emit_missing_double_values_records(readstat_writer_t *writer, por_write_ctx_t *ctx, readstat_variable_t *r_variable) { readstat_error_t retval = READSTAT_OK; int n_missing_values = 0; int n_missing_ranges = readstat_variable_get_missing_ranges_count(r_variable); /* ranges */ int j; for (j=0; j 3) retval = READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS; cleanup: return retval; } static readstat_error_t por_emit_missing_values_records(readstat_writer_t *writer, por_write_ctx_t *ctx, readstat_variable_t *r_variable) { if (r_variable->type == READSTAT_TYPE_DOUBLE) { return por_emit_missing_double_values_records(writer, ctx, r_variable); } return por_emit_missing_string_values_records(writer, ctx, r_variable); } static readstat_error_t por_emit_variable_records(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); const char *variable_name = readstat_variable_get_name(r_variable); spss_format_t print_format; if ((retval = por_write_tag(writer, ctx, '7')) != READSTAT_OK) break; retval = por_write_double(writer, ctx, (r_variable->type == READSTAT_TYPE_STRING) ? r_variable->user_width : 0); if (retval != READSTAT_OK) break; if ((retval = por_write_string_field(writer, ctx, variable_name)) != READSTAT_OK) break; if ((retval = spss_format_for_variable(r_variable, &print_format)) != READSTAT_OK) break; if ((retval = por_emit_format(writer, ctx, &print_format)) != READSTAT_OK) break; if ((retval = por_emit_format(writer, ctx, &print_format)) != READSTAT_OK) break; if ((retval = por_emit_missing_values_records(writer, ctx, r_variable)) != READSTAT_OK) break; if ((retval = por_emit_variable_label_record(writer, ctx, r_variable)) != READSTAT_OK) break; } return retval; } static readstat_error_t por_emit_value_label_records(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i, j; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); readstat_type_t user_type = r_label_set->type; if (r_label_set->value_labels_count == 0 || r_label_set->variables_count == 0) continue; if ((retval = por_write_tag(writer, ctx, 'D')) != READSTAT_OK) goto cleanup; if ((retval = por_write_double(writer, ctx, r_label_set->variables_count)) != READSTAT_OK) goto cleanup; for (j=0; jvariables_count; j++) { readstat_variable_t *r_variable = readstat_get_label_set_variable(r_label_set, j); if ((retval = por_write_string_field(writer, ctx, readstat_variable_get_name(r_variable))) != READSTAT_OK) goto cleanup; } if ((retval = por_write_double(writer, ctx, r_label_set->value_labels_count)) != READSTAT_OK) goto cleanup; for (j=0; jvalue_labels_count; j++) { readstat_value_label_t *r_value_label = readstat_get_value_label(r_label_set, j); if (user_type == READSTAT_TYPE_STRING) { retval = por_write_string_field_n(writer, ctx, r_value_label->string_key, r_value_label->string_key_len); } else if (user_type == READSTAT_TYPE_DOUBLE) { retval = por_write_double(writer, ctx, r_value_label->double_key); } else if (user_type == READSTAT_TYPE_INT32) { retval = por_write_double(writer, ctx, r_value_label->int32_key); } if (retval != READSTAT_OK) goto cleanup; if ((retval = por_write_string_field_n(writer, ctx, r_value_label->label, r_value_label->label_len)) != READSTAT_OK) goto cleanup; } } cleanup: return retval; } static readstat_error_t por_emit_document_record(readstat_writer_t *writer, por_write_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; if ((retval = por_write_tag(writer, ctx, 'E')) != READSTAT_OK) goto cleanup; if ((retval = por_write_double(writer, ctx, writer->notes_count)) != READSTAT_OK) goto cleanup; int i; for (i=0; inotes_count; i++) { size_t len = strlen(writer->notes[i]); if (len > SPSS_DOC_LINE_SIZE) { retval = READSTAT_ERROR_NOTE_IS_TOO_LONG; goto cleanup; } if ((retval = por_write_string_field_n(writer, ctx, writer->notes[i], len)) != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t por_emit_data_tag(readstat_writer_t *writer, por_write_ctx_t *ctx) { return por_write_tag(writer, ctx, 'F'); } static readstat_error_t por_begin_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; por_write_ctx_t *ctx = por_write_ctx_init(); readstat_error_t retval = READSTAT_OK; if ((retval = por_emit_header(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_version_and_timestamp(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_identification_records(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_variable_count_record(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_precision_record(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_case_weight_variable_record(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_variable_records(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_value_label_records(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_document_record(writer, ctx)) != READSTAT_OK) goto cleanup; if ((retval = por_emit_data_tag(writer, ctx)) != READSTAT_OK) goto cleanup; cleanup: if (retval != READSTAT_OK) { por_write_ctx_free(ctx); } else { writer->module_ctx = ctx; } return retval; } static readstat_error_t por_end_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t error = READSTAT_OK; if ((error = por_write_tag(writer, writer->module_ctx, 'Z')) != READSTAT_OK) goto cleanup; if ((error = por_finish(writer)) != READSTAT_OK) goto cleanup; cleanup: por_write_ctx_free(writer->module_ctx); return error; } static size_t por_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) { return POR_BASE30_PRECISION + 4 + user_width; } return POR_BASE30_PRECISION + 4; // minus sign + period + plus/minus + slash } static readstat_error_t por_variable_ok(const readstat_variable_t *variable) { return validate_variable_name(readstat_variable_get_name(variable)); } static readstat_error_t por_write_double_value(void *row, const readstat_variable_t *var, double value) { if (por_write_double_to_buffer(row, POR_BASE30_PRECISION + 4, value, POR_BASE30_PRECISION) == -1) { return READSTAT_ERROR_WRITE; } return READSTAT_OK; } static readstat_error_t por_write_int8_value(void *row, const readstat_variable_t *var, int8_t value) { return por_write_double_value(row, var, value); } static readstat_error_t por_write_int16_value(void *row, const readstat_variable_t *var, int16_t value) { return por_write_double_value(row, var, value); } static readstat_error_t por_write_int32_value(void *row, const readstat_variable_t *var, int32_t value) { return por_write_double_value(row, var, value); } static readstat_error_t por_write_float_value(void *row, const readstat_variable_t *var, float value) { return por_write_double_value(row, var, value); } static readstat_error_t por_write_missing_number(void *row, const readstat_variable_t *var) { return por_write_double_value(row, var, NAN); } static readstat_error_t por_write_missing_string(void *row, const readstat_variable_t *var) { return por_write_double_value(row, var, 0); } static readstat_error_t por_write_string_value(void *row, const readstat_variable_t *var, const char *string) { size_t len = strlen(string); if (len == 0) { string = " "; len = 1; } size_t storage_width = readstat_variable_get_storage_width(var); if (len > storage_width) { len = storage_width; } ssize_t bytes_written = por_write_double_to_buffer(row, POR_BASE30_PRECISION + 4, len, POR_BASE30_PRECISION); if (bytes_written == -1) { return READSTAT_ERROR_WRITE; } strncpy(((char *)row) + bytes_written, string, len); return READSTAT_OK; } static readstat_error_t por_write_row(void *writer_ctx, void *row, size_t row_len) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; char *row_chars = (char *)row; int offset = 0, output = 0; for (offset=0; offsetmodule_ctx, row_chars, output); } static readstat_error_t por_metadata_ok(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; if (writer->compression != READSTAT_COMPRESS_NONE) return READSTAT_ERROR_UNSUPPORTED_COMPRESSION; return READSTAT_OK; } readstat_error_t readstat_begin_writing_por(readstat_writer_t *writer, void *user_ctx, long row_count) { writer->callbacks.metadata_ok = &por_metadata_ok; writer->callbacks.variable_width = &por_variable_width; writer->callbacks.variable_ok = &por_variable_ok; writer->callbacks.write_int8 = &por_write_int8_value; writer->callbacks.write_int16 = &por_write_int16_value; writer->callbacks.write_int32 = &por_write_int32_value; writer->callbacks.write_float = &por_write_float_value; writer->callbacks.write_double = &por_write_double_value; writer->callbacks.write_string = &por_write_string_value; writer->callbacks.write_missing_string = &por_write_missing_string; writer->callbacks.write_missing_number = &por_write_missing_number; writer->callbacks.begin_data = &por_begin_data; writer->callbacks.write_row = &por_write_row; writer->callbacks.end_data = &por_end_data; return readstat_begin_writing_file(writer, user_ctx, row_count); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav.c0000644000076500000240000000640514674240614016656 0ustar00dialout// // sav.c // #include #include #include #include #include #include #include #include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "../readstat_malloc.h" #include "readstat_sav.h" #define SAV_VARINFO_INITIAL_CAPACITY 512 sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) { sav_ctx_t *ctx = readstat_calloc(1, sizeof(sav_ctx_t)); if (ctx == NULL) { return NULL; } if (memcmp(&header->rec_type, "$FL2", 4) == 0) { ctx->format_version = 2; } else if (memcmp(&header->rec_type, "$FL3", 4) == 0) { ctx->format_version = 3; } else { sav_ctx_free(ctx); return NULL; } ctx->bswap = !(header->layout_code == 2 || header->layout_code == 3); ctx->endianness = (machine_is_little_endian() ^ ctx->bswap) ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG; if (header->compression == 1 || byteswap4(header->compression) == 1) { ctx->compression = READSTAT_COMPRESS_ROWS; } else if (header->compression == 2 || byteswap4(header->compression) == 2) { ctx->compression = READSTAT_COMPRESS_BINARY; } ctx->record_count = ctx->bswap ? byteswap4(header->ncases) : header->ncases; ctx->fweight_index = ctx->bswap ? byteswap4(header->weight_index) : header->weight_index; ctx->missing_double = SAV_MISSING_DOUBLE; ctx->lowest_double = SAV_LOWEST_DOUBLE; ctx->highest_double = SAV_HIGHEST_DOUBLE; ctx->bias = ctx->bswap ? byteswap_double(header->bias) : header->bias; ctx->varinfo_capacity = SAV_VARINFO_INITIAL_CAPACITY; if ((ctx->varinfo = readstat_calloc(ctx->varinfo_capacity, sizeof(spss_varinfo_t *))) == NULL) { sav_ctx_free(ctx); return NULL; } ctx->mr_sets = NULL; ctx->io = io; return ctx; } void sav_ctx_free(sav_ctx_t *ctx) { if (ctx->varinfo) { int i; for (i=0; ivar_index; i++) { spss_varinfo_free(ctx->varinfo[i]); } free(ctx->varinfo); } if (ctx->variables) { int i; for (i=0; ivar_count; i++) { if (ctx->variables[i]) free(ctx->variables[i]); } free(ctx->variables); } if (ctx->raw_string) free(ctx->raw_string); if (ctx->utf8_string) free(ctx->utf8_string); if (ctx->converter) iconv_close(ctx->converter); if (ctx->variable_display_values) { free(ctx->variable_display_values); } if (ctx->mr_sets) { for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) { if (ctx->mr_sets[i].name) { free(ctx->mr_sets[i].name); } if (ctx->mr_sets[i].label) { free(ctx->mr_sets[i].label); } if (ctx->mr_sets[i].subvariables) { for (size_t j = 0; j < ctx->mr_sets[i].num_subvars; j++) { if (ctx->mr_sets[i].subvariables[j]) { free(ctx->mr_sets[i].subvariables[j]); } } free(ctx->mr_sets[i].subvariables); } } free(ctx->mr_sets); } free(ctx); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav.h0000644000076500000240000001014614674240614016660 0ustar00dialout// // readstat_sav.h // #include "readstat_spss.h" #include "../readstat.h" #pragma pack(push, 1) // SAV files typedef struct sav_file_header_record_s { char rec_type[4]; char prod_name[60]; int32_t layout_code; int32_t nominal_case_size; int32_t compression; int32_t weight_index; int32_t ncases; double bias; /* TODO is this portable? */ char creation_date[9]; char creation_time[8]; char file_label[64]; char padding[3]; } sav_file_header_record_t; typedef struct sav_variable_record_s { int32_t type; int32_t has_var_label; int32_t n_missing_values; int32_t print; int32_t write; char name[8]; } sav_variable_record_t; typedef struct sav_info_record_header_s { int32_t rec_type; int32_t subtype; int32_t size; int32_t count; } sav_info_record_t; typedef struct sav_machine_integer_info_record_s { int32_t version_major; int32_t version_minor; int32_t version_revision; int32_t machine_code; int32_t floating_point_rep; int32_t compression_code; int32_t endianness; int32_t character_code; } sav_machine_integer_info_record_t; typedef struct sav_machine_floating_point_info_record_s { uint64_t sysmis; uint64_t highest; uint64_t lowest; } sav_machine_floating_point_info_record_t; typedef struct sav_dictionary_termination_record_s { int32_t rec_type; int32_t filler; } sav_dictionary_termination_record_t; #pragma pack(pop) typedef struct sav_ctx_s { readstat_callbacks_t handle; size_t file_size; readstat_io_t *io; void *user_ctx; spss_varinfo_t **varinfo; size_t varinfo_capacity; readstat_variable_t **variables; const char *input_encoding; const char *output_encoding; char file_label[4*64+1]; time_t timestamp; uint32_t *variable_display_values; size_t variable_display_values_count; iconv_t converter; int var_index; int var_offset; int var_count; int record_count; int row_limit; int row_offset; int current_row; int value_labels_count; int fweight_index; char *raw_string; size_t raw_string_len; char *utf8_string; size_t utf8_string_len; uint64_t missing_double; uint64_t lowest_double; uint64_t highest_double; size_t multiple_response_sets_length; mr_set_t *mr_sets; double bias; int format_version; readstat_compress_t compression; readstat_endian_t endianness; unsigned int bswap:1; } sav_ctx_t; #define SAV_RECORD_TYPE_VARIABLE 2 #define SAV_RECORD_TYPE_VALUE_LABEL 3 #define SAV_RECORD_TYPE_VALUE_LABEL_VARIABLES 4 #define SAV_RECORD_TYPE_DOCUMENT 6 #define SAV_RECORD_TYPE_HAS_DATA 7 #define SAV_RECORD_TYPE_DICT_TERMINATION 999 #define SAV_RECORD_SUBTYPE_INTEGER_INFO 3 #define SAV_RECORD_SUBTYPE_FP_INFO 4 #define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS 7 #define SAV_RECORD_SUBTYPE_PRODUCT_INFO 10 #define SAV_RECORD_SUBTYPE_VAR_DISPLAY 11 #define SAV_RECORD_SUBTYPE_LONG_VAR_NAME 13 #define SAV_RECORD_SUBTYPE_VERY_LONG_STR 14 #define SAV_RECORD_SUBTYPE_NUMBER_OF_CASES 16 #define SAV_RECORD_SUBTYPE_DATA_FILE_ATTRS 17 #define SAV_RECORD_SUBTYPE_VARIABLE_ATTRS 18 #define SAV_RECORD_SUBTYPE_CHAR_ENCODING 20 #define SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS 21 #define SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES 22 #define SAV_FLOATING_POINT_REP_IEEE 1 #define SAV_FLOATING_POINT_REP_IBM 2 #define SAV_FLOATING_POINT_REP_VAX 3 #define SAV_ENDIANNESS_BIG 1 #define SAV_ENDIANNESS_LITTLE 2 #define SAV_EIGHT_SPACES " " sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io); void sav_ctx_free(sav_ctx_t *ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav_compress.c0000644000076500000240000001132314674240614020564 0ustar00dialout#include #include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "readstat_sav.h" #include "readstat_sav_compress.h" size_t sav_compressed_row_bound(size_t uncompressed_length) { return uncompressed_length + (uncompressed_length/8 + 8)/8*8; } size_t sav_compress_row(void *output_row, void *input_row, size_t input_len, readstat_writer_t *writer) { unsigned char *output = output_row; unsigned char *input = input_row; off_t input_offset = 0; off_t output_offset = 8; off_t control_offset = 0; int i; memset(&output[control_offset], 0, 8); for (i=0; ivariables_count; i++) { readstat_variable_t *variable = readstat_get_variable(writer, i); if (variable->type == READSTAT_TYPE_STRING) { size_t width = variable->storage_width; while (width > 0) { if (memcmp(&input[input_offset], SAV_EIGHT_SPACES, 8) == 0) { output[control_offset++] = 254; } else { output[control_offset++] = 253; memcpy(&output[output_offset], &input[input_offset], 8); output_offset += 8; } if (control_offset % 8 == 0) { control_offset = output_offset; memset(&output[control_offset], 0, 8); output_offset += 8; } input_offset += 8; width -= 8; } } else { uint64_t int_value; memcpy(&int_value, &input[input_offset], 8); if (int_value == SAV_MISSING_DOUBLE) { output[control_offset++] = 255; } else { double fp_value; memcpy(&fp_value, &input[input_offset], 8); if (fp_value > -100 && fp_value < 152 && (int)fp_value == fp_value) { output[control_offset++] = (int)fp_value + 100; } else { output[control_offset++] = 253; memcpy(&output[output_offset], &input[input_offset], 8); output_offset += 8; } } if (control_offset % 8 == 0) { control_offset = output_offset; memset(&output[control_offset], 0, 8); output_offset += 8; } input_offset += 8; } } if (writer->current_row + 1 == writer->row_count) output[control_offset] = 252; return output_offset; } void sav_decompress_row(struct sav_row_stream_s *state) { double fp_value; uint64_t missing_value = state->bswap ? byteswap8(state->missing_value) : state->missing_value; int i = 8 - state->i; while (1) { if (i == 8) { if (state->avail_in < 8) { state->status = SAV_ROW_STREAM_NEED_DATA; goto done; } memcpy(state->chunk, state->next_in, 8); state->next_in += 8; state->avail_in -= 8; i = 0; } while (i<8) { switch (state->chunk[i]) { case 0: break; case 252: state->status = SAV_ROW_STREAM_FINISHED_ALL; goto done; case 253: if (state->avail_in < 8) { state->status = SAV_ROW_STREAM_NEED_DATA; goto done; } memcpy(state->next_out, state->next_in, 8); state->next_out += 8; state->avail_out -= 8; state->next_in += 8; state->avail_in -= 8; break; case 254: memset(state->next_out, ' ', 8); state->next_out += 8; state->avail_out -= 8; break; case 255: memcpy(state->next_out, &missing_value, sizeof(uint64_t)); state->next_out += 8; state->avail_out -= 8; break; default: fp_value = state->chunk[i] - state->bias; fp_value = state->bswap ? byteswap_double(fp_value) : fp_value; memcpy(state->next_out, &fp_value, sizeof(double)); state->next_out += 8; state->avail_out -= 8; break; } i++; if (state->avail_out < 8) { state->status = SAV_ROW_STREAM_FINISHED_ROW; goto done; } } } done: state->i = 8 - i; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav_compress.h0000644000076500000240000000141014674240614020565 0ustar00dialoutenum sav_row_stream_status { SAV_ROW_STREAM_NEED_DATA, SAV_ROW_STREAM_HAVE_DATA, SAV_ROW_STREAM_FINISHED_ROW, SAV_ROW_STREAM_FINISHED_ALL }; struct sav_row_stream_s { const unsigned char *next_in; size_t avail_in; unsigned char *next_out; size_t avail_out; uint64_t missing_value; double bias; unsigned char chunk[8]; int i; int bswap; enum sav_row_stream_status status; }; size_t sav_compressed_row_bound(size_t uncompressed_length); size_t sav_compress_row(void *output_row, void *input_row, size_t input_len, readstat_writer_t *writer); void sav_decompress_row(struct sav_row_stream_s *state); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1748268530.0 pyreadstat-1.3.3/src/spss/readstat_sav_parse.c0000644000076500000240000006073215015072762020050 0ustar00dialout #line 1 "src/spss/readstat_sav_parse.rl" #include #include #include "../readstat.h" #include "../readstat_malloc.h" #include "../readstat_strings.h" #include "readstat_sav.h" #include "readstat_sav_parse.h" #line 21 "src/spss/readstat_sav_parse.rl" typedef struct varlookup { char name[8*4+1]; int index; } varlookup_t; static int compare_key_varlookup(const void *elem1, const void *elem2) { const char *key = (const char *)elem1; const varlookup_t *v = (const varlookup_t *)elem2; return strcasecmp(key, v->name); } static int compare_varlookups(const void *elem1, const void *elem2) { const varlookup_t *v1 = (const varlookup_t *)elem1; const varlookup_t *v2 = (const varlookup_t *)elem2; return strcasecmp(v1->name, v2->name); } static int count_vars(sav_ctx_t *ctx) { int i; spss_varinfo_t *last_info = NULL; int var_count = 0; for (i=0; ivar_index; i++) { spss_varinfo_t *info = ctx->varinfo[i]; if (last_info == NULL || strcmp(info->name, last_info->name) != 0) { var_count++; } last_info = info; } return var_count; } static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) { varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t)); int offset = 0; int i; spss_varinfo_t *last_info = NULL; for (i=0; ivar_index; i++) { spss_varinfo_t *info = ctx->varinfo[i]; if (last_info == NULL || strcmp(info->name, last_info->name) != 0) { varlookup_t *entry = &table[offset++]; memcpy(entry->name, info->name, sizeof(info->name)); entry->index = info->index; } last_info = info; } qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups); return table; } #line 69 "src/spss/readstat_sav_parse.c" static const char _sav_long_variable_parse_actions[] = { 0, 1, 1, 1, 5, 2, 2, 0, 3, 6, 4, 3 }; static const short _sav_long_variable_parse_key_offsets[] = { 0, 0, 5, 19, 33, 47, 61, 75, 89, 103, 104, 108, 113, 118, 123, 128, 133, 138, 143, 148, 153, 158, 163, 168, 173, 178, 183, 188, 193, 198, 203, 208, 213, 218, 223, 228, 233, 238, 243, 248, 253, 258, 263, 268, 273, 278, 283, 288, 293, 298, 303, 308, 313, 318, 323, 328, 333, 338, 343, 348, 353, 358, 363, 368, 373, 378, 383, 388, 393, 398, 403, 408, 413, 418, 423, 428 }; static const unsigned char _sav_long_variable_parse_trans_keys[] = { 255u, 0u, 63u, 91u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 61u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 255u, 0u, 63u, 91u, 127u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u, 0 }; static const char _sav_long_variable_parse_single_lengths[] = { 0, 1, 4, 4, 4, 4, 4, 4, 4, 1, 2, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1 }; static const char _sav_long_variable_parse_range_lengths[] = { 0, 2, 5, 5, 5, 5, 5, 5, 5, 0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; static const short _sav_long_variable_parse_index_offsets[] = { 0, 0, 4, 14, 24, 34, 44, 54, 64, 74, 76, 80, 85, 89, 94, 99, 104, 109, 114, 119, 124, 129, 134, 139, 144, 149, 154, 159, 164, 169, 174, 179, 184, 189, 194, 199, 204, 209, 214, 219, 224, 229, 234, 239, 244, 249, 254, 259, 264, 269, 274, 279, 284, 289, 294, 299, 304, 309, 314, 319, 324, 329, 334, 339, 344, 349, 354, 359, 364, 369, 374, 379, 384, 389, 394, 399 }; static const char _sav_long_variable_parse_indicies[] = { 1, 1, 1, 0, 1, 3, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 1, 3, 1, 1, 1, 1, 1, 1, 1, 5, 1, 3, 1, 1, 1, 1, 1, 1, 1, 6, 1, 3, 1, 1, 1, 1, 1, 1, 1, 7, 1, 3, 1, 1, 1, 1, 1, 1, 1, 8, 1, 3, 1, 1, 1, 1, 1, 1, 1, 9, 3, 1, 1, 1, 1, 10, 11, 1, 1, 1, 12, 1, 1, 1, 0, 11, 1, 1, 1, 13, 11, 1, 1, 1, 14, 11, 1, 1, 1, 15, 11, 1, 1, 1, 16, 11, 1, 1, 1, 17, 11, 1, 1, 1, 18, 11, 1, 1, 1, 19, 11, 1, 1, 1, 20, 11, 1, 1, 1, 21, 11, 1, 1, 1, 22, 11, 1, 1, 1, 23, 11, 1, 1, 1, 24, 11, 1, 1, 1, 25, 11, 1, 1, 1, 26, 11, 1, 1, 1, 27, 11, 1, 1, 1, 28, 11, 1, 1, 1, 29, 11, 1, 1, 1, 30, 11, 1, 1, 1, 31, 11, 1, 1, 1, 32, 11, 1, 1, 1, 33, 11, 1, 1, 1, 34, 11, 1, 1, 1, 35, 11, 1, 1, 1, 36, 11, 1, 1, 1, 37, 11, 1, 1, 1, 38, 11, 1, 1, 1, 39, 11, 1, 1, 1, 40, 11, 1, 1, 1, 41, 11, 1, 1, 1, 42, 11, 1, 1, 1, 43, 11, 1, 1, 1, 44, 11, 1, 1, 1, 45, 11, 1, 1, 1, 46, 11, 1, 1, 1, 47, 11, 1, 1, 1, 48, 11, 1, 1, 1, 49, 11, 1, 1, 1, 50, 11, 1, 1, 1, 51, 11, 1, 1, 1, 52, 11, 1, 1, 1, 53, 11, 1, 1, 1, 54, 11, 1, 1, 1, 55, 11, 1, 1, 1, 56, 11, 1, 1, 1, 57, 11, 1, 1, 1, 58, 11, 1, 1, 1, 59, 11, 1, 1, 1, 60, 11, 1, 1, 1, 61, 11, 1, 1, 1, 62, 11, 1, 1, 1, 63, 11, 1, 1, 1, 64, 11, 1, 1, 1, 65, 11, 1, 1, 1, 66, 11, 1, 1, 1, 67, 11, 1, 1, 1, 68, 11, 1, 1, 1, 69, 11, 1, 1, 1, 70, 11, 1, 1, 1, 71, 11, 1, 1, 1, 72, 11, 1, 1, 1, 73, 11, 1, 1, 1, 74, 11, 1, 0 }; static const char _sav_long_variable_parse_trans_targs[] = { 2, 0, 3, 10, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75 }; static const char _sav_long_variable_parse_trans_actions[] = { 1, 0, 0, 5, 0, 0, 0, 0, 0, 0, 3, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const char _sav_long_variable_parse_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; static const int sav_long_variable_parse_start = 1; static const int sav_long_variable_parse_en_main = 1; #line 79 "src/spss/readstat_sav_parse.rl" readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) { unsigned char *c_data = (unsigned char *)data; int var_count = count_vars(ctx); readstat_error_t retval = READSTAT_OK; char temp_key[8+1]; char temp_val[64+1]; unsigned char *str_start = NULL; size_t str_len = 0; char error_buf[8192]; unsigned char *p = c_data; unsigned char *pe = c_data + count; varlookup_t *table = build_lookup_table(var_count, ctx); unsigned char *eof = pe; int cs; #line 306 "src/spss/readstat_sav_parse.c" { cs = sav_long_variable_parse_start; } #line 311 "src/spss/readstat_sav_parse.c" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const unsigned char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _sav_long_variable_parse_trans_keys + _sav_long_variable_parse_key_offsets[cs]; _trans = _sav_long_variable_parse_index_offsets[cs]; _klen = _sav_long_variable_parse_single_lengths[cs]; if ( _klen > 0 ) { const unsigned char *_lower = _keys; const unsigned char *_mid; const unsigned char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _sav_long_variable_parse_range_lengths[cs]; if ( _klen > 0 ) { const unsigned char *_lower = _keys; const unsigned char *_mid; const unsigned char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _sav_long_variable_parse_indicies[_trans]; cs = _sav_long_variable_parse_trans_targs[_trans]; if ( _sav_long_variable_parse_trans_actions[_trans] == 0 ) goto _again; _acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 13 "src/spss/readstat_sav_parse.rl" { memcpy(temp_key, str_start, str_len); temp_key[str_len] = '\0'; } break; case 1: #line 20 "src/spss/readstat_sav_parse.rl" { str_start = p; } break; case 2: #line 20 "src/spss/readstat_sav_parse.rl" { str_len = p - str_start; } break; case 3: #line 102 "src/spss/readstat_sav_parse.rl" { varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup); if (!found) { snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key); if (ctx->handle.error) ctx->handle.error(error_buf, ctx->user_ctx); } else { // Handle the edge case where a ghost variable name (from a multi-segment // variable) is identical to a real variable name. Normally we handle this // by incrementing the loop variable by n_segments, but n_segments hasn't // been set when this record is processed. So just set the longname to every // matching variable, ghost or real. varlookup_t *iter_match = found; while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) { spss_varinfo_t *info = ctx->varinfo[iter_match->index]; snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val); iter_match--; } iter_match = found + 1; while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) { spss_varinfo_t *info = ctx->varinfo[iter_match->index]; snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val); iter_match++; } } } break; case 4: #line 129 "src/spss/readstat_sav_parse.rl" { memcpy(temp_val, str_start, str_len); temp_val[str_len] = '\0'; } break; case 5: #line 134 "src/spss/readstat_sav_parse.rl" { str_start = p; } break; case 6: #line 134 "src/spss/readstat_sav_parse.rl" { str_len = p - str_start; } break; #line 444 "src/spss/readstat_sav_parse.c" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} if ( p == eof ) { const char *__acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_eof_actions[cs]; unsigned int __nacts = (unsigned int) *__acts++; while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 3: #line 102 "src/spss/readstat_sav_parse.rl" { varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup); if (!found) { snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key); if (ctx->handle.error) ctx->handle.error(error_buf, ctx->user_ctx); } else { // Handle the edge case where a ghost variable name (from a multi-segment // variable) is identical to a real variable name. Normally we handle this // by incrementing the loop variable by n_segments, but n_segments hasn't // been set when this record is processed. So just set the longname to every // matching variable, ghost or real. varlookup_t *iter_match = found; while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) { spss_varinfo_t *info = ctx->varinfo[iter_match->index]; snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val); iter_match--; } iter_match = found + 1; while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) { spss_varinfo_t *info = ctx->varinfo[iter_match->index]; snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val); iter_match++; } } } break; case 4: #line 129 "src/spss/readstat_sav_parse.rl" { memcpy(temp_val, str_start, str_len); temp_val[str_len] = '\0'; } break; case 6: #line 134 "src/spss/readstat_sav_parse.rl" { str_len = p - str_start; } break; #line 500 "src/spss/readstat_sav_parse.c" } } } _out: {} } #line 142 "src/spss/readstat_sav_parse.rl" if (cs < 11|| p != pe) { if (ctx->handle.error) { snprintf(error_buf, sizeof(error_buf), "Error parsing string \"%.*s\" around byte #%ld/%d, character %c", count, (char *)data, (long)(p - c_data), count, *p); ctx->handle.error(error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_PARSE; } if (table) free(table); /* suppress warning */ (void)sav_long_variable_parse_en_main; return retval; } #line 531 "src/spss/readstat_sav_parse.c" static const char _sav_very_long_string_parse_actions[] = { 0, 1, 1, 1, 3, 1, 4, 2, 2, 0, 2, 5, 4 }; static const char _sav_very_long_string_parse_key_offsets[] = { 0, 0, 5, 19, 33, 47, 61, 75, 89, 103, 104, 106, 110, 112 }; static const unsigned char _sav_very_long_string_parse_trans_keys[] = { 255u, 0u, 63u, 91u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u, 127u, 61u, 48u, 57u, 0u, 9u, 48u, 57u, 0u, 9u, 255u, 0u, 63u, 91u, 127u, 0 }; static const char _sav_very_long_string_parse_single_lengths[] = { 0, 1, 4, 4, 4, 4, 4, 4, 4, 1, 0, 2, 2, 1 }; static const char _sav_very_long_string_parse_range_lengths[] = { 0, 2, 5, 5, 5, 5, 5, 5, 5, 0, 1, 1, 0, 2 }; static const char _sav_very_long_string_parse_index_offsets[] = { 0, 0, 4, 14, 24, 34, 44, 54, 64, 74, 76, 78, 82, 85 }; static const char _sav_very_long_string_parse_indicies[] = { 1, 1, 1, 0, 1, 3, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 1, 3, 1, 1, 1, 1, 1, 1, 1, 5, 1, 3, 1, 1, 1, 1, 1, 1, 1, 6, 1, 3, 1, 1, 1, 1, 1, 1, 1, 7, 1, 3, 1, 1, 1, 1, 1, 1, 1, 8, 1, 3, 1, 1, 1, 1, 1, 1, 1, 9, 3, 1, 10, 1, 11, 12, 13, 1, 14, 15, 1, 1, 1, 1, 0, 0 }; static const char _sav_very_long_string_parse_trans_targs[] = { 2, 0, 3, 10, 4, 5, 6, 7, 8, 9, 11, 12, 13, 11, 12, 13 }; static const char _sav_very_long_string_parse_trans_actions[] = { 1, 0, 0, 7, 0, 0, 0, 0, 0, 0, 10, 3, 3, 5, 0, 0 }; static const char _sav_very_long_string_parse_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 }; static const int sav_very_long_string_parse_start = 1; static const int sav_very_long_string_parse_en_main = 1; #line 168 "src/spss/readstat_sav_parse.rl" readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) { unsigned char *c_data = (unsigned char *)data; int var_count = count_vars(ctx); readstat_error_t retval = READSTAT_OK; char temp_key[8*4+1]; unsigned int temp_val = 0; unsigned char *str_start = NULL; size_t str_len = 0; size_t error_buf_len = 1024 + count; char *error_buf = NULL; unsigned char *p = c_data; unsigned char *pe = c_data + count; unsigned char *eof = pe; varlookup_t *table = NULL; int cs; error_buf = readstat_malloc(error_buf_len); table = build_lookup_table(var_count, ctx); #line 636 "src/spss/readstat_sav_parse.c" { cs = sav_very_long_string_parse_start; } #line 641 "src/spss/readstat_sav_parse.c" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const unsigned char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _sav_very_long_string_parse_trans_keys + _sav_very_long_string_parse_key_offsets[cs]; _trans = _sav_very_long_string_parse_index_offsets[cs]; _klen = _sav_very_long_string_parse_single_lengths[cs]; if ( _klen > 0 ) { const unsigned char *_lower = _keys; const unsigned char *_mid; const unsigned char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _sav_very_long_string_parse_range_lengths[cs]; if ( _klen > 0 ) { const unsigned char *_lower = _keys; const unsigned char *_mid; const unsigned char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _sav_very_long_string_parse_indicies[_trans]; cs = _sav_very_long_string_parse_trans_targs[_trans]; if ( _sav_very_long_string_parse_trans_actions[_trans] == 0 ) goto _again; _acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 13 "src/spss/readstat_sav_parse.rl" { memcpy(temp_key, str_start, str_len); temp_key[str_len] = '\0'; } break; case 1: #line 20 "src/spss/readstat_sav_parse.rl" { str_start = p; } break; case 2: #line 20 "src/spss/readstat_sav_parse.rl" { str_len = p - str_start; } break; case 3: #line 193 "src/spss/readstat_sav_parse.rl" { varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup); if (found) { // See logic above; we need to apply this to all matching variables since ghost variable // names may conflict with real variable names. varlookup_t *first_match = found, *last_match = found; varlookup_t *iter_match = found - 1; while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) { first_match = iter_match; iter_match--; } iter_match = found + 1; while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) { last_match = iter_match; iter_match++; } for (iter_match=first_match; iter_match<=last_match; iter_match++) { ctx->varinfo[iter_match->index]->string_length = temp_val; ctx->varinfo[iter_match->index]->write_format.width = temp_val; ctx->varinfo[iter_match->index]->print_format.width = temp_val; } } } break; case 4: #line 217 "src/spss/readstat_sav_parse.rl" { if ((*p) != '\0') { unsigned char digit = (*p) - '0'; if (temp_val <= (UINT_MAX - digit) / 10) { temp_val = 10 * temp_val + digit; } else { {p++; goto _out; } } } } break; case 5: #line 228 "src/spss/readstat_sav_parse.rl" { temp_val = 0; } break; #line 773 "src/spss/readstat_sav_parse.c" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} if ( p == eof ) { const char *__acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_eof_actions[cs]; unsigned int __nacts = (unsigned int) *__acts++; while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 3: #line 193 "src/spss/readstat_sav_parse.rl" { varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup); if (found) { // See logic above; we need to apply this to all matching variables since ghost variable // names may conflict with real variable names. varlookup_t *first_match = found, *last_match = found; varlookup_t *iter_match = found - 1; while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) { first_match = iter_match; iter_match--; } iter_match = found + 1; while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) { last_match = iter_match; iter_match++; } for (iter_match=first_match; iter_match<=last_match; iter_match++) { ctx->varinfo[iter_match->index]->string_length = temp_val; ctx->varinfo[iter_match->index]->write_format.width = temp_val; ctx->varinfo[iter_match->index]->print_format.width = temp_val; } } } break; #line 815 "src/spss/readstat_sav_parse.c" } } } _out: {} } #line 236 "src/spss/readstat_sav_parse.rl" if (cs < 11 || p != pe) { if (ctx->handle.error) { snprintf(error_buf, error_buf_len, "Parsed %ld of %ld bytes. Remaining bytes: %.*s", (long)(p - c_data), (long)(pe - c_data), (int)(pe - p), p); ctx->handle.error(error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_PARSE; } if (table) free(table); if (error_buf) free(error_buf); /* suppress warning */ (void)sav_very_long_string_parse_en_main; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav_parse.h0000644000076500000240000000032114674240614020044 0ustar00dialout// // sav_parse.h // readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx); readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/spss/readstat_sav_parse_mr_name.c0000644000076500000240000002761015134704512021541 0ustar00dialout #line 1 "./readstat_sav_parse_mr_name.rl" #include #include #include #include "../readstat.h" #include "../readstat_malloc.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "readstat_sav.h" #line 11 "./readstat_sav_parse_mr_name.c" static const char _mr_extractor_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4 }; static const char _mr_extractor_key_offsets[] = { 0, 0, 2, 4, 6, 9, 11, 14, 16, 21, 26 }; static const char _mr_extractor_trans_keys[] = { 32, 61, 32, 61, 67, 68, 32, 48, 57, 48, 57, 32, 48, 57, 32, 61, 0, 32, 61, 9, 13, 0, 32, 61, 9, 13, 32, 61, 0 }; static const char _mr_extractor_single_lengths[] = { 0, 2, 2, 0, 1, 0, 1, 2, 3, 3, 2 }; static const char _mr_extractor_range_lengths[] = { 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0 }; static const char _mr_extractor_index_offsets[] = { 0, 0, 3, 6, 8, 11, 13, 16, 19, 24, 29 }; static const char _mr_extractor_indicies[] = { 1, 1, 0, 1, 2, 0, 3, 1, 4, 5, 1, 6, 1, 7, 6, 1, 9, 1, 8, 10, 11, 1, 10, 8, 10, 11, 1, 10, 8, 1, 1, 8, 0 }; static const char _mr_extractor_trans_targs[] = { 2, 0, 3, 4, 5, 4, 6, 7, 8, 7, 9, 10 }; static const char _mr_extractor_trans_actions[] = { 0, 0, 1, 3, 5, 0, 0, 7, 0, 0, 9, 9 }; static const int mr_extractor_start = 1; static const int mr_extractor_en_main = 1; #line 121 "./readstat_sav_parse_mr_name.rl" readstat_error_t extract_mr_data(const char *line, mr_set_t *result, sav_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; // Variables needed for Ragel operation int cs = 0; char *p = (char *)line; char *start = p; char *pe = p + strlen(p) + 1; // Variables needed for passing Ragel intermediate results char mr_type = '\0'; int mr_counted_value = -1; int mr_subvar_count = 0; char **mr_subvariables = NULL; char *mr_name = NULL; char *mr_label = NULL; // Execute Ragel finite state machine (FSM) #line 85 "./readstat_sav_parse_mr_name.c" { cs = mr_extractor_start; } #line 142 "./readstat_sav_parse_mr_name.rl" #line 88 "./readstat_sav_parse_mr_name.c" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _mr_extractor_trans_keys + _mr_extractor_key_offsets[cs]; _trans = _mr_extractor_index_offsets[cs]; _klen = _mr_extractor_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _mr_extractor_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _mr_extractor_indicies[_trans]; cs = _mr_extractor_trans_targs[_trans]; if ( _mr_extractor_trans_actions[_trans] == 0 ) goto _again; _acts = _mr_extractor_actions + _mr_extractor_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 13 "./readstat_sav_parse_mr_name.rl" { size_t src_len = p - start; size_t dst_len = 4 * src_len + 1; // UTF-8 expansion: up to 4 bytes per char mr_name = (char *)readstat_malloc(dst_len); if (mr_name == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } retval = readstat_convert(mr_name, dst_len, start, src_len, ctx->converter); if (retval != READSTAT_OK) { goto cleanup; } } break; case 1: #line 27 "./readstat_sav_parse_mr_name.rl" { mr_type = *p; start = p + 1; } break; case 2: #line 32 "./readstat_sav_parse_mr_name.rl" { int n_cv_digs = p - start; char *n_dig_str = (char *)readstat_malloc(n_cv_digs + 1); if (n_dig_str == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memcpy(n_dig_str, start, n_cv_digs); n_dig_str[n_cv_digs] = '\0'; int n_digs = strtol(n_dig_str, NULL, 10); free(n_dig_str); if (n_digs != 0) { char *cv = (char *)readstat_malloc(n_digs + 1); if (cv == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memcpy(cv, p + 1, n_digs); cv[n_digs] = '\0'; mr_counted_value = strtol(cv, NULL, 10); free(cv); p = p + 1 + n_digs; start = p + 1; } else { mr_counted_value = -1; } } break; case 3: #line 61 "./readstat_sav_parse_mr_name.rl" { char *lbl_len_str = (char *)readstat_malloc(p - start + 1); if (lbl_len_str == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memcpy(lbl_len_str, start, p - start); lbl_len_str[p - start] = '\0'; int len = strtol(lbl_len_str, NULL, 10); free(lbl_len_str); size_t dst_len = 4 * len + 1; // UTF-8 expansion: up to 4 bytes per char mr_label = (char *)readstat_malloc(dst_len); if (mr_label == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } retval = readstat_convert(mr_label, dst_len, p + 1, len, ctx->converter); if (retval != READSTAT_OK) { goto cleanup; } p = p + 1 + len; start = p + 1; } break; case 4: #line 85 "./readstat_sav_parse_mr_name.rl" { size_t src_len = p - start; size_t dst_len = 4 * src_len + 1; // UTF-8 expansion: up to 4 bytes per char char *subvar = (char *)readstat_malloc(dst_len); if (subvar == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } retval = readstat_convert(subvar, dst_len, start, src_len, ctx->converter); if (retval != READSTAT_OK) { free(subvar); goto cleanup; } start = p + 1; char **new_subvariables = readstat_realloc(mr_subvariables, sizeof(char *) * (mr_subvar_count + 1)); if (new_subvariables == NULL) { free(subvar); retval = READSTAT_ERROR_MALLOC; goto cleanup; } mr_subvariables = new_subvariables; mr_subvariables[mr_subvar_count++] = subvar; } break; #line 262 "./readstat_sav_parse_mr_name.c" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} _out: {} } #line 143 "./readstat_sav_parse_mr_name.rl" // Check if FSM finished successfully if (cs < 9 || p != pe) { retval = READSTAT_ERROR_BAD_MR_STRING; goto cleanup; } (void)mr_extractor_en_main; // Assign parsed values to output parameter result->name = mr_name; result->label = mr_label; result->type = mr_type; result->counted_value = mr_counted_value; result->subvariables = mr_subvariables; result->num_subvars = mr_subvar_count; if (result->type == 'D') { result->is_dichotomy = 1; } cleanup: if (retval != READSTAT_OK) { if (mr_subvariables != NULL) { for (int i = 0; i < mr_subvar_count; i++) { if (mr_subvariables[i] != NULL) free(mr_subvariables[i]); } free(mr_subvariables); } if (mr_name != NULL) free(mr_name); if (mr_label != NULL) free(mr_label); } return retval; } readstat_error_t parse_mr_line(const char *line, mr_set_t *result, sav_ctx_t *ctx) { *result = (mr_set_t){0}; return extract_mr_data(line, result, ctx); } #line 313 "./readstat_sav_parse_mr_name.c" static const char _mr_parser_actions[] = { 0, 1, 0 }; static const char _mr_parser_key_offsets[] = { 0, 0, 1, 2, 4 }; static const char _mr_parser_trans_keys[] = { 36, 10, 0, 10, 10, 0 }; static const char _mr_parser_single_lengths[] = { 0, 1, 1, 2, 1 }; static const char _mr_parser_range_lengths[] = { 0, 0, 0, 0, 0 }; static const char _mr_parser_index_offsets[] = { 0, 0, 2, 4, 7 }; static const char _mr_parser_indicies[] = { 0, 1, 2, 0, 3, 2, 0, 2, 0, 0 }; static const char _mr_parser_trans_targs[] = { 2, 0, 3, 4 }; static const char _mr_parser_trans_actions[] = { 0, 0, 1, 0 }; static const int mr_parser_start = 1; static const int mr_parser_en_main = 1; #line 216 "./readstat_sav_parse_mr_name.rl" readstat_error_t parse_mr_string(const char *line, mr_set_t **mr_sets, size_t *n_mr_lines, sav_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int cs = 0; char *p = (char *)line; char *start = p; char *pe = p + strlen(p) + 1; *mr_sets = NULL; *n_mr_lines = 0; #line 365 "./readstat_sav_parse_mr_name.c" { cs = mr_parser_start; } #line 228 "./readstat_sav_parse_mr_name.rl" #line 368 "./readstat_sav_parse_mr_name.c" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _mr_parser_trans_keys + _mr_parser_key_offsets[cs]; _trans = _mr_parser_index_offsets[cs]; _klen = _mr_parser_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _mr_parser_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _mr_parser_indicies[_trans]; cs = _mr_parser_trans_targs[_trans]; if ( _mr_parser_trans_actions[_trans] == 0 ) goto _again; _acts = _mr_parser_actions + _mr_parser_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 186 "./readstat_sav_parse_mr_name.rl" { char *mln = (char *)readstat_malloc(p - start); if (mln == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memcpy(mln, start + 1, p - start); mln[p - start - 1] = '\0'; mr_set_t *new_mr_sets = readstat_realloc(*mr_sets, ((*n_mr_lines) + 1) * sizeof(mr_set_t)); if (new_mr_sets == NULL) { free(mln); retval = READSTAT_ERROR_MALLOC; goto cleanup; } *mr_sets = new_mr_sets; retval = parse_mr_line(mln, &(*mr_sets)[*n_mr_lines], ctx); free(mln); if (retval != READSTAT_OK) { goto cleanup; } (*n_mr_lines)++; start = p + 1; } break; #line 466 "./readstat_sav_parse_mr_name.c" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} _out: {} } #line 229 "./readstat_sav_parse_mr_name.rl" if (cs < 4 || p != pe) { retval = READSTAT_ERROR_BAD_MR_STRING; goto cleanup; } (void)mr_parser_en_main; cleanup: return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/spss/readstat_sav_parse_mr_name.h0000644000076500000240000000041515134704512021540 0ustar00dialout#ifndef READSTAT_PARSE_MR_NAME_H #define READSTAT_PARSE_MR_NAME_H #include "../readstat.h" #include "../readstat_malloc.h" readstat_error_t parse_mr_string(const char *line, mr_set_t **mr_sets, size_t *n_mr_lines, sav_ctx_t *ctx); #endif // READSTAT_PARSE_MR_NAME_H ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav_parse_timestamp.c0000644000076500000240000003655514674240614022144 0ustar00dialout#line 1 "src/spss/readstat_sav_parse_timestamp.rl" #include #include "../readstat.h" #include "../readstat_iconv.h" #include "readstat_sav.h" #include "readstat_sav_parse_timestamp.h" #line 12 "src/spss/readstat_sav_parse_timestamp.c" static const signed char _sav_time_parse_actions[] = { 0, 1, 0, 1, 2, 1, 3, 1, 4, 1, 5, 2, 1, 0, 0 }; static const signed char _sav_time_parse_key_offsets[] = { 0, 0, 3, 5, 6, 9, 11, 12, 15, 17, 19, 21, 23, 0 }; static const char _sav_time_parse_trans_keys[] = { 32, 48, 57, 48, 57, 58, 32, 48, 57, 48, 57, 58, 32, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 0 }; static const signed char _sav_time_parse_single_lengths[] = { 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 }; static const signed char _sav_time_parse_range_lengths[] = { 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0 }; static const signed char _sav_time_parse_index_offsets[] = { 0, 0, 3, 5, 7, 10, 12, 14, 17, 19, 21, 23, 25, 0 }; static const signed char _sav_time_parse_cond_targs[] = { 2, 11, 0, 3, 0, 4, 0, 5, 10, 0, 6, 0, 7, 0, 8, 9, 0, 12, 0, 12, 0, 6, 0, 3, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 }; static const signed char _sav_time_parse_cond_actions[] = { 0, 3, 0, 11, 0, 5, 0, 0, 3, 0, 11, 0, 7, 0, 0, 3, 0, 11, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0 }; static const signed char _sav_time_parse_eof_trans[] = { 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0 }; static const int sav_time_parse_start = 1; static const int sav_time_parse_en_main = 1; #line 12 "src/spss/readstat_sav_parse_timestamp.rl" readstat_error_t sav_parse_time(const char *data, size_t len, struct tm *timestamp, readstat_error_handler error_cb, void *user_ctx) { readstat_error_t retval = READSTAT_OK; char error_buf[8192]; const char *p = data; const char *pe = p + len; const char *eof = pe; int cs; int temp_val = 0; #line 83 "src/spss/readstat_sav_parse_timestamp.c" { cs = (int)sav_time_parse_start; } #line 88 "src/spss/readstat_sav_parse_timestamp.c" { int _klen; unsigned int _trans = 0; const char * _keys; const signed char * _acts; unsigned int _nacts; _resume: {} if ( p == pe && p != eof ) goto _out; if ( p == eof ) { if ( _sav_time_parse_eof_trans[cs] > 0 ) { _trans = (unsigned int)_sav_time_parse_eof_trans[cs] - 1; } } else { _keys = ( _sav_time_parse_trans_keys + (_sav_time_parse_key_offsets[cs])); _trans = (unsigned int)_sav_time_parse_index_offsets[cs]; _klen = (int)_sav_time_parse_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + _klen - 1; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _keys += _klen; _trans += (unsigned int)_klen; break; } _mid = _lower + ((_upper-_lower) >> 1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 1; else if ( ( (*( p))) > (*( _mid)) ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } } _klen = (int)_sav_time_parse_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + (_klen<<1) - 2; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _trans += (unsigned int)_klen; break; } _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 2; else if ( ( (*( p))) > (*( _mid + 1)) ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); break; } } } _match: {} } cs = (int)_sav_time_parse_cond_targs[_trans]; if ( _sav_time_parse_cond_actions[_trans] != 0 ) { _acts = ( _sav_time_parse_actions + (_sav_time_parse_cond_actions[_trans])); _nacts = (unsigned int)(*( _acts)); _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts)) ) { case 0: { { #line 24 "src/spss/readstat_sav_parse_timestamp.rl" temp_val = 10 * temp_val + ((( (*( p)))) - '0'); } #line 173 "src/spss/readstat_sav_parse_timestamp.c" break; } case 1: { { #line 28 "src/spss/readstat_sav_parse_timestamp.rl" temp_val = 0; } #line 182 "src/spss/readstat_sav_parse_timestamp.c" break; } case 2: { { #line 28 "src/spss/readstat_sav_parse_timestamp.rl" temp_val = (( (*( p)))) - '0'; } #line 191 "src/spss/readstat_sav_parse_timestamp.c" break; } case 3: { { #line 30 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_hour = temp_val; } #line 200 "src/spss/readstat_sav_parse_timestamp.c" break; } case 4: { { #line 32 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_min = temp_val; } #line 209 "src/spss/readstat_sav_parse_timestamp.c" break; } case 5: { { #line 34 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_sec = temp_val; } #line 218 "src/spss/readstat_sav_parse_timestamp.c" break; } } _nacts -= 1; _acts += 1; } } if ( p == eof ) { if ( cs >= 12 ) goto _out; } else { if ( cs != 0 ) { p += 1; goto _resume; } } _out: {} } #line 40 "src/spss/readstat_sav_parse_timestamp.rl" if (cs < #line 246 "src/spss/readstat_sav_parse_timestamp.c" 12 #line 42 "src/spss/readstat_sav_parse_timestamp.rl" || p != pe) { if (error_cb) { snprintf(error_buf, sizeof(error_buf), "Invalid time string (length=%d): %.*s", (int)len, (int)len, data); error_cb(error_buf, user_ctx); } retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING; } (void)sav_time_parse_en_main; return retval; } #line 264 "src/spss/readstat_sav_parse_timestamp.c" static const signed char _sav_date_parse_actions[] = { 0, 1, 0, 1, 1, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 2, 2, 0, 0 }; static const signed char _sav_date_parse_key_offsets[] = { 0, 0, 3, 6, 8, 16, 20, 21, 23, 26, 29, 30, 32, 33, 34, 36, 37, 39, 40, 42, 43, 45, 46, 50, 51, 53, 55, 57, 59, 60, 62, 64, 66, 68, 70, 72, 74, 75, 77, 78, 80, 81, 83, 84, 86, 87, 89, 90, 0 }; static const char _sav_date_parse_trans_keys[] = { 32, 48, 57, 32, 48, 57, 32, 45, 65, 68, 70, 74, 77, 78, 79, 83, 80, 85, 112, 117, 82, 32, 45, 32, 48, 57, 32, 48, 57, 71, 32, 45, 114, 103, 69, 101, 67, 32, 45, 99, 69, 101, 66, 32, 45, 98, 65, 85, 97, 117, 78, 32, 45, 76, 78, 32, 45, 32, 45, 110, 108, 110, 65, 97, 82, 89, 32, 45, 32, 45, 114, 121, 79, 111, 86, 32, 45, 118, 67, 99, 84, 32, 45, 116, 69, 101, 80, 32, 45, 112, 0 }; static const signed char _sav_date_parse_single_lengths[] = { 0, 1, 1, 2, 8, 4, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 4, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0, 0 }; static const signed char _sav_date_parse_range_lengths[] = { 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const short _sav_date_parse_index_offsets[] = { 0, 0, 3, 6, 9, 18, 23, 25, 28, 31, 34, 36, 39, 41, 43, 46, 48, 51, 53, 56, 58, 61, 63, 68, 70, 73, 76, 79, 82, 84, 87, 90, 93, 96, 99, 102, 105, 107, 110, 112, 115, 117, 120, 122, 125, 127, 130, 132, 0 }; static const signed char _sav_date_parse_cond_targs[] = { 2, 2, 0, 3, 3, 0, 4, 4, 0, 5, 14, 18, 22, 30, 35, 39, 43, 0, 6, 10, 12, 13, 0, 7, 0, 8, 8, 0, 9, 9, 0, 47, 47, 0, 11, 0, 8, 8, 0, 7, 0, 11, 0, 15, 17, 0, 16, 0, 8, 8, 0, 16, 0, 19, 21, 0, 20, 0, 8, 8, 0, 20, 0, 23, 25, 28, 29, 0, 24, 0, 8, 8, 0, 26, 27, 0, 8, 8, 0, 8, 8, 0, 24, 0, 26, 27, 0, 31, 34, 0, 32, 33, 0, 8, 8, 0, 8, 8, 0, 32, 33, 0, 36, 38, 0, 37, 0, 8, 8, 0, 37, 0, 40, 42, 0, 41, 0, 8, 8, 0, 41, 0, 44, 46, 0, 45, 0, 8, 8, 0, 45, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 0 }; static const signed char _sav_date_parse_cond_actions[] = { 31, 31, 0, 1, 1, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13, 0, 31, 31, 0, 1, 1, 0, 0, 0, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 29, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 19, 19, 0, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0 }; static const short _sav_date_parse_eof_trans[] = { 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 0 }; static const int sav_date_parse_start = 1; static const int sav_date_parse_en_main = 1; #line 59 "src/spss/readstat_sav_parse_timestamp.rl" readstat_error_t sav_parse_date(const char *data, size_t len, struct tm *timestamp, readstat_error_handler error_cb, void *user_ctx) { readstat_error_t retval = READSTAT_OK; char error_buf[8192]; const char *p = data; const char *pe = p + len; const char *eof = pe; int cs; int temp_val = 0; #line 408 "src/spss/readstat_sav_parse_timestamp.c" { cs = (int)sav_date_parse_start; } #line 413 "src/spss/readstat_sav_parse_timestamp.c" { int _klen; unsigned int _trans = 0; const char * _keys; const signed char * _acts; unsigned int _nacts; _resume: {} if ( p == pe && p != eof ) goto _out; if ( p == eof ) { if ( _sav_date_parse_eof_trans[cs] > 0 ) { _trans = (unsigned int)_sav_date_parse_eof_trans[cs] - 1; } } else { _keys = ( _sav_date_parse_trans_keys + (_sav_date_parse_key_offsets[cs])); _trans = (unsigned int)_sav_date_parse_index_offsets[cs]; _klen = (int)_sav_date_parse_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + _klen - 1; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _keys += _klen; _trans += (unsigned int)_klen; break; } _mid = _lower + ((_upper-_lower) >> 1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 1; else if ( ( (*( p))) > (*( _mid)) ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } } _klen = (int)_sav_date_parse_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + (_klen<<1) - 2; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _trans += (unsigned int)_klen; break; } _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 2; else if ( ( (*( p))) > (*( _mid + 1)) ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); break; } } } _match: {} } cs = (int)_sav_date_parse_cond_targs[_trans]; if ( _sav_date_parse_cond_actions[_trans] != 0 ) { _acts = ( _sav_date_parse_actions + (_sav_date_parse_cond_actions[_trans])); _nacts = (unsigned int)(*( _acts)); _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts)) ) { case 0: { { #line 71 "src/spss/readstat_sav_parse_timestamp.rl" char digit = ((( (*( p)))) - '0'); if (digit >= 0 && digit <= 9) { temp_val = 10 * temp_val + digit; } } #line 501 "src/spss/readstat_sav_parse_timestamp.c" break; } case 1: { { #line 78 "src/spss/readstat_sav_parse_timestamp.rl" if (temp_val < 70) { timestamp->tm_year = 100 + temp_val; } else { timestamp->tm_year = temp_val; } } #line 516 "src/spss/readstat_sav_parse_timestamp.c" break; } case 2: { { #line 87 "src/spss/readstat_sav_parse_timestamp.rl" temp_val = 0; } #line 525 "src/spss/readstat_sav_parse_timestamp.c" break; } case 3: { { #line 89 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mday = temp_val; } #line 534 "src/spss/readstat_sav_parse_timestamp.c" break; } case 4: { { #line 94 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 0; } #line 543 "src/spss/readstat_sav_parse_timestamp.c" break; } case 5: { { #line 95 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 1; } #line 552 "src/spss/readstat_sav_parse_timestamp.c" break; } case 6: { { #line 96 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 2; } #line 561 "src/spss/readstat_sav_parse_timestamp.c" break; } case 7: { { #line 97 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 3; } #line 570 "src/spss/readstat_sav_parse_timestamp.c" break; } case 8: { { #line 98 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 4; } #line 579 "src/spss/readstat_sav_parse_timestamp.c" break; } case 9: { { #line 99 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 5; } #line 588 "src/spss/readstat_sav_parse_timestamp.c" break; } case 10: { { #line 100 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 6; } #line 597 "src/spss/readstat_sav_parse_timestamp.c" break; } case 11: { { #line 101 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 7; } #line 606 "src/spss/readstat_sav_parse_timestamp.c" break; } case 12: { { #line 102 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 8; } #line 615 "src/spss/readstat_sav_parse_timestamp.c" break; } case 13: { { #line 103 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 9; } #line 624 "src/spss/readstat_sav_parse_timestamp.c" break; } case 14: { { #line 104 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 10; } #line 633 "src/spss/readstat_sav_parse_timestamp.c" break; } case 15: { { #line 105 "src/spss/readstat_sav_parse_timestamp.rl" timestamp->tm_mon = 11; } #line 642 "src/spss/readstat_sav_parse_timestamp.c" break; } } _nacts -= 1; _acts += 1; } } if ( p == eof ) { if ( cs >= 47 ) goto _out; } else { if ( cs != 0 ) { p += 1; goto _resume; } } _out: {} } #line 112 "src/spss/readstat_sav_parse_timestamp.rl" if (cs < #line 670 "src/spss/readstat_sav_parse_timestamp.c" 47 #line 114 "src/spss/readstat_sav_parse_timestamp.rl" || p != pe) { if (error_cb) { snprintf(error_buf, sizeof(error_buf), "Invalid date string (length=%d): %.*s", (int)len, (int)len, data); error_cb(error_buf, user_ctx); } retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING; } (void)sav_date_parse_en_main; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_sav_parse_timestamp.h0000644000076500000240000000043514674240614022135 0ustar00dialout readstat_error_t sav_parse_time(const char *data, size_t len, struct tm *timestamp, readstat_error_handler error_cb, void *user_ctx); readstat_error_t sav_parse_date(const char *data, size_t len, struct tm *timestamp, readstat_error_handler error_cb, void *user_ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/spss/readstat_sav_read.c0000644000076500000240000017067215134704512017653 0ustar00dialout #include #include #include #include #include #include #include #include #include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" #include "../CKHashTable.h" #include "readstat_sav.h" #include "readstat_sav_compress.h" #include "readstat_sav_parse.h" #include "readstat_sav_parse_timestamp.h" #include "readstat_sav_parse_mr_name.h" #if HAVE_ZLIB #include "readstat_zsav_read.h" #endif #define DATA_BUFFER_SIZE 65536 #define VERY_LONG_STRING_MAX_LENGTH INT_MAX /* Others defined in table below */ /* See http://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx */ static readstat_charset_entry_t _charset_table[] = { { .code = 1, .name = "EBCDIC-US" }, { .code = 2, .name = "WINDOWS-1252" }, /* supposed to be ASCII, but some files are miscoded */ { .code = 3, .name = "WINDOWS-1252" }, { .code = 4, .name = "DEC-KANJI" }, { .code = 437, .name = "CP437" }, { .code = 708, .name = "ASMO-708" }, { .code = 737, .name = "CP737" }, { .code = 775, .name = "CP775" }, { .code = 850, .name = "CP850" }, { .code = 852, .name = "CP852" }, { .code = 855, .name = "CP855" }, { .code = 857, .name = "CP857" }, { .code = 858, .name = "CP858" }, { .code = 860, .name = "CP860" }, { .code = 861, .name = "CP861" }, { .code = 862, .name = "CP862" }, { .code = 863, .name = "CP863" }, { .code = 864, .name = "CP864" }, { .code = 865, .name = "CP865" }, { .code = 866, .name = "CP866" }, { .code = 869, .name = "CP869" }, { .code = 874, .name = "CP874" }, { .code = 932, .name = "CP932" }, { .code = 936, .name = "CP936" }, { .code = 949, .name = "CP949" }, { .code = 950, .name = "BIG-5" }, { .code = 1200, .name = "UTF-16LE" }, { .code = 1201, .name = "UTF-16BE" }, { .code = 1250, .name = "WINDOWS-1250" }, { .code = 1251, .name = "WINDOWS-1251" }, { .code = 1252, .name = "WINDOWS-1252" }, { .code = 1253, .name = "WINDOWS-1253" }, { .code = 1254, .name = "WINDOWS-1254" }, { .code = 1255, .name = "WINDOWS-1255" }, { .code = 1256, .name = "WINDOWS-1256" }, { .code = 1257, .name = "WINDOWS-1257" }, { .code = 1258, .name = "WINDOWS-1258" }, { .code = 1361, .name = "CP1361" }, { .code = 10000, .name = "MACROMAN" }, { .code = 10004, .name = "MACARABIC" }, { .code = 10005, .name = "MACHEBREW" }, { .code = 10006, .name = "MACGREEK" }, { .code = 10007, .name = "MACCYRILLIC" }, { .code = 10010, .name = "MACROMANIA" }, { .code = 10017, .name = "MACUKRAINE" }, { .code = 10021, .name = "MACTHAI" }, { .code = 10029, .name = "MACCENTRALEUROPE" }, { .code = 10079, .name = "MACICELAND" }, { .code = 10081, .name = "MACTURKISH" }, { .code = 10082, .name = "MACCROATIAN" }, { .code = 12000, .name = "UTF-32LE" }, { .code = 12001, .name = "UTF-32BE" }, { .code = 20127, .name = "US-ASCII" }, { .code = 20866, .name = "KOI8-R" }, { .code = 20932, .name = "EUC-JP" }, { .code = 21866, .name = "KOI8-U" }, { .code = 28591, .name = "ISO-8859-1" }, { .code = 28592, .name = "ISO-8859-2" }, { .code = 28593, .name = "ISO-8859-3" }, { .code = 28594, .name = "ISO-8859-4" }, { .code = 28595, .name = "ISO-8859-5" }, { .code = 28596, .name = "ISO-8859-6" }, { .code = 28597, .name = "ISO-8859-7" }, { .code = 28598, .name = "ISO-8859-8" }, { .code = 28599, .name = "ISO-8859-9" }, { .code = 28603, .name = "ISO-8859-13" }, { .code = 28605, .name = "ISO-8859-15" }, { .code = 50220, .name = "ISO-2022-JP" }, { .code = 50221, .name = "ISO-2022-JP" }, // same as above? { .code = 50222, .name = "ISO-2022-JP" }, // same as above? { .code = 50225, .name = "ISO-2022-KR" }, { .code = 50229, .name = "ISO-2022-CN" }, { .code = 51932, .name = "EUC-JP" }, { .code = 51936, .name = "GBK" }, { .code = 51949, .name = "EUC-KR" }, { .code = 52936, .name = "HZ-GB-2312" }, { .code = 54936, .name = "GB18030" }, { .code = 65000, .name = "UTF-7" }, { .code = 65001, .name = "UTF-8" } }; #define SAV_LABEL_NAME_PREFIX "labels" typedef struct value_label_s { char raw_value[8]; char utf8_string_value[8*4+1]; readstat_value_t final_value; char *label; } value_label_t; static readstat_error_t sav_update_progress(sav_ctx_t *ctx); static readstat_error_t sav_read_data(sav_ctx_t *ctx); static readstat_error_t sav_read_compressed_data(sav_ctx_t *ctx, readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)); static readstat_error_t sav_read_uncompressed_data(sav_ctx_t *ctx, readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)); static readstat_error_t sav_skip_variable_record(sav_ctx_t *ctx); static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx); static readstat_error_t sav_skip_document_record(sav_ctx_t *ctx); static readstat_error_t sav_read_document_record(sav_ctx_t *ctx); static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx); static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx); static readstat_error_t sav_read_dictionary_termination_record(sav_ctx_t *ctx); static readstat_error_t sav_parse_machine_floating_point_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx); static readstat_error_t sav_store_variable_display_parameter_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx); static readstat_error_t sav_parse_variable_display_parameter_record(sav_ctx_t *ctx); static readstat_error_t sav_parse_machine_integer_info_record(const void *data, size_t data_len, sav_ctx_t *ctx); static readstat_error_t sav_parse_long_string_value_labels_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx); static readstat_error_t sav_parse_long_string_missing_values_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx); static readstat_error_t sav_read_multiple_response_sets(size_t data_len, sav_ctx_t *ctx); static readstat_error_t sav_read_multiple_response_sets(size_t data_len, sav_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; char *mr_string = readstat_malloc(data_len + 1); if (mr_string == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } mr_string[data_len] = '\0'; if (ctx->io->read(mr_string, data_len, ctx->io->io_ctx) < data_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (mr_string[0] != '$') { retval = READSTAT_ERROR_BAD_MR_STRING; goto cleanup; } retval = parse_mr_string(mr_string, &ctx->mr_sets, &ctx->multiple_response_sets_length, ctx); cleanup: free(mr_string); return retval; } static void sav_tag_missing_double(readstat_value_t *value, sav_ctx_t *ctx) { double fp_value = value->v.double_value; uint64_t long_value = 0; memcpy(&long_value, &fp_value, 8); if (long_value == ctx->missing_double) value->is_system_missing = 1; if (long_value == ctx->lowest_double) value->is_system_missing = 1; if (long_value == ctx->highest_double) value->is_system_missing = 1; if (isnan(fp_value)) value->is_system_missing = 1; } static readstat_error_t sav_update_progress(sav_ctx_t *ctx) { readstat_io_t *io = ctx->io; return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx); } static readstat_error_t sav_skip_variable_record(sav_ctx_t *ctx) { sav_variable_record_t variable; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (variable.has_var_label) { uint32_t label_len; if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } label_len = ctx->bswap ? byteswap4(label_len) : label_len; uint32_t label_capacity = (label_len + 3) / 4 * 4; if (io->seek(label_capacity, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } } if (variable.n_missing_values) { int n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values; if (io->seek(abs(n_missing_values) * sizeof(double), READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } } cleanup: return retval; } static readstat_error_t sav_read_variable_label(spss_varinfo_t *info, sav_ctx_t *ctx) { readstat_io_t *io = ctx->io; readstat_error_t retval = READSTAT_OK; uint32_t label_len, label_capacity; size_t out_label_len; char *label_buf = NULL; if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } label_len = ctx->bswap ? byteswap4(label_len) : label_len; if (label_len == 0) goto cleanup; label_capacity = (label_len + 3) / 4 * 4; if ((label_buf = readstat_malloc(label_capacity)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } out_label_len = (size_t)label_len*4+1; if ((info->label = readstat_malloc(out_label_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (io->read(label_buf, label_capacity, io->io_ctx) < label_capacity) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = readstat_convert(info->label, out_label_len, label_buf, label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; cleanup: if (label_buf) free(label_buf); if (retval != READSTAT_OK) { if (info->label) { free(info->label); info->label = NULL; } } return retval; } static readstat_error_t sav_read_variable_missing_double_values(spss_varinfo_t *info, sav_ctx_t *ctx) { readstat_io_t *io = ctx->io; int i; readstat_error_t retval = READSTAT_OK; if (io->read(info->missing_double_values, info->n_missing_values * sizeof(double), io->io_ctx) < info->n_missing_values * sizeof(double)) { retval = READSTAT_ERROR_READ; goto cleanup; } for (i=0; in_missing_values; i++) { if (ctx->bswap) { info->missing_double_values[i] = byteswap_double(info->missing_double_values[i]); } uint64_t long_value = 0; memcpy(&long_value, &info->missing_double_values[i], 8); if (long_value == ctx->missing_double) info->missing_double_values[i] = NAN; if (long_value == ctx->lowest_double) info->missing_double_values[i] = -HUGE_VAL; if (long_value == ctx->highest_double) info->missing_double_values[i] = HUGE_VAL; } cleanup: return retval; } static readstat_error_t sav_read_variable_missing_string_values(spss_varinfo_t *info, sav_ctx_t *ctx) { readstat_io_t *io = ctx->io; int i; readstat_error_t retval = READSTAT_OK; for (i=0; in_missing_values; i++) { char missing_value[8]; if (io->read(missing_value, sizeof(missing_value), io->io_ctx) < sizeof(missing_value)) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = readstat_convert(info->missing_string_values[i], sizeof(info->missing_string_values[0]), missing_value, sizeof(missing_value), ctx->converter); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t sav_read_variable_missing_values(spss_varinfo_t *info, sav_ctx_t *ctx) { if (info->n_missing_values > 3 || info->n_missing_values < -3) { return READSTAT_ERROR_PARSE; } if (info->n_missing_values < 0) { info->missing_range = 1; info->n_missing_values = abs(info->n_missing_values); } else { info->missing_range = 0; } if (info->type == READSTAT_TYPE_DOUBLE) { return sav_read_variable_missing_double_values(info, ctx); } return sav_read_variable_missing_string_values(info, ctx); } static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) { readstat_io_t *io = ctx->io; sav_variable_record_t variable = { 0 }; spss_varinfo_t *info = NULL; readstat_error_t retval = READSTAT_OK; if (ctx->var_index == ctx->varinfo_capacity) { if ((ctx->varinfo = readstat_realloc(ctx->varinfo, (ctx->varinfo_capacity *= 2) * sizeof(spss_varinfo_t *))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } } if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } variable.print = ctx->bswap ? byteswap4(variable.print) : variable.print; variable.write = ctx->bswap ? byteswap4(variable.write) : variable.write; int32_t type = ctx->bswap ? byteswap4(variable.type) : variable.type; if (type < 0) { if (ctx->var_index == 0) { return READSTAT_ERROR_PARSE; } ctx->var_offset++; ctx->varinfo[ctx->var_index-1]->width++; return retval; } if ((info = readstat_calloc(1, sizeof(spss_varinfo_t))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } info->width = 1; info->n_segments = 1; info->index = ctx->var_index; info->offset = ctx->var_offset; info->labels_index = -1; retval = readstat_convert(info->name, sizeof(info->name), variable.name, sizeof(variable.name), NULL); if (retval != READSTAT_OK) goto cleanup; retval = readstat_convert(info->longname, sizeof(info->longname), variable.name, sizeof(variable.name), NULL); if (retval != READSTAT_OK) goto cleanup; info->print_format.decimal_places = (variable.print & 0x000000FF); info->print_format.width = (variable.print & 0x0000FF00) >> 8; info->print_format.type = (variable.print & 0x00FF0000) >> 16; info->write_format.decimal_places = (variable.write & 0x000000FF); info->write_format.width = (variable.write & 0x0000FF00) >> 8; info->write_format.type = (variable.write & 0x00FF0000) >> 16; if (type > 0 || info->print_format.type == SPSS_FORMAT_TYPE_A || info->write_format.type == SPSS_FORMAT_TYPE_A) { info->type = READSTAT_TYPE_STRING; } else { info->type = READSTAT_TYPE_DOUBLE; } if (variable.has_var_label) { if ((retval = sav_read_variable_label(info, ctx)) != READSTAT_OK) { goto cleanup; } } if (variable.n_missing_values) { info->n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values; if ((retval = sav_read_variable_missing_values(info, ctx)) != READSTAT_OK) { goto cleanup; } } ctx->varinfo[ctx->var_index] = info; ctx->var_index++; ctx->var_offset++; cleanup: if (retval != READSTAT_OK) { spss_varinfo_free(info); } return retval; } static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) { uint32_t label_count; uint32_t rec_type; uint32_t var_count; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) label_count = byteswap4(label_count); int i; for (i=0; iseek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(&unpadded_len, 1, io->io_ctx) < 1) { retval = READSTAT_ERROR_READ; goto cleanup; } padded_len = (unpadded_len + 8) / 8 * 8 - 1; if (io->seek(padded_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } } if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) rec_type = byteswap4(rec_type); if (rec_type != 4) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) var_count = byteswap4(var_count); if (io->seek(var_count * sizeof(uint32_t), READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } cleanup: return retval; } static readstat_error_t sav_submit_value_labels(value_label_t *value_labels, int32_t label_count, readstat_type_t value_type, sav_ctx_t *ctx) { char label_name_buf[256]; readstat_error_t retval = READSTAT_OK; int32_t i; snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", ctx->value_labels_count); for (i=0; ihandle.value_label(label_name_buf, vlabel->final_value, vlabel->label, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } cleanup: return retval; } static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) { uint32_t label_count; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; uint32_t *vars = NULL; uint32_t var_count; int32_t rec_type; readstat_type_t value_type = READSTAT_TYPE_STRING; char label_buf[256]; value_label_t *value_labels = NULL; if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) label_count = byteswap4(label_count); if (label_count && (value_labels = readstat_calloc(label_count, sizeof(value_label_t))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } int i; for (i=0; iread(vlabel->raw_value, 8, io->io_ctx) < 8) { retval = READSTAT_ERROR_READ; goto cleanup; } if (io->read(&unpadded_label_len, 1, io->io_ctx) < 1) { retval = READSTAT_ERROR_READ; goto cleanup; } padded_label_len = (unpadded_label_len + 8) / 8 * 8 - 1; if (io->read(label_buf, padded_label_len, io->io_ctx) < padded_label_len) { retval = READSTAT_ERROR_READ; goto cleanup; } utf8_label_len = padded_label_len*4+1; if ((vlabel->label = readstat_malloc(utf8_label_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } retval = readstat_convert(vlabel->label, utf8_label_len, label_buf, padded_label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; } if (io->read(&rec_type, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) rec_type = byteswap4(rec_type); if (rec_type != 4) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) var_count = byteswap4(var_count); if (var_count && (vars = readstat_malloc(var_count * sizeof(uint32_t))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (io->read(vars, var_count * sizeof(uint32_t), io->io_ctx) < var_count * sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } for (i=0; ibswap) var_offset = byteswap4(var_offset); var_offset--; // Why subtract 1???? spss_varinfo_t **var = bsearch(&var_offset, ctx->varinfo, ctx->var_index, sizeof(spss_varinfo_t *), &spss_varinfo_compare); if (var) { (*var)->labels_index = ctx->value_labels_count; value_type = (*var)->type; } } for (i=0; ifinal_value.type = value_type; if (value_type == READSTAT_TYPE_DOUBLE) { memcpy(&val_d, vlabel->raw_value, 8); if (ctx->bswap) val_d = byteswap_double(val_d); vlabel->final_value.v.double_value = val_d; sav_tag_missing_double(&vlabel->final_value, ctx); } else { retval = readstat_convert(vlabel->utf8_string_value, sizeof(vlabel->utf8_string_value), vlabel->raw_value, 8, ctx->converter); if (retval != READSTAT_OK) break; vlabel->final_value.v.string_value = vlabel->utf8_string_value; } } if (ctx->handle.value_label) { sav_submit_value_labels(value_labels, label_count, value_type, ctx); } ctx->value_labels_count++; cleanup: if (vars) free(vars); if (value_labels) { for (i=0; ilabel) free(vlabel->label); } free(value_labels); } return retval; } static readstat_error_t sav_skip_document_record(sav_ctx_t *ctx) { uint32_t n_lines; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) n_lines = byteswap4(n_lines); if (io->seek(n_lines * SPSS_DOC_LINE_SIZE, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } cleanup: return retval; } static readstat_error_t sav_read_document_record(sav_ctx_t *ctx) { if (!ctx->handle.note) return sav_skip_document_record(ctx); uint32_t n_lines; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) n_lines = byteswap4(n_lines); char raw_buffer[SPSS_DOC_LINE_SIZE]; char utf8_buffer[4*SPSS_DOC_LINE_SIZE+1]; int i; for (i=0; iread(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) { retval = READSTAT_ERROR_READ; goto cleanup; } retval = readstat_convert(utf8_buffer, sizeof(utf8_buffer), raw_buffer, sizeof(raw_buffer), ctx->converter); if (retval != READSTAT_OK) goto cleanup; if (ctx->handle.note(i, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } cleanup: return retval; } static readstat_error_t sav_read_dictionary_termination_record(sav_ctx_t *ctx) { int32_t filler; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (io->read(&filler, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) { retval = READSTAT_ERROR_READ; } return retval; } static readstat_error_t sav_process_row(unsigned char *buffer, size_t buffer_len, sav_ctx_t *ctx) { if (ctx->row_offset) { ctx->row_offset--; return READSTAT_OK; } readstat_error_t retval = READSTAT_OK; double fp_value; int offset = 0; readstat_off_t data_offset = 0; size_t raw_str_used = 0; int segment_offset = 0; int var_index = 0, col = 0; int raw_str_is_utf8 = ctx->input_encoding && !strcmp(ctx->input_encoding, "UTF-8"); while (data_offset < buffer_len && col < ctx->var_index && var_index < ctx->var_index) { spss_varinfo_t *col_info = ctx->varinfo[col]; spss_varinfo_t *var_info = ctx->varinfo[var_index]; readstat_value_t value = { .type = var_info->type }; if (offset > 31) { retval = READSTAT_ERROR_PARSE; goto done; } if (var_info->type == READSTAT_TYPE_STRING) { // If we're in the last column of a segment, only read 7 bytes // (Segments contain 255 bytes but have room for 256) size_t read_len = 8 - (offset == 31); if (raw_str_used + read_len <= ctx->raw_string_len) { if (raw_str_is_utf8) { /* Skip null bytes, see https://github.com/tidyverse/haven/issues/560 */ char c; for (int i=0; iraw_string[raw_str_used++] = c; } else { memcpy(ctx->raw_string + raw_str_used, &buffer[data_offset], read_len); raw_str_used += read_len; } } if (++offset == col_info->width) { offset = 0; col++; segment_offset++; } if (segment_offset == var_info->n_segments) { if (!ctx->variables[var_info->index]->skip) { retval = readstat_convert(ctx->utf8_string, ctx->utf8_string_len, ctx->raw_string, raw_str_used, ctx->converter); if (retval != READSTAT_OK) goto done; value.v.string_value = ctx->utf8_string; if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index], value, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto done; } } raw_str_used = 0; segment_offset = 0; var_index += var_info->n_segments; } } else if (var_info->type == READSTAT_TYPE_DOUBLE) { if (!ctx->variables[var_info->index]->skip) { memcpy(&fp_value, &buffer[data_offset], 8); if (ctx->bswap) { fp_value = byteswap_double(fp_value); } value.v.double_value = fp_value; sav_tag_missing_double(&value, ctx); if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index], value, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto done; } } var_index += var_info->n_segments; col++; } data_offset += 8; } ctx->current_row++; done: return retval; } static readstat_error_t sav_read_data(sav_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t longest_string = 256; int i; for (i=0; ivar_index;) { spss_varinfo_t *info = ctx->varinfo[i]; if (info->string_length > longest_string) { longest_string = info->string_length; } i += info->n_segments; } ctx->raw_string_len = longest_string + sizeof(SAV_EIGHT_SPACES)-2; ctx->raw_string = readstat_malloc(ctx->raw_string_len); ctx->utf8_string_len = 4*longest_string+1 + sizeof(SAV_EIGHT_SPACES)-2; ctx->utf8_string = readstat_malloc(ctx->utf8_string_len); if (ctx->raw_string == NULL || ctx->utf8_string == NULL) { retval = READSTAT_ERROR_MALLOC; goto done; } if (ctx->compression == READSTAT_COMPRESS_ROWS) { retval = sav_read_compressed_data(ctx, &sav_process_row); } else if (ctx->compression == READSTAT_COMPRESS_BINARY) { #if HAVE_ZLIB retval = zsav_read_compressed_data(ctx, &sav_process_row); #else retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION; #endif } else { retval = sav_read_uncompressed_data(ctx, &sav_process_row); } if (retval != READSTAT_OK) goto done; if (ctx->record_count >= 0 && ctx->current_row != ctx->row_limit) { retval = READSTAT_ERROR_ROW_COUNT_MISMATCH; } done: return retval; } static readstat_error_t sav_read_uncompressed_data(sav_ctx_t *ctx, readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; unsigned char *buffer = NULL; size_t bytes_read = 0; size_t buffer_len = ctx->var_offset * 8; buffer = readstat_malloc(buffer_len); if (ctx->row_offset) { if (io->seek(buffer_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto done; } ctx->row_offset = 0; } while (ctx->row_limit == -1 || ctx->current_row < ctx->row_limit) { retval = sav_update_progress(ctx); if (retval != READSTAT_OK) goto done; if ((bytes_read = io->read(buffer, buffer_len, io->io_ctx)) != buffer_len) goto done; retval = row_handler(buffer, buffer_len, ctx); if (retval != READSTAT_OK) goto done; } done: if (buffer) free(buffer); return retval; } static readstat_error_t sav_read_compressed_data(sav_ctx_t *ctx, readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; readstat_off_t data_offset = 0; unsigned char buffer[DATA_BUFFER_SIZE]; int buffer_used = 0; size_t uncompressed_row_len = ctx->var_offset * 8; readstat_off_t uncompressed_offset = 0; unsigned char *uncompressed_row = NULL; struct sav_row_stream_s state = { .missing_value = ctx->missing_double, .bias = ctx->bias, .bswap = ctx->bswap }; if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto done; } while (1) { retval = sav_update_progress(ctx); if (retval != READSTAT_OK) goto done; buffer_used = io->read(buffer, sizeof(buffer), io->io_ctx); if (buffer_used == -1 || buffer_used == 0 || (buffer_used % 8) != 0) goto done; state.status = SAV_ROW_STREAM_HAVE_DATA; data_offset = 0; while (state.status != SAV_ROW_STREAM_NEED_DATA) { state.next_in = &buffer[data_offset]; state.avail_in = buffer_used - data_offset; state.next_out = &uncompressed_row[uncompressed_offset]; state.avail_out = uncompressed_row_len - uncompressed_offset; sav_decompress_row(&state); uncompressed_offset = uncompressed_row_len - state.avail_out; data_offset = buffer_used - state.avail_in; if (state.status == SAV_ROW_STREAM_FINISHED_ROW) { retval = row_handler(uncompressed_row, uncompressed_row_len, ctx); if (retval != READSTAT_OK) goto done; uncompressed_offset = 0; } if (state.status == SAV_ROW_STREAM_FINISHED_ALL) goto done; if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit) goto done; } } done: if (uncompressed_row) free(uncompressed_row); return retval; } static readstat_error_t sav_parse_machine_integer_info_record(const void *data, size_t data_len, sav_ctx_t *ctx) { if (data_len != 32) return READSTAT_ERROR_PARSE; const char *src_charset = NULL; const char *dst_charset = ctx->output_encoding; sav_machine_integer_info_record_t record; memcpy(&record, data, data_len); if (ctx->bswap) { record.character_code = byteswap4(record.character_code); } if (ctx->input_encoding) { src_charset = ctx->input_encoding; } else { int i; for (i=0; ihandle.error) { char error_buf[1024]; snprintf(error_buf, sizeof(error_buf), "Unsupported character set: %d\n", record.character_code); ctx->handle.error(error_buf, ctx->user_ctx); } return READSTAT_ERROR_UNSUPPORTED_CHARSET; } ctx->input_encoding = src_charset; } if (src_charset && dst_charset) { // You might be tempted to skip the charset conversion when src_charset // and dst_charset are the same. However, some versions of SPSS insert // illegally truncated strings (e.g. the last character is three bytes // but the field only has room for two bytes). So to prevent the client // from receiving an invalid byte sequence, we ram everything through // our iconv machinery. iconv_t converter = iconv_open(dst_charset, src_charset); if (converter == (iconv_t)-1) { return READSTAT_ERROR_UNSUPPORTED_CHARSET; } if (ctx->converter) { iconv_close(ctx->converter); } ctx->converter = converter; } return READSTAT_OK; } static readstat_error_t sav_parse_machine_floating_point_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) { if (size != 8 || count != 3) return READSTAT_ERROR_PARSE; sav_machine_floating_point_info_record_t fp_info; memcpy(&fp_info, data, sizeof(sav_machine_floating_point_info_record_t)); ctx->missing_double = ctx->bswap ? byteswap8(fp_info.sysmis) : fp_info.sysmis; ctx->highest_double = ctx->bswap ? byteswap8(fp_info.highest) : fp_info.highest; ctx->lowest_double = ctx->bswap ? byteswap8(fp_info.lowest) : fp_info.lowest; return READSTAT_OK; } /* We don't yet know how many real variables there are, so store the values in the record * and make sense of them later. */ static readstat_error_t sav_store_variable_display_parameter_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) { if (size != 4) return READSTAT_ERROR_PARSE; const uint32_t *data_ptr = data; int i; ctx->variable_display_values = readstat_realloc(ctx->variable_display_values, count * sizeof(uint32_t)); if (count > 0 && ctx->variable_display_values == NULL) return READSTAT_ERROR_MALLOC; ctx->variable_display_values_count = count; for (i=0; ivariable_display_values[i] = ctx->bswap ? byteswap4(data_ptr[i]) : data_ptr[i]; } return READSTAT_OK; } static readstat_error_t sav_parse_variable_display_parameter_record(sav_ctx_t *ctx) { if (!ctx->variable_display_values) return READSTAT_OK; int i; long count = ctx->variable_display_values_count; if (count != 2 * ctx->var_index && count != 3 * ctx->var_index) { return READSTAT_ERROR_PARSE; } int has_display_width = ctx->var_index > 0 && (count / ctx->var_index == 3); int offset = 0; for (i=0; ivar_index;) { spss_varinfo_t *info = ctx->varinfo[i]; offset = (2 + has_display_width)*i; info->measure = spss_measure_to_readstat_measure(ctx->variable_display_values[offset++]); if (has_display_width) { info->display_width = ctx->variable_display_values[offset++]; } info->alignment = spss_alignment_to_readstat_alignment(ctx->variable_display_values[offset++]); i += info->n_segments; } return READSTAT_OK; } static readstat_error_t sav_read_pascal_string(char *buf, size_t buf_len, const char **inout_data_ptr, size_t data_ptr_len, sav_ctx_t *ctx) { const char *data_ptr = *inout_data_ptr; const char *data_end = data_ptr + data_ptr_len; readstat_error_t retval = READSTAT_OK; uint32_t var_name_len = 0; if (data_ptr + sizeof(uint32_t) > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } memcpy(&var_name_len, data_ptr, sizeof(uint32_t)); if (ctx->bswap) var_name_len = byteswap4(var_name_len); data_ptr += sizeof(uint32_t); if (data_ptr + var_name_len > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } retval = readstat_convert(buf, buf_len, data_ptr, var_name_len, NULL); if (retval != READSTAT_OK) goto cleanup; data_ptr += var_name_len; cleanup: *inout_data_ptr = data_ptr; return retval; } static readstat_error_t sav_parse_long_string_value_labels_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) { if (!ctx->handle.value_label) return READSTAT_OK; if (size != 1) return READSTAT_ERROR_PARSE; readstat_error_t retval = READSTAT_OK; uint32_t label_count = 0; uint32_t i = 0; const char *data_ptr = data; const char *data_end = data_ptr + count; char var_name_buf[256+1]; // unconverted char label_name_buf[256]; char *value_buffer = NULL; char *label_buffer = NULL; while (data_ptr < data_end) { memset(label_name_buf, '\0', sizeof(label_name_buf)); retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf), &data_ptr, data_end - data_ptr, ctx); if (retval != READSTAT_OK) goto cleanup; for (i=0; ivar_index;) { spss_varinfo_t *info = ctx->varinfo[i]; if (strcmp(var_name_buf, info->longname) == 0) { info->labels_index = ctx->value_labels_count++; snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", info->labels_index); break; } i += info->n_segments; } if (label_name_buf[0] == '\0') { retval = READSTAT_ERROR_PARSE; goto cleanup; } data_ptr += sizeof(uint32_t); if (data_ptr + sizeof(uint32_t) > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } memcpy(&label_count, data_ptr, sizeof(uint32_t)); if (ctx->bswap) label_count = byteswap4(label_count); data_ptr += sizeof(uint32_t); for (i=0; i data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } memcpy(&value_len, data_ptr, sizeof(uint32_t)); if (ctx->bswap) value_len = byteswap4(value_len); data_ptr += sizeof(uint32_t); value_buffer_len = value_len*4+1; value_buffer = readstat_realloc(value_buffer, value_buffer_len); if (value_buffer == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (data_ptr + value_len > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } retval = readstat_convert(value_buffer, value_buffer_len, data_ptr, value_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; data_ptr += value_len; if (data_ptr + sizeof(uint32_t) > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } memcpy(&label_len, data_ptr, sizeof(uint32_t)); if (ctx->bswap) label_len = byteswap4(label_len); data_ptr += sizeof(uint32_t); label_buffer_len = label_len*4+1; label_buffer = readstat_realloc(label_buffer, label_buffer_len); if (label_buffer == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (data_ptr + label_len > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } retval = readstat_convert(label_buffer, label_buffer_len, data_ptr, label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; data_ptr += label_len; readstat_value_t value = { .type = READSTAT_TYPE_STRING }; value.v.string_value = value_buffer; if (ctx->handle.value_label(label_name_buf, value, label_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } if (data_ptr != data_end) { retval = READSTAT_ERROR_PARSE; } cleanup: if (value_buffer) free(value_buffer); if (label_buffer) free(label_buffer); return retval; } static readstat_error_t sav_parse_long_string_missing_values_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) { if (size != 1) return READSTAT_ERROR_PARSE; readstat_error_t retval = READSTAT_OK; uint32_t i = 0, j = 0; const char *data_ptr = data; const char *data_end = data_ptr + count; char var_name_buf[256+1]; while (data_ptr < data_end) { retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf), &data_ptr, data_end - data_ptr, ctx); if (retval != READSTAT_OK) goto cleanup; if (data_ptr == data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } char n_missing_values = *data_ptr++; if (n_missing_values < 1 || n_missing_values > 3) { retval = READSTAT_ERROR_PARSE; goto cleanup; } for (i=0; ivar_index;) { spss_varinfo_t *info = ctx->varinfo[i]; if (strcmp(var_name_buf, info->longname) == 0) { info->n_missing_values = n_missing_values; uint32_t var_name_len = 0; if (data_ptr + sizeof(uint32_t) > data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } memcpy(&var_name_len, data_ptr, sizeof(uint32_t)); if (ctx->bswap) var_name_len = byteswap4(var_name_len); data_ptr += sizeof(uint32_t); for (j=0; j data_end) { retval = READSTAT_ERROR_PARSE; goto cleanup; } retval = readstat_convert(info->missing_string_values[j], sizeof(info->missing_string_values[0]), data_ptr, var_name_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; data_ptr += var_name_len; } break; } i += info->n_segments; } if (i == ctx->var_index) { retval = READSTAT_ERROR_PARSE; goto cleanup; } } if (data_ptr != data_end) { retval = READSTAT_ERROR_PARSE; } cleanup: return retval; } static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) { char data_buf[4096]; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; while (1) { uint32_t rec_type; uint32_t extra_info[3]; size_t data_len = 0; int i; int done = 0; if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) { rec_type = byteswap4(rec_type); } switch (rec_type) { case SAV_RECORD_TYPE_VARIABLE: retval = sav_skip_variable_record(ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_TYPE_VALUE_LABEL: retval = sav_skip_value_label_record(ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_TYPE_DOCUMENT: retval = sav_skip_document_record(ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_TYPE_DICT_TERMINATION: done = 1; break; case SAV_RECORD_TYPE_HAS_DATA: if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) { for (i=0; i<3; i++) extra_info[i] = byteswap4(extra_info[i]); } uint32_t subtype = extra_info[0]; size_t size = extra_info[1]; size_t count = extra_info[2]; data_len = size * count; if (subtype == SAV_RECORD_SUBTYPE_INTEGER_INFO) { if (data_len > sizeof(data_buf)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (io->read(data_buf, data_len, io->io_ctx) < data_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } retval = sav_parse_machine_integer_info_record(data_buf, data_len, ctx); if (retval != READSTAT_OK) goto cleanup; } else if (subtype == SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS) { if (ctx->mr_sets != NULL) { retval = READSTAT_ERROR_BAD_MR_STRING; goto cleanup; } retval = sav_read_multiple_response_sets(data_len, ctx); if (retval != READSTAT_OK) goto cleanup; } else { if (io->seek(data_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } } break; default: retval = READSTAT_ERROR_PARSE; goto cleanup; break; } if (done) break; } cleanup: return retval; } static readstat_error_t sav_parse_records_pass2(sav_ctx_t *ctx) { void *data_buf = NULL; size_t data_buf_capacity = 4096; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if ((data_buf = readstat_malloc(data_buf_capacity)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } while (1) { uint32_t rec_type; uint32_t extra_info[3]; size_t data_len = 0; int i; int done = 0; if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) { rec_type = byteswap4(rec_type); } switch (rec_type) { case SAV_RECORD_TYPE_VARIABLE: if ((retval = sav_read_variable_record(ctx)) != READSTAT_OK) goto cleanup; break; case SAV_RECORD_TYPE_VALUE_LABEL: if ((retval = sav_read_value_label_record(ctx)) != READSTAT_OK) goto cleanup; break; case SAV_RECORD_TYPE_DOCUMENT: if ((retval = sav_read_document_record(ctx)) != READSTAT_OK) goto cleanup; break; case SAV_RECORD_TYPE_DICT_TERMINATION: if ((retval = sav_read_dictionary_termination_record(ctx)) != READSTAT_OK) goto cleanup; done = 1; break; case SAV_RECORD_TYPE_HAS_DATA: if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (ctx->bswap) { for (i=0; i<3; i++) extra_info[i] = byteswap4(extra_info[i]); } uint32_t subtype = extra_info[0]; size_t size = extra_info[1]; size_t count = extra_info[2]; data_len = size * count; if (data_buf_capacity < data_len) { if ((data_buf = readstat_realloc(data_buf, data_buf_capacity = data_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } } if (data_len == 0 || io->read(data_buf, data_len, io->io_ctx) < data_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } switch (subtype) { case SAV_RECORD_SUBTYPE_INTEGER_INFO: /* parsed in pass 1 */ break; case SAV_RECORD_SUBTYPE_FP_INFO: retval = sav_parse_machine_floating_point_record(data_buf, size, count, ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_SUBTYPE_VAR_DISPLAY: retval = sav_store_variable_display_parameter_record(data_buf, size, count, ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_SUBTYPE_LONG_VAR_NAME: retval = sav_parse_long_variable_names_record(data_buf, count, ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_SUBTYPE_VERY_LONG_STR: retval = sav_parse_very_long_string_record(data_buf, count, ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS: retval = sav_parse_long_string_value_labels_record(data_buf, size, count, ctx); if (retval != READSTAT_OK) goto cleanup; break; case SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES: retval = sav_parse_long_string_missing_values_record(data_buf, size, count, ctx); if (retval != READSTAT_OK) goto cleanup; break; default: /* misc. info */ break; } break; default: retval = READSTAT_ERROR_PARSE; goto cleanup; break; } if (done) break; } cleanup: if (data_buf) free(data_buf); return retval; } static readstat_error_t sav_set_n_segments_and_var_count(sav_ctx_t *ctx) { int i; ctx->var_count = 0; for (i=0; ivar_index;) { spss_varinfo_t *info = ctx->varinfo[i]; if (info->string_length > VERY_LONG_STRING_MAX_LENGTH) return READSTAT_ERROR_PARSE; if (info->string_length) { info->n_segments = (info->string_length + 251) / 252; } info->index = ctx->var_count++; i += info->n_segments; } ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *)); return READSTAT_OK; } static readstat_error_t sav_handle_variables(sav_ctx_t *ctx) { int i; int index_after_skipping = 0; readstat_error_t retval = READSTAT_OK; if (!ctx->handle.variable) return retval; for (i=0; ivar_index;) { char label_name_buf[256]; spss_varinfo_t *info = ctx->varinfo[i]; ctx->variables[info->index] = spss_init_variable_for_info(info, index_after_skipping, ctx->converter); snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", info->labels_index); int cb_retval = ctx->handle.variable(info->index, ctx->variables[info->index], info->labels_index == -1 ? NULL : label_name_buf, ctx->user_ctx); if (cb_retval == READSTAT_HANDLER_ABORT) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) { ctx->variables[info->index]->skip = 1; } else { index_after_skipping++; } i += info->n_segments; } cleanup: return retval; } static readstat_error_t sav_handle_fweight(sav_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i; if (ctx->handle.fweight && ctx->fweight_index >= 0) { for (i=0; ivar_index;) { spss_varinfo_t *info = ctx->varinfo[i]; if (info->offset == ctx->fweight_index - 1) { if (ctx->handle.fweight(ctx->variables[info->index], ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } break; } i += info->n_segments; } } cleanup: return retval; } readstat_error_t sav_parse_timestamp(sav_ctx_t *ctx, sav_file_header_record_t *header) { readstat_error_t retval = READSTAT_OK; struct tm timestamp = { .tm_isdst = -1 }; if ((retval = sav_parse_time(header->creation_time, sizeof(header->creation_time), ×tamp, ctx->handle.error, ctx->user_ctx)) != READSTAT_OK) goto cleanup; if ((retval = sav_parse_date(header->creation_date, sizeof(header->creation_date), ×tamp, ctx->handle.error, ctx->user_ctx)) != READSTAT_OK) goto cleanup; ctx->timestamp = mktime(×tamp); cleanup: return retval; } readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, void *user_ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = parser->io; sav_file_header_record_t header; sav_ctx_t *ctx = NULL; size_t file_size = 0; if (io->open(path, io->io_ctx) == -1) { return READSTAT_ERROR_OPEN; } file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx); if (file_size == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(&header, sizeof(sav_file_header_record_t), io->io_ctx) < sizeof(sav_file_header_record_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } ctx = sav_ctx_init(&header, io); if (ctx == NULL) { retval = READSTAT_ERROR_PARSE; goto cleanup; } ctx->handle = parser->handlers; ctx->input_encoding = parser->input_encoding; ctx->output_encoding = parser->output_encoding; ctx->user_ctx = user_ctx; ctx->file_size = file_size; if (parser->row_offset > 0) ctx->row_offset = parser->row_offset; if (ctx->record_count >= 0) { int record_count_after_skipping = ctx->record_count - ctx->row_offset; if (record_count_after_skipping < 0) { record_count_after_skipping = 0; ctx->row_offset = ctx->record_count; } ctx->row_limit = record_count_after_skipping; if (parser->row_limit > 0 && parser->row_limit < record_count_after_skipping) ctx->row_limit = parser->row_limit; } else if (parser->row_limit > 0) { ctx->row_limit = parser->row_limit; } /* ignore errors */ sav_parse_timestamp(ctx, &header); if ((retval = sav_parse_records_pass1(ctx)) != READSTAT_OK) goto cleanup; if (io->seek(sizeof(sav_file_header_record_t), READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if ((retval = sav_update_progress(ctx)) != READSTAT_OK) goto cleanup; if ((retval = sav_parse_records_pass2(ctx)) != READSTAT_OK) goto cleanup; if ((retval = sav_set_n_segments_and_var_count(ctx)) != READSTAT_OK) goto cleanup; if (ctx->var_count == 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (ctx->handle.metadata) { readstat_metadata_t metadata = { .row_count = ctx->record_count < 0 ? -1 : ctx->row_limit, .var_count = ctx->var_count, .file_encoding = ctx->input_encoding, .file_format_version = ctx->format_version, .creation_time = ctx->timestamp, .modified_time = ctx->timestamp, .compression = ctx->compression, .endianness = ctx->endianness }; if ((retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label), header.file_label, sizeof(header.file_label), ctx->converter)) != READSTAT_OK) goto cleanup; metadata.file_label = ctx->file_label; // Replace short MR names with long names ck_hash_table_t *var_dict = ck_hash_table_init(ctx->var_index, 8); for (size_t i = 0; i < ctx->var_index; i++) { spss_varinfo_t *current_varinfo = ctx->varinfo[i]; if (current_varinfo != NULL && current_varinfo->name[0] != '\0') { ck_str_hash_insert(current_varinfo->name, current_varinfo, var_dict); } } for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) { mr_set_t mr = ctx->mr_sets[i]; for (size_t j = 0; j < mr.num_subvars; j++) { char* sv_name_upper = readstat_malloc(strlen(mr.subvariables[j]) + 1); if (sv_name_upper == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } sv_name_upper[strlen(mr.subvariables[j])] = '\0'; for (int c = 0; mr.subvariables[j][c] != '\0'; c++) { sv_name_upper[c] = toupper((unsigned char) mr.subvariables[j][c]); } spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(sv_name_upper, var_dict); if (info) { free(mr.subvariables[j]); // mr.subvariables[j] = NULL; if ((mr.subvariables[j] = readstat_malloc(strlen(info->longname) + 1)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } // mr.subvariables[j][strlen(info->longname)] = '\0'; strcpy(mr.subvariables[j], info->longname); // mr.subvariables[j] = info->longname; } free(sv_name_upper); // sv_name_upper = NULL; } } if (var_dict) ck_hash_table_free(var_dict); metadata.multiple_response_sets_length = ctx->multiple_response_sets_length; metadata.mr_sets = ctx->mr_sets; if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } if ((retval = sav_parse_variable_display_parameter_record(ctx)) != READSTAT_OK) goto cleanup; if ((retval = sav_handle_variables(ctx)) != READSTAT_OK) goto cleanup; if ((retval = sav_handle_fweight(ctx)) != READSTAT_OK) goto cleanup; if (ctx->handle.value) { retval = sav_read_data(ctx); } cleanup: io->close(io->io_ctx); if (ctx) sav_ctx_free(ctx); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179466.0 pyreadstat-1.3.3/src/spss/readstat_sav_write.c0000644000076500000240000014600615134704512020064 0ustar00dialout #include #include #include #include #include #include #include #include #include #include "../readstat.h" #include "../readstat_iconv.h" #include "../readstat_bits.h" #include "../readstat_malloc.h" #include "../readstat_writer.h" #include "../CKHashTable.h" #include "readstat_sav.h" #include "readstat_sav_compress.h" #include "readstat_spss_parse.h" #if HAVE_ZLIB #include #include "readstat_zsav_compress.h" #include "readstat_zsav_write.h" #endif #define MAX_STRING_SIZE 255 #define MAX_LABEL_SIZE 256 #define MAX_VALUE_LABEL_SIZE 120 typedef struct sav_varnames_s { char shortname[9]; char stem[6]; } sav_varnames_t; static long readstat_label_set_number_short_variables(readstat_label_set_t *r_label_set) { long count = 0; int j; for (j=0; jvariables_count; j++) { readstat_variable_t *r_variable = readstat_get_label_set_variable(r_label_set, j); if (r_variable->storage_width <= 8) { count++; } } return count; } static int readstat_label_set_needs_short_value_labels_record(readstat_label_set_t *r_label_set) { return readstat_label_set_number_short_variables(r_label_set) > 0; } static int readstat_label_set_needs_long_value_labels_record(readstat_label_set_t *r_label_set) { return readstat_label_set_number_short_variables(r_label_set) < r_label_set->variables_count; } static int32_t sav_encode_format(spss_format_t *spss_format) { uint8_t width = spss_format->width > 0xff ? 0xff : spss_format->width; return ((spss_format->type << 16) | (width << 8) | spss_format->decimal_places); } static readstat_error_t sav_encode_base_variable_format(readstat_variable_t *r_variable, int32_t *out_code) { spss_format_t spss_format; readstat_error_t retval = spss_format_for_variable(r_variable, &spss_format); if (retval == READSTAT_OK && out_code) *out_code = sav_encode_format(&spss_format); return retval; } static readstat_error_t sav_encode_ghost_variable_format(readstat_variable_t *r_variable, size_t user_width, int32_t *out_code) { spss_format_t spss_format; readstat_error_t retval = spss_format_for_variable(r_variable, &spss_format); spss_format.width = user_width; if (retval == READSTAT_OK && out_code) *out_code = sav_encode_format(&spss_format); return retval; } static size_t sav_format_variable_name(char *output, size_t output_len, sav_varnames_t *varnames) { snprintf(output, output_len, "%s", varnames->shortname); return strlen(output); } static size_t sav_format_ghost_variable_name(char *output, size_t output_len, sav_varnames_t *varnames, unsigned int segment) { snprintf(output, output_len, "%s", varnames->stem); size_t len = strlen(output); int letter = segment % 36; if (letter < 10) { output[len++] = '0' + letter; } else { output[len++] = 'A' + (letter - 10); } return len; } static int sav_variable_segments(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING && user_width > MAX_STRING_SIZE) { return (user_width + 251) / 252; } return 1; } static readstat_error_t sav_emit_header(readstat_writer_t *writer) { sav_file_header_record_t header = { { 0 } }; readstat_error_t retval = READSTAT_OK; time_t now = writer->timestamp; struct tm *time_s = localtime(&now); /* There are portability issues with strftime so hack something up */ char months[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; char creation_date[sizeof(header.creation_date)+1] = { 0 }; char creation_time[sizeof(header.creation_time)+1] = { 0 }; if (!time_s) { retval = READSTAT_ERROR_BAD_TIMESTAMP_VALUE; goto cleanup; } memcpy(header.rec_type, "$FL2", sizeof("$FL2")-1); if (writer->compression == READSTAT_COMPRESS_BINARY) { header.rec_type[3] = '3'; } memset(header.prod_name, ' ', sizeof(header.prod_name)); memcpy(header.prod_name, "@(#) SPSS DATA FILE - " READSTAT_PRODUCT_URL, sizeof("@(#) SPSS DATA FILE - " READSTAT_PRODUCT_URL)-1); header.layout_code = 2; header.nominal_case_size = writer->row_len / 8; if (writer->compression == READSTAT_COMPRESS_ROWS) { header.compression = 1; } else if (writer->compression == READSTAT_COMPRESS_BINARY) { header.compression = 2; } if (writer->fweight_variable) { int32_t dictionary_index = 1 + writer->fweight_variable->offset / 8; header.weight_index = dictionary_index; } else { header.weight_index = 0; } header.ncases = writer->row_count; header.bias = 100.0; snprintf(creation_date, sizeof(creation_date), "%02d %3.3s %02d", (unsigned int)time_s->tm_mday % 100, months[time_s->tm_mon], (unsigned int)time_s->tm_year % 100); memcpy(header.creation_date, creation_date, sizeof(header.creation_date)); snprintf(creation_time, sizeof(creation_time), "%02d:%02d:%02d", (unsigned int)time_s->tm_hour % 100, (unsigned int)time_s->tm_min % 100, (unsigned int)time_s->tm_sec % 100); memcpy(header.creation_time, creation_time, sizeof(header.creation_time)); memset(header.file_label, ' ', sizeof(header.file_label)); size_t file_label_len = strlen(writer->file_label); if (file_label_len > sizeof(header.file_label)) file_label_len = sizeof(header.file_label); if (writer->file_label[0]) memcpy(header.file_label, writer->file_label, file_label_len); retval = readstat_write_bytes(writer, &header, sizeof(header)); cleanup: return retval; } static readstat_error_t sav_emit_variable_label(readstat_writer_t *writer, readstat_variable_t *r_variable) { readstat_error_t retval = READSTAT_OK; const char *title_data = r_variable->label; size_t title_data_len = strlen(title_data); if (title_data_len > 0) { char padded_label[MAX_LABEL_SIZE]; uint32_t label_len = title_data_len; if (label_len > sizeof(padded_label)) label_len = sizeof(padded_label); retval = readstat_write_bytes(writer, &label_len, sizeof(label_len)); if (retval != READSTAT_OK) goto cleanup; strncpy(padded_label, title_data, (label_len + 3) / 4 * 4); retval = readstat_write_bytes(writer, padded_label, (label_len + 3) / 4 * 4); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static int sav_n_missing_double_values(readstat_variable_t *r_variable) { int n_missing_ranges = readstat_variable_get_missing_ranges_count(r_variable); int n_missing_values = n_missing_ranges; int has_missing_range = 0; int j; for (j=0; j 3) { return READSTAT_ERROR_TOO_MANY_MISSING_VALUE_DEFINITIONS; } if (out_n_missing_values) *out_n_missing_values = n_missing_values; return READSTAT_OK; } static readstat_error_t sav_emit_variable_missing_string_values(readstat_writer_t *writer, readstat_variable_t *r_variable) { readstat_error_t retval = READSTAT_OK; int n_missing_values = 0; int n_missing_ranges = readstat_variable_get_missing_ranges_count(r_variable); /* ranges */ int j; for (j=0; jtype == READSTAT_TYPE_STRING) { variable.type = r_variable->user_width > MAX_STRING_SIZE ? MAX_STRING_SIZE : r_variable->user_width; } variable.has_var_label = (r_variable->label[0] != '\0'); retval = sav_n_missing_values(&variable.n_missing_values, r_variable); if (retval != READSTAT_OK) goto cleanup; retval = sav_encode_base_variable_format(r_variable, &variable.print); if (retval != READSTAT_OK) goto cleanup; variable.write = variable.print; memset(variable.name, ' ', sizeof(variable.name)); if (name_data_len > 0 && name_data_len <= sizeof(variable.name)) memcpy(variable.name, name_data, name_data_len); retval = readstat_write_bytes(writer, &variable, sizeof(variable)); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_variable_label(writer, r_variable); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_variable_missing_values(writer, r_variable); if (retval != READSTAT_OK) goto cleanup; int extra_fields = r_variable->storage_width / 8 - 1; if (extra_fields > 31) extra_fields = 31; retval = sav_emit_blank_variable_records(writer, extra_fields); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sav_emit_ghost_variable_record(readstat_writer_t *writer, readstat_variable_t *r_variable, sav_varnames_t *varnames, int segment, size_t user_width) { readstat_error_t retval = READSTAT_OK; int32_t rec_type = SAV_RECORD_TYPE_VARIABLE; sav_variable_record_t variable = { 0 }; char name_data[9]; size_t name_len = sav_format_ghost_variable_name(name_data, sizeof(name_data), varnames, segment); retval = readstat_write_bytes(writer, &rec_type, sizeof(rec_type)); if (retval != READSTAT_OK) goto cleanup; variable.type = user_width; retval = sav_encode_ghost_variable_format(r_variable, user_width, &variable.print); if (retval != READSTAT_OK) goto cleanup; variable.write = variable.print; memset(variable.name, ' ', sizeof(variable.name)); if (name_len > 0 && name_len <= sizeof(variable.name)) memcpy(variable.name, name_data, name_len); retval = readstat_write_bytes(writer, &variable, sizeof(variable)); if (retval != READSTAT_OK) goto cleanup; int extra_fields = (user_width + 7) / 8 - 1; if (extra_fields > 31) extra_fields = 31; retval = sav_emit_blank_variable_records(writer, extra_fields); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sav_emit_full_variable_record(readstat_writer_t *writer, readstat_variable_t *r_variable, sav_varnames_t *varnames) { readstat_error_t retval = READSTAT_OK; retval = sav_emit_base_variable_record(writer, r_variable, varnames); if (retval != READSTAT_OK) goto cleanup; int n_segments = sav_variable_segments(r_variable->type, r_variable->user_width); int i; for (i=1; iuser_width - (n_segments - 1) * 252); } retval = sav_emit_ghost_variable_record(writer, r_variable, varnames, i, storage_size); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t sav_emit_variable_records(readstat_writer_t *writer, sav_varnames_t *varnames) { readstat_error_t retval = READSTAT_OK; int i; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); retval = sav_emit_full_variable_record(writer, r_variable, &varnames[i]); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t sav_emit_value_label_records(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; int i, j; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); if (!readstat_label_set_needs_short_value_labels_record(r_label_set)) continue; readstat_type_t user_type = r_label_set->type; int32_t label_count = r_label_set->value_labels_count; int32_t rec_type = 0; if (label_count) { rec_type = SAV_RECORD_TYPE_VALUE_LABEL; retval = readstat_write_bytes(writer, &rec_type, sizeof(rec_type)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &label_count, sizeof(label_count)); if (retval != READSTAT_OK) goto cleanup; for (j=0; jstring_key_len; if (key_len > sizeof(value)) key_len = sizeof(value); memset(value, ' ', sizeof(value)); memcpy(value, r_value_label->string_key, key_len); } else if (user_type == READSTAT_TYPE_DOUBLE) { double num_val = r_value_label->double_key; memcpy(value, &num_val, sizeof(double)); } else if (user_type == READSTAT_TYPE_INT32) { double num_val = r_value_label->int32_key; memcpy(value, &num_val, sizeof(double)); } retval = readstat_write_bytes(writer, value, sizeof(value)); const char *label_data = r_value_label->label; uint8_t label_len = MAX_VALUE_LABEL_SIZE; if (label_len > r_value_label->label_len) label_len = r_value_label->label_len; retval = readstat_write_bytes(writer, &label_len, sizeof(label_len)); if (retval != READSTAT_OK) goto cleanup; char label[MAX_VALUE_LABEL_SIZE+8]; memset(label, ' ', sizeof(label)); memcpy(label, label_data, label_len); retval = readstat_write_bytes(writer, label, (label_len + sizeof(label_len) + 7) / 8 * 8 - sizeof(label_len)); if (retval != READSTAT_OK) goto cleanup; } rec_type = SAV_RECORD_TYPE_VALUE_LABEL_VARIABLES; int32_t var_count = readstat_label_set_number_short_variables(r_label_set); retval = readstat_write_bytes(writer, &rec_type, sizeof(rec_type)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &var_count, sizeof(var_count)); if (retval != READSTAT_OK) goto cleanup; for (j=0; jvariables_count; j++) { readstat_variable_t *r_variable = readstat_get_label_set_variable(r_label_set, j); if (r_variable->storage_width > 8) continue; int32_t dictionary_index = 1 + r_variable->offset / 8; retval = readstat_write_bytes(writer, &dictionary_index, sizeof(dictionary_index)); if (retval != READSTAT_OK) goto cleanup; } } } cleanup: return retval; } static readstat_error_t sav_emit_document_record(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; int32_t rec_type = SAV_RECORD_TYPE_DOCUMENT; int32_t n_lines = writer->notes_count; if (n_lines == 0) goto cleanup; retval = readstat_write_bytes(writer, &rec_type, sizeof(rec_type)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &n_lines, sizeof(n_lines)); if (retval != READSTAT_OK) goto cleanup; int i; for (i=0; inotes_count; i++) { size_t len = strlen(writer->notes[i]); if (len > SPSS_DOC_LINE_SIZE) { retval = READSTAT_ERROR_NOTE_IS_TOO_LONG; goto cleanup; } retval = readstat_write_bytes(writer, writer->notes[i], len); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_spaces(writer, SPSS_DOC_LINE_SIZE - len); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t sav_emit_integer_info_record(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_INTEGER_INFO, .size = 4, .count = 8 }; sav_machine_integer_info_record_t machine_info = { .version_major = 20, .version_minor = 0, .version_revision = 0, .machine_code = -1, .floating_point_rep = SAV_FLOATING_POINT_REP_IEEE, .compression_code = 1, .endianness = machine_is_little_endian() ? SAV_ENDIANNESS_LITTLE : SAV_ENDIANNESS_BIG, .character_code = 65001 // UTF-8 }; retval = readstat_write_bytes(writer, &info_header, sizeof(info_header)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &machine_info, sizeof(machine_info)); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sav_emit_floating_point_info_record(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_FP_INFO, .size = 8, .count = 3 }; retval = readstat_write_bytes(writer, &info_header, sizeof(info_header)); if (retval != READSTAT_OK) goto cleanup; sav_machine_floating_point_info_record_t fp_info = {0}; fp_info.sysmis = SAV_MISSING_DOUBLE; fp_info.highest = SAV_HIGHEST_DOUBLE; fp_info.lowest = SAV_LOWEST_DOUBLE; retval = readstat_write_bytes(writer, &fp_info, sizeof(fp_info)); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sav_emit_variable_display_record(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; int i; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_VAR_DISPLAY, .size = sizeof(int32_t) }; int total_segments = 0; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); total_segments += sav_variable_segments(r_variable->type, r_variable->user_width); } info_header.count = 3 * total_segments; retval = readstat_write_bytes(writer, &info_header, sizeof(info_header)); if (retval != READSTAT_OK) goto cleanup; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); readstat_measure_t measure = readstat_variable_get_measure(r_variable); int32_t sav_measure = spss_measure_from_readstat_measure(measure); int32_t sav_display_width = readstat_variable_get_display_width(r_variable); if (sav_display_width <= 0) sav_display_width = 8; readstat_alignment_t alignment = readstat_variable_get_alignment(r_variable); int32_t sav_alignment = spss_alignment_from_readstat_alignment(alignment); int n_segments = sav_variable_segments(r_variable->type, r_variable->user_width); while (n_segments--) { retval = readstat_write_bytes(writer, &sav_measure, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &sav_display_width, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &sav_alignment, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; } } cleanup: return retval; } static readstat_error_t sav_emit_long_var_name_record(readstat_writer_t *writer, sav_varnames_t *varnames) { readstat_error_t retval = READSTAT_OK; int i; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_LONG_VAR_NAME, .size = 1, .count = 0 }; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); char name_data[9]; size_t name_data_len = sav_format_variable_name(name_data, sizeof(name_data), &varnames[i]); const char *title_data = r_variable->name; size_t title_data_len = strlen(title_data); if (title_data_len > 0 && name_data_len > 0) { if (title_data_len > 64) title_data_len = 64; info_header.count += name_data_len; info_header.count += sizeof("=")-1; info_header.count += title_data_len; info_header.count += sizeof("\x09")-1; } } if (info_header.count > 0) { info_header.count--; /* no trailing 0x09 */ retval = readstat_write_bytes(writer, &info_header, sizeof(info_header)); if (retval != READSTAT_OK) goto cleanup; int is_first = 1; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); char name_data[9]; sav_format_variable_name(name_data, sizeof(name_data), &varnames[i]); const char *title_data = r_variable->name; size_t title_data_len = strlen(title_data); char kv_separator = '='; char tuple_separator = 0x09; if (title_data_len > 0) { if (title_data_len > 64) title_data_len = 64; if (!is_first) { retval = readstat_write_bytes(writer, &tuple_separator, sizeof(tuple_separator)); if (retval != READSTAT_OK) goto cleanup; } retval = readstat_write_string(writer, name_data); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &kv_separator, sizeof(kv_separator)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, title_data, title_data_len); if (retval != READSTAT_OK) goto cleanup; is_first = 0; } } } cleanup: return retval; } static readstat_error_t sav_emit_very_long_string_record(readstat_writer_t *writer, sav_varnames_t *varnames) { readstat_error_t retval = READSTAT_OK; int i; char tuple_separator[2] = { 0x00, 0x09 }; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_VERY_LONG_STR, .size = 1, .count = 0 }; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); if (r_variable->user_width <= MAX_STRING_SIZE) continue; char name_data[9]; sav_format_variable_name(name_data, sizeof(name_data), &varnames[i]); char kv_data[8+1+5+1]; snprintf(kv_data, sizeof(kv_data), "%.8s=%d", name_data, (unsigned int)r_variable->user_width % 100000); info_header.count += strlen(kv_data) + sizeof(tuple_separator); } if (info_header.count == 0) return READSTAT_OK; retval = readstat_write_bytes(writer, &info_header, sizeof(info_header)); if (retval != READSTAT_OK) goto cleanup; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); if (r_variable->user_width <= MAX_STRING_SIZE) continue; char name_data[9]; sav_format_variable_name(name_data, sizeof(name_data), &varnames[i]); char kv_data[8+1+5+1]; snprintf(kv_data, sizeof(kv_data), "%.8s=%d", name_data, (unsigned int)r_variable->user_width % 100000); retval = readstat_write_string(writer, kv_data); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, tuple_separator, sizeof(tuple_separator)); if (retval != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t sav_emit_long_string_value_labels_record(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; int i, j, k; char *space_buffer = NULL; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS, .size = 1, .count = 0 }; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); if (!readstat_label_set_needs_long_value_labels_record(r_label_set)) continue; int32_t label_count = r_label_set->value_labels_count; int32_t var_count = r_label_set->variables_count; for (k=0; kname); int32_t user_width = r_variable->user_width; int32_t storage_width = readstat_variable_get_storage_width(r_variable); if (storage_width <= 8) continue; info_header.count += sizeof(int32_t); // name length info_header.count += name_len; info_header.count += sizeof(int32_t); // variable width info_header.count += sizeof(int32_t); // label count for (j=0; jlabel_len; if (label_len > MAX_VALUE_LABEL_SIZE) label_len = MAX_VALUE_LABEL_SIZE; if (r_value_label->string_key_len > user_width) { retval = READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG; goto cleanup; } info_header.count += sizeof(int32_t); // value length info_header.count += user_width; info_header.count += sizeof(int32_t); // label length info_header.count += label_len; } } } if (info_header.count == 0) goto cleanup; retval = readstat_write_bytes(writer, &info_header, sizeof(info_header)); if (retval != READSTAT_OK) goto cleanup; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); if (!readstat_label_set_needs_long_value_labels_record(r_label_set)) continue; int32_t label_count = r_label_set->value_labels_count; int32_t var_count = r_label_set->variables_count; for (k=0; kname); int32_t user_width = r_variable->user_width; int32_t storage_width = readstat_variable_get_storage_width(r_variable); if (storage_width <= 8) continue; space_buffer = realloc(space_buffer, user_width); memset(space_buffer, ' ', user_width); retval = readstat_write_bytes(writer, &name_len, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, r_variable->name, name_len); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &user_width, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &label_count, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; for (j=0; jstring_key_len; int32_t label_len = r_value_label->label_len; if (label_len > MAX_VALUE_LABEL_SIZE) label_len = MAX_VALUE_LABEL_SIZE; retval = readstat_write_bytes(writer, &user_width, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, r_value_label->string_key, value_len); if (retval != READSTAT_OK) goto cleanup; if (value_len < user_width) { retval = readstat_write_bytes(writer, space_buffer, user_width - value_len); if (retval != READSTAT_OK) goto cleanup; } retval = readstat_write_bytes(writer, &label_len, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, r_value_label->label, label_len); if (retval != READSTAT_OK) goto cleanup; } } } cleanup: if (space_buffer) free(space_buffer); return retval; } static readstat_error_t sav_emit_long_string_missing_values_record(readstat_writer_t *writer) { readstat_error_t retval = READSTAT_OK; int j, k; sav_info_record_t info_header = { .rec_type = SAV_RECORD_TYPE_HAS_DATA, .subtype = SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES, .size = 1, .count = 0 }; int32_t var_count = writer->variables_count; for (k=0; kname); int32_t storage_width = readstat_variable_get_storage_width(r_variable); if (storage_width <= 8) continue; int n_missing_values = 0; for (j=0; jname); int8_t n_missing_values = 0; int32_t storage_width = readstat_variable_get_storage_width(r_variable); if (storage_width <= 8) continue; for (j=0; jname, name_len); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &n_missing_values, sizeof(int8_t)); if (retval != READSTAT_OK) goto cleanup; uint32_t value_len = 8; retval = readstat_write_bytes(writer, &value_len, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; for (j=0; jrow_count; retval = readstat_write_bytes(writer, &info_header, sizeof(sav_info_record_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &one, sizeof(uint64_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &ncases, sizeof(uint64_t)); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t sav_emit_termination_record(readstat_writer_t *writer) { sav_dictionary_termination_record_t termination_record = { .rec_type = SAV_RECORD_TYPE_DICT_TERMINATION }; return readstat_write_bytes(writer, &termination_record, sizeof(termination_record)); } static readstat_error_t sav_write_int8(void *row, const readstat_variable_t *var, int8_t value) { double dval = value; memcpy(row, &dval, sizeof(double)); return READSTAT_OK; } static readstat_error_t sav_write_int16(void *row, const readstat_variable_t *var, int16_t value) { double dval = value; memcpy(row, &dval, sizeof(double)); return READSTAT_OK; } static readstat_error_t sav_write_int32(void *row, const readstat_variable_t *var, int32_t value) { double dval = value; memcpy(row, &dval, sizeof(double)); return READSTAT_OK; } static readstat_error_t sav_write_float(void *row, const readstat_variable_t *var, float value) { double dval = value; memcpy(row, &dval, sizeof(double)); return READSTAT_OK; } static readstat_error_t sav_write_double(void *row, const readstat_variable_t *var, double value) { double dval = value; memcpy(row, &dval, sizeof(double)); return READSTAT_OK; } static readstat_error_t sav_write_string(void *row, const readstat_variable_t *var, const char *value) { memset(row, ' ', var->storage_width); if (value != NULL && value[0] != '\0') { size_t value_len = strlen(value); off_t row_offset = 0; off_t val_offset = 0; unsigned char *row_bytes = (unsigned char *)row; if (value_len > var->storage_width) return READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG; while (value_len - val_offset > 255) { memcpy(&row_bytes[row_offset], &value[val_offset], 255); row_offset += 256; val_offset += 255; } memcpy(&row_bytes[row_offset], &value[val_offset], value_len - val_offset); } return READSTAT_OK; } static readstat_error_t sav_write_missing_string(void *row, const readstat_variable_t *var) { memset(row, ' ', var->storage_width); return READSTAT_OK; } static readstat_error_t sav_write_missing_number(void *row, const readstat_variable_t *var) { uint64_t missing_val = SAV_MISSING_DOUBLE; memcpy(row, &missing_val, sizeof(uint64_t)); return READSTAT_OK; } static size_t sav_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) { if (user_width > MAX_STRING_SIZE) { size_t n_segments = sav_variable_segments(type, user_width); size_t last_segment_width = ((user_width - (n_segments - 1) * 252) + 7)/8*8; return (n_segments-1)*256 + last_segment_width; } if (user_width == 0) { return 8; } return (user_width + 7) / 8 * 8; } return 8; } static readstat_error_t sav_validate_name_chars(const char *name, int unicode) { /* TODO check Unicode class */ int j; for (j=0; name[j]; j++) { if (name[j] == ' ') return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER; if (((unsigned char)name[j] < 0x80 || !unicode) && name[j] != '@' && name[j] != '.' && name[j] != '_' && name[j] != '$' && name[j] != '#' && !(name[j] >= 'a' && name[j] <= 'z') && !(name[j] >= 'A' && name[j] <= 'Z') && !(name[j] >= '0' && name[j] <= '9')) { return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER; } } char first_char = name[0]; if (((unsigned char)first_char < 0x80 || !unicode) && first_char != '@' && !(first_char >= 'a' && first_char <= 'z') && !(first_char >= 'A' && first_char <= 'Z')) { return READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER; } return READSTAT_OK; } static readstat_error_t sav_validate_name_unreserved(const char *name) { if (strcmp(name, "ALL") == 0 || strcmp(name, "AND") == 0 || strcmp(name, "BY") == 0 || strcmp(name, "EQ") == 0 || strcmp(name, "GE") == 0 || strcmp(name, "GT") == 0 || strcmp(name, "GT") == 0 || strcmp(name, "LE") == 0 || strcmp(name, "LT") == 0 || strcmp(name, "NE") == 0 || strcmp(name, "NOT") == 0 || strcmp(name, "OR") == 0 || strcmp(name, "TO") == 0 || strcmp(name, "WITH") == 0) return READSTAT_ERROR_NAME_IS_RESERVED_WORD; return READSTAT_OK; } static readstat_error_t sav_validate_name_length(size_t name_len) { if (name_len > 64) return READSTAT_ERROR_NAME_IS_TOO_LONG; if (name_len == 0) return READSTAT_ERROR_NAME_IS_ZERO_LENGTH; return READSTAT_OK; } static readstat_error_t sav_variable_ok(const readstat_variable_t *variable) { readstat_error_t error = READSTAT_OK; error = sav_validate_name_length(strlen(variable->name)); if (error != READSTAT_OK) return error; error = sav_validate_name_unreserved(variable->name); if (error != READSTAT_OK) return error; return sav_validate_name_chars(variable->name, 1); } static sav_varnames_t *sav_varnames_init(readstat_writer_t *writer) { sav_varnames_t *varnames = calloc(writer->variables_count, sizeof(sav_varnames_t)); ck_hash_table_t *table = ck_hash_table_init(writer->variables_count, 8); int i, k; for (i=0; ivariables_count; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); const char *name = r_variable->name; char *shortname = varnames[i].shortname; char *stem = varnames[i].stem; snprintf(shortname, sizeof(varnames[0].shortname), "%.8s", name); for (k=0; shortname[k]; k++) { // upcase shortname[k] = toupper(shortname[k]); } if (ck_str_hash_lookup(shortname, table)) { snprintf(shortname, sizeof(varnames[0].shortname), "V%d_A", ((unsigned int)i+1)%100000); } ck_str_hash_insert(shortname, r_variable, table); if (r_variable->user_width <= MAX_STRING_SIZE) continue; snprintf(stem, sizeof(varnames[0].stem), "%.5s", shortname); // conflict resolution? } ck_hash_table_free(table); return varnames; } static readstat_error_t sav_begin_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t retval = READSTAT_OK; if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; sav_varnames_t *varnames = sav_varnames_init(writer); retval = sav_emit_header(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_variable_records(writer, varnames); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_value_label_records(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_document_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_integer_info_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_floating_point_info_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_variable_display_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_long_var_name_record(writer, varnames); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_very_long_string_record(writer, varnames); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_long_string_value_labels_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_long_string_missing_values_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_number_of_cases_record(writer); if (retval != READSTAT_OK) goto cleanup; retval = sav_emit_termination_record(writer); if (retval != READSTAT_OK) goto cleanup; cleanup: free(varnames); if (retval == READSTAT_OK) { size_t row_bound = sav_compressed_row_bound(writer->row_len); if (writer->compression == READSTAT_COMPRESS_ROWS) { writer->module_ctx = readstat_malloc(row_bound); #if HAVE_ZLIB } else if (writer->compression == READSTAT_COMPRESS_BINARY) { writer->module_ctx = zsav_ctx_init(row_bound, writer->bytes_written); #endif } } return retval; } static readstat_error_t sav_write_compressed_row(void *writer_ctx, void *row, size_t len) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; unsigned char *output = writer->module_ctx; size_t output_offset = sav_compress_row(output, row, len, writer); return readstat_write_bytes(writer, output, output_offset); } static readstat_error_t sav_metadata_ok(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; if (writer->version == 2 && writer->compression == READSTAT_COMPRESS_BINARY) return READSTAT_ERROR_UNSUPPORTED_COMPRESSION; if (writer->version != 2 && writer->version != 3) return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION; return READSTAT_OK; } readstat_error_t readstat_begin_writing_sav(readstat_writer_t *writer, void *user_ctx, long row_count) { writer->callbacks.metadata_ok = &sav_metadata_ok; writer->callbacks.variable_width = &sav_variable_width; writer->callbacks.variable_ok = &sav_variable_ok; writer->callbacks.write_int8 = &sav_write_int8; writer->callbacks.write_int16 = &sav_write_int16; writer->callbacks.write_int32 = &sav_write_int32; writer->callbacks.write_float = &sav_write_float; writer->callbacks.write_double = &sav_write_double; writer->callbacks.write_string = &sav_write_string; writer->callbacks.write_missing_string = &sav_write_missing_string; writer->callbacks.write_missing_number = &sav_write_missing_number; writer->callbacks.begin_data = &sav_begin_data; if (writer->version == 3) { writer->compression = READSTAT_COMPRESS_BINARY; } else if (writer->version == 0) { writer->version = (writer->compression == READSTAT_COMPRESS_BINARY) ? 3 : 2; } if (writer->compression == READSTAT_COMPRESS_ROWS) { writer->callbacks.write_row = &sav_write_compressed_row; writer->callbacks.module_ctx_free = &free; #if HAVE_ZLIB } else if (writer->compression == READSTAT_COMPRESS_BINARY) { writer->callbacks.write_row = &zsav_write_compressed_row; writer->callbacks.end_data = &zsav_end_data; writer->callbacks.module_ctx_free = (readstat_module_ctx_free_callback)&zsav_ctx_free; #endif } else if (writer->compression == READSTAT_COMPRESS_NONE) { /* void */ } else { return READSTAT_ERROR_UNSUPPORTED_COMPRESSION; } return readstat_begin_writing_file(writer, user_ctx, row_count); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_spss.c0000644000076500000240000002151314674240614017052 0ustar00dialout #include #include #include "../readstat.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "readstat_spss.h" #include "readstat_spss_parse.h" static char spss_type_strings[][16] = { [SPSS_FORMAT_TYPE_A] = "A", [SPSS_FORMAT_TYPE_AHEX] = "AHEX", [SPSS_FORMAT_TYPE_COMMA] = "COMMA", [SPSS_FORMAT_TYPE_DOLLAR] = "DOLLAR", [SPSS_FORMAT_TYPE_F] = "F", [SPSS_FORMAT_TYPE_IB] = "IB", [SPSS_FORMAT_TYPE_PIBHEX] = "PIBHEX", [SPSS_FORMAT_TYPE_P] = "P", [SPSS_FORMAT_TYPE_PIB] = "PIB", [SPSS_FORMAT_TYPE_PK] = "PK", [SPSS_FORMAT_TYPE_RB] = "RB", [SPSS_FORMAT_TYPE_RBHEX] = "RBHEX", [SPSS_FORMAT_TYPE_Z] = "Z", [SPSS_FORMAT_TYPE_N] = "N", [SPSS_FORMAT_TYPE_E] = "E", [SPSS_FORMAT_TYPE_DATE] = "DATE", [SPSS_FORMAT_TYPE_TIME] = "TIME", [SPSS_FORMAT_TYPE_DATETIME] = "DATETIME", [SPSS_FORMAT_TYPE_ADATE] = "ADATE", [SPSS_FORMAT_TYPE_JDATE] = "JDATE", [SPSS_FORMAT_TYPE_DTIME] = "DTIME", [SPSS_FORMAT_TYPE_WKDAY] = "WKDAY", [SPSS_FORMAT_TYPE_MONTH] = "MONTH", [SPSS_FORMAT_TYPE_MOYR] = "MOYR", [SPSS_FORMAT_TYPE_QYR] = "QYR", [SPSS_FORMAT_TYPE_WKYR] = "WKYR", [SPSS_FORMAT_TYPE_PCT] = "PCT", [SPSS_FORMAT_TYPE_DOT] = "DOT", [SPSS_FORMAT_TYPE_CCA] = "CCA", [SPSS_FORMAT_TYPE_CCB] = "CCB", [SPSS_FORMAT_TYPE_CCC] = "CCC", [SPSS_FORMAT_TYPE_CCD] = "CCD", [SPSS_FORMAT_TYPE_CCE] = "CCE", [SPSS_FORMAT_TYPE_EDATE] = "EDATE", [SPSS_FORMAT_TYPE_SDATE] = "SDATE", [SPSS_FORMAT_TYPE_MTIME] = "MTIME", [SPSS_FORMAT_TYPE_YMDHMS] = "YMDHMS", }; int spss_format(char *buffer, size_t len, spss_format_t *format) { if (format->type < 0 || format->type >= sizeof(spss_type_strings)/sizeof(spss_type_strings[0]) || spss_type_strings[format->type][0] == '\0') { return 0; } char *string = spss_type_strings[format->type]; if (format->decimal_places || format->type == SPSS_FORMAT_TYPE_F) { snprintf(buffer, len, "%s%d.%d", string, format->width, format->decimal_places); } else if (format->width) { snprintf(buffer, len, "%s%d", string, format->width); } else { snprintf(buffer, len, "%s", string); } return 1; } int spss_varinfo_compare(const void *elem1, const void *elem2) { int offset = *(int *)elem1; const spss_varinfo_t *v = *(const spss_varinfo_t **)elem2; if (offset < v->offset) return -1; return (offset > v->offset); } void spss_varinfo_free(spss_varinfo_t *info) { if (info) { if (info->label) free(info->label); free(info); } } uint64_t spss_64bit_value(readstat_value_t value) { double dval = readstat_double_value(value); uint64_t special_val; memcpy(&special_val, &dval, sizeof(double)); if (isinf(dval)) { if (dval < 0.0) { special_val = SAV_LOWEST_DOUBLE; } else { special_val = SAV_HIGHEST_DOUBLE; } } else if (isnan(dval)) { special_val = SAV_MISSING_DOUBLE; } return special_val; } static readstat_value_t spss_boxed_double_value(double fp_value) { readstat_value_t value = { .type = READSTAT_TYPE_DOUBLE, .v = { .double_value = fp_value }, .is_system_missing = isnan(fp_value) }; return value; } static readstat_value_t spss_boxed_string_value(const char *string) { readstat_value_t value = { .type = READSTAT_TYPE_STRING, .v = { .string_value = string } }; return value; } static readstat_value_t spss_boxed_missing_value(spss_varinfo_t *info, int i) { if (info->type == READSTAT_TYPE_DOUBLE) { return spss_boxed_double_value(info->missing_double_values[i]); } return spss_boxed_string_value(info->missing_string_values[i]); } readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info) { readstat_missingness_t missingness; memset(&missingness, '\0', sizeof(readstat_missingness_t)); if (info->missing_range) { missingness.missing_ranges_count++; missingness.missing_ranges[0] = spss_boxed_missing_value(info, 0); missingness.missing_ranges[1] = spss_boxed_missing_value(info, 1); if (info->n_missing_values == 3) { missingness.missing_ranges_count++; missingness.missing_ranges[2] = missingness.missing_ranges[3] = spss_boxed_missing_value(info, 2); } } else if (info->n_missing_values > 0) { missingness.missing_ranges_count = info->n_missing_values; int i=0; for (i=0; in_missing_values; i++) { missingness.missing_ranges[2*i] = missingness.missing_ranges[2*i+1] = spss_boxed_missing_value(info, i); } } return missingness; } readstat_variable_t *spss_init_variable_for_info(spss_varinfo_t *info, int index_after_skipping, iconv_t converter) { readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t)); variable->index = info->index; variable->index_after_skipping = index_after_skipping; variable->type = info->type; if (info->string_length) { variable->storage_width = info->string_length; } else { variable->storage_width = 8 * info->width; } if (info->longname[0]) { readstat_convert(variable->name, sizeof(variable->name), info->longname, sizeof(info->longname), converter); } else { readstat_convert(variable->name, sizeof(variable->name), info->name, sizeof(info->name), converter); } if (info->label) { snprintf(variable->label, sizeof(variable->label), "%s", info->label); } spss_format(variable->format, sizeof(variable->format), &info->print_format); variable->missingness = spss_missingness_for_info(info); variable->measure = info->measure; if (info->display_width) { variable->display_width = info->display_width; } else { variable->display_width = info->print_format.width; } return variable; } uint32_t spss_measure_from_readstat_measure(readstat_measure_t measure) { uint32_t sav_measure = SAV_MEASURE_UNKNOWN; if (measure == READSTAT_MEASURE_NOMINAL) { sav_measure = SAV_MEASURE_NOMINAL; } else if (measure == READSTAT_MEASURE_ORDINAL) { sav_measure = SAV_MEASURE_ORDINAL; } else if (measure == READSTAT_MEASURE_SCALE) { sav_measure = SAV_MEASURE_SCALE; } return sav_measure; } readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure) { if (sav_measure == SAV_MEASURE_NOMINAL) return READSTAT_MEASURE_NOMINAL; if (sav_measure == SAV_MEASURE_ORDINAL) return READSTAT_MEASURE_ORDINAL; if (sav_measure == SAV_MEASURE_SCALE) return READSTAT_MEASURE_SCALE; return READSTAT_MEASURE_UNKNOWN; } uint32_t spss_alignment_from_readstat_alignment(readstat_alignment_t alignment) { uint32_t sav_alignment = 0; if (alignment == READSTAT_ALIGNMENT_LEFT) { sav_alignment = SAV_ALIGNMENT_LEFT; } else if (alignment == READSTAT_ALIGNMENT_CENTER) { sav_alignment = SAV_ALIGNMENT_CENTER; } else if (alignment == READSTAT_ALIGNMENT_RIGHT) { sav_alignment = SAV_ALIGNMENT_RIGHT; } return sav_alignment; } readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment) { if (sav_alignment == SAV_ALIGNMENT_LEFT) return READSTAT_ALIGNMENT_LEFT; if (sav_alignment == SAV_ALIGNMENT_CENTER) return READSTAT_ALIGNMENT_CENTER; if (sav_alignment == SAV_ALIGNMENT_RIGHT) return READSTAT_ALIGNMENT_RIGHT; return READSTAT_ALIGNMENT_UNKNOWN; } readstat_error_t spss_format_for_variable(readstat_variable_t *r_variable, spss_format_t *spss_format) { readstat_error_t retval = READSTAT_OK; memset(spss_format, 0, sizeof(spss_format_t)); if (r_variable->type == READSTAT_TYPE_STRING) { spss_format->type = SPSS_FORMAT_TYPE_A; if (r_variable->display_width) { spss_format->width = r_variable->display_width; } else if (r_variable->user_width) { spss_format->width = r_variable->user_width; } else { spss_format->width = r_variable->storage_width; } } else { spss_format->type = SPSS_FORMAT_TYPE_F; if (r_variable->display_width) { spss_format->width = r_variable->display_width; } else { spss_format->width = 8; } if (r_variable->type == READSTAT_TYPE_DOUBLE || r_variable->type == READSTAT_TYPE_FLOAT) { spss_format->decimal_places = 2; } } if (r_variable->format[0]) { spss_format->decimal_places = 0; const char *fmt = r_variable->format; if (spss_parse_format(fmt, strlen(fmt), spss_format) != READSTAT_OK) { retval = READSTAT_ERROR_BAD_FORMAT_STRING; goto cleanup; } } cleanup: return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_spss.h0000644000076500000240000000761714674240614017070 0ustar00dialout #define SPSS_FORMAT_TYPE_A 1 #define SPSS_FORMAT_TYPE_AHEX 2 #define SPSS_FORMAT_TYPE_COMMA 3 #define SPSS_FORMAT_TYPE_DOLLAR 4 #define SPSS_FORMAT_TYPE_F 5 #define SPSS_FORMAT_TYPE_IB 6 #define SPSS_FORMAT_TYPE_PIBHEX 7 #define SPSS_FORMAT_TYPE_P 8 #define SPSS_FORMAT_TYPE_PIB 9 #define SPSS_FORMAT_TYPE_PK 10 #define SPSS_FORMAT_TYPE_RB 11 #define SPSS_FORMAT_TYPE_RBHEX 12 #define SPSS_FORMAT_TYPE_Z 15 #define SPSS_FORMAT_TYPE_N 16 #define SPSS_FORMAT_TYPE_E 17 #define SPSS_FORMAT_TYPE_DATE 20 #define SPSS_FORMAT_TYPE_TIME 21 #define SPSS_FORMAT_TYPE_DATETIME 22 #define SPSS_FORMAT_TYPE_ADATE 23 #define SPSS_FORMAT_TYPE_JDATE 24 #define SPSS_FORMAT_TYPE_DTIME 25 #define SPSS_FORMAT_TYPE_WKDAY 26 #define SPSS_FORMAT_TYPE_MONTH 27 #define SPSS_FORMAT_TYPE_MOYR 28 #define SPSS_FORMAT_TYPE_QYR 29 #define SPSS_FORMAT_TYPE_WKYR 30 #define SPSS_FORMAT_TYPE_PCT 31 #define SPSS_FORMAT_TYPE_DOT 32 #define SPSS_FORMAT_TYPE_CCA 33 #define SPSS_FORMAT_TYPE_CCB 34 #define SPSS_FORMAT_TYPE_CCC 35 #define SPSS_FORMAT_TYPE_CCD 36 #define SPSS_FORMAT_TYPE_CCE 37 #define SPSS_FORMAT_TYPE_EDATE 38 #define SPSS_FORMAT_TYPE_SDATE 39 #define SPSS_FORMAT_TYPE_MTIME 40 #define SPSS_FORMAT_TYPE_YMDHMS 41 #define SPSS_DOC_LINE_SIZE 80 #define SAV_HIGHEST_DOUBLE 0x7FEFFFFFFFFFFFFFUL #define SAV_MISSING_DOUBLE 0xFFEFFFFFFFFFFFFFUL #define SAV_LOWEST_DOUBLE 0xFFEFFFFFFFFFFFFEUL #define SAV_MEASURE_UNKNOWN 0 #define SAV_MEASURE_NOMINAL 1 #define SAV_MEASURE_ORDINAL 2 #define SAV_MEASURE_SCALE 3 #define SAV_ALIGNMENT_LEFT 0 #define SAV_ALIGNMENT_RIGHT 1 #define SAV_ALIGNMENT_CENTER 2 #include typedef struct spss_format_s { int type; int width; int decimal_places; } spss_format_t; // The reason some fields are stored unconverted is that some versions of SPSS // store truncated UTF-8 in the fields, and also use the truncated strings for // internal logic (such as matching names). If we convert them too early, the // last character of a truncated string will be dropped, and some of the column // information won't be found (e.g. in the key=value long variable record). typedef struct spss_varinfo_s { readstat_type_t type; int labels_index; int index; int offset; int width; unsigned int string_length; spss_format_t print_format; spss_format_t write_format; int n_segments; int n_missing_values; int missing_range; double missing_double_values[3]; char missing_string_values[3][8*4+1]; // stored UTF-8 char name[8+1]; // stored UNCONVERTED char longname[64+1]; // stored UNCONVERTED char *label; // stored UTF-8 readstat_measure_t measure; readstat_alignment_t alignment; int display_width; } spss_varinfo_t; int spss_format(char *buffer, size_t len, spss_format_t *format); int spss_varinfo_compare(const void *elem1, const void *elem2); void spss_varinfo_free(spss_varinfo_t *info); readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info); readstat_variable_t *spss_init_variable_for_info(spss_varinfo_t *info, int index_after_skipping, iconv_t converter); uint64_t spss_64bit_value(readstat_value_t value); uint32_t spss_measure_from_readstat_measure(readstat_measure_t measure); readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure); uint32_t spss_alignment_from_readstat_alignment(readstat_alignment_t alignment); readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment); readstat_error_t spss_format_for_variable(readstat_variable_t *r_variable, spss_format_t *spss_format); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_spss_parse.c0000644000076500000240000004606214674240614020252 0ustar00dialout#line 1 "src/spss/readstat_spss_parse.rl" #include #include "../readstat.h" #include "readstat_spss.h" #include "readstat_spss_parse.h" #line 11 "src/spss/readstat_spss_parse.c" static const signed char _spss_format_parser_actions[] = { 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20, 1, 21, 1, 22, 1, 23, 1, 24, 1, 25, 1, 26, 1, 27, 1, 28, 1, 29, 1, 30, 1, 31, 1, 32, 1, 33, 1, 34, 1, 35, 1, 36, 1, 37, 1, 38, 1, 39, 1, 40, 2, 0, 1, 3, 4, 0, 1, 3, 5, 0, 1, 3, 6, 0, 1, 3, 7, 0, 1, 3, 8, 0, 1, 3, 9, 0, 1, 3, 10, 0, 1, 3, 11, 0, 1, 3, 12, 0, 1, 3, 13, 0, 1, 3, 14, 0, 1, 3, 15, 0, 1, 3, 16, 0, 1, 3, 17, 0, 1, 3, 18, 0, 1, 3, 19, 0, 1, 3, 20, 0, 1, 3, 21, 0, 1, 3, 22, 0, 1, 3, 23, 0, 1, 3, 24, 0, 1, 3, 25, 0, 1, 3, 26, 0, 1, 3, 27, 0, 1, 3, 28, 0, 1, 3, 29, 0, 1, 3, 30, 0, 1, 3, 31, 0, 1, 3, 32, 0, 1, 3, 33, 0, 1, 3, 34, 0, 1, 3, 35, 0, 1, 3, 36, 0, 1, 3, 37, 0, 1, 3, 38, 0, 1, 3, 39, 0, 1, 3, 40, 0, 1, 0 }; static const short _spss_format_parser_key_offsets[] = { 0, 0, 34, 36, 38, 40, 42, 44, 46, 50, 60, 62, 64, 66, 72, 74, 76, 78, 80, 82, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 118, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 172, 174, 176, 178, 180, 182, 184, 186, 188, 194, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 219, 221, 223, 225, 227, 231, 233, 235, 237, 239, 241, 243, 245, 247, 255, 257, 261, 263, 265, 267, 271, 273, 275, 277, 279, 281, 283, 0 }; static const char _spss_format_parser_trans_keys[] = { 65, 67, 68, 69, 70, 73, 74, 77, 78, 80, 81, 82, 83, 84, 87, 89, 90, 97, 99, 100, 101, 102, 105, 106, 109, 110, 112, 113, 114, 115, 116, 119, 121, 122, 48, 57, 65, 97, 84, 116, 69, 101, 69, 101, 88, 120, 67, 79, 99, 111, 65, 66, 67, 68, 69, 97, 98, 99, 100, 101, 77, 109, 77, 109, 65, 97, 65, 79, 84, 97, 111, 116, 84, 116, 69, 101, 73, 105, 77, 109, 69, 101, 76, 84, 108, 116, 76, 108, 65, 97, 82, 114, 73, 105, 77, 109, 69, 101, 65, 97, 84, 116, 69, 101, 66, 98, 68, 100, 65, 97, 84, 116, 69, 101, 79, 84, 111, 116, 78, 89, 110, 121, 84, 116, 72, 104, 82, 114, 73, 105, 77, 109, 69, 101, 84, 116, 66, 98, 69, 101, 88, 120, 89, 121, 82, 114, 66, 98, 69, 101, 88, 120, 68, 100, 65, 97, 84, 116, 69, 101, 73, 105, 77, 109, 69, 101, 75, 107, 68, 89, 100, 121, 65, 97, 89, 121, 82, 114, 77, 109, 68, 100, 72, 104, 77, 109, 83, 115, 68, 72, 100, 104, 48, 57, 46, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 84, 116, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 68, 100, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 67, 73, 75, 99, 105, 107, 48, 57, 48, 57, 72, 104, 48, 57, 48, 57, 48, 57, 48, 57, 72, 104, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 0 }; static const signed char _spss_format_parser_single_lengths[] = { 0, 34, 0, 2, 2, 2, 2, 2, 4, 10, 2, 2, 2, 6, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0 }; static const signed char _spss_format_parser_range_lengths[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; static const short _spss_format_parser_index_offsets[] = { 0, 0, 35, 37, 40, 43, 46, 49, 52, 57, 68, 71, 74, 77, 84, 87, 90, 93, 96, 99, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 151, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 230, 233, 236, 239, 242, 245, 248, 251, 254, 260, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 285, 287, 289, 291, 293, 297, 299, 301, 303, 305, 307, 309, 311, 313, 321, 323, 327, 329, 331, 333, 337, 339, 341, 343, 345, 347, 349, 0 }; static const signed char _spss_format_parser_cond_targs[] = { 68, 8, 13, 84, 86, 29, 30, 34, 92, 93, 46, 48, 51, 55, 58, 63, 106, 68, 8, 13, 84, 86, 29, 30, 34, 92, 93, 46, 48, 51, 55, 58, 63, 106, 0, 70, 0, 4, 4, 0, 5, 5, 0, 71, 71, 0, 7, 7, 0, 72, 72, 0, 9, 10, 9, 10, 0, 73, 74, 75, 76, 77, 73, 74, 75, 76, 77, 0, 11, 11, 0, 12, 12, 0, 78, 78, 0, 14, 19, 23, 14, 19, 23, 0, 15, 15, 0, 79, 79, 0, 17, 17, 0, 18, 18, 0, 80, 80, 0, 20, 82, 20, 82, 0, 21, 21, 0, 22, 22, 0, 81, 81, 0, 24, 24, 0, 25, 25, 0, 83, 83, 0, 27, 27, 0, 28, 28, 0, 85, 85, 0, 87, 87, 0, 31, 31, 0, 32, 32, 0, 33, 33, 0, 88, 88, 0, 35, 39, 35, 39, 0, 36, 38, 36, 38, 0, 37, 37, 0, 89, 89, 0, 90, 90, 0, 40, 40, 0, 41, 41, 0, 91, 91, 0, 94, 94, 0, 95, 95, 0, 45, 45, 0, 96, 96, 0, 47, 47, 0, 98, 98, 0, 99, 99, 0, 50, 50, 0, 100, 100, 0, 52, 52, 0, 53, 53, 0, 54, 54, 0, 101, 101, 0, 56, 56, 0, 57, 57, 0, 102, 102, 0, 59, 59, 0, 60, 62, 60, 62, 0, 61, 61, 0, 103, 103, 0, 104, 104, 0, 64, 64, 0, 65, 65, 0, 66, 66, 0, 67, 67, 0, 105, 105, 0, 3, 6, 3, 6, 69, 0, 2, 69, 0, 70, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 16, 16, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 26, 26, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 42, 43, 97, 42, 43, 97, 69, 0, 69, 0, 44, 44, 69, 0, 69, 0, 69, 0, 69, 0, 49, 49, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 69, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 0 }; static const short _spss_format_parser_cond_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 0, 3, 1, 0, 1, 0, 160, 0, 88, 0, 204, 0, 208, 0, 212, 0, 216, 0, 220, 0, 92, 0, 0, 0, 144, 0, 152, 0, 96, 0, 200, 0, 168, 0, 0, 0, 140, 0, 224, 0, 100, 0, 104, 0, 164, 0, 180, 0, 184, 0, 172, 0, 136, 0, 0, 0, 0, 0, 0, 0, 112, 0, 196, 0, 0, 0, 116, 0, 108, 0, 120, 0, 188, 0, 0, 0, 124, 0, 128, 0, 228, 0, 148, 0, 176, 0, 192, 0, 156, 0, 132, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 5, 45, 9, 67, 69, 71, 73, 75, 11, 37, 41, 13, 65, 49, 35, 77, 15, 17, 47, 55, 57, 51, 33, 21, 63, 23, 19, 25, 59, 27, 29, 79, 39, 53, 61, 43, 31, 0 }; static const short _spss_format_parser_eof_trans[] = { 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 0 }; static const int spss_format_parser_start = 1; static const int spss_format_parser_en_main = 1; #line 11 "src/spss/readstat_spss_parse.rl" // For minimum width information see // https://www.ibm.com/support/knowledgecenter/SSLVMB_sub/statistics_reference_project_ddita/spss/base/syn_date_and_time_date_time_formats.html readstat_error_t spss_parse_format(const char *data, int count, spss_format_t *fmt) { unsigned char *p = (unsigned char *)data; unsigned char *pe = (unsigned char *)data + count; unsigned char *eof = pe; int cs; unsigned int integer = 0; #line 310 "src/spss/readstat_spss_parse.c" { cs = (int)spss_format_parser_start; } #line 315 "src/spss/readstat_spss_parse.c" { int _klen; unsigned int _trans = 0; const char * _keys; const signed char * _acts; unsigned int _nacts; _resume: {} if ( p == pe && p != eof ) goto _out; if ( p == eof ) { if ( _spss_format_parser_eof_trans[cs] > 0 ) { _trans = (unsigned int)_spss_format_parser_eof_trans[cs] - 1; } } else { _keys = ( _spss_format_parser_trans_keys + (_spss_format_parser_key_offsets[cs])); _trans = (unsigned int)_spss_format_parser_index_offsets[cs]; _klen = (int)_spss_format_parser_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + _klen - 1; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _keys += _klen; _trans += (unsigned int)_klen; break; } _mid = _lower + ((_upper-_lower) >> 1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 1; else if ( ( (*( p))) > (*( _mid)) ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } } _klen = (int)_spss_format_parser_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + (_klen<<1) - 2; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _trans += (unsigned int)_klen; break; } _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 2; else if ( ( (*( p))) > (*( _mid + 1)) ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); break; } } } _match: {} } cs = (int)_spss_format_parser_cond_targs[_trans]; if ( _spss_format_parser_cond_actions[_trans] != 0 ) { _acts = ( _spss_format_parser_actions + (_spss_format_parser_cond_actions[_trans])); _nacts = (unsigned int)(*( _acts)); _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts)) ) { case 0: { { #line 24 "src/spss/readstat_spss_parse.rl" integer = 0; } #line 400 "src/spss/readstat_spss_parse.c" break; } case 1: { { #line 28 "src/spss/readstat_spss_parse.rl" integer = 10 * integer + ((( (*( p)))) - '0'); } #line 411 "src/spss/readstat_spss_parse.c" break; } case 2: { { #line 32 "src/spss/readstat_spss_parse.rl" fmt->width = integer; } #line 422 "src/spss/readstat_spss_parse.c" break; } case 3: { { #line 36 "src/spss/readstat_spss_parse.rl" fmt->decimal_places = integer; } #line 433 "src/spss/readstat_spss_parse.c" break; } case 4: { { #line 40 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_A; } #line 442 "src/spss/readstat_spss_parse.c" break; } case 5: { { #line 41 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_AHEX; } #line 451 "src/spss/readstat_spss_parse.c" break; } case 6: { { #line 42 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_COMMA; } #line 460 "src/spss/readstat_spss_parse.c" break; } case 7: { { #line 43 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_DOLLAR; } #line 469 "src/spss/readstat_spss_parse.c" break; } case 8: { { #line 44 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_F; } #line 478 "src/spss/readstat_spss_parse.c" break; } case 9: { { #line 45 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_IB; } #line 487 "src/spss/readstat_spss_parse.c" break; } case 10: { { #line 46 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_PIBHEX; } #line 496 "src/spss/readstat_spss_parse.c" break; } case 11: { { #line 47 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_P; } #line 505 "src/spss/readstat_spss_parse.c" break; } case 12: { { #line 48 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_PIB; } #line 514 "src/spss/readstat_spss_parse.c" break; } case 13: { { #line 49 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_PK; } #line 523 "src/spss/readstat_spss_parse.c" break; } case 14: { { #line 50 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_RB; } #line 532 "src/spss/readstat_spss_parse.c" break; } case 15: { { #line 51 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_RBHEX; } #line 541 "src/spss/readstat_spss_parse.c" break; } case 16: { { #line 52 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_Z; } #line 550 "src/spss/readstat_spss_parse.c" break; } case 17: { { #line 53 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_N; } #line 559 "src/spss/readstat_spss_parse.c" break; } case 18: { { #line 54 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_E; } #line 568 "src/spss/readstat_spss_parse.c" break; } case 19: { { #line 55 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_DATE; fmt->width = 11; } #line 577 "src/spss/readstat_spss_parse.c" break; } case 20: { { #line 56 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_TIME; } #line 586 "src/spss/readstat_spss_parse.c" break; } case 21: { { #line 57 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_DATETIME; fmt->width = 20; } #line 595 "src/spss/readstat_spss_parse.c" break; } case 22: { { #line 58 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_YMDHMS; fmt->width = 19; } #line 604 "src/spss/readstat_spss_parse.c" break; } case 23: { { #line 59 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_ADATE; fmt->width = 10; } #line 613 "src/spss/readstat_spss_parse.c" break; } case 24: { { #line 60 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_JDATE; } #line 622 "src/spss/readstat_spss_parse.c" break; } case 25: { { #line 61 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_DTIME; fmt->width = 23; } #line 631 "src/spss/readstat_spss_parse.c" break; } case 26: { { #line 62 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_MTIME; } #line 640 "src/spss/readstat_spss_parse.c" break; } case 27: { { #line 63 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_WKDAY; } #line 649 "src/spss/readstat_spss_parse.c" break; } case 28: { { #line 64 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_MONTH; } #line 658 "src/spss/readstat_spss_parse.c" break; } case 29: { { #line 65 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_MOYR; } #line 667 "src/spss/readstat_spss_parse.c" break; } case 30: { { #line 66 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_QYR; } #line 676 "src/spss/readstat_spss_parse.c" break; } case 31: { { #line 67 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_WKYR; fmt->width = 10; } #line 685 "src/spss/readstat_spss_parse.c" break; } case 32: { { #line 68 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_PCT; } #line 694 "src/spss/readstat_spss_parse.c" break; } case 33: { { #line 69 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_DOT; } #line 703 "src/spss/readstat_spss_parse.c" break; } case 34: { { #line 70 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_CCA; } #line 712 "src/spss/readstat_spss_parse.c" break; } case 35: { { #line 71 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_CCB; } #line 721 "src/spss/readstat_spss_parse.c" break; } case 36: { { #line 72 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_CCC; } #line 730 "src/spss/readstat_spss_parse.c" break; } case 37: { { #line 73 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_CCD; } #line 739 "src/spss/readstat_spss_parse.c" break; } case 38: { { #line 74 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_CCE; } #line 748 "src/spss/readstat_spss_parse.c" break; } case 39: { { #line 75 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_EDATE; fmt->width = 10; } #line 757 "src/spss/readstat_spss_parse.c" break; } case 40: { { #line 76 "src/spss/readstat_spss_parse.rl" fmt->type = SPSS_FORMAT_TYPE_SDATE; fmt->width = 10; } #line 766 "src/spss/readstat_spss_parse.c" break; } } _nacts -= 1; _acts += 1; } } if ( p == eof ) { if ( cs >= 68 ) goto _out; } else { if ( cs != 0 ) { p += 1; goto _resume; } } _out: {} } #line 89 "src/spss/readstat_spss_parse.rl" /* suppress warning */ (void)spss_format_parser_en_main; if (cs < #line 797 "src/spss/readstat_spss_parse.c" 68 #line 94 "src/spss/readstat_spss_parse.rl" || p != eof) { return READSTAT_ERROR_PARSE; } return READSTAT_OK; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_spss_parse.h0000644000076500000240000000012614674240614020246 0ustar00dialout readstat_error_t spss_parse_format(const char *data, int count, spss_format_t *fmt); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_zsav_compress.c0000644000076500000240000000651314674240614020763 0ustar00dialout #include #include #include #include "readstat_zsav_compress.h" zsav_ctx_t *zsav_ctx_init(size_t max_row_len, int64_t offset) { zsav_ctx_t *ctx = calloc(1, sizeof(zsav_ctx_t)); ctx->buffer = malloc(max_row_len); ctx->blocks_capacity = 10; ctx->blocks = calloc(ctx->blocks_capacity, sizeof(zsav_block_t *)); ctx->uncompressed_block_size = 0x3FF000; ctx->zheader_ofs = offset; ctx->compression_level = Z_DEFAULT_COMPRESSION; return ctx; } void zsav_ctx_free(zsav_ctx_t *ctx) { int i; for (i=0; iblocks_count; i++) { zsav_block_t *block = ctx->blocks[i]; deflateEnd(&block->stream); free(block->compressed_data); free(block); } free(ctx->blocks); free(ctx->buffer); free(ctx); } zsav_block_t *zsav_add_block(zsav_ctx_t *ctx) { zsav_block_t *block = NULL; if (ctx->blocks_count == ctx->blocks_capacity) { ctx->blocks = realloc(ctx->blocks, (ctx->blocks_capacity *= 2 ) * sizeof(zsav_block_t *)); } block = calloc(1, sizeof(zsav_block_t)); ctx->blocks[ctx->blocks_count++] = block; deflateInit(&block->stream, ctx->compression_level); block->compressed_data_capacity = deflateBound(&block->stream, ctx->uncompressed_block_size); block->compressed_data = malloc(block->compressed_data_capacity); return block; } zsav_block_t *zsav_current_block(zsav_ctx_t *ctx) { if (ctx->blocks_count == 0) return NULL; return ctx->blocks[ctx->blocks_count-1]; } int zsav_compress_row(void *input, size_t input_len, int finish, zsav_ctx_t *ctx) { off_t row_off = 0; unsigned char *row_buffer = input; size_t row_len = input_len; zsav_block_t *block = zsav_current_block(ctx); int deflate_status = Z_OK; if (block == NULL) { block = zsav_add_block(ctx); } block->stream.next_in = row_buffer; block->stream.avail_in = row_len; block->stream.next_out = &block->compressed_data[block->compressed_size]; block->stream.avail_out = block->compressed_data_capacity - block->compressed_size; /* If the row won't fit into this block, keep writing and flushing * until the remainder fits. */ while (row_len - row_off > ctx->uncompressed_block_size - block->uncompressed_size) { block->stream.avail_in = ctx->uncompressed_block_size - block->uncompressed_size; row_off += ctx->uncompressed_block_size - block->uncompressed_size; if ((deflate_status = deflate(&block->stream, Z_FINISH)) != Z_STREAM_END) { goto cleanup; } block->compressed_size = block->compressed_data_capacity - block->stream.avail_out; block->uncompressed_size = ctx->uncompressed_block_size - block->stream.avail_in; block = zsav_add_block(ctx); block->stream.next_in = &row_buffer[row_off]; block->stream.avail_in = row_len - row_off; block->stream.next_out = block->compressed_data; block->stream.avail_out = block->compressed_data_capacity; } /* Now the rest of the row will fit in the block */ deflate_status = deflate(&block->stream, finish ? Z_FINISH : Z_NO_FLUSH); block->compressed_size = block->compressed_data_capacity - block->stream.avail_out; block->uncompressed_size += (row_len - row_off) - block->stream.avail_in; cleanup: return deflate_status; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_zsav_compress.h0000644000076500000240000000144414674240614020766 0ustar00dialout typedef struct zsav_block_s { int32_t uncompressed_size; int32_t compressed_size; z_stream stream; unsigned char *compressed_data; size_t compressed_data_capacity; } zsav_block_t; typedef struct zsav_ctx_s { void *buffer; zsav_block_t **blocks; int blocks_count; int blocks_capacity; int64_t uncompressed_block_size; int64_t zheader_ofs; int compression_level; } zsav_ctx_t; zsav_ctx_t *zsav_ctx_init(size_t max_row_len, int64_t offset); void zsav_ctx_free(zsav_ctx_t *ctx); zsav_block_t *zsav_add_block(zsav_ctx_t *ctx); zsav_block_t *zsav_current_block(zsav_ctx_t *ctx); int zsav_compress_row(void *input, size_t input_len, int finish, zsav_ctx_t *zctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_zsav_read.c0000644000076500000240000001452314674240614020043 0ustar00dialout#include #include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "../readstat_malloc.h" #include "readstat_sav.h" #include "readstat_sav_compress.h" struct zheader { uint64_t zheader_ofs; uint64_t ztrailer_ofs; uint64_t ztrailer_len; }; struct ztrailer { int64_t bias; int64_t zero; int32_t block_size; int32_t n_blocks; }; struct ztrailer_entry { int64_t uncompressed_ofs; int64_t compressed_ofs; int32_t uncompressed_size; int32_t compressed_size; }; readstat_error_t zsav_read_compressed_data(sav_ctx_t *ctx, readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; readstat_off_t data_offset = 0; size_t uncompressed_row_len = ctx->var_offset * 8; readstat_off_t uncompressed_offset = 0; unsigned char *uncompressed_row = NULL; uLongf uncompressed_block_len = 0; unsigned char *compressed_block = NULL, *uncompressed_block = NULL; struct sav_row_stream_s state = { .missing_value = ctx->missing_double, .bias = ctx->bias, .bswap = ctx->bswap }; struct zheader zheader; struct ztrailer ztrailer; struct ztrailer_entry *ztrailer_entries = NULL; int n_blocks = 0; int block_i = 0; int i; if (io->read(&zheader, sizeof(struct zheader), io->io_ctx) < sizeof(struct zheader)) { retval = READSTAT_ERROR_READ; goto cleanup; } zheader.zheader_ofs = ctx->bswap ? byteswap8(zheader.zheader_ofs) : zheader.zheader_ofs; zheader.ztrailer_ofs = ctx->bswap ? byteswap8(zheader.ztrailer_ofs) : zheader.ztrailer_ofs; zheader.ztrailer_len = ctx->bswap ? byteswap8(zheader.ztrailer_len) : zheader.ztrailer_len; if (zheader.zheader_ofs != io->seek(0, READSTAT_SEEK_CUR, io->io_ctx) - sizeof(struct zheader)) { retval = READSTAT_ERROR_PARSE; goto cleanup; } n_blocks = (zheader.ztrailer_len - 24) / 24; if (io->seek(zheader.ztrailer_ofs, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->read(&ztrailer, sizeof(struct ztrailer), io->io_ctx) < sizeof(struct ztrailer)) { retval = READSTAT_ERROR_READ; goto cleanup; } ztrailer.bias = ctx->bswap ? byteswap8(ztrailer.bias) : ztrailer.bias; ztrailer.zero = ctx->bswap ? byteswap8(ztrailer.zero) : ztrailer.zero; ztrailer.block_size = ctx->bswap ? byteswap4(ztrailer.block_size) : ztrailer.block_size; ztrailer.n_blocks = ctx->bswap ? byteswap4(ztrailer.n_blocks) : ztrailer.n_blocks; if (n_blocks != ztrailer.n_blocks) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (n_blocks && (ztrailer_entries = readstat_malloc(n_blocks * sizeof(struct ztrailer_entry))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (io->read(ztrailer_entries, n_blocks * sizeof(struct ztrailer_entry), io->io_ctx) < n_blocks * sizeof(struct ztrailer_entry)) { retval = READSTAT_ERROR_READ; goto cleanup; } for (i=0; iuncompressed_ofs = ctx->bswap ? byteswap8(entry->uncompressed_ofs) : entry->uncompressed_ofs; entry->compressed_ofs = ctx->bswap ? byteswap8(entry->compressed_ofs) : entry->compressed_ofs; entry->uncompressed_size = ctx->bswap ? byteswap4(entry->uncompressed_size) : entry->uncompressed_size; entry->compressed_size = ctx->bswap ? byteswap4(entry->compressed_size) : entry->compressed_size; } if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } while (1) { if (block_i == n_blocks) goto cleanup; struct ztrailer_entry *entry = &ztrailer_entries[block_i]; if (io->seek(entry->compressed_ofs, READSTAT_SEEK_SET, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } if ((compressed_block = readstat_realloc(compressed_block, entry->compressed_size)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (io->read(compressed_block, entry->compressed_size, io->io_ctx) != entry->compressed_size) { retval = READSTAT_ERROR_READ; goto cleanup; } uncompressed_block_len = entry->uncompressed_size; if ((uncompressed_block = readstat_realloc(uncompressed_block, uncompressed_block_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } int status = uncompress(uncompressed_block, &uncompressed_block_len, compressed_block, entry->compressed_size); if (status != Z_OK || uncompressed_block_len != entry->uncompressed_size) { retval = READSTAT_ERROR_PARSE; goto cleanup; } block_i++; state.status = SAV_ROW_STREAM_HAVE_DATA; data_offset = 0; while (state.status != SAV_ROW_STREAM_NEED_DATA) { state.next_in = &uncompressed_block[data_offset]; state.avail_in = uncompressed_block_len - data_offset; state.next_out = &uncompressed_row[uncompressed_offset]; state.avail_out = uncompressed_row_len - uncompressed_offset; sav_decompress_row(&state); uncompressed_offset = uncompressed_row_len - state.avail_out; data_offset = uncompressed_block_len - state.avail_in; if (state.status == SAV_ROW_STREAM_FINISHED_ROW) { retval = row_handler(uncompressed_row, uncompressed_row_len, ctx); if (retval != READSTAT_OK) goto cleanup; uncompressed_offset = 0; } if (state.status == SAV_ROW_STREAM_FINISHED_ALL) goto cleanup; if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit) goto cleanup; } } cleanup: if (uncompressed_row) free(uncompressed_row); if (ztrailer_entries) free(ztrailer_entries); if (compressed_block) free(compressed_block); if (uncompressed_block) free(uncompressed_block); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_zsav_read.h0000644000076500000240000000021414674240614020040 0ustar00dialout readstat_error_t zsav_read_compressed_data(sav_ctx_t *ctx, readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_zsav_write.c0000644000076500000240000001134214674240614020256 0ustar00dialout#include #include #include #include "../readstat.h" #include "../readstat_writer.h" #include "readstat_sav_compress.h" #include "readstat_zsav_compress.h" #include "readstat_zsav_write.h" readstat_error_t zsav_write_compressed_row(void *writer_ctx, void *row, size_t len) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; zsav_ctx_t *zctx = writer->module_ctx; /* Kind of frustrating that SPSS does double compression. If they just * z-compressed the uncompressed data, we could calculate the block count * in advance and write out the file in a streaming manner. As things stand * we have to build up the file in memory until we know the final block * count. A possible streaming solution would be to declare the number of * blocks required to hold the maximum possible row-compressed size and * then fill out the end with no-op zero bytes (that get z-compressed very * small). */ size_t row_len = sav_compress_row(zctx->buffer, row, len, writer); int deflate_status = zsav_compress_row(zctx->buffer, row_len, writer->current_row + 1 == writer->row_count, zctx); if (deflate_status != Z_OK && deflate_status != Z_STREAM_END) return READSTAT_ERROR_WRITE; return READSTAT_OK; } static readstat_error_t zsav_write_data_header(readstat_writer_t *writer, zsav_ctx_t *zctx) { readstat_error_t retval = READSTAT_OK; uint64_t zheader_ofs = zctx->zheader_ofs; uint64_t ztrailer_ofs = zheader_ofs + 24; uint64_t ztrailer_len = 24 + zctx->blocks_count * 24; int i; for (i=0; iblocks_count; i++) { zsav_block_t *block = zctx->blocks[i]; ztrailer_ofs += block->compressed_size; } if ((retval = readstat_write_bytes(writer, &zheader_ofs, sizeof(uint64_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &ztrailer_ofs, sizeof(uint64_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &ztrailer_len, sizeof(uint64_t))) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t zsav_write_data_blocks(readstat_writer_t *writer, zsav_ctx_t *zctx) { readstat_error_t retval = READSTAT_OK; int i; for (i=0; iblocks_count; i++) { zsav_block_t *block = zctx->blocks[i]; if ((retval = readstat_write_bytes(writer, block->compressed_data, block->compressed_size)) != READSTAT_OK) goto cleanup; } cleanup: return retval; } static readstat_error_t zsav_write_data_trailer(readstat_writer_t *writer, zsav_ctx_t *zctx) { readstat_error_t retval = READSTAT_OK; int64_t bias = -100; int64_t zero = 0; int32_t block_size = zctx->uncompressed_block_size; int32_t n_blocks = zctx->blocks_count; if ((retval = readstat_write_bytes(writer, &bias, sizeof(int64_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &zero, sizeof(int64_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &block_size, sizeof(int32_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &n_blocks, sizeof(int32_t))) != READSTAT_OK) goto cleanup; int i; int64_t uncompressed_ofs = zctx->zheader_ofs; int64_t compressed_ofs = zctx->zheader_ofs + 24; for (i=0; iblocks_count; i++) { zsav_block_t *block = zctx->blocks[i]; int32_t uncompressed_size = block->uncompressed_size; int32_t compressed_size = block->compressed_size; if ((retval = readstat_write_bytes(writer, &uncompressed_ofs, sizeof(int64_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &compressed_ofs, sizeof(int64_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &uncompressed_size, sizeof(int32_t))) != READSTAT_OK) goto cleanup; if ((retval = readstat_write_bytes(writer, &compressed_size, sizeof(int32_t))) != READSTAT_OK) goto cleanup; uncompressed_ofs += uncompressed_size; compressed_ofs += compressed_size; } cleanup: return retval; } readstat_error_t zsav_end_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; zsav_ctx_t *zctx = writer->module_ctx; readstat_error_t retval = READSTAT_OK; retval = zsav_write_data_header(writer, zctx); if (retval != READSTAT_OK) goto cleanup; retval = zsav_write_data_blocks(writer, zctx); if (retval != READSTAT_OK) goto cleanup; retval = zsav_write_data_trailer(writer, zctx); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/spss/readstat_zsav_write.h0000644000076500000240000000021014674240614020253 0ustar00dialout readstat_error_t zsav_write_compressed_row(void *writer_ctx, void *row, size_t len); readstat_error_t zsav_end_data(void *writer_ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/src/stata/0000755000076500000240000000000015134706453014151 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/stata/readstat_dta.c0000644000076500000240000002326614674240614016765 0ustar00dialout#include #include #include #include #include #include "../readstat.h" #include "../readstat_iconv.h" #include "../readstat_malloc.h" #include "../readstat_bits.h" #include "readstat_dta.h" #define DTA_MIN_VERSION 104 #define DTA_MAX_VERSION 119 dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) { dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t)); if (ctx == NULL) { return NULL; } ctx->io = io; ctx->initialized = 0; return ctx; } readstat_error_t dta_ctx_init(dta_ctx_t *ctx, uint32_t nvar, uint64_t nobs, unsigned char byteorder, unsigned char ds_format, const char *input_encoding, const char *output_encoding) { readstat_error_t retval = READSTAT_OK; int machine_byteorder = DTA_HILO; if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION) return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION; if (machine_is_little_endian()) { machine_byteorder = DTA_LOHI; } ctx->bswap = (byteorder != machine_byteorder); ctx->ds_format = ds_format; ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG; ctx->nvar = nvar; ctx->nobs = nobs; if (ctx->nvar) { if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } } ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT; if (ds_format < 105) { ctx->fmtlist_entry_len = 7; } else if (ds_format < 114) { ctx->fmtlist_entry_len = 12; } else if (ds_format < 118) { ctx->fmtlist_entry_len = 49; } else { ctx->fmtlist_entry_len = 57; } if (ds_format >= 117) { ctx->typlist_version = 117; } else if (ds_format >= 111) { ctx->typlist_version = 111; } else { ctx->typlist_version = 0; } if (ds_format >= 118) { ctx->data_label_len_len = 2; ctx->strl_v_len = 2; ctx->strl_o_len = 6; } else if (ds_format >= 117) { ctx->data_label_len_len = 1; ctx->strl_v_len = 4; ctx->strl_o_len = 4; } if (ds_format < 105) { ctx->expansion_len_len = 0; } else if (ds_format < 110) { ctx->expansion_len_len = 2; } else { ctx->expansion_len_len = 4; } if (ds_format < 110) { ctx->lbllist_entry_len = 9; ctx->variable_name_len = 9; ctx->ch_metadata_len = 9; } else if (ds_format < 118) { ctx->lbllist_entry_len = 33; ctx->variable_name_len = 33; ctx->ch_metadata_len = 33; } else { ctx->lbllist_entry_len = 129; ctx->variable_name_len = 129; ctx->ch_metadata_len = 129; } if (ds_format < 108) { ctx->variable_labels_entry_len = 32; ctx->data_label_len = 32; } else if (ds_format < 118) { ctx->variable_labels_entry_len = 81; ctx->data_label_len = 81; } else { ctx->variable_labels_entry_len = 321; ctx->data_label_len = 321; } if (ds_format < 105) { ctx->timestamp_len = 0; ctx->value_label_table_len_len = 2; ctx->value_label_table_labname_len = 12; ctx->value_label_table_padding_len = 2; } else { ctx->timestamp_len = 18; ctx->value_label_table_len_len = 4; if (ds_format < 118) { ctx->value_label_table_labname_len = 33; } else { ctx->value_label_table_labname_len = 129; } ctx->value_label_table_padding_len = 3; } if (ds_format < 117) { ctx->typlist_entry_len = 1; ctx->file_is_xmlish = 0; } else { ctx->typlist_entry_len = 2; ctx->file_is_xmlish = 1; } if (ds_format < 113) { ctx->max_int8 = DTA_OLD_MAX_INT8; ctx->max_int16 = DTA_OLD_MAX_INT16; ctx->max_int32 = DTA_OLD_MAX_INT32; ctx->max_float = DTA_OLD_MAX_FLOAT; ctx->max_double = DTA_OLD_MAX_DOUBLE; } else { ctx->max_int8 = DTA_113_MAX_INT8; ctx->max_int16 = DTA_113_MAX_INT16; ctx->max_int32 = DTA_113_MAX_INT32; ctx->max_float = DTA_113_MAX_FLOAT; ctx->max_double = DTA_113_MAX_DOUBLE; ctx->supports_tagged_missing = 1; } if (output_encoding) { if (input_encoding) { ctx->converter = iconv_open(output_encoding, input_encoding); } else if (ds_format < 118) { ctx->converter = iconv_open(output_encoding, "WINDOWS-1252"); } else if (strcmp(output_encoding, "UTF-8") != 0) { ctx->converter = iconv_open(output_encoding, "UTF-8"); } if (ctx->converter == (iconv_t)-1) { ctx->converter = NULL; retval = READSTAT_ERROR_UNSUPPORTED_CHARSET; goto cleanup; } } if (ds_format < 119) { ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t); } else { ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t); } if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (ctx->nvar > 0) { ctx->typlist_len = ctx->nvar * sizeof(uint16_t); ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char); ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char); ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char); ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char); if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } } ctx->initialized = 1; cleanup: return retval; } void dta_ctx_free(dta_ctx_t *ctx) { if (ctx->typlist) free(ctx->typlist); if (ctx->varlist) free(ctx->varlist); if (ctx->srtlist) free(ctx->srtlist); if (ctx->fmtlist) free(ctx->fmtlist); if (ctx->lbllist) free(ctx->lbllist); if (ctx->variable_labels) free(ctx->variable_labels); if (ctx->converter) iconv_close(ctx->converter); if (ctx->data_label) free(ctx->data_label); if (ctx->variables) { int i; for (i=0; invar; i++) { if (ctx->variables[i]) free(ctx->variables[i]); } free(ctx->variables); } if (ctx->strls) { int i; for (i=0; istrls_count; i++) { free(ctx->strls[i]); } free(ctx->strls); } free(ctx); } readstat_error_t dta_type_info(uint16_t typecode, dta_ctx_t *ctx, size_t *max_len, readstat_type_t *out_type) { readstat_error_t retval = READSTAT_OK; size_t len = 0; readstat_type_t type = READSTAT_TYPE_STRING; if (ctx->typlist_version == 111) { switch (typecode) { case DTA_111_TYPE_CODE_INT8: len = 1; type = READSTAT_TYPE_INT8; break; case DTA_111_TYPE_CODE_INT16: len = 2; type = READSTAT_TYPE_INT16; break; case DTA_111_TYPE_CODE_INT32: len = 4; type = READSTAT_TYPE_INT32; break; case DTA_111_TYPE_CODE_FLOAT: len = 4; type = READSTAT_TYPE_FLOAT; break; case DTA_111_TYPE_CODE_DOUBLE: len = 8; type = READSTAT_TYPE_DOUBLE; break; default: len = typecode; type = READSTAT_TYPE_STRING; break; } } else if (ctx->typlist_version == 117) { switch (typecode) { case DTA_117_TYPE_CODE_INT8: len = 1; type = READSTAT_TYPE_INT8; break; case DTA_117_TYPE_CODE_INT16: len = 2; type = READSTAT_TYPE_INT16; break; case DTA_117_TYPE_CODE_INT32: len = 4; type = READSTAT_TYPE_INT32; break; case DTA_117_TYPE_CODE_FLOAT: len = 4; type = READSTAT_TYPE_FLOAT; break; case DTA_117_TYPE_CODE_DOUBLE: len = 8; type = READSTAT_TYPE_DOUBLE; break; case DTA_117_TYPE_CODE_STRL: len = 8; type = READSTAT_TYPE_STRING_REF; break; default: len = typecode; type = READSTAT_TYPE_STRING; break; } } else if (typecode < 0x7F) { switch (typecode) { case DTA_OLD_TYPE_CODE_INT8: len = 1; type = READSTAT_TYPE_INT8; break; case DTA_OLD_TYPE_CODE_INT16: len = 2; type = READSTAT_TYPE_INT16; break; case DTA_OLD_TYPE_CODE_INT32: len = 4; type = READSTAT_TYPE_INT32; break; case DTA_OLD_TYPE_CODE_FLOAT: len = 4; type = READSTAT_TYPE_FLOAT; break; case DTA_OLD_TYPE_CODE_DOUBLE: len = 8; type = READSTAT_TYPE_DOUBLE; break; default: retval = READSTAT_ERROR_PARSE; break; } } else { len = typecode - 0x7F; type = READSTAT_TYPE_STRING; } if (max_len) *max_len = len; if (out_type) *out_type = type; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/stata/readstat_dta.h0000644000076500000240000001360214674240614016763 0ustar00dialout#pragma pack(push, 1) // DTA files typedef struct dta_header_s { unsigned char ds_format; unsigned char byteorder; unsigned char filetype; unsigned char unused; uint16_t nvar; uint32_t nobs; } dta_header_t; typedef struct dta_header64_s { unsigned char ds_format; unsigned char byteorder; unsigned char filetype; unsigned char unused; uint32_t nvar; uint64_t nobs; } dta_header64_t; /* Some compilers will pack the elements, but still round up * the total size of the structure. So use macros in place of * sizeof(dta_117_strl_header_t)/sizeof(dta_118_strl_header_t). */ typedef struct dta_117_strl_header_s { uint32_t v; uint32_t o; unsigned char type; int32_t len; } dta_117_strl_header_t; #define SIZEOF_DTA_117_STRL_HEADER_T 13 typedef struct dta_118_strl_header_s { uint32_t v; uint64_t o; unsigned char type; int32_t len; } dta_118_strl_header_t; #define SIZEOF_DTA_118_STRL_HEADER_T 17 #pragma pack(pop) typedef struct dta_strl_s { uint16_t v; uint64_t o; unsigned char type; size_t len; char data[1]; // Flexible array; use [1] for C++98 compatibility } dta_strl_t; typedef struct dta_ctx_s { char *data_label; size_t data_label_len; size_t data_label_len_len; time_t timestamp; size_t timestamp_len; char typlist_version; size_t typlist_entry_len; uint16_t *typlist; size_t typlist_len; char *varlist; size_t varlist_len; int16_t *srtlist; size_t srtlist_len; char *fmtlist; size_t fmtlist_len; char *lbllist; size_t lbllist_len; char *variable_labels; size_t variable_labels_len; size_t variable_name_len; size_t fmtlist_entry_len; size_t lbllist_entry_len; size_t variable_labels_entry_len; size_t expansion_len_len; size_t ch_metadata_len; size_t value_label_table_len_len; size_t value_label_table_labname_len; size_t value_label_table_padding_len; size_t strl_v_len; size_t strl_o_len; int64_t data_offset; int64_t strls_offset; int64_t value_labels_offset; int ds_format; int nvar; int64_t nobs; size_t record_len; int64_t row_limit; int64_t row_offset; int64_t current_row; unsigned int bswap:1; unsigned int machine_is_twos_complement:1; unsigned int file_is_xmlish:1; unsigned int supports_tagged_missing:1; int8_t max_int8; int16_t max_int16; int32_t max_int32; int32_t max_float; int64_t max_double; dta_strl_t **strls; size_t strls_count; size_t strls_capacity; readstat_variable_t **variables; readstat_endian_t endianness; iconv_t converter; readstat_callbacks_t handle; size_t file_size; void *user_ctx; readstat_io_t *io; int initialized; char error_buf[256]; } dta_ctx_t; #define DTA_HILO 0x01 #define DTA_LOHI 0x02 #define DTA_OLD_MAX_INT8 0x7e #define DTA_OLD_MAX_INT16 0x7ffe #define DTA_OLD_MAX_INT32 0x7ffffffe #define DTA_OLD_MAX_FLOAT 0x7effffff // +1.7e38f #define DTA_OLD_MAX_DOUBLE 0x7fdfffffffffffffL // +8.9e307 #define DTA_OLD_MISSING_INT8 0x7F #define DTA_OLD_MISSING_INT16 0x7FFF #define DTA_OLD_MISSING_INT32 0x7FFFFFFF #define DTA_OLD_MISSING_FLOAT 0x7F000000 #define DTA_OLD_MISSING_DOUBLE 0x7FE0000000000000L #define DTA_113_MAX_INT8 0x64 #define DTA_113_MAX_INT16 0x7fe4 #define DTA_113_MAX_INT32 0x7fffffe4 #define DTA_113_MAX_FLOAT 0x7effffff // +1.7e38f #define DTA_113_MAX_DOUBLE 0x7fdfffffffffffffL // +8.9e307 #define DTA_113_MISSING_INT8 0x65 #define DTA_113_MISSING_INT16 0x7FE5 #define DTA_113_MISSING_INT32 0x7FFFFFE5 #define DTA_113_MISSING_FLOAT 0x7F000000 #define DTA_113_MISSING_DOUBLE 0x7FE0000000000000L #define DTA_113_MISSING_INT8_A (DTA_113_MISSING_INT8+1) #define DTA_113_MISSING_INT16_A (DTA_113_MISSING_INT16+1) #define DTA_113_MISSING_INT32_A (DTA_113_MISSING_INT32+1) #define DTA_113_MISSING_FLOAT_A (DTA_113_MISSING_FLOAT+0x0800) #define DTA_113_MISSING_DOUBLE_A (DTA_113_MISSING_DOUBLE+0x010000000000) #define DTA_GSO_TYPE_BINARY 0x81 #define DTA_GSO_TYPE_ASCII 0x82 #define DTA_117_TYPE_CODE_INT8 0xFFFA #define DTA_117_TYPE_CODE_INT16 0xFFF9 #define DTA_117_TYPE_CODE_INT32 0xFFF8 #define DTA_117_TYPE_CODE_FLOAT 0xFFF7 #define DTA_117_TYPE_CODE_DOUBLE 0xFFF6 #define DTA_117_TYPE_CODE_STRL 0x8000 #define DTA_111_TYPE_CODE_INT8 0xFB #define DTA_111_TYPE_CODE_INT16 0xFC #define DTA_111_TYPE_CODE_INT32 0xFD #define DTA_111_TYPE_CODE_FLOAT 0xFE #define DTA_111_TYPE_CODE_DOUBLE 0xFF #define DTA_OLD_TYPE_CODE_INT8 'b' #define DTA_OLD_TYPE_CODE_INT16 'i' #define DTA_OLD_TYPE_CODE_INT32 'l' #define DTA_OLD_TYPE_CODE_FLOAT 'f' #define DTA_OLD_TYPE_CODE_DOUBLE 'd' dta_ctx_t *dta_ctx_alloc(readstat_io_t *io); readstat_error_t dta_ctx_init(dta_ctx_t *ctx, uint32_t nvar, uint64_t nobs, unsigned char byteorder, unsigned char ds_format, const char *input_encoding, const char *output_encoding); void dta_ctx_free(dta_ctx_t *ctx); readstat_error_t dta_type_info(uint16_t typecode, dta_ctx_t *ctx, size_t *max_len, readstat_type_t *out_type); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/stata/readstat_dta_parse_timestamp.c0000644000076500000240000002460314674240614022236 0ustar00dialout#line 1 "src/stata/readstat_dta_parse_timestamp.rl" #include #include "../readstat.h" #include "readstat_dta_parse_timestamp.h" #line 9 "src/stata/readstat_dta_parse_timestamp.c" static const signed char _dta_timestamp_parse_actions[] = { 0, 1, 0, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 2, 1, 0, 0 }; static const signed char _dta_timestamp_parse_key_offsets[] = { 0, 0, 3, 5, 8, 26, 34, 36, 37, 39, 42, 45, 48, 50, 52, 53, 55, 59, 63, 64, 66, 68, 70, 71, 73, 75, 76, 80, 82, 86, 87, 88, 90, 96, 97, 98, 100, 102, 103, 107, 109, 110, 112, 114, 115, 0 }; static const char _dta_timestamp_parse_trans_keys[] = { 32, 48, 57, 48, 57, 32, 48, 57, 65, 68, 69, 70, 74, 77, 78, 79, 83, 97, 100, 101, 102, 106, 109, 110, 111, 115, 66, 71, 80, 85, 98, 103, 112, 117, 82, 114, 32, 48, 57, 32, 48, 57, 32, 48, 57, 58, 48, 57, 48, 57, 79, 111, 32, 71, 103, 69, 73, 101, 105, 67, 90, 99, 122, 32, 67, 99, 78, 110, 69, 101, 32, 69, 101, 66, 98, 32, 65, 85, 97, 117, 78, 110, 76, 78, 108, 110, 32, 32, 65, 97, 73, 82, 89, 105, 114, 121, 32, 32, 79, 111, 86, 118, 32, 67, 75, 99, 107, 84, 116, 32, 69, 101, 80, 112, 32, 48, 57, 0 }; static const signed char _dta_timestamp_parse_single_lengths[] = { 0, 1, 0, 1, 18, 8, 2, 1, 0, 1, 1, 1, 0, 2, 1, 2, 4, 4, 1, 2, 2, 2, 1, 2, 2, 1, 4, 2, 4, 1, 1, 2, 6, 1, 1, 2, 2, 1, 4, 2, 1, 2, 2, 1, 0, 0 }; static const signed char _dta_timestamp_parse_range_lengths[] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; static const short _dta_timestamp_parse_index_offsets[] = { 0, 0, 3, 5, 8, 27, 36, 39, 41, 43, 46, 49, 52, 54, 57, 59, 62, 67, 72, 74, 77, 80, 83, 85, 88, 91, 93, 98, 101, 106, 108, 110, 113, 120, 122, 124, 127, 130, 132, 137, 140, 142, 145, 148, 150, 0 }; static const signed char _dta_timestamp_parse_cond_targs[] = { 2, 3, 0, 3, 0, 4, 3, 0, 5, 16, 20, 23, 26, 31, 35, 38, 41, 5, 16, 20, 23, 26, 31, 35, 38, 41, 0, 6, 13, 6, 15, 6, 13, 6, 15, 0, 7, 7, 0, 8, 0, 9, 0, 10, 9, 0, 10, 11, 0, 12, 11, 0, 44, 0, 14, 14, 0, 8, 0, 14, 14, 0, 17, 19, 17, 19, 0, 18, 18, 18, 18, 0, 8, 0, 18, 18, 0, 21, 21, 0, 22, 22, 0, 8, 0, 24, 24, 0, 25, 25, 0, 8, 0, 27, 28, 27, 28, 0, 22, 22, 0, 29, 30, 29, 30, 0, 8, 0, 8, 0, 32, 32, 0, 33, 34, 33, 33, 34, 33, 0, 8, 0, 8, 0, 36, 36, 0, 37, 37, 0, 8, 0, 39, 39, 39, 39, 0, 40, 40, 0, 8, 0, 42, 42, 0, 43, 43, 0, 8, 0, 44, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 0 }; static const signed char _dta_timestamp_parse_cond_actions[] = { 0, 35, 0, 35, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 35, 0, 29, 1, 0, 0, 35, 0, 31, 1, 0, 35, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 9, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 21, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0 }; static const short _dta_timestamp_parse_eof_trans[] = { 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 0 }; static const int dta_timestamp_parse_start = 1; static const int dta_timestamp_parse_en_main = 1; #line 9 "src/stata/readstat_dta_parse_timestamp.rl" readstat_error_t dta_parse_timestamp(const char *data, size_t len, struct tm *timestamp, readstat_error_handler error_handler, void *user_ctx) { readstat_error_t retval = READSTAT_OK; const char *p = data; const char *pe = p + len; const char *eof = pe; int cs; unsigned int temp_val = 0; #line 154 "src/stata/readstat_dta_parse_timestamp.c" { cs = (int)dta_timestamp_parse_start; } #line 159 "src/stata/readstat_dta_parse_timestamp.c" { int _klen; unsigned int _trans = 0; const char * _keys; const signed char * _acts; unsigned int _nacts; _resume: {} if ( p == pe && p != eof ) goto _out; if ( p == eof ) { if ( _dta_timestamp_parse_eof_trans[cs] > 0 ) { _trans = (unsigned int)_dta_timestamp_parse_eof_trans[cs] - 1; } } else { _keys = ( _dta_timestamp_parse_trans_keys + (_dta_timestamp_parse_key_offsets[cs])); _trans = (unsigned int)_dta_timestamp_parse_index_offsets[cs]; _klen = (int)_dta_timestamp_parse_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + _klen - 1; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _keys += _klen; _trans += (unsigned int)_klen; break; } _mid = _lower + ((_upper-_lower) >> 1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 1; else if ( ( (*( p))) > (*( _mid)) ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } } _klen = (int)_dta_timestamp_parse_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_upper = _keys + (_klen<<1) - 2; const char *_mid; while ( 1 ) { if ( _upper < _lower ) { _trans += (unsigned int)_klen; break; } _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( ( (*( p))) < (*( _mid)) ) _upper = _mid - 2; else if ( ( (*( p))) > (*( _mid + 1)) ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); break; } } } _match: {} } cs = (int)_dta_timestamp_parse_cond_targs[_trans]; if ( _dta_timestamp_parse_cond_actions[_trans] != 0 ) { _acts = ( _dta_timestamp_parse_actions + (_dta_timestamp_parse_cond_actions[_trans])); _nacts = (unsigned int)(*( _acts)); _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts)) ) { case 0: { { #line 20 "src/stata/readstat_dta_parse_timestamp.rl" temp_val = 10 * temp_val + ((( (*( p)))) - '0'); } #line 244 "src/stata/readstat_dta_parse_timestamp.c" break; } case 1: { { #line 24 "src/stata/readstat_dta_parse_timestamp.rl" temp_val = 0; } #line 253 "src/stata/readstat_dta_parse_timestamp.c" break; } case 2: { { #line 26 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mday = temp_val; } #line 262 "src/stata/readstat_dta_parse_timestamp.c" break; } case 3: { { #line 29 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 0; } #line 271 "src/stata/readstat_dta_parse_timestamp.c" break; } case 4: { { #line 30 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 1; } #line 280 "src/stata/readstat_dta_parse_timestamp.c" break; } case 5: { { #line 31 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 2; } #line 289 "src/stata/readstat_dta_parse_timestamp.c" break; } case 6: { { #line 32 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 3; } #line 298 "src/stata/readstat_dta_parse_timestamp.c" break; } case 7: { { #line 33 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 4; } #line 307 "src/stata/readstat_dta_parse_timestamp.c" break; } case 8: { { #line 34 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 5; } #line 316 "src/stata/readstat_dta_parse_timestamp.c" break; } case 9: { { #line 35 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 6; } #line 325 "src/stata/readstat_dta_parse_timestamp.c" break; } case 10: { { #line 36 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 7; } #line 334 "src/stata/readstat_dta_parse_timestamp.c" break; } case 11: { { #line 37 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 8; } #line 343 "src/stata/readstat_dta_parse_timestamp.c" break; } case 12: { { #line 38 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 9; } #line 352 "src/stata/readstat_dta_parse_timestamp.c" break; } case 13: { { #line 39 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 10; } #line 361 "src/stata/readstat_dta_parse_timestamp.c" break; } case 14: { { #line 40 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_mon = 11; } #line 370 "src/stata/readstat_dta_parse_timestamp.c" break; } case 15: { { #line 42 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_year = temp_val - 1900; } #line 379 "src/stata/readstat_dta_parse_timestamp.c" break; } case 16: { { #line 44 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_hour = temp_val; } #line 388 "src/stata/readstat_dta_parse_timestamp.c" break; } case 17: { { #line 46 "src/stata/readstat_dta_parse_timestamp.rl" timestamp->tm_min = temp_val; } #line 397 "src/stata/readstat_dta_parse_timestamp.c" break; } } _nacts -= 1; _acts += 1; } } if ( p == eof ) { if ( cs >= 44 ) goto _out; } else { if ( cs != 0 ) { p += 1; goto _resume; } } _out: {} } #line 52 "src/stata/readstat_dta_parse_timestamp.rl" if (cs < #line 425 "src/stata/readstat_dta_parse_timestamp.c" 44 #line 54 "src/stata/readstat_dta_parse_timestamp.rl" || p != pe) { char error_buf[1024]; if (error_handler) { snprintf(error_buf, sizeof(error_buf), "Invalid timestamp string (length=%d): %.*s", (int)len, (int)len, data); error_handler(error_buf, user_ctx); } retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING; } (void)dta_timestamp_parse_en_main; return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/stata/readstat_dta_parse_timestamp.h0000644000076500000240000000023114674240614022232 0ustar00dialout readstat_error_t dta_parse_timestamp(const char *data, size_t len, struct tm *timestamp, readstat_error_handler error_handler, void *user_ctx); ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/stata/readstat_dta_read.c0000644000076500000240000012062014674240614017750 0ustar00dialout #define _XOPEN_SOURCE 700 /* for strnlen */ #include #include #include #include #include #include #include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" #include "readstat_dta.h" #include "readstat_dta_parse_timestamp.h" #define MAX_VALUE_LABEL_LEN 32000 static readstat_error_t dta_update_progress(dta_ctx_t *ctx); static readstat_error_t dta_read_descriptors(dta_ctx_t *ctx); static readstat_error_t dta_read_tag(dta_ctx_t *ctx, const char *tag); static readstat_error_t dta_read_expansion_fields(dta_ctx_t *ctx); static readstat_error_t dta_update_progress(dta_ctx_t *ctx) { double progress = 0.0; if (ctx->row_limit > 0) progress = 1.0 * ctx->current_row / ctx->row_limit; if (ctx->handle.progress && ctx->handle.progress(progress, ctx->user_ctx) != READSTAT_HANDLER_OK) return READSTAT_ERROR_USER_ABORT; return READSTAT_OK; } static readstat_variable_t *dta_init_variable(dta_ctx_t *ctx, int i, int index_after_skipping, readstat_type_t type, size_t max_len) { readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t)); variable->type = type; variable->index = i; variable->index_after_skipping = index_after_skipping; variable->storage_width = max_len; readstat_convert(variable->name, sizeof(variable->name), &ctx->varlist[ctx->variable_name_len*i], strnlen(&ctx->varlist[ctx->variable_name_len*i], ctx->variable_name_len), ctx->converter); if (ctx->variable_labels[ctx->variable_labels_entry_len*i]) { readstat_convert(variable->label, sizeof(variable->label), &ctx->variable_labels[ctx->variable_labels_entry_len*i], strnlen(&ctx->variable_labels[ctx->variable_labels_entry_len*i], ctx->variable_labels_entry_len), ctx->converter); } if (ctx->fmtlist[ctx->fmtlist_entry_len*i]) { readstat_convert(variable->format, sizeof(variable->format), &ctx->fmtlist[ctx->fmtlist_entry_len*i], strnlen(&ctx->fmtlist[ctx->fmtlist_entry_len*i], ctx->fmtlist_entry_len), ctx->converter); if (variable->format[0] == '%') { if (variable->format[1] == '-') { variable->alignment = READSTAT_ALIGNMENT_LEFT; } else if (variable->format[1] == '~') { variable->alignment = READSTAT_ALIGNMENT_CENTER; } else { variable->alignment = READSTAT_ALIGNMENT_RIGHT; } } int display_width; if (sscanf(variable->format, "%%%ds", &display_width) == 1 || sscanf(variable->format, "%%-%ds", &display_width) == 1) { variable->display_width = display_width; } } return variable; } static readstat_error_t dta_read_chunk( dta_ctx_t *ctx, const char *start_tag, void *dst, size_t dst_len, const char *end_tag) { char *dst_buffer = (char *)dst; readstat_io_t *io = ctx->io; readstat_error_t retval = READSTAT_OK; if ((retval = dta_read_tag(ctx, start_tag)) != READSTAT_OK) goto cleanup; if (io->read(dst_buffer, dst_len, io->io_ctx) != dst_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = dta_read_tag(ctx, end_tag)) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t dta_read_map(dta_ctx_t *ctx) { if (!ctx->file_is_xmlish) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; uint64_t map_buffer[14]; if ((retval = dta_read_chunk(ctx, "", map_buffer, sizeof(map_buffer), "")) != READSTAT_OK) { goto cleanup; } ctx->data_offset = ctx->bswap ? byteswap8(map_buffer[9]) : map_buffer[9]; ctx->strls_offset = ctx->bswap ? byteswap8(map_buffer[10]) : map_buffer[10]; ctx->value_labels_offset = ctx->bswap ? byteswap8(map_buffer[11]) : map_buffer[11]; cleanup: return retval; } static readstat_error_t dta_read_descriptors(dta_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; size_t buffer_len = ctx->nvar * ctx->typlist_entry_len; unsigned char *buffer = NULL; int i; if (ctx->nvar && (buffer = readstat_malloc(buffer_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if ((retval = dta_read_chunk(ctx, "", buffer, buffer_len, "")) != READSTAT_OK) goto cleanup; if (ctx->typlist_entry_len == 1) { for (i=0; invar; i++) { ctx->typlist[i] = buffer[i]; } } else if (ctx->typlist_entry_len == 2) { memcpy(ctx->typlist, buffer, buffer_len); if (ctx->bswap) { for (i=0; invar; i++) { ctx->typlist[i] = byteswap2(ctx->typlist[i]); } } } if ((retval = dta_read_chunk(ctx, "", ctx->varlist, ctx->varlist_len, "")) != READSTAT_OK) goto cleanup; if ((retval = dta_read_chunk(ctx, "", ctx->srtlist, ctx->srtlist_len, "")) != READSTAT_OK) goto cleanup; if ((retval = dta_read_chunk(ctx, "", ctx->fmtlist, ctx->fmtlist_len, "")) != READSTAT_OK) goto cleanup; if ((retval = dta_read_chunk(ctx, "", ctx->lbllist, ctx->lbllist_len, "")) != READSTAT_OK) goto cleanup; if ((retval = dta_read_chunk(ctx, "", ctx->variable_labels, ctx->variable_labels_len, "")) != READSTAT_OK) goto cleanup; cleanup: if (buffer) free(buffer); return retval; } static readstat_error_t dta_read_expansion_fields(dta_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; char *buffer = NULL; if (ctx->expansion_len_len == 0) return READSTAT_OK; if (ctx->file_is_xmlish && !ctx->handle.note) { if (io->seek(ctx->data_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to data section (offset=%" PRId64 ")", ctx->data_offset); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } return READSTAT_ERROR_SEEK; } return READSTAT_OK; } retval = dta_read_tag(ctx, ""); if (retval != READSTAT_OK) goto cleanup; while (1) { size_t len; char data_type; if (ctx->file_is_xmlish) { char start[4]; if (io->read(start, sizeof(start), io->io_ctx) != sizeof(start)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (memcmp(start, ""); if (retval != READSTAT_OK) goto cleanup; break; } else if (memcmp(start, "", sizeof(start)) != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } data_type = 1; } else { if (io->read(&data_type, 1, io->io_ctx) != 1) { retval = READSTAT_ERROR_READ; goto cleanup; } } if (ctx->expansion_len_len == 2) { uint16_t len16; if (io->read(&len16, sizeof(uint16_t), io->io_ctx) != sizeof(uint16_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } len = ctx->bswap ? byteswap2(len16) : len16; } else { uint32_t len32; if (io->read(&len32, sizeof(uint32_t), io->io_ctx) != sizeof(uint32_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } len = ctx->bswap ? byteswap4(len32) : len32; } if (data_type == 0 && len == 0) break; if (data_type != 1 || len > (1<<20)) { retval = READSTAT_ERROR_NOTE_IS_TOO_LONG; goto cleanup; } if (ctx->handle.note && len >= 2 * ctx->ch_metadata_len) { if ((buffer = readstat_realloc(buffer, len + 1)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } buffer[len] = '\0'; if (io->read(buffer, len, io->io_ctx) != len) { retval = READSTAT_ERROR_READ; goto cleanup; } int index = 0; if (strncmp(&buffer[0], "_dta", 4) == 0 && sscanf(&buffer[ctx->ch_metadata_len], "note%d", &index) == 1) { if (ctx->handle.note(index, &buffer[2*ctx->ch_metadata_len], ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } else { if (io->seek(len, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } } retval = dta_read_tag(ctx, ""); if (retval != READSTAT_OK) goto cleanup; } cleanup: if (buffer) free(buffer); return retval; } static readstat_error_t dta_read_tag(dta_ctx_t *ctx, const char *tag) { readstat_error_t retval = READSTAT_OK; if (ctx->initialized && !ctx->file_is_xmlish) return retval; char buffer[256]; size_t len = strlen(tag); if (ctx->io->read(buffer, len, ctx->io->io_ctx) != len) { retval = READSTAT_ERROR_READ; goto cleanup; } if (strncmp(buffer, tag, len) != 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } cleanup: return retval; } static int dta_compare_strls(const void *elem1, const void *elem2) { const dta_strl_t *key = (const dta_strl_t *)elem1; const dta_strl_t *target = *(const dta_strl_t **)elem2; if (key->o == target->o) return key->v - target->v; return key->o - target->o; } static dta_strl_t dta_interpret_strl_vo_bytes(dta_ctx_t *ctx, const unsigned char *vo_bytes) { dta_strl_t strl = {0}; if (ctx->strl_v_len == 2) { if (ctx->endianness == READSTAT_ENDIAN_BIG) { strl.v = (vo_bytes[0] << 8) + vo_bytes[1]; strl.o = (((uint64_t)vo_bytes[2] << 40) + ((uint64_t)vo_bytes[3] << 32) + ((uint64_t)vo_bytes[4] << 24) + (vo_bytes[5] << 16) + (vo_bytes[6] << 8) + vo_bytes[7]); } else { strl.v = vo_bytes[0] + (vo_bytes[1] << 8); strl.o = (vo_bytes[2] + (vo_bytes[3] << 8) + (vo_bytes[4] << 16) + ((uint64_t)vo_bytes[5] << 24) + ((uint64_t)vo_bytes[6] << 32) + ((uint64_t)vo_bytes[7] << 40)); } } else if (ctx->strl_v_len == 4) { uint32_t v, o; memcpy(&v, &vo_bytes[0], sizeof(uint32_t)); memcpy(&o, &vo_bytes[4], sizeof(uint32_t)); strl.v = ctx->bswap ? byteswap4(v) : v; strl.o = ctx->bswap ? byteswap4(o) : o; } return strl; } static readstat_error_t dta_117_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; dta_117_strl_header_t header; if (io->read(&header, SIZEOF_DTA_117_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_117_STRL_HEADER_T) { retval = READSTAT_ERROR_READ; goto cleanup; } strl->v = ctx->bswap ? byteswap4(header.v) : header.v; strl->o = ctx->bswap ? byteswap4(header.o) : header.o; strl->type = header.type; strl->len = ctx->bswap ? byteswap4(header.len) : header.len; cleanup: return retval; } static readstat_error_t dta_118_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; dta_118_strl_header_t header; if (io->read(&header, SIZEOF_DTA_118_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_118_STRL_HEADER_T) { retval = READSTAT_ERROR_READ; goto cleanup; } strl->v = ctx->bswap ? byteswap4(header.v) : header.v; strl->o = ctx->bswap ? byteswap8(header.o) : header.o; strl->type = header.type; strl->len = ctx->bswap ? byteswap4(header.len) : header.len; cleanup: return retval; } static readstat_error_t dta_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) { if (ctx->strl_o_len > 4) { return dta_118_read_strl(ctx, strl); } return dta_117_read_strl(ctx, strl); } static readstat_error_t dta_read_strls(dta_ctx_t *ctx) { if (!ctx->file_is_xmlish) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (io->seek(ctx->strls_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to strls section (offset=%" PRId64 ")", ctx->strls_offset); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_SEEK; goto cleanup; } retval = dta_read_tag(ctx, ""); if (retval != READSTAT_OK) goto cleanup; ctx->strls_capacity = 100; ctx->strls = readstat_malloc(ctx->strls_capacity * sizeof(dta_strl_t *)); while (1) { char tag[3]; if (io->read(tag, sizeof(tag), io->io_ctx) != sizeof(tag)) { retval = READSTAT_ERROR_READ; goto cleanup; } if (memcmp(tag, "GSO", sizeof(tag)) == 0) { dta_strl_t strl; retval = dta_read_strl(ctx, &strl); if (retval != READSTAT_OK) goto cleanup; if (strl.type != DTA_GSO_TYPE_ASCII) continue; if (ctx->strls_count == ctx->strls_capacity) { ctx->strls_capacity *= 2; if ((ctx->strls = readstat_realloc(ctx->strls, sizeof(dta_strl_t *) * ctx->strls_capacity)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } } dta_strl_t *strl_ptr = readstat_malloc(sizeof(dta_strl_t) + strl.len); if (strl_ptr == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } memcpy(strl_ptr, &strl, sizeof(dta_strl_t)); ctx->strls[ctx->strls_count++] = strl_ptr; if (io->read(&strl_ptr->data[0], strl_ptr->len, io->io_ctx) != strl_ptr->len) { retval = READSTAT_ERROR_READ; goto cleanup; } } else if (memcmp(tag, ""); if (retval != READSTAT_OK) goto cleanup; break; } else { retval = READSTAT_ERROR_PARSE; goto cleanup; } } cleanup: return retval; } static readstat_value_t dta_interpret_int8_bytes(dta_ctx_t *ctx, const void *buf) { readstat_value_t value = { .type = READSTAT_TYPE_INT8 }; int8_t byte = 0; memcpy(&byte, buf, sizeof(int8_t)); if (ctx->machine_is_twos_complement) { byte = ones_to_twos_complement1(byte); } if (byte > ctx->max_int8) { if (ctx->supports_tagged_missing && byte > DTA_113_MISSING_INT8) { value.tag = 'a' + (byte - DTA_113_MISSING_INT8_A); value.is_tagged_missing = 1; } else { value.is_system_missing = 1; } } value.v.i8_value = byte; return value; } static readstat_value_t dta_interpret_int16_bytes(dta_ctx_t *ctx, const void *buf) { readstat_value_t value = { .type = READSTAT_TYPE_INT16 }; int16_t num = 0; memcpy(&num, buf, sizeof(int16_t)); if (ctx->bswap) { num = byteswap2(num); } if (ctx->machine_is_twos_complement) { num = ones_to_twos_complement2(num); } if (num > ctx->max_int16) { if (ctx->supports_tagged_missing && num > DTA_113_MISSING_INT16) { value.tag = 'a' + (num - DTA_113_MISSING_INT16_A); value.is_tagged_missing = 1; } else { value.is_system_missing = 1; } } value.v.i16_value = num; return value; } static readstat_value_t dta_interpret_int32_bytes(dta_ctx_t *ctx, const void *buf) { readstat_value_t value = { .type = READSTAT_TYPE_INT32 }; int32_t num = 0; memcpy(&num, buf, sizeof(int32_t)); if (ctx->bswap) { num = byteswap4(num); } if (ctx->machine_is_twos_complement) { num = ones_to_twos_complement4(num); } if (num > ctx->max_int32) { if (ctx->supports_tagged_missing && num > DTA_113_MISSING_INT32) { value.tag = 'a' + (num - DTA_113_MISSING_INT32_A); value.is_tagged_missing = 1; } else { value.is_system_missing = 1; } } value.v.i32_value = num; return value; } static readstat_value_t dta_interpret_float_bytes(dta_ctx_t *ctx, const void *buf) { readstat_value_t value = { .type = READSTAT_TYPE_FLOAT }; float f_num = NAN; int32_t num = 0; memcpy(&num, buf, sizeof(int32_t)); if (ctx->bswap) { num = byteswap4(num); } if (num > ctx->max_float) { if (ctx->supports_tagged_missing && num > DTA_113_MISSING_FLOAT) { value.tag = 'a' + ((num - DTA_113_MISSING_FLOAT_A) >> 11); value.is_tagged_missing = 1; } else { value.is_system_missing = 1; } } else { memcpy(&f_num, &num, sizeof(int32_t)); } value.v.float_value = f_num; return value; } static readstat_value_t dta_interpret_double_bytes(dta_ctx_t *ctx, const void *buf) { readstat_value_t value = { .type = READSTAT_TYPE_DOUBLE }; double d_num = NAN; int64_t num = 0; memcpy(&num, buf, sizeof(int64_t)); if (ctx->bswap) { num = byteswap8(num); } if (num > ctx->max_double) { if (ctx->supports_tagged_missing && num > DTA_113_MISSING_DOUBLE) { value.tag = 'a' + ((num - DTA_113_MISSING_DOUBLE_A) >> 40); value.is_tagged_missing = 1; } else { value.is_system_missing = 1; } } else { memcpy(&d_num, &num, sizeof(int64_t)); } value.v.double_value = d_num; return value; } static readstat_error_t dta_handle_row(const unsigned char *buf, dta_ctx_t *ctx) { char str_buf[2048]; int j; readstat_off_t offset = 0; readstat_error_t retval = READSTAT_OK; for (j=0; jnvar; j++) { size_t max_len; readstat_value_t value = { { 0 } }; retval = dta_type_info(ctx->typlist[j], ctx, &max_len, &value.type); if (retval != READSTAT_OK) goto cleanup; if (ctx->variables[j]->skip) { offset += max_len; continue; } if (offset + max_len > ctx->record_len) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if (value.type == READSTAT_TYPE_STRING) { if (max_len == 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } size_t str_len = strnlen((const char *)&buf[offset], max_len); retval = readstat_convert(str_buf, sizeof(str_buf), (const char *)&buf[offset], str_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; value.v.string_value = str_buf; } else if (value.type == READSTAT_TYPE_STRING_REF) { dta_strl_t key = dta_interpret_strl_vo_bytes(ctx, &buf[offset]); dta_strl_t **found = bsearch(&key, ctx->strls, ctx->strls_count, sizeof(dta_strl_t *), &dta_compare_strls); if (found) { value.v.string_value = (*found)->data; } value.type = READSTAT_TYPE_STRING; } else if (value.type == READSTAT_TYPE_INT8) { value = dta_interpret_int8_bytes(ctx, &buf[offset]); } else if (value.type == READSTAT_TYPE_INT16) { value = dta_interpret_int16_bytes(ctx, &buf[offset]); } else if (value.type == READSTAT_TYPE_INT32) { value = dta_interpret_int32_bytes(ctx, &buf[offset]); } else if (value.type == READSTAT_TYPE_FLOAT) { value = dta_interpret_float_bytes(ctx, &buf[offset]); } else if (value.type == READSTAT_TYPE_DOUBLE) { value = dta_interpret_double_bytes(ctx, &buf[offset]); } if (ctx->handle.value(ctx->current_row, ctx->variables[j], value, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } offset += max_len; } cleanup: return retval; } static readstat_error_t dta_handle_rows(dta_ctx_t *ctx) { readstat_io_t *io = ctx->io; unsigned char *buf = NULL; int i; readstat_error_t retval = READSTAT_OK; if (ctx->record_len && (buf = readstat_malloc(ctx->record_len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (ctx->row_offset) { if (io->seek(ctx->record_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } } for (i=0; irow_limit; i++) { if (io->read(buf, ctx->record_len, io->io_ctx) != ctx->record_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = dta_handle_row(buf, ctx)) != READSTAT_OK) { goto cleanup; } ctx->current_row++; if ((retval = dta_update_progress(ctx)) != READSTAT_OK) { goto cleanup; } } if (ctx->row_limit < ctx->nobs - ctx->row_offset) { if (io->seek(ctx->record_len * (ctx->nobs - ctx->row_offset - ctx->row_limit), READSTAT_SEEK_CUR, io->io_ctx) == -1) retval = READSTAT_ERROR_SEEK; } cleanup: if (buf) free(buf); return retval; } static readstat_error_t dta_read_data(dta_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; if (!ctx->handle.value) { return READSTAT_OK; } if (io->seek(ctx->data_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to data section (offset=%" PRId64 ")", ctx->data_offset); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_SEEK; goto cleanup; } if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) goto cleanup; if ((retval = dta_update_progress(ctx)) != READSTAT_OK) goto cleanup; if ((retval = dta_handle_rows(ctx)) != READSTAT_OK) goto cleanup; if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t dta_read_header(dta_ctx_t *ctx, dta_header_t *header) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = ctx->io; int bswap = 0; if (io->read(header, sizeof(dta_header_t), io->io_ctx) != sizeof(dta_header_t)) { retval = READSTAT_ERROR_READ; goto cleanup; } bswap = (header->byteorder == DTA_LOHI) ^ machine_is_little_endian(); header->nvar = bswap ? byteswap2(header->nvar) : header->nvar; header->nobs = bswap ? byteswap4(header->nobs) : header->nobs; cleanup: return retval; } static readstat_error_t dta_read_xmlish_header(dta_ctx_t *ctx, dta_header64_t *header) { readstat_error_t retval = READSTAT_OK; if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) { goto cleanup; } if ((retval = dta_read_tag(ctx, "
")) != READSTAT_OK) { goto cleanup; } char ds_format[3]; if ((retval = dta_read_chunk(ctx, "", ds_format, sizeof(ds_format), "")) != READSTAT_OK) { goto cleanup; } header->ds_format = 100 * (ds_format[0] - '0') + 10 * (ds_format[1] - '0') + (ds_format[2] - '0'); char byteorder[3]; int byteswap = 0; if ((retval = dta_read_chunk(ctx, "", byteorder, sizeof(byteorder), "")) != READSTAT_OK) { goto cleanup; } if (strncmp(byteorder, "MSF", 3) == 0) { header->byteorder = DTA_HILO; } else if (strncmp(byteorder, "LSF", 3) == 0) { header->byteorder = DTA_LOHI; } else { retval = READSTAT_ERROR_PARSE; goto cleanup; } byteswap = (header->byteorder == DTA_LOHI) ^ machine_is_little_endian(); if (header->ds_format >= 119) { uint32_t nvar; if ((retval = dta_read_chunk(ctx, "", &nvar, sizeof(uint32_t), "")) != READSTAT_OK) { goto cleanup; } header->nvar = byteswap ? byteswap4(nvar) : nvar; } else { uint16_t nvar; if ((retval = dta_read_chunk(ctx, "", &nvar, sizeof(uint16_t), "")) != READSTAT_OK) { goto cleanup; } header->nvar = byteswap ? byteswap2(nvar) : nvar; } if (header->ds_format >= 118) { uint64_t nobs; if ((retval = dta_read_chunk(ctx, "", &nobs, sizeof(uint64_t), "")) != READSTAT_OK) { goto cleanup; } header->nobs = byteswap ? byteswap8(nobs) : nobs; } else { uint32_t nobs; if ((retval = dta_read_chunk(ctx, "", &nobs, sizeof(uint32_t), "")) != READSTAT_OK) { goto cleanup; } header->nobs = byteswap ? byteswap4(nobs) : nobs; } cleanup: return retval; } static readstat_error_t dta_read_label_and_timestamp(dta_ctx_t *ctx) { readstat_io_t *io = ctx->io; readstat_error_t retval = READSTAT_OK; char *data_label_buffer = NULL; char *timestamp_buffer = NULL; uint16_t label_len = 0; unsigned char timestamp_len = 0; char last_data_label_char = 0; struct tm timestamp = { .tm_isdst = -1 }; if (ctx->file_is_xmlish) { if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) { goto cleanup; } if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) { goto cleanup; } if (io->read(×tamp_len, 1, io->io_ctx) != 1) { retval = READSTAT_ERROR_READ; goto cleanup; } } else { timestamp_len = ctx->timestamp_len; } if (timestamp_len) { timestamp_buffer = readstat_malloc(timestamp_len); if (io->read(timestamp_buffer, timestamp_len, io->io_ctx) != timestamp_len) { retval = READSTAT_ERROR_READ; goto cleanup; } if (!ctx->file_is_xmlish) timestamp_len--; if (timestamp_buffer[0]) { if (timestamp_buffer[timestamp_len-1] == '\0' && last_data_label_char != '\0') { /* Stupid hack for miswritten files with off-by-one timestamp, DTA 114 era? */ memmove(timestamp_buffer+1, timestamp_buffer, timestamp_len-1); timestamp_buffer[0] = last_data_label_char; } if (dta_parse_timestamp(timestamp_buffer, timestamp_len, ×tamp, ctx->handle.error, ctx->user_ctx) == READSTAT_OK) { ctx->timestamp = mktime(×tamp); } } } if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) { goto cleanup; } cleanup: if (data_label_buffer) free(data_label_buffer); if (timestamp_buffer) free(timestamp_buffer); return retval; } static readstat_error_t dta_handle_variables(dta_ctx_t *ctx) { if (!ctx->handle.variable) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; int i; int index_after_skipping = 0; for (i=0; invar; i++) { size_t max_len; readstat_type_t type; retval = dta_type_info(ctx->typlist[i], ctx, &max_len, &type); if (retval != READSTAT_OK) goto cleanup; if (type == READSTAT_TYPE_STRING) max_len++; /* might append NULL */ if (type == READSTAT_TYPE_STRING_REF) { type = READSTAT_TYPE_STRING; max_len = 0; } ctx->variables[i] = dta_init_variable(ctx, i, index_after_skipping, type, max_len); const char *value_labels = NULL; if (ctx->lbllist[ctx->lbllist_entry_len*i]) value_labels = &ctx->lbllist[ctx->lbllist_entry_len*i]; int cb_retval = ctx->handle.variable(i, ctx->variables[i], value_labels, ctx->user_ctx); if (cb_retval == READSTAT_HANDLER_ABORT) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) { ctx->variables[i]->skip = 1; } else { index_after_skipping++; } } cleanup: return retval; } static readstat_error_t dta_handle_value_labels(dta_ctx_t *ctx) { readstat_io_t *io = ctx->io; readstat_error_t retval = READSTAT_OK; char *table_buffer = NULL; char *utf8_buffer = NULL; if (io->seek(ctx->value_labels_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to value labels section (offset=%" PRId64 ")", ctx->value_labels_offset); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_SEEK; goto cleanup; } if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) { goto cleanup; } if (!ctx->handle.value_label) { return READSTAT_OK; } while (1) { size_t len = 0; char labname[129]; uint32_t i = 0, n = 0; if (ctx->value_label_table_len_len == 2) { int16_t table_header_len; if (io->read(&table_header_len, sizeof(int16_t), io->io_ctx) < sizeof(int16_t)) break; len = table_header_len; if (ctx->bswap) len = byteswap2(table_header_len); n = len / 8; } else { if (dta_read_tag(ctx, "") != READSTAT_OK) { break; } int32_t table_header_len; if (io->read(&table_header_len, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) break; len = table_header_len; if (ctx->bswap) len = byteswap4(table_header_len); } if (io->read(labname, ctx->value_label_table_labname_len, io->io_ctx) < ctx->value_label_table_labname_len) break; if (io->seek(ctx->value_label_table_padding_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) break; if ((table_buffer = readstat_realloc(table_buffer, len)) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (io->read(table_buffer, len, io->io_ctx) < len) { break; } if (ctx->value_label_table_len_len == 2) { for (i=0; iconverter); if (retval != READSTAT_OK) goto cleanup; if (label_buf[0] && ctx->handle.value_label(labname, value, label_buf, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } else if (len >= 8) { if ((retval = dta_read_tag(ctx, "")) != READSTAT_OK) { goto cleanup; } n = *(uint32_t *)table_buffer; uint32_t txtlen = *((uint32_t *)table_buffer+1); if (ctx->bswap) { n = byteswap4(n); txtlen = byteswap4(txtlen); } if (txtlen > len - 8 || n > (len - 8 - txtlen) / 8) { break; } uint32_t *off = (uint32_t *)table_buffer+2; uint32_t *val = (uint32_t *)table_buffer+2+n; char *txt = &table_buffer[8LL*n+8]; size_t utf8_buffer_len = 4*txtlen+1; if (txtlen > MAX_VALUE_LABEL_LEN+1) utf8_buffer_len = 4*MAX_VALUE_LABEL_LEN+1; utf8_buffer = realloc(utf8_buffer, utf8_buffer_len); /* Much bigger than we need but whatever */ if (utf8_buffer == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; } if (ctx->bswap) { for (i=0; i= txtlen) { retval = READSTAT_ERROR_PARSE; goto cleanup; } readstat_value_t value = dta_interpret_int32_bytes(ctx, &val[i]); size_t max_label_len = txtlen - off[i]; if (max_label_len > MAX_VALUE_LABEL_LEN) max_label_len = MAX_VALUE_LABEL_LEN; size_t label_len = strnlen(&txt[off[i]], max_label_len); retval = readstat_convert(utf8_buffer, utf8_buffer_len, &txt[off[i]], label_len, ctx->converter); if (retval != READSTAT_OK) goto cleanup; if (ctx->handle.value_label(labname, value, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } } } cleanup: if (table_buffer) free(table_buffer); if (utf8_buffer) free(utf8_buffer); return retval; } readstat_error_t readstat_parse_dta(readstat_parser_t *parser, const char *path, void *user_ctx) { readstat_error_t retval = READSTAT_OK; readstat_io_t *io = parser->io; int i; dta_ctx_t *ctx; size_t file_size = 0; ctx = dta_ctx_alloc(io); if (io->open(path, io->io_ctx) == -1) { retval = READSTAT_ERROR_OPEN; goto cleanup; } char magic[4]; if (io->read(magic, 4, io->io_ctx) != 4) { retval = READSTAT_ERROR_READ; goto cleanup; } file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx); if (file_size == -1) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to end of file"); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_SEEK; goto cleanup; } if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) { if (ctx->handle.error) { snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to start of file"); ctx->handle.error(ctx->error_buf, ctx->user_ctx); } retval = READSTAT_ERROR_SEEK; goto cleanup; } if (strncmp(magic, "input_encoding, parser->output_encoding); } else { dta_header_t header; if ((retval = dta_read_header(ctx, &header)) != READSTAT_OK) { goto cleanup; } retval = dta_ctx_init(ctx, header.nvar, header.nobs, header.byteorder, header.ds_format, parser->input_encoding, parser->output_encoding); } if (retval != READSTAT_OK) { goto cleanup; } ctx->user_ctx = user_ctx; ctx->file_size = file_size; ctx->handle = parser->handlers; if (parser->row_offset > 0) ctx->row_offset = parser->row_offset; int64_t nobs_after_skipping = ctx->nobs - ctx->row_offset; if (nobs_after_skipping < 0) { nobs_after_skipping = 0; ctx->row_offset = ctx->nobs; } ctx->row_limit = nobs_after_skipping; if (parser->row_limit > 0 && parser->row_limit < nobs_after_skipping) ctx->row_limit = parser->row_limit; retval = dta_update_progress(ctx); if (retval != READSTAT_OK) goto cleanup; if ((retval = dta_read_label_and_timestamp(ctx)) != READSTAT_OK) goto cleanup; if ((retval = dta_read_tag(ctx, "
")) != READSTAT_OK) { goto cleanup; } if (ctx->handle.metadata) { readstat_metadata_t metadata = { .row_count = ctx->row_limit, .var_count = ctx->nvar, .file_label = ctx->data_label, .creation_time = ctx->timestamp, .modified_time = ctx->timestamp, .file_format_version = ctx->ds_format, .is64bit = ctx->ds_format >= 118, .endianness = ctx->endianness }; if (ctx->handle.metadata(&metadata, user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; } } if ((retval = dta_read_map(ctx)) != READSTAT_OK) { retval = READSTAT_ERROR_READ; goto cleanup; } if ((retval = dta_read_descriptors(ctx)) != READSTAT_OK) { goto cleanup; } for (i=0; invar; i++) { size_t max_len; if ((retval = dta_type_info(ctx->typlist[i], ctx, &max_len, NULL)) != READSTAT_OK) goto cleanup; ctx->record_len += max_len; } if ((ctx->nvar > 0 || ctx->nobs > 0) && ctx->record_len == 0) { retval = READSTAT_ERROR_PARSE; goto cleanup; } if ((retval = dta_handle_variables(ctx)) != READSTAT_OK) goto cleanup; if ((retval = dta_read_expansion_fields(ctx)) != READSTAT_OK) goto cleanup; if (!ctx->file_is_xmlish) { ctx->data_offset = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx); if (ctx->data_offset == -1) { retval = READSTAT_ERROR_SEEK; goto cleanup; } ctx->value_labels_offset = ctx->data_offset + ctx->record_len * ctx->nobs; } if ((retval = dta_read_strls(ctx)) != READSTAT_OK) goto cleanup; if ((retval = dta_read_data(ctx)) != READSTAT_OK) goto cleanup; if ((retval = dta_handle_value_labels(ctx)) != READSTAT_OK) goto cleanup; cleanup: io->close(io->io_ctx); if (ctx) dta_ctx_free(ctx); return retval; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727086988.0 pyreadstat-1.3.3/src/stata/readstat_dta_write.c0000644000076500000240000014207214674240614020174 0ustar00dialout #include #include #include #include #include #include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "../readstat_writer.h" #include "readstat_dta.h" #define DTA_DEFAULT_DISPLAY_WIDTH_BYTE 8 #define DTA_DEFAULT_DISPLAY_WIDTH_INT16 8 #define DTA_DEFAULT_DISPLAY_WIDTH_INT32 12 #define DTA_DEFAULT_DISPLAY_WIDTH_FLOAT 9 #define DTA_DEFAULT_DISPLAY_WIDTH_DOUBLE 10 #define DTA_DEFAULT_DISPLAY_WIDTH_STRING 9 #define DTA_FILE_VERSION_MIN 104 #define DTA_FILE_VERSION_MAX 119 #define DTA_FILE_VERSION_DEFAULT 118 #define DTA_OLD_MAX_WIDTH 128 #define DTA_111_MAX_WIDTH 244 #define DTA_117_MAX_WIDTH 2045 #define DTA_OLD_MAX_NAME_LEN 9 #define DTA_110_MAX_NAME_LEN 33 #define DTA_118_MAX_NAME_LEN 129 static readstat_error_t dta_113_write_missing_numeric(void *row, const readstat_variable_t *var); static readstat_error_t dta_write_tag(readstat_writer_t *writer, dta_ctx_t *ctx, const char *tag) { if (!ctx->file_is_xmlish) return READSTAT_OK; return readstat_write_string(writer, tag); } static readstat_error_t dta_write_chunk(readstat_writer_t *writer, dta_ctx_t *ctx, const char *start_tag, const void *bytes, size_t len, const char *end_tag) { readstat_error_t error = READSTAT_OK; if ((error = dta_write_tag(writer, ctx, start_tag)) != READSTAT_OK) goto cleanup; if ((error = readstat_write_bytes(writer, bytes, len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, end_tag)) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_header_data_label(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; char *data_label = NULL; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: if (data_label) free(data_label); return error; } static readstat_error_t dta_emit_header_time_stamp(readstat_writer_t *writer, dta_ctx_t *ctx) { if (!ctx->timestamp_len) return READSTAT_OK; readstat_error_t error = READSTAT_OK; time_t now = writer->timestamp; struct tm *time_s = localtime(&now); char *timestamp = calloc(1, ctx->timestamp_len); /* There are locale/portability issues with strftime so hack something up */ char months[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; if (!time_s) { error = READSTAT_ERROR_BAD_TIMESTAMP_VALUE; goto cleanup; } if (!timestamp) { error = READSTAT_ERROR_MALLOC; goto cleanup; } uint8_t actual_timestamp_len = snprintf(timestamp, ctx->timestamp_len, "%02d %3s %04d %02d:%02d", time_s->tm_mday, months[time_s->tm_mon], time_s->tm_year + 1900, time_s->tm_hour, time_s->tm_min); if (actual_timestamp_len == 0) { error = READSTAT_ERROR_WRITE; goto cleanup; } if (ctx->file_is_xmlish) { if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; if ((error = readstat_write_bytes(writer, &actual_timestamp_len, sizeof(uint8_t))) != READSTAT_OK) goto cleanup; if ((error = readstat_write_bytes(writer, timestamp, actual_timestamp_len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; } else { error = readstat_write_bytes(writer, timestamp, ctx->timestamp_len); } cleanup: free(timestamp); return error; } static readstat_error_t dta_111_typecode_for_variable(readstat_variable_t *r_variable, uint16_t *out_typecode) { readstat_error_t retval = READSTAT_OK; size_t max_len = r_variable->storage_width; uint16_t typecode = 0; switch (r_variable->type) { case READSTAT_TYPE_INT8: typecode = DTA_111_TYPE_CODE_INT8; break; case READSTAT_TYPE_INT16: typecode = DTA_111_TYPE_CODE_INT16; break; case READSTAT_TYPE_INT32: typecode = DTA_111_TYPE_CODE_INT32; break; case READSTAT_TYPE_FLOAT: typecode = DTA_111_TYPE_CODE_FLOAT; break; case READSTAT_TYPE_DOUBLE: typecode = DTA_111_TYPE_CODE_DOUBLE; break; case READSTAT_TYPE_STRING: typecode = max_len; break; case READSTAT_TYPE_STRING_REF: retval = READSTAT_ERROR_STRING_REFS_NOT_SUPPORTED; break; } if (out_typecode && retval == READSTAT_OK) *out_typecode = typecode; return retval; } static readstat_error_t dta_117_typecode_for_variable(readstat_variable_t *r_variable, uint16_t *out_typecode) { readstat_error_t retval = READSTAT_OK; size_t max_len = r_variable->storage_width; uint16_t typecode = 0; switch (r_variable->type) { case READSTAT_TYPE_INT8: typecode = DTA_117_TYPE_CODE_INT8; break; case READSTAT_TYPE_INT16: typecode = DTA_117_TYPE_CODE_INT16; break; case READSTAT_TYPE_INT32: typecode = DTA_117_TYPE_CODE_INT32; break; case READSTAT_TYPE_FLOAT: typecode = DTA_117_TYPE_CODE_FLOAT; break; case READSTAT_TYPE_DOUBLE: typecode = DTA_117_TYPE_CODE_DOUBLE; break; case READSTAT_TYPE_STRING: typecode = max_len; break; case READSTAT_TYPE_STRING_REF: typecode = DTA_117_TYPE_CODE_STRL; break; } if (out_typecode) *out_typecode = typecode; return retval; } static readstat_error_t dta_old_typecode_for_variable(readstat_variable_t *r_variable, uint16_t *out_typecode) { readstat_error_t retval = READSTAT_OK; size_t max_len = r_variable->storage_width; uint16_t typecode = 0; switch (r_variable->type) { case READSTAT_TYPE_INT8: typecode = DTA_OLD_TYPE_CODE_INT8; break; case READSTAT_TYPE_INT16: typecode = DTA_OLD_TYPE_CODE_INT16; break; case READSTAT_TYPE_INT32: typecode = DTA_OLD_TYPE_CODE_INT32; break; case READSTAT_TYPE_FLOAT: typecode = DTA_OLD_TYPE_CODE_FLOAT; break; case READSTAT_TYPE_DOUBLE: typecode = DTA_OLD_TYPE_CODE_DOUBLE; break; case READSTAT_TYPE_STRING: typecode = max_len + 0x7F; break; case READSTAT_TYPE_STRING_REF: retval = READSTAT_ERROR_STRING_REFS_NOT_SUPPORTED; break; } if (out_typecode && retval == READSTAT_OK) *out_typecode = typecode; return retval; } static readstat_error_t dta_typecode_for_variable(readstat_variable_t *r_variable, int typlist_version, uint16_t *typecode) { if (typlist_version == 111) { return dta_111_typecode_for_variable(r_variable, typecode); } if (typlist_version == 117) { return dta_117_typecode_for_variable(r_variable, typecode); } return dta_old_typecode_for_variable(r_variable, typecode); } static readstat_error_t dta_emit_typlist(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; int i; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; for (i=0; invar; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); uint16_t typecode = 0; error = dta_typecode_for_variable(r_variable, ctx->typlist_version, &typecode); if (error != READSTAT_OK) goto cleanup; ctx->typlist[i] = typecode; } for (i=0; invar; i++) { if (ctx->typlist_entry_len == 1) { uint8_t byte = ctx->typlist[i]; error = readstat_write_bytes(writer, &byte, sizeof(uint8_t)); } else if (ctx->typlist_entry_len == 2) { uint16_t val = ctx->typlist[i]; error = readstat_write_bytes(writer, &val, sizeof(uint16_t)); } if (error != READSTAT_OK) goto cleanup; } if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_validate_name_chars(const char *name, int unicode) { /* TODO check Unicode class */ int j; for (j=0; name[j]; j++) { if (((unsigned char)name[j] < 0x80 || !unicode) && name[j] != '_' && !(name[j] >= 'a' && name[j] <= 'z') && !(name[j] >= 'A' && name[j] <= 'Z') && !(name[j] >= '0' && name[j] <= '9')) { return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER; } } char first_char = name[0]; if (((unsigned char)first_char < 0x80 || !unicode) && first_char != '_' && !(first_char >= 'a' && first_char <= 'z') && !(first_char >= 'A' && first_char <= 'Z')) { return READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER; } return READSTAT_OK; } static readstat_error_t dta_validate_name_unreserved(const char *name) { if (strcmp(name, "_all") == 0 || strcmp(name, "_b") == 0 || strcmp(name, "byte") == 0 || strcmp(name, "_coef") == 0 || strcmp(name, "_cons") == 0 || strcmp(name, "double") == 0 || strcmp(name, "float") == 0 || strcmp(name, "if") == 0 || strcmp(name, "in") == 0 || strcmp(name, "int") == 0 || strcmp(name, "long") == 0 || strcmp(name, "_n") == 0 || strcmp(name, "_N") == 0 || strcmp(name, "_pi") == 0 || strcmp(name, "_pred") == 0 || strcmp(name, "_rc") == 0 || strcmp(name, "_skip") == 0 || strcmp(name, "strL") == 0 || strcmp(name, "using") == 0 || strcmp(name, "with") == 0) { return READSTAT_ERROR_NAME_IS_RESERVED_WORD; } int len; if (sscanf(name, "str%d", &len) == 1) return READSTAT_ERROR_NAME_IS_RESERVED_WORD; return READSTAT_OK; } static readstat_error_t dta_validate_name(const char *name, int unicode, size_t max_len) { readstat_error_t error = READSTAT_OK; if (strlen(name) > max_len) return READSTAT_ERROR_NAME_IS_TOO_LONG; if (strlen(name) == 0) return READSTAT_ERROR_NAME_IS_ZERO_LENGTH; if ((error = dta_validate_name_chars(name, unicode)) != READSTAT_OK) return error; return dta_validate_name_unreserved(name); } static readstat_error_t dta_old_variable_ok(const readstat_variable_t *variable) { return dta_validate_name(readstat_variable_get_name(variable), 0, DTA_OLD_MAX_NAME_LEN); } static readstat_error_t dta_110_variable_ok(const readstat_variable_t *variable) { return dta_validate_name(readstat_variable_get_name(variable), 0, DTA_110_MAX_NAME_LEN); } static readstat_error_t dta_118_variable_ok(const readstat_variable_t *variable) { return dta_validate_name(readstat_variable_get_name(variable), 1, DTA_118_MAX_NAME_LEN); } static readstat_error_t dta_emit_varlist(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; int i; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; for (i=0; invar; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); strncpy(&ctx->varlist[ctx->variable_name_len*i], r_variable->name, ctx->variable_name_len); } if ((error = readstat_write_bytes(writer, ctx->varlist, ctx->varlist_len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_srtlist(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; memset(ctx->srtlist, '\0', ctx->srtlist_len); if ((error = readstat_write_bytes(writer, ctx->srtlist, ctx->srtlist_len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_fmtlist(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; int i; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; for (i=0; invar; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); if (r_variable->format[0]) { strncpy(&ctx->fmtlist[ctx->fmtlist_entry_len*i], r_variable->format, ctx->fmtlist_entry_len); } else { char format_letter = 'g'; int display_width = r_variable->display_width; if (readstat_type_class(r_variable->type) == READSTAT_TYPE_CLASS_STRING) { format_letter = 's'; } if (!display_width) { if (r_variable->type == READSTAT_TYPE_INT8) { display_width = DTA_DEFAULT_DISPLAY_WIDTH_BYTE; } else if (r_variable->type == READSTAT_TYPE_INT16) { display_width = DTA_DEFAULT_DISPLAY_WIDTH_INT16; } else if (r_variable->type == READSTAT_TYPE_INT32) { display_width = DTA_DEFAULT_DISPLAY_WIDTH_INT32; } else if (r_variable->type == READSTAT_TYPE_FLOAT) { display_width = DTA_DEFAULT_DISPLAY_WIDTH_FLOAT; } else if (r_variable->type == READSTAT_TYPE_DOUBLE) { display_width = DTA_DEFAULT_DISPLAY_WIDTH_DOUBLE; } else { display_width = DTA_DEFAULT_DISPLAY_WIDTH_STRING; } } char format[64]; if (format_letter == 'g') { snprintf(format, sizeof(format), "%%%s%d.0g", r_variable->alignment == READSTAT_ALIGNMENT_LEFT ? "-" : "", display_width); } else { snprintf(format, sizeof(format), "%%%s%ds", r_variable->alignment == READSTAT_ALIGNMENT_LEFT ? "-" : "", display_width); } strncpy(&ctx->fmtlist[ctx->fmtlist_entry_len*i], format, ctx->fmtlist_entry_len); } } if ((error = readstat_write_bytes(writer, ctx->fmtlist, ctx->fmtlist_len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_lbllist(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; int i; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; for (i=0; invar; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); if (r_variable->label_set) { strncpy(&ctx->lbllist[ctx->lbllist_entry_len*i], r_variable->label_set->name, ctx->lbllist_entry_len); } else { memset(&ctx->lbllist[ctx->lbllist_entry_len*i], '\0', ctx->lbllist_entry_len); } } if ((error = readstat_write_bytes(writer, ctx->lbllist, ctx->lbllist_len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_descriptors(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; error = dta_emit_typlist(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_varlist(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_srtlist(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_fmtlist(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_lbllist(writer, ctx); if (error != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_variable_labels(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; int i; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; for (i=0; invar; i++) { readstat_variable_t *r_variable = readstat_get_variable(writer, i); strncpy(&ctx->variable_labels[ctx->variable_labels_entry_len*i], r_variable->label, ctx->variable_labels_entry_len); } if ((error = readstat_write_bytes(writer, ctx->variable_labels, ctx->variable_labels_len)) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_characteristics(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; int i; char *buffer = NULL; if (ctx->expansion_len_len == 0) return READSTAT_OK; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) return error; buffer = malloc(ctx->ch_metadata_len); for (i=0; inotes_count; i++) { if (ctx->file_is_xmlish) { error = dta_write_tag(writer, ctx, ""); } else { char data_type = 1; error = readstat_write_bytes(writer, &data_type, 1); } if (error != READSTAT_OK) goto cleanup; size_t len = strlen(writer->notes[i]); if (ctx->expansion_len_len == 2) { int16_t len16 = 2*ctx->ch_metadata_len + len + 1; error = readstat_write_bytes(writer, &len16, sizeof(len16)); } else if (ctx->expansion_len_len == 4) { int32_t len32 = 2*ctx->ch_metadata_len + len + 1; error = readstat_write_bytes(writer, &len32, sizeof(len32)); } if (error != READSTAT_OK) goto cleanup; strncpy(buffer, "_dta", ctx->ch_metadata_len); error = readstat_write_bytes(writer, buffer, ctx->ch_metadata_len); if (error != READSTAT_OK) goto cleanup; snprintf(buffer, ctx->ch_metadata_len, "note%d", i+1); error = readstat_write_bytes(writer, buffer, ctx->ch_metadata_len); if (error != READSTAT_OK) goto cleanup; error = readstat_write_bytes(writer, writer->notes[i], len + 1); if (error != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; } if (ctx->file_is_xmlish) { error = dta_write_tag(writer, ctx, ""); } else { error = readstat_write_zeros(writer, 1 + ctx->expansion_len_len); } if (error != READSTAT_OK) goto cleanup; cleanup: free(buffer); return error; } static readstat_error_t dta_117_emit_strl_header(readstat_writer_t *writer, readstat_string_ref_t *ref) { dta_117_strl_header_t header = { .v = ref->first_v, .o = ref->first_o, .type = DTA_GSO_TYPE_ASCII, .len = ref->len }; return readstat_write_bytes(writer, &header, SIZEOF_DTA_117_STRL_HEADER_T); } static readstat_error_t dta_118_emit_strl_header(readstat_writer_t *writer, readstat_string_ref_t *ref) { dta_118_strl_header_t header = { .v = ref->first_v, .o = ref->first_o, .type = DTA_GSO_TYPE_ASCII, .len = ref->len }; return readstat_write_bytes(writer, &header, SIZEOF_DTA_118_STRL_HEADER_T); } static readstat_error_t dta_emit_strls(readstat_writer_t *writer, dta_ctx_t *ctx) { if (!ctx->file_is_xmlish) return READSTAT_OK; readstat_error_t retval = READSTAT_OK; retval = readstat_write_string(writer, ""); if (retval != READSTAT_OK) goto cleanup; int i; for (i=0; istring_refs_count; i++) { readstat_string_ref_t *ref = writer->string_refs[i]; retval = readstat_write_string(writer, "GSO"); if (retval != READSTAT_OK) goto cleanup; if (ctx->strl_o_len > 4) { retval = dta_118_emit_strl_header(writer, ref); } else { retval = dta_117_emit_strl_header(writer, ref); } if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &ref->data[0], ref->len); if (retval != READSTAT_OK) goto cleanup; } retval = readstat_write_string(writer, ""); if (retval != READSTAT_OK) goto cleanup; cleanup: return retval; } static readstat_error_t dta_old_emit_value_labels(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t retval = READSTAT_OK; int i, j; char labname[12+2]; char *label_buffer = NULL; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); int32_t max_value = 0; for (j=0; jvalue_labels_count; j++) { readstat_value_label_t *value_label = readstat_get_value_label(r_label_set, j); if (value_label->tag) { retval = READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED; goto cleanup; } if (value_label->int32_key < 0 || value_label->int32_key > 1024) { retval = READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; goto cleanup; } if (value_label->int32_key > max_value) { max_value = value_label->int32_key; } } int16_t table_len = 8*(max_value + 1); retval = readstat_write_bytes(writer, &table_len, sizeof(int16_t)); if (retval != READSTAT_OK) goto cleanup; memset(labname, 0, sizeof(labname)); strncpy(labname, r_label_set->name, ctx->value_label_table_labname_len); retval = readstat_write_bytes(writer, labname, ctx->value_label_table_labname_len + ctx->value_label_table_padding_len); if (retval != READSTAT_OK) goto cleanup; label_buffer = realloc(label_buffer, table_len); memset(label_buffer, 0, table_len); for (j=0; jvalue_labels_count; j++) { readstat_value_label_t *value_label = readstat_get_value_label(r_label_set, j); size_t len = value_label->label_len; if (len > 8) len = 8; memcpy(&label_buffer[8*value_label->int32_key], value_label->label, len); } retval = readstat_write_bytes(writer, label_buffer, table_len); if (retval != READSTAT_OK) goto cleanup; } cleanup: if (label_buffer) free(label_buffer); return retval; } static int dta_compare_value_labels(const readstat_value_label_t *vl1, const readstat_value_label_t *vl2) { if (vl1->tag) { if (vl2->tag) { return vl1->tag - vl2->tag; } return 1; } if (vl2->tag) { return -1; } return vl1->int32_key - vl2->int32_key; } static readstat_error_t dta_emit_value_labels(readstat_writer_t *writer, dta_ctx_t *ctx) { if (ctx->value_label_table_len_len == 2) return dta_old_emit_value_labels(writer, ctx); readstat_error_t retval = READSTAT_OK; int i, j; int32_t *off = NULL; int32_t *val = NULL; char *txt = NULL; char *labname = calloc(1, ctx->value_label_table_labname_len + ctx->value_label_table_padding_len); retval = dta_write_tag(writer, ctx, ""); if (retval != READSTAT_OK) goto cleanup; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); int32_t n = r_label_set->value_labels_count; int32_t txtlen = 0; for (j=0; jlabel_len + 1; } retval = dta_write_tag(writer, ctx, ""); if (retval != READSTAT_OK) goto cleanup; int32_t table_len = 8 + 8*n + txtlen; retval = readstat_write_bytes(writer, &table_len, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; strncpy(labname, r_label_set->name, ctx->value_label_table_labname_len); retval = readstat_write_bytes(writer, labname, ctx->value_label_table_labname_len + ctx->value_label_table_padding_len); if (retval != READSTAT_OK) goto cleanup; if (txtlen == 0) { retval = readstat_write_bytes(writer, &txtlen, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &txtlen, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = dta_write_tag(writer, ctx, ""); if (retval != READSTAT_OK) goto cleanup; continue; } off = realloc(off, 4*n); val = realloc(val, 4*n); txt = realloc(txt, txtlen); readstat_off_t offset = 0; readstat_sort_label_set(r_label_set, &dta_compare_value_labels); for (j=0; jlabel; size_t label_data_len = value_label->label_len; off[j] = offset; if (value_label->tag) { if (writer->version < 113) { retval = READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED; goto cleanup; } val[j] = DTA_113_MISSING_INT32_A + (value_label->tag - 'a'); } else { val[j] = value_label->int32_key; } memcpy(txt + offset, label, label_data_len); offset += label_data_len; txt[offset++] = '\0'; } retval = readstat_write_bytes(writer, &n, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, &txtlen, sizeof(int32_t)); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, off, 4*n); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, val, 4*n); if (retval != READSTAT_OK) goto cleanup; retval = readstat_write_bytes(writer, txt, txtlen); if (retval != READSTAT_OK) goto cleanup; retval = dta_write_tag(writer, ctx, ""); if (retval != READSTAT_OK) goto cleanup; } retval = dta_write_tag(writer, ctx, ""); if (retval != READSTAT_OK) goto cleanup; cleanup: if (off) free(off); if (val) free(val); if (txt) free(txt); if (labname) free(labname); return retval; } static size_t dta_numeric_variable_width(readstat_type_t type, size_t user_width) { size_t len = 0; if (type == READSTAT_TYPE_DOUBLE) { len = 8; } else if (type == READSTAT_TYPE_FLOAT) { len = 4; } else if (type == READSTAT_TYPE_INT32) { len = 4; } else if (type == READSTAT_TYPE_INT16) { len = 2; } else if (type == READSTAT_TYPE_INT8) { len = 1; } return len; } static size_t dta_111_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) { if (user_width > DTA_111_MAX_WIDTH || user_width == 0) user_width = DTA_111_MAX_WIDTH; return user_width; } return dta_numeric_variable_width(type, user_width); } static size_t dta_117_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) { if (user_width > DTA_117_MAX_WIDTH || user_width == 0) user_width = DTA_117_MAX_WIDTH; return user_width; } if (type == READSTAT_TYPE_STRING_REF) return 8; return dta_numeric_variable_width(type, user_width); } static size_t dta_old_variable_width(readstat_type_t type, size_t user_width) { if (type == READSTAT_TYPE_STRING) { if (user_width > DTA_OLD_MAX_WIDTH || user_width == 0) user_width = DTA_OLD_MAX_WIDTH; return user_width; } return dta_numeric_variable_width(type, user_width); } static readstat_error_t dta_emit_xmlish_header(readstat_writer_t *writer, dta_ctx_t *ctx) { readstat_error_t error = READSTAT_OK; if ((error = dta_write_tag(writer, ctx, "")) != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "
")) != READSTAT_OK) goto cleanup; char release[128]; snprintf(release, sizeof(release), "%ld", writer->version); if ((error = readstat_write_string(writer, release)) != READSTAT_OK) goto cleanup; error = dta_write_chunk(writer, ctx, "", machine_is_little_endian() ? "LSF" : "MSF", sizeof("MSF")-1, ""); if (error != READSTAT_OK) goto cleanup; if (writer->version >= 119) { uint32_t nvar = writer->variables_count; error = dta_write_chunk(writer, ctx, "", &nvar, sizeof(uint32_t), ""); if (error != READSTAT_OK) goto cleanup; } else { uint16_t nvar = writer->variables_count; error = dta_write_chunk(writer, ctx, "", &nvar, sizeof(uint16_t), ""); if (error != READSTAT_OK) goto cleanup; } if (writer->version >= 118) { uint64_t nobs = writer->row_count; error = dta_write_chunk(writer, ctx, "", &nobs, sizeof(uint64_t), ""); if (error != READSTAT_OK) goto cleanup; } else { uint32_t nobs = writer->row_count; error = dta_write_chunk(writer, ctx, "", &nobs, sizeof(uint32_t), ""); if (error != READSTAT_OK) goto cleanup; } error = dta_emit_header_data_label(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_header_time_stamp(writer, ctx); if (error != READSTAT_OK) goto cleanup; if ((error = dta_write_tag(writer, ctx, "
")) != READSTAT_OK) goto cleanup; cleanup: return error; } static readstat_error_t dta_emit_header(readstat_writer_t *writer, dta_ctx_t *ctx) { if (ctx->file_is_xmlish) { return dta_emit_xmlish_header(writer, ctx); } readstat_error_t error = READSTAT_OK; dta_header_t header = {0}; header.ds_format = writer->version; header.byteorder = machine_is_little_endian() ? DTA_LOHI : DTA_HILO; header.filetype = 0x01; header.unused = 0x00; header.nvar = writer->variables_count; header.nobs = writer->row_count; if (writer->variables_count > 32767) { error = READSTAT_ERROR_TOO_MANY_COLUMNS; goto cleanup; } if ((error = readstat_write_bytes(writer, &header, sizeof(dta_header_t))) != READSTAT_OK) goto cleanup; if ((error = dta_emit_header_data_label(writer, ctx)) != READSTAT_OK) goto cleanup; if ((error = dta_emit_header_time_stamp(writer, ctx)) != READSTAT_OK) goto cleanup; cleanup: return READSTAT_OK; } static size_t dta_measure_tag(dta_ctx_t *ctx, const char *tag) { if (!ctx->file_is_xmlish) return 0; return strlen(tag); } static size_t dta_measure_map(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + 14 * sizeof(uint64_t) + dta_measure_tag(ctx, "")); } static size_t dta_measure_typlist(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + ctx->typlist_entry_len * ctx->nvar + dta_measure_tag(ctx, "")); } static size_t dta_measure_varlist(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + ctx->varlist_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_srtlist(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + ctx->srtlist_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_fmtlist(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + ctx->fmtlist_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_lbllist(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + ctx->lbllist_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_variable_labels(dta_ctx_t *ctx) { return (dta_measure_tag(ctx, "") + ctx->variable_labels_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_characteristics(readstat_writer_t *writer, dta_ctx_t *ctx) { size_t characteristics_len = 0; int i; for (i=0; inotes_count; i++) { size_t ch_len = dta_measure_tag(ctx, "") + ctx->expansion_len_len + 2 * ctx->ch_metadata_len + strlen(writer->notes[i]) + 1 + dta_measure_tag(ctx, ""); characteristics_len += ch_len; } return (dta_measure_tag(ctx, "") + characteristics_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_data(readstat_writer_t *writer, dta_ctx_t *ctx) { int i; for (i=0; invar; i++) { size_t max_len = 0; readstat_variable_t *r_variable = readstat_get_variable(writer, i); uint16_t typecode = 0; dta_typecode_for_variable(r_variable, ctx->typlist_version, &typecode); if (dta_type_info(typecode, ctx, &max_len, NULL) == READSTAT_OK) ctx->record_len += max_len; } return (dta_measure_tag(ctx, "") + ctx->record_len * ctx->nobs + dta_measure_tag(ctx, "")); } static size_t dta_measure_strls(readstat_writer_t *writer, dta_ctx_t *ctx) { int i; size_t strls_len = 0; for (i=0; istring_refs_count; i++) { readstat_string_ref_t *ref = writer->string_refs[i]; if (ctx->strl_o_len > 4) { strls_len += sizeof("GSO") - 1 + SIZEOF_DTA_118_STRL_HEADER_T + ref->len; } else { strls_len += sizeof("GSO") - 1 + SIZEOF_DTA_117_STRL_HEADER_T + ref->len; } } return (dta_measure_tag(ctx, "") + strls_len + dta_measure_tag(ctx, "")); } static size_t dta_measure_value_labels(readstat_writer_t *writer, dta_ctx_t *ctx) { size_t len = dta_measure_tag(ctx, ""); int i, j; for (i=0; ilabel_sets_count; i++) { readstat_label_set_t *r_label_set = readstat_get_label_set(writer, i); int32_t n = r_label_set->value_labels_count; int32_t txtlen = 0; for (j=0; jlabel_len + 1; } len += dta_measure_tag(ctx, ""); len += sizeof(int32_t); len += ctx->value_label_table_labname_len; len += ctx->value_label_table_padding_len; len += 8 + 8*n + txtlen; len += dta_measure_tag(ctx, ""); } len += dta_measure_tag(ctx, ""); return len; } static readstat_error_t dta_emit_map(readstat_writer_t *writer, dta_ctx_t *ctx) { if (!ctx->file_is_xmlish) return READSTAT_OK; uint64_t map[14]; map[0] = 0; /* */ map[1] = writer->bytes_written; /* */ map[2] = map[1] + dta_measure_map(ctx); /* */ map[3] = map[2] + dta_measure_typlist(ctx); /* */ map[4] = map[3] + dta_measure_varlist(ctx); /* */ map[5] = map[4] + dta_measure_srtlist(ctx); /* */ map[6] = map[5] + dta_measure_fmtlist(ctx); /* */ map[7] = map[6] + dta_measure_lbllist(ctx); /* */ map[8] = map[7] + dta_measure_variable_labels(ctx); /* */ map[9] = map[8] + dta_measure_characteristics(writer, ctx); /* */ map[10]= map[9] + dta_measure_data(writer, ctx); /* */ map[11]= map[10]+ dta_measure_strls(writer, ctx); /* */ map[12]= map[11]+ dta_measure_value_labels(writer, ctx); /* */ map[13]= map[12]+ dta_measure_tag(ctx, "
"); return dta_write_chunk(writer, ctx, "", map, sizeof(map), ""); } static readstat_error_t dta_begin_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; readstat_error_t error = READSTAT_OK; if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; dta_ctx_t *ctx = dta_ctx_alloc(NULL); error = dta_ctx_init(ctx, writer->variables_count, writer->row_count, machine_is_little_endian() ? DTA_LOHI : DTA_HILO, writer->version, NULL, NULL); if (error != READSTAT_OK) goto cleanup; error = dta_emit_header(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_map(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_descriptors(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_variable_labels(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_characteristics(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_write_tag(writer, ctx, ""); if (error != READSTAT_OK) goto cleanup; cleanup: if (error != READSTAT_OK) { dta_ctx_free(ctx); } else { writer->module_ctx = ctx; } return error; } static readstat_error_t dta_write_raw_int8(void *row, int8_t value) { memcpy(row, &value, sizeof(char)); return READSTAT_OK; } static readstat_error_t dta_write_raw_int16(void *row, int16_t value) { memcpy(row, &value, sizeof(int16_t)); return READSTAT_OK; } static readstat_error_t dta_write_raw_int32(void *row, int32_t value) { memcpy(row, &value, sizeof(int32_t)); return READSTAT_OK; } static readstat_error_t dta_write_raw_int64(void *row, int64_t value) { memcpy(row, &value, sizeof(int64_t)); return READSTAT_OK; } static readstat_error_t dta_write_raw_float(void *row, float value) { memcpy(row, &value, sizeof(float)); return READSTAT_OK; } static readstat_error_t dta_write_raw_double(void *row, double value) { memcpy(row, &value, sizeof(double)); return READSTAT_OK; } static readstat_error_t dta_113_write_int8(void *row, const readstat_variable_t *var, int8_t value) { if (value > DTA_113_MAX_INT8) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } return dta_write_raw_int8(row, value); } static readstat_error_t dta_old_write_int8(void *row, const readstat_variable_t *var, int8_t value) { if (value > DTA_OLD_MAX_INT8) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } return dta_write_raw_int8(row, value); } static readstat_error_t dta_113_write_int16(void *row, const readstat_variable_t *var, int16_t value) { if (value > DTA_113_MAX_INT16) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } return dta_write_raw_int16(row, value); } static readstat_error_t dta_old_write_int16(void *row, const readstat_variable_t *var, int16_t value) { if (value > DTA_OLD_MAX_INT16) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } return dta_write_raw_int16(row, value); } static readstat_error_t dta_113_write_int32(void *row, const readstat_variable_t *var, int32_t value) { if (value > DTA_113_MAX_INT32) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } return dta_write_raw_int32(row, value); } static readstat_error_t dta_old_write_int32(void *row, const readstat_variable_t *var, int32_t value) { if (value > DTA_OLD_MAX_INT32) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } return dta_write_raw_int32(row, value); } static readstat_error_t dta_write_float(void *row, const readstat_variable_t *var, float value) { int32_t max_flt_i32 = DTA_113_MAX_FLOAT; float max_flt; memcpy(&max_flt, &max_flt_i32, sizeof(float)); if (value > max_flt) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } else if (isnan(value)) { return dta_113_write_missing_numeric(row, var); } return dta_write_raw_float(row, value); } static readstat_error_t dta_write_double(void *row, const readstat_variable_t *var, double value) { int64_t max_dbl_i64 = DTA_113_MAX_DOUBLE; double max_dbl; memcpy(&max_dbl, &max_dbl_i64, sizeof(double)); if (value > max_dbl) { return READSTAT_ERROR_NUMERIC_VALUE_IS_OUT_OF_RANGE; } else if (isnan(value)) { return dta_113_write_missing_numeric(row, var); } return dta_write_raw_double(row, value); } static readstat_error_t dta_write_string(void *row, const readstat_variable_t *var, const char *value) { size_t max_len = var->storage_width; if (value == NULL || value[0] == '\0') { memset(row, '\0', max_len); } else { size_t value_len = strlen(value); if (value_len > max_len) return READSTAT_ERROR_STRING_VALUE_IS_TOO_LONG; strncpy((char *)row, value, max_len); } return READSTAT_OK; } static readstat_error_t dta_118_write_string_ref(void *row, const readstat_variable_t *var, readstat_string_ref_t *ref) { if (ref == NULL) return READSTAT_ERROR_STRING_REF_IS_REQUIRED; int16_t v = ref->first_v; int64_t o = ref->first_o; char *row_bytes = (char *)row; memcpy(&row_bytes[0], &v, sizeof(int16_t)); if (!machine_is_little_endian()) { o <<= 16; } memcpy(&row_bytes[2], &o, 6); return READSTAT_OK; } static readstat_error_t dta_117_write_string_ref(void *row, const readstat_variable_t *var, readstat_string_ref_t *ref) { if (ref == NULL) return READSTAT_ERROR_STRING_REF_IS_REQUIRED; int32_t v = ref->first_v; int32_t o = ref->first_o; char *row_bytes = (char *)row; memcpy(&row_bytes[0], &v, sizeof(int32_t)); memcpy(&row_bytes[4], &o, sizeof(int32_t)); return READSTAT_OK; } static readstat_error_t dta_113_write_missing_numeric(void *row, const readstat_variable_t *var) { readstat_error_t retval = READSTAT_OK; if (var->type == READSTAT_TYPE_INT8) { retval = dta_write_raw_int8(row, DTA_113_MISSING_INT8); } else if (var->type == READSTAT_TYPE_INT16) { retval = dta_write_raw_int16(row, DTA_113_MISSING_INT16); } else if (var->type == READSTAT_TYPE_INT32) { retval = dta_write_raw_int32(row, DTA_113_MISSING_INT32); } else if (var->type == READSTAT_TYPE_FLOAT) { retval = dta_write_raw_int32(row, DTA_113_MISSING_FLOAT); } else if (var->type == READSTAT_TYPE_DOUBLE) { retval = dta_write_raw_int64(row, DTA_113_MISSING_DOUBLE); } return retval; } static readstat_error_t dta_old_write_missing_numeric(void *row, const readstat_variable_t *var) { readstat_error_t retval = READSTAT_OK; if (var->type == READSTAT_TYPE_INT8) { retval = dta_write_raw_int8(row, DTA_OLD_MISSING_INT8); } else if (var->type == READSTAT_TYPE_INT16) { retval = dta_write_raw_int16(row, DTA_OLD_MISSING_INT16); } else if (var->type == READSTAT_TYPE_INT32) { retval = dta_write_raw_int32(row, DTA_OLD_MISSING_INT32); } else if (var->type == READSTAT_TYPE_FLOAT) { retval = dta_write_raw_int32(row, DTA_OLD_MISSING_FLOAT); } else if (var->type == READSTAT_TYPE_DOUBLE) { retval = dta_write_raw_int64(row, DTA_OLD_MISSING_DOUBLE); } return retval; } static readstat_error_t dta_write_missing_string(void *row, const readstat_variable_t *var) { return dta_write_string(row, var, NULL); } static readstat_error_t dta_113_write_missing_tagged(void *row, const readstat_variable_t *var, char tag) { readstat_error_t retval = READSTAT_OK; if (tag < 'a' || tag > 'z') return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE; if (var->type == READSTAT_TYPE_INT8) { retval = dta_write_raw_int8(row, DTA_113_MISSING_INT8_A + (tag - 'a')); } else if (var->type == READSTAT_TYPE_INT16) { retval = dta_write_raw_int16(row, DTA_113_MISSING_INT16_A + (tag - 'a')); } else if (var->type == READSTAT_TYPE_INT32) { retval = dta_write_raw_int32(row, DTA_113_MISSING_INT32_A + (tag - 'a')); } else if (var->type == READSTAT_TYPE_FLOAT) { retval = dta_write_raw_int32(row, DTA_113_MISSING_FLOAT_A + ((tag - 'a') << 11)); } else if (var->type == READSTAT_TYPE_DOUBLE) { retval = dta_write_raw_int64(row, DTA_113_MISSING_DOUBLE_A + ((int64_t)(tag - 'a') << 40)); } else { retval = READSTAT_ERROR_TAGGED_VALUES_NOT_SUPPORTED; } return retval; } static readstat_error_t dta_end_data(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; dta_ctx_t *ctx = writer->module_ctx; readstat_error_t error = READSTAT_OK; if (!writer->initialized) return READSTAT_ERROR_WRITER_NOT_INITIALIZED; error = dta_write_tag(writer, ctx, ""); if (error != READSTAT_OK) goto cleanup; error = dta_emit_strls(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_emit_value_labels(writer, ctx); if (error != READSTAT_OK) goto cleanup; error = dta_write_tag(writer, ctx, "
"); if (error != READSTAT_OK) goto cleanup; cleanup: return error; } static void dta_module_ctx_free(void *module_ctx) { dta_ctx_free(module_ctx); } readstat_error_t dta_metadata_ok(void *writer_ctx) { readstat_writer_t *writer = (readstat_writer_t *)writer_ctx; if (writer->compression != READSTAT_COMPRESS_NONE) return READSTAT_ERROR_UNSUPPORTED_COMPRESSION; if (writer->version > DTA_FILE_VERSION_MAX || writer->version < DTA_FILE_VERSION_MIN) return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION; return READSTAT_OK; } readstat_error_t readstat_begin_writing_dta(readstat_writer_t *writer, void *user_ctx, long row_count) { if (writer->version == 0) writer->version = DTA_FILE_VERSION_DEFAULT; writer->callbacks.metadata_ok = &dta_metadata_ok; if (writer->version >= 117) { writer->callbacks.variable_width = &dta_117_variable_width; } else if (writer->version >= 111) { writer->callbacks.variable_width = &dta_111_variable_width; } else { writer->callbacks.variable_width = &dta_old_variable_width; } if (writer->version >= 118) { writer->callbacks.variable_ok = &dta_118_variable_ok; } else if (writer->version >= 110) { writer->callbacks.variable_ok = &dta_110_variable_ok; } else { writer->callbacks.variable_ok = &dta_old_variable_ok; } if (writer->version >= 118) { writer->callbacks.write_string_ref = &dta_118_write_string_ref; } else if (writer->version == 117) { writer->callbacks.write_string_ref = &dta_117_write_string_ref; } if (writer->version >= 113) { writer->callbacks.write_int8 = &dta_113_write_int8; writer->callbacks.write_int16 = &dta_113_write_int16; writer->callbacks.write_int32 = &dta_113_write_int32; writer->callbacks.write_missing_number = &dta_113_write_missing_numeric; writer->callbacks.write_missing_tagged = &dta_113_write_missing_tagged; } else { writer->callbacks.write_int8 = &dta_old_write_int8; writer->callbacks.write_int16 = &dta_old_write_int16; writer->callbacks.write_int32 = &dta_old_write_int32; writer->callbacks.write_missing_number = &dta_old_write_missing_numeric; } writer->callbacks.write_float = &dta_write_float; writer->callbacks.write_double = &dta_write_double; writer->callbacks.write_string = &dta_write_string; writer->callbacks.write_missing_string = &dta_write_missing_string; writer->callbacks.begin_data = &dta_begin_data; writer->callbacks.end_data = &dta_end_data; writer->callbacks.module_ctx_free = &dta_module_ctx_free; return readstat_begin_writing_file(writer, user_ctx, row_count); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769180459.0 pyreadstat-1.3.3/tests/0000755000076500000240000000000015134706453013410 5ustar00dialout././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769172646.0 pyreadstat-1.3.3/tests/test_basic.py0000644000076500000240000017000015134667246016106 0ustar00dialout#-*- coding: utf-8 -*- # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# from datetime import datetime, timedelta, date import unittest import os import sys import shutil import pandas as pd import numpy as np is_pathlib_available = False try: from pathlib import Path is_pathlib_available = True except: pass is_pandas_version_newer_than_2 = int(pd.__version__.split(".")[0])>2 class TestBasic(unittest.TestCase): """ Test suite for pyreadstat. """ def _prepare_data(self): self.script_folder = os.path.dirname(os.path.realpath(__file__)) self.parent_folder = os.path.split(self.script_folder)[0] self.data_folder = os.path.join(self.parent_folder, "test_data") self.basic_data_folder = os.path.join(self.data_folder, "basic") self.catalog_data_folder = os.path.join(self.data_folder, "sas_catalog") self.international_data_folder = os.path.join(self.data_folder, "ínternátionál") self.missing_data_folder = os.path.join(self.data_folder, "missing_data") self.mr_data_folder = os.path.join(self.data_folder, "multiple_response") self.write_folder = os.path.join(self.data_folder, "write") if not os.path.isdir(self.write_folder): os.makedirs(self.write_folder) # basic pandas_csv = os.path.join(self.basic_data_folder, "sample.csv") df_pandas = pd.read_csv(pandas_csv) df_pandas["mydate"] = [datetime.strptime(x, '%Y-%m-%d').date() if type(x) == str else float('nan') for x in df_pandas["mydate"]] df_pandas["dtime"] = [datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.000000') if type(x) == str else float('nan') for x in df_pandas["dtime"]] df_pandas["mytime"] = [datetime.strptime(x, '%H:%M:%S.000000').time() if type(x) == str else float('nan') for x in df_pandas["mytime"]] df_pandas["myord"] = df_pandas["myord"].astype(float) df_pandas["mylabl"] = df_pandas["mylabl"].astype(float) self.df_pandas = df_pandas # formatted mylabl_format = {1.0:"Male", 2.0:"Female"} myord_format = {1.0:"low", 2.0:"medium", 3.0:"high"} df_pandas_formatted = df_pandas.copy() df_pandas_formatted["mylabl"] = df_pandas_formatted["mylabl"].apply(lambda x: mylabl_format[x]) df_pandas_formatted["myord"] = df_pandas_formatted["myord"].apply(lambda x: myord_format[x]) df_pandas_formatted["mylabl"] = df_pandas_formatted["mylabl"].astype("category") df_pandas_formatted["myord"] = df_pandas_formatted["myord"].astype("category") self.df_pandas_formatted = df_pandas_formatted # skip some columns self.usecols = ['mynum', 'myord'] cols_to_drop = list(set(df_pandas.columns.values.tolist()) - set(self.usecols)) self.df_usecols = df_pandas.drop(cols_to_drop, axis=1) # sas formatted sas_formatted = os.path.join(self.catalog_data_folder, "sas_formatted.csv") df_sas = pd.read_csv(sas_formatted) df_sas["SEXA"] = df_sas["SEXA"].astype("category") df_sas["SEXB"] = df_sas["SEXB"].astype("category") self.df_sas_format = df_sas # dates sas_dates = os.path.join(self.basic_data_folder, "dates.csv") df_dates1 = pd.read_csv(sas_dates) df_dates1["date"] = pd.to_datetime(df_dates1["date"]) df_dates1["dtime"] = pd.to_datetime(df_dates1["dtime"]) df_dates1["time"] = pd.to_datetime(df_dates1["time"], format='%H:%M:%S') df_dates1["time"] = df_dates1["time"].apply(lambda x: x.time()) self.df_sas_dates_as_pandas = df_dates1 df_dates2 = df_dates1.copy() df_dates2["date"] = df_dates2["date"].apply(lambda x: x.date()) self.df_sas_dates = df_dates2 self.df_sas_dates2 = pd.concat([self.df_sas_dates, pd.DataFrame([[np.nan, pd.NaT, np.nan]],columns=["date", "dtime", "time"])], ignore_index=True) # missing data pandas_missing_sav_csv = os.path.join(self.basic_data_folder, "sample_missing.csv") df_missing_sav = pd.read_csv(pandas_missing_sav_csv, na_values="#NULL!", keep_default_na=False) df_missing_sav["mydate"] = [datetime.strptime(x, '%Y-%m-%d').date() if type(x) == str else float('nan') for x in df_missing_sav["mydate"]] df_missing_sav["dtime"] = [datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.000000') if type(x) == str else float('nan') for x in df_missing_sav["dtime"]] df_missing_sav["mytime"] = [datetime.strptime(x, '%H:%M:%S.000000').time() if type(x) == str else float('nan') for x in df_missing_sav["mytime"]] self.df_missing_sav = df_missing_sav pandas_missing_user_sav_csv = os.path.join(self.basic_data_folder, "sample_missing_user.csv") df_user_missing_sav = pd.read_csv(pandas_missing_user_sav_csv, na_values="#NULL!", keep_default_na=False) df_user_missing_sav["mydate"] = [datetime.strptime(x, '%Y-%m-%d').date() if type(x) == str else float('nan') for x in df_user_missing_sav["mydate"]] df_user_missing_sav["dtime"] = [datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.000000') if type(x) == str else float('nan') for x in df_user_missing_sav["dtime"]] df_user_missing_sav["mytime"] = [datetime.strptime(x, '%H:%M:%S.000000').time() if type(x) == str else float('nan') for x in df_user_missing_sav["mytime"]] self.df_user_missing_sav = df_user_missing_sav # no dates nodates_spss_csv = os.path.join(self.basic_data_folder, "sample_nodate_spss.csv") df_nodates_spss = pd.read_csv(nodates_spss_csv) df_nodates_spss["myord"] = df_nodates_spss["myord"].astype(float) df_nodates_spss["mylabl"] = df_nodates_spss["mylabl"].astype(float) self.df_nodates_spss = df_nodates_spss nodates_sastata_csv = os.path.join(self.basic_data_folder, "sample_nodate_sas_stata.csv") df_nodates_sastata = pd.read_csv(nodates_sastata_csv) df_nodates_sastata["myord"] = df_nodates_sastata["myord"].astype(float) df_nodates_sastata["mylabl"] = df_nodates_sastata["mylabl"].astype(float) self.df_nodates_sastata = df_nodates_sastata # character column with nan and object column with nan (object pyreadstat writer doesn't know what to do with) self.df_charnan = pd.DataFrame([[0,np.nan,np.nan],[1,"test", timedelta]], columns = ["integer", "string", "object"]) # xport files v5 vs v8 self.xptv5v8 = pd.DataFrame([[float(x)] for x in range(1,11)], columns=["i"]) # long string self.df_longstr = pd.DataFrame({ "v1": { "10001": """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac pretium sem. Fusce aliquet augue rhoncus consequat pulvinar. In est ex, porta congue diam sed, laoreet suscipit purus. Phasellus mollis lobortis tellus at vehicula. Etiam egestas augue id massa bibendum volutpat id et ipsum. Praesent ut lorem rhoncus, pharetra risus sed, pharetra sem. In pulvinar egestas erat, id condimentum tortor tempus sed. Duis ornare lacus ut ligula congue, non convallis urna dignissim. Etiam vehicula turpis sit amet nisi finibus laoreet. Duis molestie consequat nulla, non lobortis est tempus sit amet. Quisque elit est, congue non commodo vitae, porttitor ac erat. """, "10002": "fgsdghshsgh", "10003": "gsfdgsdg", }, "v2": { "10001": "gsfdgsfdgsfg", "10002": "fgsdghshsgh", "10003": "gsfdgsdg", }, }) def setUp(self): # set paths self._prepare_data() def test_sas7bdat(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat")) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) #self.assertTrue(meta.creation_time==datetime(2018, 8, 16, 18, 21, 52)) #self.assertTrue(meta.modification_time==datetime(2018, 8, 16, 18, 21, 52)) def test_sas7bdat_bincompressed(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample_bincompressed.sas7bdat")) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) def test_sas7bdat_metaonly(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat")) df2, meta2 = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), metadataonly=True) self.assertTrue(df2.empty) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="double") self.assertTrue(meta.readstat_variable_types["dtime"]=="double") def test_sas7bdat_usecols(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), usecols=self.usecols) self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_sas7bdat_international(self): """ On windows, paths with international characters are problematic. This is verifying that it is working as expected """ # in addition, this works only in python 3 if sys.version_info[0]>2: df, meta = pyreadstat.read_sas7bdat(os.path.join(self.international_data_folder, "sample.sas7bdat")) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) def test_sas7bdat_nodates(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), disable_datetime_conversion=True) self.assertTrue(df.equals(self.df_nodates_sastata)) def test_sas7bdat_chunk(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), row_limit = 2, row_offset =1) df_pandas = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_xport(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt")) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(meta.number_rows==len(df)) #self.assertTrue(meta.creation_time==datetime(2018, 8, 14, 10, 55, 46)) #self.assertTrue(meta.modification_time==datetime(2018, 8, 14, 10, 55, 46)) def test_xport_v5(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sas.xpt5")) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.xptv5v8)) self.assertTrue(meta.number_rows==len(df)) def test_xport_v8(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sas.xpt8")) self.assertTrue(df.equals(self.xptv5v8)) self.assertTrue(meta.number_rows==len(df)) def test_xport_metaonly(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt")) df2, meta2 = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), metadataonly=True) self.assertTrue(df2.empty) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta2.number_rows is None) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) def test_xport_usecols(self): # Currently readstat does not support skipping cols for XPT files, usecols = [x.upper() for x in self.usecols] df, meta = pyreadstat.pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), usecols=usecols) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) def test_xport_nodates(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), disable_datetime_conversion=True) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_nodates_sastata)) def test_xport_chunks(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), row_limit = 2, row_offset =1) df.columns = [x.lower() for x in df.columns] df_pandas = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_dta(self): # discard dtime and arrange time df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta")) df_pandas = self.df_pandas.copy() df_pandas["myord"] = df_pandas["myord"].astype(np.int64) df_pandas["mylabl"] = df_pandas["mylabl"].astype(np.int64) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="int8") self.assertTrue(meta.readstat_variable_types["dtime"]=="double") #self.assertTrue(meta.creation_time==datetime(2018, 12, 17, 14, 53)) #self.assertTrue(meta.modification_time==datetime(2018, 12, 17, 14, 53)) def test_dta_metaonly(self): df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta")) df2, meta2 = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), metadataonly=True) self.assertTrue(df2.empty) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) def test_dta_usecols(self): df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), usecols=self.usecols) df_pandas = self.df_usecols.copy() df_pandas["myord"] = df_pandas["myord"].astype(np.int64) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_dta_nodates(self): df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder,"sample.dta"), disable_datetime_conversion=True) df_pandas = self.df_nodates_sastata df_pandas["myord"] = df_pandas["myord"].astype(np.int64) df_pandas["mylabl"] = df_pandas["mylabl"].astype(np.int64) df_pandas["dtime"] = df_pandas["dtime"] * 1000 df_pandas["mytime"] = df_pandas["mytime"] * 1000 self.assertTrue(df.equals(df_pandas)) def test_dta_chunks(self): # discard dtime and arrange time df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), row_limit = 2, row_offset =1) df_pandas = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) df_pandas["myord"] = df_pandas["myord"].astype(np.int64) df_pandas["mylabl"] = df_pandas["mylabl"].astype(np.int64) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_sav(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav")) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="double") #self.assertTrue(meta.creation_time==datetime(2018, 8, 16, 17, 22, 33)) #self.assertTrue(meta.modification_time==datetime(2018, 8, 16, 17, 22, 33)) def test_sav_metaonly(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav")) df2, meta2 = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), metadataonly=True) self.assertTrue(df2.empty) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(len(meta2.notes) > 0) def test_sav_formatted(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), apply_value_formats=True, formats_as_category=True) #df.columns = self.df_pandas_formatted.columns self.assertTrue(df.equals(self.df_pandas_formatted)) self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas_formatted)) self.assertTrue(len(meta.notes) > 0) def test_sav_usecols(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), usecols=self.usecols) self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_sav_missing(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample_missing.sav")) self.assertTrue(df.equals(self.df_missing_sav)) self.assertTrue(meta.missing_ranges == {}) df_user, meta_user = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample_missing.sav"), user_missing=True) self.assertTrue(df_user.equals(self.df_user_missing_sav)) self.assertTrue(meta_user.missing_ranges['mynum'][0]=={'lo': 2000.0, 'hi': 3000.0}) # user missing with usecols df_user, meta_user = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample_missing.sav"), user_missing=True, usecols=["mynum", "mylabl"]) df_sub = self.df_user_missing_sav[["mynum", "mylabl"]] self.assertTrue(df_user.equals(df_sub)) def test_sav_nodates(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), disable_datetime_conversion=True) self.assertTrue(df.equals(self.df_nodates_spss)) def test_sav_chunks(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), row_limit = 2, row_offset =1) df_pandas = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") def test_sav_expand(self): src = os.path.join(self.basic_data_folder, "sample.sav") dst = "~/sample.sav" shutil.copyfile(src, os.path.expanduser(dst)) df, meta = pyreadstat.read_sav(dst) os.remove(os.path.expanduser(dst)) self.assertTrue(df.equals(self.df_pandas)) def test_zsav(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav")) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(len(meta.notes) > 0) def test_zsav_metaonly(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav")) df2, meta2 = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), metadataonly=True) self.assertTrue(df2.empty) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(len(meta2.notes) > 0) def test_zsav_formatted(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), apply_value_formats=True, formats_as_category=True) self.assertTrue(df.equals(self.df_pandas_formatted)) self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas_formatted)) self.assertTrue(len(meta.notes) > 0) def test_zsav_usecols(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), usecols=self.usecols) self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_zsav_nodates(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), disable_datetime_conversion=True) self.assertTrue(df.equals(self.df_nodates_spss)) def test_zsav_chunks(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), row_limit = 2, row_offset =1) df_pandas = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") def test_por(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por")) df_pandas_por = self.df_pandas.copy() df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas_por)) self.assertTrue(len(meta.notes) > 0) #self.assertTrue(meta.creation_time==datetime(2018, 12, 16, 17, 28, 21)) #self.assertTrue(meta.modification_time==datetime(2018, 12, 16, 17, 28, 21)) def test_por_formatted(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), apply_value_formats=True, formats_as_category=True) df_pandas_por = self.df_pandas_formatted.copy() df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns)) self.assertTrue(meta.number_rows == len(df_pandas_por)) self.assertTrue(len(meta.notes) > 0) def test_por_metaonly(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por")) df2, meta2 = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), metadataonly=True) self.assertTrue(df2.empty) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta2.number_rows is None) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(len(meta2.notes) > 0) def test_por_usecols(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), usecols=["MYNUM"]) df_pandas_por = self.df_pandas[["mynum"]] df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(df_pandas_por.columns.values.tolist())) def test_por_nodates(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), disable_datetime_conversion=True) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_nodates_spss)) def test_por_chunks(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), row_limit = 2, row_offset =1) df_pandas_por = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas_por['dtime'] = pd.to_datetime(df_pandas_por.dtime) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas_por)) self.assertTrue(len(meta.notes) > 0) def test_sas_catalog_win(self): """these sas7bdat and sasbcat where produced on windows, probably 32 bit""" dat = os.path.join(self.catalog_data_folder, "test_data_win.sas7bdat") cat = os.path.join(self.catalog_data_folder, "test_formats_win.sas7bcat") df, meta = pyreadstat.read_sas7bdat(dat, catalog_file=cat) self.assertTrue(df.equals(self.df_sas_format)) def test_sas_catalog_linux(self): """these sas7bdat and sasbcat where produced on linux 64 bit""" dat = os.path.join(self.catalog_data_folder, "test_data_linux.sas7bdat") cat = os.path.join(self.catalog_data_folder, "test_formats_linux.sas7bcat") df, meta = pyreadstat.read_sas7bdat(dat, catalog_file=cat) self.assertTrue(df.equals(self.df_sas_format)) def test_sas_dates(self): sas_file = os.path.join(self.basic_data_folder, "dates.sas7bdat") df_sas, meta = pyreadstat.read_sas7bdat(sas_file) self.assertTrue(df_sas.equals(self.df_sas_dates)) def test_sas_dates_as_pandas(self): sas_file = os.path.join(self.basic_data_folder, "dates.sas7bdat") df_sas, meta = pyreadstat.read_sas7bdat(sas_file, dates_as_pandas_datetime=True) self.assertTrue(df_sas.equals(self.df_sas_dates_as_pandas)) def test_sas_user_missing(self): sas_file = os.path.join(self.missing_data_folder, "missing_test.sas7bdat") cat_file = os.path.join(self.missing_data_folder, "missing_formats.sas7bcat") unformatted_csv = os.path.join(self.missing_data_folder, "missing_unformatted.csv") formatted_csv = os.path.join(self.missing_data_folder, "missing_sas_formatted.csv") labeled_csv = os.path.join(self.missing_data_folder, "missing_sas_labeled.csv") df_sas, meta = pyreadstat.read_sas7bdat(sas_file) df_csv = pd.read_csv(unformatted_csv) self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_sas7bdat(sas_file, user_missing=True) df_csv = pd.read_csv(formatted_csv) self.assertTrue(df_sas.equals(df_csv)) missing_user_values = {'var1':['A'],'var2': ['B'], 'var3':['C'], 'var4':['X'], 'var5':['Y'], 'var6':['Z'], 'var7':['_']} self.assertDictEqual(meta.missing_user_values, missing_user_values) df_sas, meta = pyreadstat.read_sas7bdat(sas_file, catalog_file=cat_file, user_missing=True, formats_as_category=False) df_csv = pd.read_csv(labeled_csv) self.assertTrue(df_sas.equals(df_csv)) def test_dta_user_missing(self): dta_file = os.path.join(self.missing_data_folder, "missing_test.dta") unformatted_csv = os.path.join(self.missing_data_folder, "missing_unformatted.csv") formatted_csv = os.path.join(self.missing_data_folder, "missing_dta_formatted.csv") labeled_csv = os.path.join(self.missing_data_folder, "missing_dta_labeled.csv") df_sas, meta = pyreadstat.read_dta(dta_file) df_csv = pd.read_csv(unformatted_csv) self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_dta(dta_file, user_missing=True) df_csv = pd.read_csv(formatted_csv) self.assertTrue(df_sas.equals(df_csv)) missing_user_values = {'var1':['a'],'var2': ['b'], 'var3':['c'], 'var4':['x'], 'var5':['y'], 'var6':['z']} self.assertDictEqual(meta.missing_user_values, missing_user_values) df_sas, meta = pyreadstat.read_dta(dta_file, apply_value_formats=True, user_missing=True, formats_as_category=False) df_csv = pd.read_csv(labeled_csv) self.assertTrue(df_sas.equals(df_csv)) def test_sav_user_missing(self): sav_file = os.path.join(self.missing_data_folder, "missing_test.sav") unformatted_csv = os.path.join(self.missing_data_folder, "missing_sav_unformatted.csv") formatted_csv = os.path.join(self.missing_data_folder, "missing_sav_formatted.csv") labeled_csv = os.path.join(self.missing_data_folder, "missing_sav_labeled.csv") df_sas, meta = pyreadstat.read_sav(sav_file) df_csv = pd.read_csv(unformatted_csv) self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_sav(sav_file, user_missing=True) df_csv = pd.read_csv(formatted_csv) self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_sav(sav_file, apply_value_formats=True, user_missing=True, formats_as_category=False) df_sas.loc[1, 'var1'] = int(df_sas['var1'][1]) df_sas['var1'] = df_sas['var1'].astype(str) df_csv = pd.read_csv(labeled_csv) self.assertTrue(df_sas.equals(df_csv)) def test_sav_missing_char(self): df, meta = pyreadstat.read_sav(os.path.join(self.missing_data_folder, "missing_char.sav")) mdf = pd.DataFrame([[np.nan], ["a"]], columns=["mychar"]) self.assertTrue(df.equals(mdf)) self.assertTrue(meta.missing_ranges == {}) df2, meta2 = pyreadstat.read_sav(os.path.join(self.missing_data_folder, "missing_char.sav"), user_missing=True) mdf2 = pd.DataFrame([["Z"], ["a"]], columns=["mychar"]) self.assertTrue(df2.equals(mdf2)) self.assertTrue(meta2.missing_ranges['mychar'][0]=={'lo': "Z", 'hi': "Z"}) # test reading metadata for multiple response data def test_sav_multiple_response(self): """Assert MR data is correctly read from sav into metadata.""" _, meta = pyreadstat.read_sav(os.path.join(self.mr_data_folder, "simple_alltypes.sav")) assert meta.mr_sets == { "categorical_array": { "type": "C", "is_dichotomy": False, "counted_value": None, "label": "", "variable_list": ["ca_subvar_1", "ca_subvar_2", "ca_subvar_3"] }, "mymrset": { "type": "D", "is_dichotomy": True, "counted_value": 1, "label": "My multiple response set", "variable_list": ["bool1", "bool2", "bool3"] } } def test_sav_without_multiple_response(self): """Assert MR data is read as empty dict when not present in sav.""" _, meta = pyreadstat.read_sav(os.path.join(self.missing_data_folder, "missing_char.sav")) assert meta.mr_sets == {} # read in chunks def test_chunk_reader(self): fpath = os.path.join(self.basic_data_folder, "sample.sas7bdat") reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sas7bdat, fpath, chunksize= 2, offset=1, limit=2, disable_datetime_conversion=True) for df, meta in reader: pass currow = self.df_nodates_sastata.iloc[1:3,:].reset_index(drop=True) self.assertTrue(df.equals(currow)) # read multiprocessing def test_multiprocess_reader(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") df_multi, meta_multi = pyreadstat.read_file_multiprocessing(pyreadstat.read_sav, fpath) df_single, meta_single = pyreadstat.read_sav(fpath) self.assertTrue(df_multi.equals(df_single)) self.assertEqual(meta_multi.number_rows, meta_single.number_rows) def test_chunk_reader_multiprocess(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sav, fpath, chunksize= 50, multiprocess=True) alldfs = list() for df, meta in reader: alldfs.append(df) df_multi = pd.concat(alldfs, axis=0, ignore_index=True) df_single, meta_single = pyreadstat.read_sav(fpath) self.assertTrue(df_multi.equals(df_single)) def test_chunk_reader_multiprocess_dict(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sav, fpath, chunksize= 50, multiprocess=True, output_format='dict') alldfs = list() for chunkdict, meta in reader: df = pd.DataFrame(chunkdict) alldfs.append(df) df_multi = pd.concat(alldfs, axis=0, ignore_index=True) df_single, meta_single = pyreadstat.read_sav(fpath) self.assertTrue(df_multi.equals(df_single)) def test_multiprocess_reader_xport(self): fpath = os.path.join(self.basic_data_folder, "sample.xpt") df_multi, meta_multi = pyreadstat.read_file_multiprocessing(pyreadstat.read_xport, fpath, num_rows=1000) df_single, meta_single = pyreadstat.read_xport(fpath) if is_pandas_version_newer_than_2: # because in multi there are NaN values in a chunk these columns get object type df_single['DTIME'] = df_single['DTIME'].astype(object) df_single['MYCHAR'] = df_single['MYCHAR'].astype(object) self.assertTrue(df_multi.equals(df_single)) # writing def test_sav_write_basic(self): file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = os.path.join(self.write_folder, "basic_write.sav") pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) self.assertEqual(meta.variable_display_width['mychar'], variable_display_width['mychar']) #self.assertDictEqual(meta.variable_alignment, variable_alignment) self.assertEqual(meta.variable_measure["mychar"], variable_measure["mychar"]) def test_sav_write_basic_expanduser(self): file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = "~/sav_expand.sav" pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True) os.remove(os.path.expanduser(path)) self.assertTrue(df.equals(self.df_pandas)) def test_zsav_write_basic(self): file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} path = os.path.join(self.write_folder, "basic_write.zsav") pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, compress=True, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges) df, meta = pyreadstat.read_sav(path, user_missing=True) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) def test_dta_write_basic(self): df_pandas = self.df_pandas.copy() df_pandas["myord"] = df_pandas["myord"].astype(np.int32) df_pandas["mylabl"] = df_pandas["mylabl"].astype(np.int32) file_label = "basic write" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1: 'Male', 2: 'Female'}, 'myord': {1: 'low', 2: 'medium', 3: 'high'}} path = os.path.join(self.write_folder, "basic_write.dta") pyreadstat.write_dta(df_pandas, path, file_label=file_label, column_labels=col_labels, version=12, variable_value_labels=variable_value_labels) df, meta = pyreadstat.read_dta(path) df_pandas["myord"] = df_pandas["myord"].astype(np.int64) df_pandas["mylabl"] = df_pandas["mylabl"].astype(np.int64) self.assertTrue(df.equals(df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) def test_dta_write_user_missing(self): df_csv = pd.DataFrame([[3,"a"],["a","b"]], columns=["Var1", "Var2"]) df_csv2 = pd.DataFrame([[3,"a"],["labeled","b"]], columns=["Var1", "Var2"]) missing_user_values = {'Var1': ['a']} variable_value_labels = {'Var1':{'a':'labeled'}} path = os.path.join(self.write_folder, "user_missing_write.dta") pyreadstat.write_dta(df_csv, path, version=12, missing_user_values=missing_user_values, variable_value_labels=variable_value_labels) df_dta, meta = pyreadstat.read_dta(path, user_missing=True) self.assertTrue(df_csv.equals(df_dta)) self.assertDictEqual(meta.missing_user_values, missing_user_values) df_dta2, meta2 = pyreadstat.read_dta(path, user_missing=True, apply_value_formats=True, formats_as_category=False) self.assertTrue(df_csv2.equals(df_dta2)) def test_xport_write_basic_v8(self): file_label = "basic write" table_name = "TEST" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] path = os.path.join(self.write_folder, "write.xpt") pyreadstat.write_xport(self.df_pandas, path, file_label=file_label, column_labels=col_labels, table_name=table_name, file_format_version=8) df, meta = pyreadstat.read_xport(path) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(table_name, meta.table_name) def test_xport_write_basic_v5(self): file_label = "basic write" table_name = "TEST" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] path = os.path.join(self.write_folder, "write.xpt") pyreadstat.write_xport(self.df_pandas, path, file_label=file_label, column_labels=col_labels, table_name=table_name, file_format_version=5) df, meta = pyreadstat.read_xport(path) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(table_name, meta.table_name) def test_por_write_basic(self): file_label = "basic write" #file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] path = os.path.join(self.write_folder, "write.por") pyreadstat.write_por(self.df_pandas, path, file_label=file_label, column_labels=col_labels) #, note=file_note) df, meta = pyreadstat.read_por(path) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) #self.assertEqual(meta.notes[0], file_note) def test_sav_write_dates(self): path = os.path.join(self.write_folder, "dates_write.sav") pyreadstat.write_sav(self.df_sas_dates2, path) df, meta = pyreadstat.read_sav(path) self.assertTrue(df.equals(self.df_sas_dates2)) def test_zsav_write_dates(self): path = os.path.join(self.write_folder, "dates_write_zsav.sav") pyreadstat.write_sav(self.df_sas_dates2, path, compress=True) df, meta = pyreadstat.read_sav(path) self.assertTrue(df.equals(self.df_sas_dates2)) def test_dta_write_dates(self): path = os.path.join(self.write_folder, "dates_write.dta") pyreadstat.write_dta(self.df_sas_dates, path) df, meta = pyreadstat.read_dta(path) self.assertTrue(df.equals(self.df_sas_dates)) def test_xport_write_dates(self): path = os.path.join(self.write_folder, "dates_write.xpt") pyreadstat.write_xport(self.df_sas_dates2, path) df, meta = pyreadstat.read_xport(path) self.assertTrue(df.equals(self.df_sas_dates2)) def test_sav_write_charnan(self): path = os.path.join(self.write_folder, "charnan.sav") pyreadstat.write_sav(self.df_charnan, path) df, meta = pyreadstat.read_sav(path) df2 = self.df_charnan df2.iloc[0,1] = "" df2.iloc[0,2] = "" df2['integer'] = df2["integer"].astype(float) df2['object'] = df2['object'].astype(str) self.assertTrue(df2.equals(df)) def test_zsav_write_charnan(self): path = os.path.join(self.write_folder, "charnan_zsav.sav") pyreadstat.write_sav(self.df_charnan, path, compress=True) df, meta = pyreadstat.read_sav(path) df2 = self.df_charnan df2.iloc[0,1] = "" df2.iloc[0,2] = "" df2['integer'] = df2["integer"].astype(float) df2['object'] = df2['object'].astype(str) self.assertTrue(df2.equals(df)) def test_xport_write_charnan(self): path = os.path.join(self.write_folder, "charnan.xpt") pyreadstat.write_xport(self.df_charnan, path) df, meta = pyreadstat.read_xport(path) df2 = self.df_charnan df2.iloc[0,1] = "" df2.iloc[0,2] = "" df2['integer'] = df2["integer"].astype(float) df2['object'] = df2['object'].astype(str) self.assertTrue(df2.equals(df)) def test_por_write_charnan(self): path = os.path.join(self.write_folder, "charnan_zsav.por") pyreadstat.write_por(self.df_charnan, path) df, meta = pyreadstat.read_por(path) df.columns = [x.lower() for x in df.columns] df2 = self.df_charnan df2.iloc[0,1] = "" df2.iloc[0,2] = "" df2['integer'] = df2["integer"].astype(float) df2['object'] = df2['object'].astype(str) self.assertTrue(df2.equals(df)) def test_dta_write_charnan(self): path = os.path.join(self.write_folder, "charnan.dta") pyreadstat.write_dta(self.df_charnan, path) df, meta = pyreadstat.read_dta(path) df2 = self.df_charnan df2.iloc[0,1] = "" df2.iloc[0,2] = "" df2['integer'] = df2["integer"].astype(float) df2['object'] = df2['object'].astype(str) self.assertTrue(df2.equals(df)) def test_set_value_labels(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav")) df_formatted = pyreadstat.set_value_labels(df, meta, formats_as_category=True) #df.columns = self.df_pandas_formatted.columns self.assertTrue(df_formatted.equals(self.df_pandas_formatted)) # partial sub1_raw = df[['myord']] sub1 = pyreadstat.set_value_labels(sub1_raw, meta, formats_as_category=True) sub2 = self.df_pandas_formatted[['myord']] self.assertTrue(sub1.equals(sub2)) def test_update_delete_file(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav")) dst_path = os.path.join(self.write_folder, "update_test.sav") pyreadstat.write_sav(df, dst_path, variable_value_labels = meta.variable_value_labels) # update meta.variable_value_labels.update({'mylabl':{1.0:"Gents", 2.0:"Ladies"}}) pyreadstat.write_sav(df, dst_path, variable_value_labels = meta.variable_value_labels) df2, meta2 = pyreadstat.read_sav(dst_path) self.assertDictEqual(meta2.variable_value_labels, meta.variable_value_labels) os.remove(dst_path) def test_xport_write_dates2_v8(self): # this sas7bdat file has features that are not compatible with v5 df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "dates_xpt.sas7bdat")) dst_path = os.path.join(self.write_folder, "dates_xptv8.xpt") pyreadstat.write_xport(df, dst_path, file_format_version=8) df2, meta2 = pyreadstat.read_xport(dst_path) self.assertTrue(df.equals(df2)) def test_xport_dates2_v8(self): # this sas7bdat file has features that are not compatible with v5 df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "dates_xpt.sas7bdat")) # this xpt file was written in SAS from the sas7bdat file df2, meta2 = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "dates_xpt_v8.xpt")) self.assertTrue(df.equals(df2)) self.assertListEqual(meta.column_labels, meta2.column_labels) def test_sav_international_utf8_char_value(self): # a file that has a value with international characters and the file is coded in utf-8 df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "tegulu.sav")) self.assertTrue(df.iloc[0,1] == "నేను గతంలో వాడిన బ") def test_sav_international_varname(self): # a file with a varname with international characters df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "hebrews.sav")) self.assertTrue(df.columns[0] == "ותק_ב") def test_sav_original_var_types(self): # a file with a varname with international characters df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "test_width.sav")) self.assertEqual(meta.original_variable_types['StartDate'],'A1024') self.assertEqual(meta.original_variable_types['ResponseId'],'A18') self.assertEqual(meta.original_variable_types['Duration__in_seconds_'],'F40.2') self.assertEqual(meta.original_variable_types['Finished'],'F1.0') self.assertEqual(meta.readstat_variable_types['Finished'],'double') def test_sav_write_longstr(self): path = os.path.join(self.write_folder, "longstr.sav") pyreadstat.write_sav(self.df_longstr, path, variable_display_width={"v1": 1000}) df, meta = pyreadstat.read_sav(path) self.assertTrue(meta.variable_display_width['v1']==1000) self.assertTrue(len(df.iloc[0,0])==781) def test_dta_write_longstr(self): path = os.path.join(self.write_folder, "longstr.dta") df_longstr = self.df_longstr # for dta string ref the threshold is 2045, so we need to make the string longer df_longstr.iloc[0,0] = df_longstr.iloc[0,0]*3 pyreadstat.write_dta(self.df_longstr, path) df, meta = pyreadstat.read_dta(path) self.assertTrue(df.equals(df_longstr.reset_index(drop=True))) def test_sas7bdat_file_label_linux(self): "testing file label for file produced on linux" path = os.path.join(self.basic_data_folder, "test_file_label_linux.sas7bdat") df, meta = pyreadstat.read_sas7bdat(path) self.assertEqual(meta.file_label, "mytest label") self.assertEqual(meta.table_name, "TEST_DATA") def test_sas7bdat_extra_date_formats(self): "testing extra date format argument" path = os.path.join(self.basic_data_folder, "date_test.sas7bdat") df, meta = pyreadstat.read_sas7bdat(path, extra_date_formats=["MMYY", "YEAR"]) self.assertEqual(df['yr'].iloc[0], date(2023,1,1)) self.assertEqual(df['dtc4'].iloc[0], date(2023,7,1)) def test_sas7bdat_file_label_windows(self): "testing file label for file produced on windows" path = os.path.join(self.basic_data_folder, "test_file_label_win.sas7bdat") df, meta = pyreadstat.read_sas7bdat(path) self.assertEqual(meta.file_label, "mytest label") self.assertEqual(meta.table_name, "TEST_DATA") def test_sav_write_variable_formats(self): "testing variable formats for SAV files" path = os.path.join(self.write_folder, "variable_format.sav") df = pd.DataFrame({'restricted':[1023, 10], 'integer':[1,2]}) formats = {'restricted':'restricted_integer', 'integer':'integer'} pyreadstat.write_sav(df, path, variable_format=formats) df2, meta2 = pyreadstat.read_sav(path) self.assertEqual(meta2.original_variable_types['restricted'], "N4") self.assertEqual(meta2.original_variable_types['integer'], "F1.0") def test_sav_ordered_categories(self): path = os.path.join(self.basic_data_folder, "ordered_category.sav") df, meta = pyreadstat.read_sav(path, apply_value_formats=True, formats_as_ordered_category=True) self.assertTrue(df.Col1.cat.ordered) self.assertListEqual(list(df.Col1.cat.categories), ['high', 'low', 'medium']) def test_sav_pathlib(self): if is_pathlib_available: path = Path(self.basic_data_folder).joinpath("sample.sav") df, meta = pyreadstat.read_sav(path) self.assertTrue(df.equals(self.df_pandas)) def test_sav_write_pathlib(self): if is_pathlib_available: file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = Path(self.write_folder).joinpath('pathlib_write.sav') pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) self.assertEqual(meta.variable_display_width['mychar'], variable_display_width['mychar']) #self.assertDictEqual(meta.variable_alignment, variable_alignment) self.assertEqual(meta.variable_measure["mychar"], variable_measure["mychar"]) def test_sav_write_dictlabels(self): col_names = ["mychar", "mynum", "mydate", "dtime", "mylabl", "myord", "mytime"] col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] col_lab_dict = {k:v for k,v in zip(col_names, col_labels) if v} variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} path = os.path.join(self.write_folder, "dictlabel_write.sav") pyreadstat.write_sav(self.df_pandas, path, column_labels=col_lab_dict) df, meta = pyreadstat.read_sav(path, user_missing=True) self.assertTrue(df.equals(self.df_pandas)) self.assertListEqual(meta.column_labels, col_labels) def test_dta_write_single_value_user_missing(self): df = pd.DataFrame({"var": ["a", "a", "a", "a"]}) missing_user_values = {"var": ["a"]} path = os.path.join(self.write_folder, "singleusermissing.dta") pyreadstat.write_dta(df=df, dst_path=path, missing_user_values=missing_user_values,version=12) df2, meta2 = pyreadstat.read_dta(path, user_missing=True) self.assertTrue(df.equals(df2)) def test_dta_write_only_missing_and_user_missing(self): df = pd.DataFrame({"var": [np.nan, "a", "b"]}) path = os.path.join(self.write_folder, "onlymissing_and_usermissing.dta") variable_value_labels={"var": {1: "Val 1", 2: "Val 2", 3: "Val 3", "a": "Missing A", "b": "Missing B", } } missing_user_values={"var": ["a", "b"]} pyreadstat.write_dta(df, path, variable_value_labels=variable_value_labels, missing_user_values=missing_user_values,version=12) df2, meta2 = pyreadstat.read_dta(path, user_missing=True, ) self.assertTrue(df.equals(df2)) def test_sav_outputformat_dict(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), output_format='dict') self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="double") padic = self.df_pandas.to_dict(orient='list') for colname, data in df.items(): curdfcol = df[colname] for indx, val in enumerate(data): if pd.isna(val) and pd.isna(curdfcol[indx]): continue self.assertTrue(val==curdfcol[indx]) def test_sav_write_rowcompression(self): file_label = "row compression write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = os.path.join(self.write_folder, "rowcompression_write.sav") pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure, row_compress=True) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) self.assertEqual(meta.variable_display_width['mychar'], variable_display_width['mychar']) #self.assertDictEqual(meta.variable_alignment, variable_alignment) self.assertEqual(meta.variable_measure["mychar"], variable_measure["mychar"]) if __name__ == '__main__': import sys if "--inplace" in sys.argv: script_folder = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0] sys.path.insert(0, script_folder) sys.argv.remove('--inplace') import pyreadstat print("package location:", pyreadstat.__file__) unittest.main() ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769156913.0 pyreadstat-1.3.3/tests/test_http_integration.py0000644000076500000240000000276715134630461020412 0ustar00dialout""" Integration test: reading SAV file from HTTP server. Uses Python's built-in http.server - no external dependencies. Run with: pytest tests/test_http_integration.py -v """ import io import os import threading import urllib.request from contextlib import contextmanager from http.server import HTTPServer, SimpleHTTPRequestHandler import pyreadstat @contextmanager def http_server(directory): """Context manager that runs an HTTP server serving files from directory.""" class QuietHandler(SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs): super().__init__(*args, directory=directory, **kwargs) def log_message(self, *args): pass server = HTTPServer(("127.0.0.1", 0), QuietHandler) thread = threading.Thread(target=server.serve_forever, daemon=True) thread.start() try: yield f"http://127.0.0.1:{server.server_address[1]}" finally: server.shutdown() def test_read_sav_from_http(): """Test reading SAV file from local HTTP server (simulates remote URL).""" data_folder = os.path.join(os.path.dirname(__file__), "..", "test_data", "basic") with http_server(data_folder) as base_url: url = f"{base_url}/sample.sav" with urllib.request.urlopen(url) as response: df, meta = pyreadstat.read_sav(io.BytesIO(response.read())) assert len(df) == 5, f"Expected 5 rows, got {len(df)}" assert len(df.columns) == 7, f"Expected 7 columns, got {len(df.columns)}" ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769179047.0 pyreadstat-1.3.3/tests/test_narwhalified.py0000644000076500000240000023754215134703647017475 0ustar00dialout#-*- coding: utf-8 -*- # ############################################################################# # Copyright 2018 Hoffmann-La Roche # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################# from datetime import datetime, timedelta, date import unittest import os import sys import shutil import multiprocessing as mp import tempfile import zipfile import io import pandas as pd import narwhals as nw import numpy as np import polars as pl is_pathlib_available = False try: from pathlib import Path is_pathlib_available = True except: pass is_pandas_version_newer_than_2 = int(pd.__version__.split(".")[0])>2 class TestBasic(unittest.TestCase): """ Test suite for pyreadstat. """ def _prepare_data(self): #backend = 'polars' global backend self.backend = backend self.script_folder = os.path.dirname(os.path.realpath(__file__)) self.parent_folder = os.path.split(self.script_folder)[0] self.data_folder = os.path.join(self.parent_folder, "test_data") self.basic_data_folder = os.path.join(self.data_folder, "basic") self.catalog_data_folder = os.path.join(self.data_folder, "sas_catalog") self.international_data_folder = os.path.join(self.data_folder, "ínternátionál") self.missing_data_folder = os.path.join(self.data_folder, "missing_data") self.mr_data_folder = os.path.join(self.data_folder, "multiple_response") self.write_folder = os.path.join(self.data_folder, "write") if not os.path.isdir(self.write_folder): os.makedirs(self.write_folder) # basic pandas_csv = os.path.join(self.basic_data_folder, "sample.csv") #df_pandas = pl.read_csv(pandas_csv, try_parse_dates=True) kwds = {} if backend == "polars": kwds["try_parse_dates"] = True df_pandas = nw.read_csv(pandas_csv, backend=backend, **kwds) if backend == "pandas": df_pandas = df_pandas.to_native() df_pandas["mydate"] = [datetime.strptime(x, '%Y-%m-%d').date() if type(x) == str else float('nan') for x in df_pandas["mydate"]] df_pandas["dtime"] = [datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.000000') if type(x) == str else float('nan') for x in df_pandas["dtime"]] df_pandas["mytime"] = [datetime.strptime(x, '%H:%M:%S.000000').time() if type(x) == str else float('nan') for x in df_pandas["mytime"]] df_pandas = nw.from_native(df_pandas) df_pandas = df_pandas.with_columns(nw.col("myord", "mylabl").cast(nw.Float64)) self.df_pandas = df_pandas.to_native() # skip some columns self.usecols = ['mynum', 'myord'] cols_to_drop = list(set(df_pandas.columns) - set(self.usecols)) self.df_usecols = df_pandas.drop(cols_to_drop).to_native()#, axis=1) # no dates nodates_spss_csv = os.path.join(self.basic_data_folder, "sample_nodate_spss.csv") df_nodates_spss = nw.read_csv(nodates_spss_csv, backend=backend) df_nodates_spss = df_nodates_spss.with_columns(nw.col("myord", "mylabl").cast(nw.Float64)) self.df_nodates_spss = df_nodates_spss.to_native() nodates_sastata_csv = os.path.join(self.basic_data_folder, "sample_nodate_sas_stata.csv") df_nodates_sastata = nw.read_csv(nodates_sastata_csv, backend=backend) df_nodates_sastata = df_nodates_sastata.with_columns(nw.col("myord", "mylabl").cast(nw.Float64)) self.df_nodates_sastata = df_nodates_sastata.to_native() # xport files v5 vs v8 self.xptv5v8 = nw.from_dict({'i': [float(x) for x in range(1,11)]}, backend=backend).to_native() # formatted mylabl_format = {1.0:"Male", 2.0:"Female"} myord_format = {1.0:"low", 2.0:"medium", 3.0:"high"} df_pandas_formatted = df_pandas.clone() df_pandas_formatted = df_pandas_formatted.with_columns(nw.col("mylabl").replace_strict(mylabl_format)) df_pandas_formatted = df_pandas_formatted.with_columns(nw.col("myord").replace_strict(myord_format)) df_pandas_formatted = df_pandas_formatted.with_columns(nw.col("myord", "mylabl").cast(nw.Categorical)) self.df_pandas_formatted = df_pandas_formatted.to_native() # sas formatted sas_formatted = os.path.join(self.catalog_data_folder, "sas_formatted.csv") df_sas = nw.read_csv(sas_formatted, backend=backend) df_sas = df_sas.with_columns(nw.col("SEXA", "SEXB").cast(nw.Categorical)) self.df_sas_format = df_sas.to_native() # missing data pandas_missing_sav_csv = os.path.join(self.basic_data_folder, "sample_missing.csv") kwds = {} if backend == "pandas": kwds["na_values"] = "#NULL!" kwds["keep_default_na"] = False if backend == "polars": kwds["null_values"] = "#NULL!" kwds["try_parse_dates"] = True kwds["missing_utf8_is_empty_string"] = True df_missing_sav = nw.read_csv(pandas_missing_sav_csv, backend=backend, **kwds ) df_missing_sav = df_missing_sav.to_native() if backend == "pandas": df_missing_sav["mydate"] = [datetime.strptime(x, '%Y-%m-%d').date() if type(x) == str else float('nan') for x in df_missing_sav["mydate"]] df_missing_sav["dtime"] = [datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.000000') if type(x) == str else float('nan') for x in df_missing_sav["dtime"]] df_missing_sav["mytime"] = [datetime.strptime(x, '%H:%M:%S.000000').time() if type(x) == str else float('nan') for x in df_missing_sav["mytime"]] self.df_missing_sav = df_missing_sav # user missing pandas_missing_user_sav_csv = os.path.join(self.basic_data_folder, "sample_missing_user.csv") df_user_missing_sav = nw.read_csv(pandas_missing_user_sav_csv, backend=backend, **kwds) df_user_missing_sav = df_user_missing_sav.to_native() if backend == "pandas": df_user_missing_sav["mydate"] = [datetime.strptime(x, '%Y-%m-%d').date() if type(x) == str else float('nan') for x in df_user_missing_sav["mydate"]] df_user_missing_sav["dtime"] = [datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.000000') if type(x) == str else float('nan') for x in df_user_missing_sav["dtime"]] df_user_missing_sav["mytime"] = [datetime.strptime(x, '%H:%M:%S.000000').time() if type(x) == str else float('nan') for x in df_user_missing_sav["mytime"]] self.df_user_missing_sav = df_user_missing_sav # dates sas_dates = os.path.join(self.basic_data_folder, "dates.csv") kwds = {} if backend == "polars": kwds["try_parse_dates"] = True df_dates_raw = nw.read_csv(sas_dates,backend=backend, **kwds) df_dates1 = df_dates_raw.clone() if backend == "pandas": df_dates1 = df_dates1.to_native() df_dates1["date"] = pd.to_datetime(df_dates1["date"]) df_dates1["dtime"] = pd.to_datetime(df_dates1["dtime"]) df_dates1["time"] = pd.to_datetime(df_dates1["time"], format='%H:%M:%S') df_dates1["time"] = df_dates1["time"].apply(lambda x: x.time()) else: df_dates1 = df_dates1.with_columns(nw.col("date").cast(nw.Date)).to_native() self.df_sas_dates_as_pandas = df_dates1 if backend == "pandas": df_dates2 = df_dates1.copy() df_dates2["date"] = df_dates2["date"].apply(lambda x: x.date()) self.df_sas_dates = df_dates2 self.df_sas_dates2 = pd.concat([self.df_sas_dates, pd.DataFrame([[np.nan, pd.NaT, np.nan]],columns=["date", "dtime", "time"])], ignore_index=True) else: df_dates2 = df_dates_raw.clone()#.with_columns(nw.col("time").cast(nw.Time)) self.df_sas_dates = df_dates2.to_native() #schema = {"date": nw.Date, "dtime": nw.Datetime("ns"), "time": nw.Time()} self.df_sas_dates2 = nw.concat([df_dates2, nw.from_dict({"date":[None], "dtime":[None], "time":[None]}, backend=backend)]).to_native() #, schema=schema # character column with nan and object column with nan (object pyreadstat writer doesn't know what to do with) if backend == "pandas": self.df_charnan = pd.DataFrame([[0,np.nan,np.nan],[1,"test", timedelta]], columns = ["integer", "string", "object"]) else: self.df_charnan = nw.from_dict({'integer': [0, 1], "string": [None, "test"], "object": [None, timedelta]}, backend=backend).to_native() # long string self.df_longstr = nw.from_dict({ "v1": [ """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac pretium sem. Fusce aliquet augue rhoncus consequat pulvinar. In est ex, porta congue diam sed, laoreet suscipit purus. Phasellus mollis lobortis tellus at vehicula. Etiam egestas augue id massa bibendum volutpat id et ipsum. Praesent ut lorem rhoncus, pharetra risus sed, pharetra sem. In pulvinar egestas erat, id condimentum tortor tempus sed. Duis ornare lacus ut ligula congue, non convallis urna dignissim. Etiam vehicula turpis sit amet nisi finibus laoreet. Duis molestie consequat nulla, non lobortis est tempus sit amet. Quisque elit est, congue non commodo vitae, porttitor ac erat. """ *3, "fgsdghshsgh", "gsfdgsdg", ], "v2": [ "gsfdgsfdgsfg", "fgsdghshsgh", "gsfdgsdg", ], }, backend=backend).to_native() def setUp(self): # set paths self._prepare_data() def test_sas7bdat(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) #self.assertTrue(meta.creation_time==datetime(2018, 8, 16, 18, 21, 52)) #self.assertTrue(meta.modification_time==datetime(2018, 8, 16, 18, 21, 52)) def test_sas7bdat_bincompressed(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample_bincompressed.sas7bdat"), output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) def test_sas7bdat_metaonly(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), output_format=self.backend) df2, meta2 = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), metadataonly=True, output_format=self.backend) self.assertTrue(len(df2)==0) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="double") self.assertTrue(meta.readstat_variable_types["dtime"]=="double") def test_sas7bdat_usecols(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), usecols=self.usecols, output_format=self.backend) self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_sas7bdat_international(self): """ On windows, paths with international characters are problematic. This is verifying that it is working as expected """ # in addition, this works only in python 3 if sys.version_info[0]>2: df, meta = pyreadstat.read_sas7bdat(os.path.join(self.international_data_folder, "sample.sas7bdat"), output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) def test_sas7bdat_nodates(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), disable_datetime_conversion=True, output_format=self.backend) self.assertTrue(df.equals(self.df_nodates_sastata)) def test_sas7bdat_chunk(self): df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "sample.sas7bdat"), row_limit = 2, row_offset =1, output_format=self.backend) df_pandas = nw.from_native(self.df_pandas)[1:3].to_native() if self.backend == "pandas": df_pandas = df_pandas.reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_xport(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(meta.number_rows==len(df)) #self.assertTrue(meta.creation_time==datetime(2018, 8, 14, 10, 55, 46)) #self.assertTrue(meta.modification_time==datetime(2018, 8, 14, 10, 55, 46)) def test_xport_v5(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sas.xpt5"), output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.xptv5v8)) self.assertTrue(meta.number_rows==len(df)) def test_xport_v8(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sas.xpt8"), output_format=self.backend) self.assertTrue(df.equals(self.xptv5v8)) self.assertTrue(meta.number_rows==len(df)) def test_xport_metaonly(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), output_format=self.backend) df2, meta2 = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), metadataonly=True, output_format=self.backend) self.assertTrue(len(df2)==0) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta2.number_rows is None) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) def test_xport_usecols(self): # Currently readstat does not support skipping cols for XPT files, usecols = [x.upper() for x in self.usecols] df, meta = pyreadstat.pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), usecols=usecols, output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) def test_xport_nodates(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), disable_datetime_conversion=True, output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_nodates_sastata)) def test_xport_chunks(self): df, meta = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "sample.xpt"), row_limit = 2, row_offset =1, output_format=self.backend) df.columns = [x.lower() for x in df.columns] df_pandas = nw.from_native(self.df_pandas)[1:3].to_native() if self.backend == "pandas": df_pandas = df_pandas.reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_dta(self): # discard dtime and arrange time df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), output_format=self.backend) df_pandas = nw.from_native(self.df_pandas).clone() df_pandas = df_pandas.with_columns(nw.col("myord", "mylabl").cast(nw.Int64)) df_pandas = df_pandas.to_native() self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="int8") self.assertTrue(meta.readstat_variable_types["dtime"]=="double") #self.assertTrue(meta.creation_time==datetime(2018, 12, 17, 14, 53)) #self.assertTrue(meta.modification_time==datetime(2018, 12, 17, 14, 53)) def test_dta_metaonly(self): df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), output_format=self.backend) df2, meta2 = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), metadataonly=True, output_format=self.backend) self.assertTrue(len(df2)==0) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) def test_dta_usecols(self): df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), usecols=self.usecols, output_format=self.backend) #df_pandas = self.df_usecols.copy() df_pandas = nw.from_native(self.df_usecols).clone() #df_pandas["myord"] = df_pandas["myord"].astype(np.int64) df_pandas = df_pandas.with_columns(nw.col("myord").cast(nw.Int64)) df_pandas = df_pandas.to_native() self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_dta_nodates(self): df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder,"sample.dta"), disable_datetime_conversion=True, output_format=self.backend) #df_pandas = self.df_nodates_sastata df_pandas = nw.from_native(self.df_nodates_sastata) df_pandas = df_pandas.with_columns(nw.col("myord", "mylabl").cast(nw.Int64)) df_pandas = df_pandas.with_columns(nw.col("dtime", "mytime")*1000) df_pandas = df_pandas.to_native() self.assertTrue(df.equals(df_pandas)) def test_dta_chunks(self): # discard dtime and arrange time df, meta = pyreadstat.read_dta(os.path.join(self.basic_data_folder, "sample.dta"), row_limit = 2, row_offset =1, output_format = self.backend) df_pandas = nw.from_native(self.df_pandas)[1:3] df_pandas = df_pandas.with_columns(nw.col("myord", "mylabl").cast(nw.Int64)) df_pandas = df_pandas.to_native() if self.backend == "pandas": df_pandas = df_pandas.reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_sav(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="double") #self.assertTrue(meta.creation_time==datetime(2018, 8, 16, 17, 22, 33)) #self.assertTrue(meta.modification_time==datetime(2018, 8, 16, 17, 22, 33)) def test_sav_metaonly(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), output_format=self.backend) df2, meta2 = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), metadataonly=True, output_format=self.backend) self.assertTrue(len(df2)==0) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(len(meta2.notes) > 0) def test_sav_formatted(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), apply_value_formats=True, formats_as_category=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas_formatted)) self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas_formatted)) self.assertTrue(len(meta.notes) > 0) def test_sav_usecols(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), usecols=self.usecols, output_format=self.backend) self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_sav_missing(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample_missing.sav"), output_format=self.backend) self.assertTrue(df.equals(self.df_missing_sav)) self.assertTrue(meta.missing_ranges == {}) df_user, meta_user = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample_missing.sav"), user_missing=True, output_format=self.backend) self.assertTrue(df_user.equals(self.df_user_missing_sav)) self.assertTrue(meta_user.missing_ranges['mynum'][0]=={'lo': 2000.0, 'hi': 3000.0}) # user missing with usecols df_user, meta_user = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample_missing.sav"), user_missing=True, usecols=["mynum", "mylabl"], output_format=self.backend) df_sub = self.df_user_missing_sav[["mynum", "mylabl"]] self.assertTrue(df_user.equals(df_sub)) def test_sav_nodates(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), disable_datetime_conversion=True, output_format=self.backend) self.assertTrue(df.equals(self.df_nodates_spss)) def test_sav_chunks(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), row_limit = 2, row_offset =1, output_format=self.backend) df_pandas = nw.from_native(self.df_pandas)[1:3].to_native() if self.backend == "pandas": #df_pandas = self.df_pandas.iloc[1:3,:].reset_index(drop=True) df_pandas = df_pandas.reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") def test_sav_expand(self): src = os.path.join(self.basic_data_folder, "sample.sav") dst = "~/sample.sav" shutil.copyfile(src, os.path.expanduser(dst)) df, meta = pyreadstat.read_sav(dst, output_format=self.backend) os.remove(os.path.expanduser(dst)) self.assertTrue(df.equals(self.df_pandas)) def test_zsav(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(len(meta.notes) > 0) def test_zsav_metaonly(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), output_format=self.backend) df2, meta2 = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), metadataonly=True, output_format=self.backend) self.assertTrue(len(df2)==0) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta.number_rows == meta2.number_rows) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(len(meta2.notes) > 0) def test_zsav_formatted(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), apply_value_formats=True, formats_as_category=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas_formatted)) self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas_formatted)) self.assertTrue(len(meta.notes) > 0) def test_zsav_usecols(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), usecols=self.usecols, output_format=self.backend) self.assertTrue(df.equals(self.df_usecols)) self.assertTrue(meta.number_columns == len(self.usecols)) self.assertTrue(meta.column_names == self.usecols) def test_zsav_nodates(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), disable_datetime_conversion=True, output_format=self.backend) self.assertTrue(df.equals(self.df_nodates_spss)) def test_zsav_chunks(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.zsav"), row_limit = 2, row_offset =1, output_format=self.backend) df_pandas = nw.from_native(self.df_pandas)[1:3].to_native() if self.backend == "pandas": df_pandas = df_pandas.reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") def test_por(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), output_format=self.backend) df_pandas_por = self.df_pandas df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas_por)) self.assertTrue(len(meta.notes) > 0) #self.assertTrue(meta.creation_time==datetime(2018, 12, 16, 17, 28, 21)) #self.assertTrue(meta.modification_time==datetime(2018, 12, 16, 17, 28, 21)) def test_por_formatted(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), apply_value_formats=True, formats_as_category=True, output_format=self.backend) df_pandas_por = self.df_pandas_formatted df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns)) self.assertTrue(meta.number_rows == len(df_pandas_por)) self.assertTrue(len(meta.notes) > 0) def test_por_metaonly(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), output_format=self.backend) df2, meta2 = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), metadataonly=True, output_format=self.backend) self.assertTrue(len(df2)==0) self.assertTrue(meta.number_columns == meta2.number_columns) self.assertTrue(meta2.number_rows is None) self.assertTrue(meta.column_names == meta2.column_names) self.assertTrue(meta.column_labels == meta2.column_labels) self.assertTrue(len(meta2.notes) > 0) def test_por_usecols(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), usecols=["MYNUM"], output_format=self.backend) df_pandas_por = nw.from_native(self.df_pandas).select("mynum").to_native() #df_pandas_por = self.df_pandas[["mynum"]] df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(df_pandas_por.columns)) def test_por_nodates(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), disable_datetime_conversion=True, output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_nodates_spss)) def test_por_chunks(self): df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), row_limit = 2, row_offset =1, output_format=self.backend) df_pandas_por = nw.from_native(self.df_pandas)[1:3].to_native() if self.backend == "pandas": df_pandas_por = df_pandas_por.reset_index(drop=True) df_pandas_por['dtime'] = pd.to_datetime(df_pandas_por.dtime) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(df_pandas_por)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas_por)) self.assertTrue(len(meta.notes) > 0) def test_sas_catalog_win(self): """these sas7bdat and sasbcat where produced on windows, probably 32 bit""" dat = os.path.join(self.catalog_data_folder, "test_data_win.sas7bdat") cat = os.path.join(self.catalog_data_folder, "test_formats_win.sas7bcat") df, meta = pyreadstat.read_sas7bdat(dat, catalog_file=cat, output_format=self.backend) self.assertTrue(df.equals(self.df_sas_format)) def test_sas_catalog_linux(self): """these sas7bdat and sasbcat where produced on linux 64 bit""" dat = os.path.join(self.catalog_data_folder, "test_data_linux.sas7bdat") cat = os.path.join(self.catalog_data_folder, "test_formats_linux.sas7bcat") df, meta = pyreadstat.read_sas7bdat(dat, catalog_file=cat, output_format=self.backend) self.assertTrue(df.equals(self.df_sas_format)) def test_sas_dates(self): sas_file = os.path.join(self.basic_data_folder, "dates.sas7bdat") df_sas, meta = pyreadstat.read_sas7bdat(sas_file, output_format=self.backend) self.assertTrue(df_sas.equals(self.df_sas_dates)) def test_sas_dates_as_pandas(self): sas_file = os.path.join(self.basic_data_folder, "dates.sas7bdat") df_sas, meta = pyreadstat.read_sas7bdat(sas_file, dates_as_pandas_datetime=True, output_format=self.backend) self.assertTrue(df_sas.equals(self.df_sas_dates_as_pandas)) def test_sas_user_missing(self): sas_file = os.path.join(self.missing_data_folder, "missing_test.sas7bdat") cat_file = os.path.join(self.missing_data_folder, "missing_formats.sas7bcat") unformatted_csv = os.path.join(self.missing_data_folder, "missing_unformatted.csv") formatted_csv = os.path.join(self.missing_data_folder, "missing_sas_formatted.csv") labeled_csv = os.path.join(self.missing_data_folder, "missing_sas_labeled.csv") df_sas, meta = pyreadstat.read_sas7bdat(sas_file, output_format=self.backend) kwds = {} if self.backend == "polars": kwds["null_values"] = "NaN" df_csv = nw.read_csv(unformatted_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_sas7bdat(sas_file, user_missing=True, output_format=self.backend) df_csv = nw.read_csv(formatted_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) missing_user_values = {'var1':['A'],'var2': ['B'], 'var3':['C'], 'var4':['X'], 'var5':['Y'], 'var6':['Z'], 'var7':['_']} self.assertDictEqual(meta.missing_user_values, missing_user_values) df_sas, meta = pyreadstat.read_sas7bdat(sas_file, catalog_file=cat_file, user_missing=True, formats_as_category=False, output_format=self.backend) df_csv = nw.read_csv(labeled_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) def test_dta_user_missing(self): dta_file = os.path.join(self.missing_data_folder, "missing_test.dta") unformatted_csv = os.path.join(self.missing_data_folder, "missing_unformatted.csv") formatted_csv = os.path.join(self.missing_data_folder, "missing_dta_formatted.csv") labeled_csv = os.path.join(self.missing_data_folder, "missing_dta_labeled.csv") df_sas, meta = pyreadstat.read_dta(dta_file, output_format=self.backend) kwds = {} if self.backend == "polars": kwds["null_values"] = "NaN" df_csv = nw.read_csv(unformatted_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_dta(dta_file, user_missing=True, output_format=self.backend) df_csv = nw.read_csv(formatted_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) missing_user_values = {'var1':['a'],'var2': ['b'], 'var3':['c'], 'var4':['x'], 'var5':['y'], 'var6':['z']} self.assertDictEqual(meta.missing_user_values, missing_user_values) df_sas, meta = pyreadstat.read_dta(dta_file, apply_value_formats=True, user_missing=True, formats_as_category=False, output_format=self.backend) df_csv = nw.read_csv(labeled_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) def test_sav_user_missing(self): sav_file = os.path.join(self.missing_data_folder, "missing_test.sav") unformatted_csv = os.path.join(self.missing_data_folder, "missing_sav_unformatted.csv") formatted_csv = os.path.join(self.missing_data_folder, "missing_sav_formatted.csv") labeled_csv = os.path.join(self.missing_data_folder, "missing_sav_labeled.csv") df_sas, meta = pyreadstat.read_sav(sav_file, output_format=self.backend) kwds = {} if self.backend == "polars": kwds["null_values"] = "NaN" df_csv = nw.read_csv(unformatted_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_sav(sav_file, user_missing=True, output_format=self.backend) df_csv = nw.read_csv(formatted_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) df_sas, meta = pyreadstat.read_sav(sav_file, apply_value_formats=True, user_missing=True, formats_as_category=False, output_format=self.backend) df_sas = nw.from_native(df_sas) # in pandas the column will be object with 'missing' and 2.0 if self.backend == "pandas": df_sas = df_sas.with_columns(nw.when(nw.col('var1')==2.0).then(nw.lit('2')).otherwise(nw.col('var1')).alias('var1')).to_native() # in polars it will be a string column with 'missing and '2.0' else: new_ser = nw.new_series(name="var1", values=[str(x) for x in df_sas["var1"]], dtype=nw.String, backend=self.backend) df_sas = df_sas.with_columns(new_ser.alias("var1")) df_sas = df_sas.with_columns(nw.when(nw.col('var1')=='2.0').then(nw.lit('2')).otherwise(nw.col('var1')).alias('var1')).to_native() df_csv = nw.read_csv(labeled_csv, backend=self.backend, **kwds).to_native() self.assertTrue(df_sas.equals(df_csv)) def test_sav_missing_char(self): df, meta = pyreadstat.read_sav(os.path.join(self.missing_data_folder, "missing_char.sav"), output_format=self.backend) if self.backend == "pandas": temp = np.nan else: temp = None mdf = nw.from_dict({"mychar": [temp, "a"]}, backend=self.backend).to_native() self.assertTrue(df.equals(mdf)) self.assertTrue(meta.missing_ranges == {}) df2, meta2 = pyreadstat.read_sav(os.path.join(self.missing_data_folder, "missing_char.sav"), user_missing=True, output_format=self.backend) mdf2 = nw.from_dict({"mychar": [ "Z", "a"]}, backend=self.backend).to_native() self.assertTrue(df2.equals(mdf2)) self.assertTrue(meta2.missing_ranges['mychar'][0]=={'lo': "Z", 'hi': "Z"}) # test reading metadata for multiple response data def test_sav_multiple_response(self): """Assert MR data is correctly read from sav into metadata.""" _, meta = pyreadstat.read_sav(os.path.join(self.mr_data_folder, "simple_alltypes.sav"), output_format=self.backend) assert meta.mr_sets == { "categorical_array": { "type": "C", "is_dichotomy": False, "counted_value": None, "label": "", "variable_list": ["ca_subvar_1", "ca_subvar_2", "ca_subvar_3"] }, "mymrset": { "type": "D", "is_dichotomy": True, "counted_value": 1, "label": "My multiple response set", "variable_list": ["bool1", "bool2", "bool3"] } } def test_sav_without_multiple_response(self): """Assert MR data is read as empty dict when not present in sav.""" _, meta = pyreadstat.read_sav(os.path.join(self.missing_data_folder, "missing_char.sav"), output_format=self.backend) assert meta.mr_sets == {} # read in chunks def test_chunk_reader(self): fpath = os.path.join(self.basic_data_folder, "sample.sas7bdat") reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sas7bdat, fpath, chunksize= 2, offset=1, limit=2, disable_datetime_conversion=True, output_format=self.backend) for df, meta in reader: pass currow = nw.from_native(self.df_nodates_sastata)[1:3].to_native() if self.backend == "pandas": currow = currow.reset_index(drop=True) self.assertTrue(df.equals(currow)) # read multiprocessing def test_multiprocess_reader(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") df_multi, meta_multi = pyreadstat.read_file_multiprocessing(pyreadstat.read_sav, fpath, output_format=self.backend) df_single, meta_single = pyreadstat.read_sav(fpath, output_format=self.backend) self.assertTrue(df_multi.equals(df_single)) self.assertEqual(meta_multi.number_rows, meta_single.number_rows) def test_chunk_reader_multiprocess(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sav, fpath, chunksize= 50, multiprocess=True, output_format=self.backend) alldfs = list() for df, meta in reader: alldfs.append(nw.from_native(df)) df_multi = nw.concat(alldfs, how='vertical').to_native() if self.backend == "pandas": df_multi = df_multi.reset_index(drop=True) df_single, meta_single = pyreadstat.read_sav(fpath, output_format=self.backend) self.assertTrue(df_multi.equals(df_single)) def test_chunk_reader_multiprocess_dict(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") reader = pyreadstat.read_file_in_chunks(pyreadstat.read_sav, fpath, chunksize= 50, multiprocess=True, output_format='dict') alldfs = list() for chunkdict, meta in reader: if self.backend != "pandas": # we need lists not numpy arrays for polars! chunkdict = {k:v.tolist() for k,v in chunkdict.items()} df = nw.from_dict(chunkdict, backend=self.backend) alldfs.append(df) df_multi = nw.concat(alldfs, how='vertical').to_native() if self.backend == "pandas": df_multi = df_multi.reset_index(drop=True) df_single, meta_single = pyreadstat.read_sav(fpath, output_format=self.backend) self.assertTrue(df_multi.equals(df_single)) def test_multiprocess_reader_xport(self): fpath = os.path.join(self.basic_data_folder, "sample.xpt") df_multi, meta_multi = pyreadstat.read_file_multiprocessing(pyreadstat.read_xport, fpath, num_rows=1000, output_format=self.backend) df_single, meta_single = pyreadstat.read_xport(fpath, output_format=self.backend) if is_pandas_version_newer_than_2 and self.backend=="pandas": # because in multi there are NaN values in a chunk these columns get object type df_single['DTIME'] = df_single['DTIME'].astype(object) df_single['MYCHAR'] = df_single['MYCHAR'].astype(object) self.assertTrue(df_multi.equals(df_single)) # writing def test_sav_write_basic(self): file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = os.path.join(self.write_folder, "basic_write.sav") pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) self.assertEqual(meta.variable_display_width['mychar'], variable_display_width['mychar']) #self.assertDictEqual(meta.variable_alignment, variable_alignment) self.assertEqual(meta.variable_measure["mychar"], variable_measure["mychar"]) def test_sav_write_basic_expanduser(self): file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = "~/sav_expand.sav" pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True, output_format=self.backend) os.remove(os.path.expanduser(path)) self.assertTrue(df.equals(self.df_pandas)) def test_zsav_write_basic(self): file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} path = os.path.join(self.write_folder, "basic_write.zsav") pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, compress=True, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges) df, meta = pyreadstat.read_sav(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) def test_dta_write_basic(self): df_pandas = nw.from_native(self.df_pandas).clone() df_pandas = df_pandas.with_columns(nw.col("myord", "mylabl").cast(nw.Int32)).to_native() file_label = "basic write" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1: 'Male', 2: 'Female'}, 'myord': {1: 'low', 2: 'medium', 3: 'high'}} path = os.path.join(self.write_folder, "basic_write.dta") pyreadstat.write_dta(df_pandas, path, file_label=file_label, column_labels=col_labels, version=12, variable_value_labels=variable_value_labels) df, meta = pyreadstat.read_dta(path, output_format=self.backend) df_pandas = nw.from_native(df_pandas).with_columns(nw.col("myord", "mylabl").cast(nw.Int64)).to_native() self.assertTrue(df.equals(df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) def test_dta_write_user_missing(self): # bug in nw, nw.Object is not translated to pd.Object if self.backend == "pandas": df_csv = pd.DataFrame.from_dict({"Var1": [3, "a"], "Var2":["a", "b"]}) df_csv2 = pd.DataFrame.from_dict({"Var1": [3, "labeled"], "Var2":["a", "b"]}) else: df_csv = nw.from_dict({"Var1": [3, "a"], "Var2":["a", "b"]}, backend=self.backend, schema={"Var1":nw.Object, "Var2":nw.String}).to_native() df_csv2 = nw.from_dict({"Var1": [3, "labeled"], "Var2":["a", "b"]}, backend=self.backend, schema={"Var1":nw.Object, "Var2":nw.String}).to_native() missing_user_values = {'Var1': ['a']} variable_value_labels = {'Var1':{'a':'labeled'}} path = os.path.join(self.write_folder, "user_missing_write.dta") pyreadstat.write_dta(df_csv, path, version=12, missing_user_values=missing_user_values, variable_value_labels=variable_value_labels) df_dta, meta = pyreadstat.read_dta(path, user_missing=True, output_format=self.backend) # in polars comparing two series of type object always gives error if self.backend != "pandas": new_ser = nw.new_series(name="Var1", values=[str(x) for x in df_csv["Var1"]], dtype=nw.String, backend=self.backend) df_csv = nw.from_native(df_csv).with_columns(new_ser.alias("Var1")).to_native() new_ser = nw.new_series(name="Var1", values=[str(x) for x in df_dta["Var1"]], dtype=nw.String, backend=self.backend) df_dta = nw.from_native(df_dta).with_columns(new_ser.alias("Var1")).to_native() self.assertTrue(df_csv.equals(df_dta)) self.assertDictEqual(meta.missing_user_values, missing_user_values) df_dta2, meta2 = pyreadstat.read_dta(path, user_missing=True, apply_value_formats=True, formats_as_category=False, output_format=self.backend) if self.backend != "pandas": new_ser = nw.new_series(name="Var1", values=[str(x) for x in df_csv2["Var1"]], dtype=nw.String, backend=self.backend) df_csv2 = nw.from_native(df_csv2).with_columns(new_ser.alias("Var1")).to_native() new_ser = nw.new_series(name="Var1", values=[str(x) for x in df_dta2["Var1"]], dtype=nw.String, backend=self.backend) df_dta2 = nw.from_native(df_dta2).with_columns(new_ser.alias("Var1")).to_native() self.assertTrue(df_csv2.equals(df_dta2)) def test_xport_write_basic_v8(self): file_label = "basic write" table_name = "TEST" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] path = os.path.join(self.write_folder, "write.xpt") pyreadstat.write_xport(self.df_pandas, path, file_label=file_label, column_labels=col_labels, table_name=table_name, file_format_version=8) df, meta = pyreadstat.read_xport(path, output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(table_name, meta.table_name) def test_xport_write_basic_v5(self): file_label = "basic write" table_name = "TEST" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] path = os.path.join(self.write_folder, "write.xpt") pyreadstat.write_xport(self.df_pandas, path, file_label=file_label, column_labels=col_labels, table_name=table_name, file_format_version=5) df, meta = pyreadstat.read_xport(path, output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(table_name, meta.table_name) def test_por_write_basic(self): file_label = "basic write" #file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] path = os.path.join(self.write_folder, "write.por") pyreadstat.write_por(self.df_pandas, path, file_label=file_label, column_labels=col_labels) #, note=file_note) df, meta = pyreadstat.read_por(path, output_format=self.backend) df.columns = [x.lower() for x in df.columns] self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) #self.assertEqual(meta.notes[0], file_note) def test_sav_write_dates(self): path = os.path.join(self.write_folder, "dates_write.sav") pyreadstat.write_sav(self.df_sas_dates2, path) df, meta = pyreadstat.read_sav(path, output_format=self.backend) self.assertTrue(df.equals(self.df_sas_dates2)) def test_zsav_write_dates(self): path = os.path.join(self.write_folder, "dates_write_zsav.sav") pyreadstat.write_sav(self.df_sas_dates2, path, compress=True) df, meta = pyreadstat.read_sav(path, output_format=self.backend) self.assertTrue(df.equals(self.df_sas_dates2)) def test_dta_write_dates(self): path = os.path.join(self.write_folder, "dates_write.dta") pyreadstat.write_dta(self.df_sas_dates, path) df, meta = pyreadstat.read_dta(path, output_format=self.backend) self.assertTrue(df.equals(self.df_sas_dates)) def test_xport_write_dates(self): path = os.path.join(self.write_folder, "dates_write.xpt") pyreadstat.write_xport(self.df_sas_dates2, path) df, meta = pyreadstat.read_xport(path, output_format=self.backend) self.assertTrue(df.equals(self.df_sas_dates2)) def test_sav_write_charnan(self): path = os.path.join(self.write_folder, "charnan.sav") pyreadstat.write_sav(self.df_charnan, path) df, meta = pyreadstat.read_sav(path, output_format=self.backend) df2 = nw.from_native(self.df_charnan) if self.backend != "pandas": new_ser = nw.new_series(name="object", values=[str(x) if x is not None else None for x in df2["object"]], dtype=nw.String, backend=self.backend) df2 = df2.with_columns(new_ser.alias("object")) df2 = df2.with_columns(nw.col("string", "object").fill_null("")) df2 = df2.with_columns(nw.col("integer").cast(nw.Float64)) if self.backend == "pandas": df2 = df2.with_columns(nw.col("object").cast(nw.String)) df2 = df2.to_native() self.assertTrue(df2.equals(df)) def test_zsav_write_charnan(self): path = os.path.join(self.write_folder, "charnan_zsav.sav") pyreadstat.write_sav(self.df_charnan, path, compress=True) df, meta = pyreadstat.read_sav(path, output_format=self.backend) df2 = nw.from_native(self.df_charnan) if self.backend != "pandas": new_ser = nw.new_series(name="object", values=[str(x) if x is not None else None for x in df2["object"]], dtype=nw.String, backend=self.backend) df2 = df2.with_columns(new_ser.alias("object")) df2 = df2.with_columns(nw.col("string", "object").fill_null("")) df2 = df2.with_columns(nw.col("integer").cast(nw.Float64)) if self.backend == "pandas": df2 = df2.with_columns(nw.col("object").cast(nw.String)) df2 = df2.to_native() self.assertTrue(df2.equals(df)) def test_xport_write_charnan(self): path = os.path.join(self.write_folder, "charnan.xpt") pyreadstat.write_xport(self.df_charnan, path) df, meta = pyreadstat.read_xport(path, output_format=self.backend) df2 = nw.from_native(self.df_charnan) if self.backend != "pandas": new_ser = nw.new_series(name="object", values=[str(x) if x is not None else None for x in df2["object"]], dtype=nw.String, backend=self.backend) df2 = df2.with_columns(new_ser.alias("object")) df2 = df2.with_columns(nw.col("string", "object").fill_null("")) df2 = df2.with_columns(nw.col("integer").cast(nw.Float64)) if self.backend == "pandas": df2 = df2.with_columns(nw.col("object").cast(nw.String)) df2 = df2.to_native() self.assertTrue(df2.equals(df)) def test_por_write_charnan(self): path = os.path.join(self.write_folder, "charnan_zsav.por") pyreadstat.write_por(self.df_charnan, path) df, meta = pyreadstat.read_por(path, output_format=self.backend) df.columns = [x.lower() for x in df.columns] df2 = nw.from_native(self.df_charnan) if self.backend != "pandas": new_ser = nw.new_series(name="object", values=[str(x) if x is not None else None for x in df2["object"]], dtype=nw.String, backend=self.backend) df2 = df2.with_columns(new_ser.alias("object")) df2 = df2.with_columns(nw.col("string", "object").fill_null("")) df2 = df2.with_columns(nw.col("integer").cast(nw.Float64)) if self.backend == "pandas": df2 = df2.with_columns(nw.col("object").cast(nw.String)) df2 = df2.to_native() self.assertTrue(df2.equals(df)) def test_dta_write_charnan(self): path = os.path.join(self.write_folder, "charnan.dta") pyreadstat.write_dta(self.df_charnan, path) df, meta = pyreadstat.read_dta(path, output_format=self.backend) df2 = nw.from_native(self.df_charnan) if self.backend != "pandas": new_ser = nw.new_series(name="object", values=[str(x) if x is not None else None for x in df2["object"]], dtype=nw.String, backend=self.backend) df2 = df2.with_columns(new_ser.alias("object")) df2 = df2.with_columns(nw.col("string", "object").fill_null("")) df2 = df2.with_columns(nw.col("integer").cast(nw.Float64)) if self.backend == "pandas": df2 = df2.with_columns(nw.col("object").cast(nw.String)) df2 = df2.to_native() self.assertTrue(df2.equals(df)) def test_set_value_labels(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), output_format=self.backend) df_formatted = pyreadstat.set_value_labels(df, meta, formats_as_category=True) self.assertTrue(df_formatted.equals(self.df_pandas_formatted)) # partial sub1_raw = df[['myord']] sub1 = pyreadstat.set_value_labels(sub1_raw, meta, formats_as_category=True) sub2 = self.df_pandas_formatted[['myord']] self.assertTrue(sub1.equals(sub2)) def test_update_delete_file(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), output_format=self.backend) dst_path = os.path.join(self.write_folder, "update_test.sav") pyreadstat.write_sav(df, dst_path, variable_value_labels = meta.variable_value_labels) # update meta.variable_value_labels.update({'mylabl':{1.0:"Gents", 2.0:"Ladies"}}) pyreadstat.write_sav(df, dst_path, variable_value_labels = meta.variable_value_labels) df2, meta2 = pyreadstat.read_sav(dst_path, output_format=self.backend) self.assertDictEqual(meta2.variable_value_labels, meta.variable_value_labels) os.remove(dst_path) def test_xport_write_dates2_v8(self): # this sas7bdat file has features that are not compatible with v5 df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "dates_xpt.sas7bdat"), output_format=self.backend) dst_path = os.path.join(self.write_folder, "dates_xptv8.xpt") pyreadstat.write_xport(df, dst_path, file_format_version=8) df2, meta2 = pyreadstat.read_xport(dst_path, output_format=self.backend) self.assertTrue(df.equals(df2)) def test_xport_dates2_v8(self): # this sas7bdat file has features that are not compatible with v5 df, meta = pyreadstat.read_sas7bdat(os.path.join(self.basic_data_folder, "dates_xpt.sas7bdat"), output_format=self.backend) # this xpt file was written in SAS from the sas7bdat file df2, meta2 = pyreadstat.read_xport(os.path.join(self.basic_data_folder, "dates_xpt_v8.xpt"), output_format=self.backend) self.assertTrue(df.equals(df2)) self.assertListEqual(meta.column_labels, meta2.column_labels) def test_sav_international_utf8_char_value(self): # a file that has a value with international characters and the file is coded in utf-8 df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "tegulu.sav"), output_format=self.backend) self.assertTrue(nw.from_native(df)[0,1] == "నేను గతంలో వాడిన బ") def test_sav_international_varname(self): # a file with a varname with international characters df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "hebrews.sav"), output_format=self.backend) self.assertTrue(df.columns[0] == "ותק_ב") def test_sav_original_var_types(self): # a file with a varname with international characters df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "test_width.sav"), output_format=self.backend) self.assertEqual(meta.original_variable_types['StartDate'],'A1024') self.assertEqual(meta.original_variable_types['ResponseId'],'A18') self.assertEqual(meta.original_variable_types['Duration__in_seconds_'],'F40.2') self.assertEqual(meta.original_variable_types['Finished'],'F1.0') self.assertEqual(meta.readstat_variable_types['Finished'],'double') def test_sav_write_longstr(self): path = os.path.join(self.write_folder, "longstr.sav") pyreadstat.write_sav(self.df_longstr, path, variable_display_width={"v1": 1000}) df, meta = pyreadstat.read_sav(path, output_format=self.backend) self.assertTrue(meta.variable_display_width['v1']==1000) self.assertTrue(len(nw.from_native(df)[0,0])==2345) def test_dta_write_longstr(self): path = os.path.join(self.write_folder, "longstr.dta") df_longstr = self.df_longstr pyreadstat.write_dta(self.df_longstr, path) df, meta = pyreadstat.read_dta(path, output_format=self.backend) self.assertTrue(df.equals(df_longstr)) def test_sas7bdat_file_label_linux(self): "testing file label for file produced on linux" path = os.path.join(self.basic_data_folder, "test_file_label_linux.sas7bdat") df, meta = pyreadstat.read_sas7bdat(path, output_format=self.backend) self.assertEqual(meta.file_label, "mytest label") self.assertEqual(meta.table_name, "TEST_DATA") def test_sas7bdat_extra_date_formats(self): "testing extra date format argument" path = os.path.join(self.basic_data_folder, "date_test.sas7bdat") df, meta = pyreadstat.read_sas7bdat(path, extra_date_formats=["MMYY", "YEAR"], output_format=self.backend) self.assertEqual(nw.from_native(df)['yr'][0], date(2023,1,1)) self.assertEqual(nw.from_native(df)['dtc4'][0], date(2023,7,1)) def test_sas7bdat_file_label_windows(self): "testing file label for file produced on windows" path = os.path.join(self.basic_data_folder, "test_file_label_win.sas7bdat") df, meta = pyreadstat.read_sas7bdat(path, output_format=self.backend) self.assertEqual(meta.file_label, "mytest label") self.assertEqual(meta.table_name, "TEST_DATA") def test_sav_write_variable_formats(self): "testing variable formats for SAV files" path = os.path.join(self.write_folder, "variable_format.sav") df = nw.from_dict({'restricted':[1023, 10], 'integer':[1,2]}, backend=self.backend) formats = {'restricted':'restricted_integer', 'integer':'integer'} pyreadstat.write_sav(df, path, variable_format=formats) df2, meta2 = pyreadstat.read_sav(path, output_format=self.backend) self.assertEqual(meta2.original_variable_types['restricted'], "N4") self.assertEqual(meta2.original_variable_types['integer'], "F1.0") def test_sav_ordered_categories(self): path = os.path.join(self.basic_data_folder, "ordered_category.sav") df, meta = pyreadstat.read_sav(path, apply_value_formats=True, formats_as_ordered_category=True, output_format=self.backend) # in polars it is enum, it is ordered by default if self.backend == "pandas": self.assertTrue(df["Col1"].cat.ordered) else: self.assertTrue(type(nw.from_native(df)["Col1"].dtype)==nw.Enum) self.assertListEqual(list(nw.from_native(df)["Col1"].cat.get_categories().to_list()), ['high', 'low', 'medium']) def test_sav_pathlib(self): if is_pathlib_available: path = Path(self.basic_data_folder).joinpath("sample.sav") df, meta = pyreadstat.read_sav(path, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) def test_sav_write_pathlib(self): if is_pathlib_available: file_label = "basic write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = Path(self.write_folder).joinpath('pathlib_write.sav') pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) self.assertEqual(meta.variable_display_width['mychar'], variable_display_width['mychar']) #self.assertDictEqual(meta.variable_alignment, variable_alignment) self.assertEqual(meta.variable_measure["mychar"], variable_measure["mychar"]) def test_sav_write_dictlabels(self): col_names = ["mychar", "mynum", "mydate", "dtime", "mylabl", "myord", "mytime"] col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] col_lab_dict = {k:v for k,v in zip(col_names, col_labels) if v} variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} path = os.path.join(self.write_folder, "dictlabel_write.sav") pyreadstat.write_sav(self.df_pandas, path, column_labels=col_lab_dict) df, meta = pyreadstat.read_sav(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertListEqual(meta.column_labels, col_labels) def test_dta_write_single_value_user_missing(self): df = nw.from_dict({"var": ["a", "a", "a", "a"]}, backend=self.backend).to_native() missing_user_values = {"var": ["a"]} path = os.path.join(self.write_folder, "singleusermissing.dta") pyreadstat.write_dta(df=df, dst_path=path, missing_user_values=missing_user_values,version=12) df2, meta2 = pyreadstat.read_dta(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(df2)) def test_dta_write_only_missing_and_user_missing(self): if self.backend=="pandas": temp = np.nan else: temp = None df = nw.from_dict({"var": [temp, "a", "b"]}, backend=self.backend).to_native() path = os.path.join(self.write_folder, "onlymissing_and_usermissing.dta") variable_value_labels={"var": {1: "Val 1", 2: "Val 2", 3: "Val 3", "a": "Missing A", "b": "Missing B", } } missing_user_values={"var": ["a", "b"]} pyreadstat.write_dta(df, path, variable_value_labels=variable_value_labels, missing_user_values=missing_user_values,version=12) df2, meta2 = pyreadstat.read_dta(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(df2)) def test_sav_outputformat_dict(self): df, meta = pyreadstat.read_sav(os.path.join(self.basic_data_folder, "sample.sav"), output_format='dict') self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(self.df_pandas)) self.assertTrue(len(meta.notes)>0) self.assertTrue(meta.variable_display_width["mychar"]==9) self.assertTrue(meta.variable_storage_width["mychar"] == 8) self.assertTrue(meta.variable_measure["mychar"]=="nominal") self.assertTrue(meta.readstat_variable_types["mychar"]=="string") self.assertTrue(meta.readstat_variable_types["myord"]=="double") kwds = {} if self.backend == "pandas": kwds['orient'] = 'list' padic = self.df_pandas.to_dict(**kwds) for colname, data in df.items(): curdfcol = df[colname] for indx, val in enumerate(data): if pd.isna(val) and pd.isna(curdfcol[indx]): continue self.assertTrue(val==curdfcol[indx]) def test_sav_write_rowcompression(self): file_label = "row compression write" file_note = "These are some notes" col_labels = ["mychar label","mynum label", "mydate label", "dtime label", None, "myord label", "mytime label"] variable_value_labels = {'mylabl': {1.0: 'Male', 2.0: 'Female'}, 'myord': {1.0: 'low', 2.0: 'medium', 3.0: 'high'}} missing_ranges = {'mychar':['a'], 'myord': [{'hi':2, 'lo':1}]} #variable_alignment = {'mychar':"center", 'myord':"right"} variable_display_width = {'mychar':20} variable_measure = {"mychar": "nominal"} path = os.path.join(self.write_folder, "rowcompression_write.sav") pyreadstat.write_sav(self.df_pandas, path, file_label=file_label, column_labels=col_labels, note=file_note, variable_value_labels=variable_value_labels, missing_ranges=missing_ranges, variable_display_width=variable_display_width, variable_measure=variable_measure, row_compress=True) #, variable_alignment=variable_alignment) df, meta = pyreadstat.read_sav(path, user_missing=True, output_format=self.backend) self.assertTrue(df.equals(self.df_pandas)) self.assertEqual(meta.file_label, file_label) self.assertListEqual(meta.column_labels, col_labels) self.assertEqual(meta.notes[0], file_note) self.assertDictEqual(meta.variable_value_labels, variable_value_labels) self.assertEqual(meta.variable_display_width['mychar'], variable_display_width['mychar']) #self.assertDictEqual(meta.variable_alignment, variable_alignment) self.assertEqual(meta.variable_measure["mychar"], variable_measure["mychar"]) def test_dta_write_int_missing(self): if self.backend == "pandas": df = pd.DataFrame.from_dict({'a': [ 1, 2, None]},dtype='Int32') else: df = nw.from_dict({'a': [ 1, 2, None]}, backend=self.backend, schema={'a': nw.Int32}).to_native() path = os.path.join(self.write_folder, "missingint.dta") pyreadstat.write_dta(df, path) df2, meta2 = pyreadstat.read_dta(path, output_format=self.backend) if self.backend == "pandas": df2["a"] = df2["a"].astype('Int32') self.assertTrue(df.equals(df2)) def test_dta_write_bool_missing(self): if self.backend == "pandas": df = pd.DataFrame.from_dict({'a': [ True, False, None]},dtype='boolean') else: df = nw.from_dict({'a': [ True, False, None]}, backend=self.backend, schema={'a': nw.Boolean}).to_native() path = os.path.join(self.write_folder, "missingbool.dta") pyreadstat.write_dta(df, path) df2, meta2 = pyreadstat.read_dta(path, output_format=self.backend) if self.backend == "pandas": df2["a"] = df2["a"].astype('boolean') else: df2 = nw.from_native(df2).with_columns(nw.col("a").cast(nw.Boolean)).to_native() self.assertTrue(df.equals(df2)) def test_sav_write_formatted(self): path = os.path.join(self.write_folder, "formatted.sav") pyreadstat.write_sav(self.df_pandas_formatted, path) df, meta = pyreadstat.read_sav(path, output_format=self.backend) df2 = nw.from_native(self.df_pandas_formatted) df2 = df2.with_columns(nw.col("myord", "mylabl").cast(nw.String)).to_native() self.assertTrue(df.equals(df2)) def test_sav_write_formatted_nulls(self): """ apply format when some columns have some nulls or all nulls all nulls raises a warning in polars """ labels = {'a': {1:'a', 2: 'b'}, 'b': {1:'c'}, 'c': {1:'d'}} data = {'a': [1,2,3], 'b':[1, 1, None], 'c': [None, None, None]} df = nw.from_dict(data, schema={'a':nw.Float64, 'b':nw.Float64, 'c': nw.Float64}, backend=self.backend).to_native() path = os.path.join(self.write_folder, "formatted_nulls.sav") pyreadstat.write_sav(df, path, variable_value_labels=labels) schema = dict() null = np.nan if self.backend != "pandas": schema={'a':nw.String, 'b':nw.Categorical, 'c': None} null = None data_result = {'a': ['a','b', '3.0'], 'b':['c', 'c', null], 'c': [null, null, null]} df_control = nw.from_dict(data_result, schema=schema, backend=self.backend).to_native() df2, meta2 = pyreadstat.read_sav(path, apply_value_formats=True, output_format=self.backend) new_ser = nw.new_series(name="a", values=[str(x) for x in df2["a"]], dtype=nw.String, backend=self.backend) df2 = nw.from_native(df2).with_columns(new_ser.alias("a")).to_native() cat_type = object if is_pandas_version_newer_than_2: cat_type = str if self.backend == "pandas": df_control = nw.from_native(df_control).with_columns(nw.col('b').cast(nw.Categorical)).to_native() df_control['c'] = df_control['c'].astype(cat_type).astype("category") self.assertTrue(df2.equals(df_control)) def test_sav_write_mixed_types(self): csv_path = os.path.join(self.basic_data_folder, "mixed_types.csv") kwds = {} if backend == "polars": kwds["try_parse_dates"] = True df_ori = nw.read_csv(csv_path, backend=self.backend, **kwds) df = df_ori.clone() time_unit = "ns" if is_pandas_version_newer_than_2: time_unit = "us" if self.backend != "pandas": # convince polars to take columns with mixed types temp = [0 if x=="0" else x for x in df["col_other"]] newser = nw.new_series(name="col_other", values=temp , dtype=nw.Object, backend=df.implementation) df = df.with_columns(newser.alias("col_other")) temp = [datetime.strptime('2814-01-01 00:00:00', '%Y-%m-%d %H:%M:%S') if x.startswith('2814') else x for x in df["total_time"]] newser = nw.new_series(name="total_time", values=temp, dtype=nw.Object, backend=df.implementation) df = df.with_columns(newser.alias("total_time")) else: df = df.with_columns(nw.when(nw.col("col_other")=='0').then(nw.lit(0)).otherwise(nw.col('col_other')).alias('col_other')) df = df.with_columns(nw.when(nw.col("total_time")=='2814-01-01 00:00:00') .then(nw.lit(datetime.strptime('2814-01-01 00:00:00', '%Y-%m-%d %H:%M:%S'))) .otherwise(nw.col('total_time')) .alias('total_time')) df = df.with_columns(nw.col("datestamp").cast(nw.Datetime(time_unit=time_unit))) df_ori = df_ori.with_columns(nw.col("datestamp").cast(nw.Datetime(time_unit=time_unit))) df = df.to_native() path = os.path.join(self.write_folder, "mixed_types.sav") pyreadstat.write_sav(df, path) df2, meta = pyreadstat.read_sav(path, output_format=self.backend) self.assertTrue(df_ori.to_native().equals(df2)) def test_read_sav_file_handle(self): """Test reading SAV file from file-like object (e.g., zip archive)""" sav_file = os.path.join(self.basic_data_folder, "sample.sav") #with tempfile.NamedTemporaryFile(suffix=".zip", delete=True, dir=self.write_folder) as tmp: with tempfile.TemporaryDirectory() as tmp_dir: zip_file = os.path.join(tmp_dir, "sample.zip") with zipfile.ZipFile(zip_file, "w", zipfile.ZIP_DEFLATED) as zf: zf.write(sav_file, "sample.sav") #with zipfile.ZipFile(tmp.name, "r") as zf: with zipfile.ZipFile(zip_file, "r") as zf: with zf.open("sample.sav", "r") as fh: df, meta = pyreadstat.read_sav(fh, output_format=self.backend) self.assertEqual(len(df.columns), len(self.df_pandas.columns)) self.assertEqual(len(df), len(self.df_pandas)) def test_read_sav_bytesio(self): """Test reading SAV file from BytesIO (simulates remote/streaming data)""" sav_file = os.path.join(self.basic_data_folder, "sample.sav") with open(sav_file, "rb") as f: file_bytes = f.read() buffer = io.BytesIO(file_bytes) df, meta = pyreadstat.read_sav(buffer, output_format=self.backend) self.assertEqual(len(df.columns), len(self.df_pandas.columns)) self.assertEqual(len(df), len(self.df_pandas)) self.assertListEqual(list(df.columns), list(self.df_pandas.columns)) def test_sas7bdat_bytesio_chunk(self): sas7bdat_file = os.path.join(self.basic_data_folder, "sample.sas7bdat") with open(sas7bdat_file, "rb") as f: file_bytes = f.read() buffer = io.BytesIO(file_bytes) df, meta = pyreadstat.read_sas7bdat(buffer, row_limit = 2, row_offset =1, output_format=self.backend) df_pandas = nw.from_native(self.df_pandas)[1:3].to_native() if self.backend == "pandas": df_pandas = df_pandas.reset_index(drop=True) df_pandas["dtime"] = pd.to_datetime(df_pandas["dtime"]) self.assertTrue(df.equals(df_pandas)) self.assertTrue(meta.number_columns == len(self.df_pandas.columns)) self.assertTrue(meta.number_rows == len(df_pandas)) def test_multiprocess_reader_bytesio(self): fpath = os.path.join(self.basic_data_folder, "sample_large.sav") with open(fpath, "rb") as f: file_bytes = f.read() buffer = io.BytesIO(file_bytes) df_multi, meta_multi = pyreadstat.read_file_multiprocessing(pyreadstat.read_sav, buffer, output_format=self.backend) df_single, meta_single = pyreadstat.read_sav(fpath, output_format=self.backend) self.assertTrue(df_multi.equals(df_single)) self.assertEqual(meta_multi.number_rows, meta_single.number_rows) if __name__ == '__main__': import sys if "--inplace" in sys.argv: script_folder = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0] sys.path.insert(0, script_folder) sys.argv.remove('--inplace') backend = "pandas" for arg in sys.argv: if arg.startswith("--backend"): backend = arg.split("=")[1] sys.argv.remove(arg) # to avoid os.fork warnings when using polars #mp.set_start_method('forkserver') can also be 'spawn' # very slow, prefer to get the warning # TODO: document this in Readme: # DeprecationWarning: This process (pid=2314) is multi-threaded, use of fork() may lead to deadlocks in the child self.pid = os.fork() print(f"Using backend: {backend}") import pyreadstat print("package location:", pyreadstat.__file__) unittest.main() ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1721316781.0 pyreadstat-1.3.3/tests/test_version.py0000644000076500000240000000215114646232655016512 0ustar00dialout""" Test if the version in pyreadstat __init__ matches the version in setup.py """ import os import sys import re script_folder = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0] sys.path.insert(0, script_folder) sys.path.insert(1,os.path.join(script_folder, "docs")) import pyreadstat import conf pyreadstat_version = pyreadstat.__version__ with open(os.path.join(script_folder, "setup.py")) as h: content = h.read() raw = re.findall("version=\'.*?\'", content) setup_version = raw[0].replace("version=", "") setup_version = setup_version.replace("'", "") with open(os.path.join(script_folder, "CITATION.cff")) as h: content = h.readlines() raw = [x for x in content if x.startswith("version")] cff_version = raw[0].replace("version:", "").strip() print("testing if module and setup versions match") assert(pyreadstat_version == setup_version) print("testing if documentation and setup versions match") assert(conf.release == setup_version) print("testing if cff and setup versions match") assert(cff_version == setup_version) print("all versions match!")