Skip to content
Snippets Groups Projects
Verified Commit eb52eb19 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

MAINT: Renamed sav -> spss

parent 87973b4e
No related branches found
No related tags found
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!171sav/spss converter
Pipeline #51027 failed
from . import converters from . import converters
from .conv_impl.sav import SAVConverter from .conv_impl.spss import SPSSConverter
from .crawl import Crawler, SecurityMode from .crawl import Crawler, SecurityMode
from .version import CfoodRequiredVersionError, get_caoscrawler_version from .version import CfoodRequiredVersionError, get_caoscrawler_version
__version__ = get_caoscrawler_version() __version__ = get_caoscrawler_version()
# Convenience members ######################################################### # Convenience members #########################################################
converters.SAVConverter = SAVConverter # mypy: disable-error-code="attr-defined"
converters.SPSSConverter = SPSSConverter
...@@ -31,6 +31,7 @@ cfood: ...@@ -31,6 +31,7 @@ cfood:
- JSONFile - JSONFile
- CSVTableConverter - CSVTableConverter
- XLSXTableConverter - XLSXTableConverter
- SPSSFile
- H5File - H5File
- H5Dataset - H5Dataset
- H5Group - H5Group
......
...@@ -18,20 +18,29 @@ ...@@ -18,20 +18,29 @@
"""Converter for SAV files (stored by SPSS).""" """Converter for SAV files (stored by SPSS)."""
# import pyreadstat # Maybe us this if we need more metadata
import pandas as pd import pandas as pd
import pyreadstat
from .. import converters from .. import converters
from ..stores import GeneralStore, RecordStore from ..stores import GeneralStore
from ..structure_elements import (BooleanElement, DictElement, Directory, File, from ..structure_elements import (File, StructureElement)
FloatElement, IntegerElement, JSONFile,
ListElement, NoneElement, StructureElement,
TextElement)
class SAVConverter(converters.TableConverter): class SPSSConverter(converters.TableConverter):
"""Converter for SAV files (stored by SPSS).""" """Converter for SAV files (stored by SPSS)."""
def create_children(self, values: GeneralStore, element: StructureElement): # def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# from IPython import embed
# embed()
def create_children(self, values: GeneralStore, element: StructureElement) -> list:
assert isinstance(element, File)
df = pd.io.spss.read_spss(element.path) df = pd.io.spss.read_spss(element.path)
# if element.path.endswith(".sav"):
# sav_df, meta = pyreadstat.read_sav(element.path, metadataonly=True)
# from IPython import embed
# embed()
return self._children_from_dataframe(df) return self._children_from_dataframe(df)
...@@ -81,6 +81,10 @@ CSVTableConverter: ...@@ -81,6 +81,10 @@ CSVTableConverter:
converter: CSVTableConverter converter: CSVTableConverter
package: caoscrawler.converters package: caoscrawler.converters
SPSSFile:
converter: SPSSConverter
package: caoscrawler.converters
XLSXTableConverter: XLSXTableConverter:
converter: XLSXTableConverter converter: XLSXTableConverter
package: caoscrawler.converters package: caoscrawler.converters
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Testing converter for SAV files.""" """Testing converter for SPSS files."""
import datetime import datetime
import importlib import importlib
...@@ -28,7 +28,7 @@ import pytest ...@@ -28,7 +28,7 @@ import pytest
from caoscrawler.converters import ( from caoscrawler.converters import (
ConverterValidationError, ConverterValidationError,
SAVConverter, SPSSConverter,
) )
from caoscrawler.structure_elements import (BooleanElement, DictElement, from caoscrawler.structure_elements import (BooleanElement, DictElement,
Directory, File, FloatElement, Directory, File, FloatElement,
...@@ -52,8 +52,8 @@ def converter_registry(): ...@@ -52,8 +52,8 @@ def converter_registry():
return converter_registry return converter_registry
def test_sav_converter(converter_registry): def test_spss_converter(converter_registry):
converter = SAVConverter({ converter = SPSSConverter({
"match": ("sample.sav") "match": ("sample.sav")
}, },
"ThisConverterNameIsIrrelevant", converter_registry "ThisConverterNameIsIrrelevant", converter_registry
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment