Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_por(self):
df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"))
# dates, datetimes and timestamps are not translated but stay as integers, let's just drop them
df_pandas_por = self.df_pandas.drop(labels=["dtime", "mydate", "mytime"], axis=1)
df.columns = [x.lower() for x in df.columns]
df = df.drop(labels=["dtime", "mydate", "mytime"], axis=1)
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_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)
# dates, datetimes and timestamps are not translated but stay as integers, let's just drop them
df_pandas_por = self.df_pandas_formatted.drop(labels=["dtime", "mydate", "mytime"], axis=1)
df.columns = [x.lower() for x in df.columns]
df = df.drop(labels=["dtime", "mydate", "mytime"], axis=1)
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_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_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_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_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)