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_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_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_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_write_dates(self):
#if sys.version_info[0] < 3:
# return
path = os.path.join(self.write_folder, "dates_write.xpt")
pyreadstat.write_xport(self.df_sas_dates, path)
df, meta = pyreadstat.read_xport(path)
self.assertTrue(df.equals(self.df_sas_dates))
def test_xport_write_basic(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)
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(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))