|
38 | 38 | from swat.utils.compat import text_types
|
39 | 39 | from bs4 import BeautifulSoup
|
40 | 40 |
|
| 41 | +pd_version = tuple([int(x) for x in re.match(r'^(\d+)\.(\d+)\.(\d+)', |
| 42 | + pd.__version__).groups()]) |
| 43 | + |
41 | 44 | USER, PASSWD = tm.get_user_pass()
|
42 | 45 | HOST, PORT, PROTOCOL = tm.get_host_port_proto()
|
43 | 46 |
|
@@ -860,6 +863,50 @@ def test_apply_formats(self):
|
860 | 863 |
|
861 | 864 | # html = data._repr_javascript_()
|
862 | 865 |
|
| 866 | + # Bug in Pandas 1.2.0-1.5.3 returns NaN |
| 867 | + # Pandas <= 1.1.5 rounds correctly, but does not propagate attributes |
| 868 | + @unittest.skipIf((pd_version >= (1, 2, 0) and pd_version < (2, 0, 0)), |
| 869 | + 'Need newer version of Pandas') |
| 870 | + def test_round(self): |
| 871 | + descdf = self.table.describe() |
| 872 | + # BUG - some versions of python/pandas table.describe() |
| 873 | + # returns pandas.DataFrame, not swat.SASDataFrame |
| 874 | + if not isinstance(descdf, swat.SASDataFrame): |
| 875 | + descdf = swat.SASDataFrame(descdf) |
| 876 | + descdf.name = "test_round_df_name" |
| 877 | + descdf.label = "test_round_df_label" |
| 878 | + descdf.title = "test round title" |
| 879 | + descdf.formatter = swat.SASFormatter(soptions='locale=fr-FR') |
| 880 | + descdf.attrs = {'ByVar1': 'Make'} |
| 881 | + descdf.colinfo['MSRP'] = swat.dataframe.SASColumnSpec('MSRP', |
| 882 | + dtype='double', |
| 883 | + width=8) |
| 884 | + result = descdf.round(decimals=1) |
| 885 | + if pd_version >= (2, 0, 0): |
| 886 | + # pandas does not propagate df properties until 2.0.0 |
| 887 | + self.assertEqual(result.name, "test_round_df_name") |
| 888 | + self.assertEqual(result.label, "test_round_df_label") |
| 889 | + self.assertEqual(result.title, "test round title") |
| 890 | + self.assertEqual(result.formatter._soptions, 'locale=fr-FR') |
| 891 | + self.assertEqual(result.attrs['ByVar1'], 'Make') |
| 892 | + self.assertEqual(len(result.colinfo), 1) |
| 893 | + self.assertNotEqual(result.colinfo.get('MSRP', None), None) |
| 894 | + # spot check results |
| 895 | + self.assertFalse(result.isnull().values.any()) |
| 896 | + self.assertEqual(result.iloc[0, 0], 428.0) |
| 897 | + self.assertEqual(result.iloc[1, 1], 30014.7) |
| 898 | + self.assertEqual(result.iloc[2, 2], 1.1) |
| 899 | + self.assertEqual(result.iloc[3, 3], 3.0) |
| 900 | + self.assertEqual(result.iloc[4, 1], 18851.0) |
| 901 | + self.assertEqual(result.iloc[4, 2], 2.3) |
| 902 | + self.assertEqual(result.iloc[5, 7], 3474.5) |
| 903 | + self.assertEqual(result.iloc[6, 2], 3.9) |
| 904 | + self.assertEqual(result.iloc[7, 9], 238.0) |
| 905 | + self.assertEqual(result.iloc[1, 4], 215.9) |
| 906 | + self.assertEqual(result.iloc[6, 5], 21.5) |
| 907 | + self.assertEqual(result.iloc[2, 6], 5.7) |
| 908 | + self.assertEqual(result.iloc[2, 8], 8.3) |
| 909 | + |
863 | 910 |
|
864 | 911 | if __name__ == '__main__':
|
865 | 912 | tm.runtests()
|
0 commit comments