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_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_zsav_write_dates(self):
#if sys.version_info[0] < 3:
# return
path = os.path.join(self.write_folder, "dates_write.sav")
pyreadstat.write_sav(self.df_sas_dates, path, compress=True)
df, meta = pyreadstat.read_sav(path)
self.assertTrue(df.equals(self.df_sas_dates))
def test_sav_write_dates(self):
#if sys.version_info[0] < 3:
# return
path = os.path.join(self.write_folder, "dates_write.sav")
pyreadstat.write_sav(self.df_sas_dates, path)
df, meta = pyreadstat.read_sav(path)
self.assertTrue(df.equals(self.df_sas_dates))
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"])