{"action":"created","issue":{"url":"https://api.github.com/repos/CoolProp/CoolProp/issues/1743","repository_url":"https://api.github.com/repos/CoolProp/CoolProp","labels_url":"https://api.github.com/repos/CoolProp/CoolProp/issues/1743/labels{/name}","comments_url":"https://api.github.com/repos/CoolProp/CoolProp/issues/1743/comments","events_url":"https://api.github.com/repos/CoolProp/CoolProp/issues/1743/events","html_url":"https://github.com/CoolProp/CoolProp/pull/1743","id":367491631,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwOTA4ODI2","number":1743,"title":"Show an actual DeprecationWarning if Props() used.","user":{"login":"henningjp","id":17114032,"node_id":"MDQ6VXNlcjE3MTE0MDMy","avatar_url":"https://avatars1.githubusercontent.com/u/17114032?v=4","gravatar_id":"","url":"https://api.github.com/users/henningjp","html_url":"https://github.com/henningjp","followers_url":"https://api.github.com/users/henningjp/followers","following_url":"https://api.github.com/users/henningjp/following{/other_user}","gists_url":"https://api.github.com/users/henningjp/gists{/gist_id}","starred_url":"https://api.github.com/users/henningjp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henningjp/subscriptions","organizations_url":"https://api.github.com/users/henningjp/orgs","repos_url":"https://api.github.com/users/henningjp/repos","events_url":"https://api.github.com/users/henningjp/events{/privacy}","received_events_url":"https://api.github.com/users/henningjp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-06T20:09:57Z","updated_at":"2018-10-08T16:37:16Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/CoolProp/CoolProp/pulls/1743","html_url":"https://github.com/CoolProp/CoolProp/pull/1743","diff_url":"https://github.com/CoolProp/CoolProp/pull/1743.diff","patch_url":"https://github.com/CoolProp/CoolProp/pull/1743.patch"},"body":"### Description of the Change\r\n\r\nWhen using the deprecated Props() routine, deprecation warnings were issued as a _UserWarning_ instead of _DeprecationWarning_ through the warnings module, using warnings.**warn_explicit()**.\r\n1.  Issue warning using warnings.**warn(dep_message, DeprecationWarning)** instead\r\n2. Set warnings filter when loading the CoolProp module to display all DeprecationWarnings triggered by ``__main__``.\r\n\r\n### Benefits\r\n\r\n1. Issues an actual DeprecationWarning which can be filtered by the calling script\r\n2. Gives the name of the calling routine and line number where Props() call was made (i.e. previous warn_explicit() call reported `CoolProp.pyx` on line ``-1``.\r\n3. Sets filter so that all versions of Python will report deprecation warnings.  Python 3.2 to 3.6 ignored all DeprecationWarnings, which is probably why UserWarnings was used in the first place.  Manually setting the warnings filter ensures consistent behavior across all versions of Python.\r\n4. Calling routine/script can override the filter to ignore the DeprecationWarning messages for legacy codes that are too difficult to change; otherwise, existing behavior of warning on all calls to Props() is not changed.\r\n\r\n### Possible Drawbacks\r\n\r\nBecause the warnings filter is being set explicitly in CoolProp.pyx for consistency, the calling routine/script must make any filter modifications after the import CoolProp is made.  Additionally, adjusting the warnings filter on the command line will not work as it will be overridden when the import of CoolProp is performed within the script. \r\n\r\nThis could still print a whole slew of Deprecation messages (as is the current behavior), making the problem and solution hard to find.  An alternative would be to set the CoolProp filter action to ``once``, which would only display the first DeprecationWarning and then ignore the rest; letting the user know that a deprecated function is being used without flooding stdout with warnings.  However, a single warning message could also easily escape attention.\r\n\r\n### Verification Process\r\n\r\nAfter recompiling the Python wrapper, the following Python script, TestProps.py was used to test the warnings behavior.\r\n```py\r\nfrom CoolProp.CoolProp import Props\r\nimport CoolProp;\r\nprint(\"\\nTesting warnings for deprecated Props() function.\")\r\nprint(\"======================================================================\")\r\nprint(\"CoolProp version - {}\".format(CoolProp.__version__))\r\nprint(\"======================================================================\")\r\n\r\nRho = Props('D','T',298.15,'P',10000,'R744')\r\nprint(\"R744 Density at {} K and {} kPa      = {} kg/m³\".format(298.15, 10000, Rho))\r\nH = Props('H','T',298.15,'Q',1,'R134a');\r\nprint(\"R134a Saturated Liquid Enthalpy at {} K = {} kJ/kg\".format(298.15, H))\r\nRho = Props('D','T',298.15,'P',10000,'R744');\r\nprint(\"R744 Density at {} K and {} kPa      = {} kg/m³\".format(298.15, 10000, Rho))\r\nH = Props('H','T',298.15,'Q',1,'R134a');\r\nprint(\"R134a Saturated Liquid Enthalpy at {} K = {} kJ/kg\".format(298.15, H))\r\nprint(\"======================================================================\\n\")\r\n```\r\nOutput from the script now shows actual DeprecationWarnings at the location of the Props() call in the calling routine/script.\r\n\r\n```\r\nTesting warnings for deprecated Props() function.\r\n======================================================================\r\nCoolProp version - 6.1.1dev\r\n======================================================================\r\nTestProps.py:14: DeprecationWarning: Props() function is deprecated; Use the PropsSI() function\r\n  Rho = Props('D','T',298.15,'P',10000,'R744')\r\nR744 Density at 298.15 K and 10000 kPa      = 817.6273812375758 kg/m³\r\nTestProps.py:16: DeprecationWarning: Props() function is deprecated; Use the PropsSI() function\r\n  H = Props('H','T',298.15,'Q',1,'R134a');\r\nR134a Saturated Liquid Enthalpy at 298.15 K = 412.33395323186807 kJ/kg\r\nTestProps.py:18: DeprecationWarning: Props() function is deprecated; Use the PropsSI() function\r\n  Rho = Props('D','T',298.15,'P',10000,'R744');\r\nR744 Density at 298.15 K and 10000 kPa      = 817.6273812375758 kg/m³\r\nTestProps.py:20: DeprecationWarning: Props() function is deprecated; Use the PropsSI() function\r\n  H = Props('H','T',298.15,'Q',1,'R134a');\r\nR134a Saturated Liquid Enthalpy at 298.15 K = 412.33395323186807 kJ/kg\r\n======================================================================\r\n```\r\nLegacy applications can create a filter override to ignore **_all_** deprecation warnings:\r\n```py\r\nimport warnings\r\nwarnings.filterwarnings('ignore', category=DeprecationWarning)\r\n```\r\nor just the deprecation messages containing the string  \"**_Props()_**\":\r\n```py\r\nimport warnings\r\nwarnings.filterwarnings('ignore', 'Props()', category=DeprecationWarning)\r\n```\r\nAs shown by the modified test script below, Props() deprecation messages are ignored, while non-Props() deprecation messages are still displayed.\r\n```py\r\nfrom CoolProp.CoolProp import Props\r\nimport CoolProp;\r\nprint(\"\\nTesting warnings for deprecated Props() function.\")\r\nprint(\"======================================================================\")\r\nprint(\"CoolProp version - {}\".format(CoolProp.__version__))\r\n\r\n# Filter out deprecation warning messages containing the string 'Props()'\r\n# Only takes effect if issued AFTER the CoolProp import\r\nimport warnings\r\nwarnings.filterwarnings(action='ignore', message='Props()', category=DeprecationWarning)\r\nprint(\"Props() DeprecationWarnings ignored\")\r\nprint(\"======================================================================\")\r\n\r\nRho = Props('D','T',298.15,'P',10000,'R744')\r\nprint(\"R744 Density at {} K and {} kPa      = {} kg/m³\".format(298.15, 10000, Rho))\r\nH = Props('H','T',298.15,'Q',1,'R134a');\r\nprint(\"R134a Saturated Liquid Enthalpy at {} K = {} kJ/kg\".format(298.15, H))\r\nRho = Props('D','T',298.15,'P',10000,'R744');\r\nprint(\"R744 Density at {} K and {} kPa      = {} kg/m³\".format(298.15, 10000, Rho))\r\nH = Props('H','T',298.15,'Q',1,'R134a');\r\nprint(\"R134a Saturated Liquid Enthalpy at {} K = {} kJ/kg\".format(298.15, H))\r\nprint(\"======================================================================\\n\")\r\n\r\nwarnings.warn(\"This is a deprecation message that is not filtered.\", DeprecationWarning)\r\nprint(\"done.\")\r\n```\r\nwith the following results:\r\n```\r\nTesting warnings for deprecated Props() function.\r\n======================================================================\r\nCoolProp version - 6.1.1dev\r\nProps() DeprecationWarnings ignored\r\n======================================================================\r\nR744 Density at 298.15 K and 10000 kPa      = 817.6273812375758 kg/m³\r\nR134a Saturated Liquid Enthalpy at 298.15 K = 412.33395323186807 kJ/kg\r\nR744 Density at 298.15 K and 10000 kPa      = 817.6273812375758 kg/m³\r\nR134a Saturated Liquid Enthalpy at 298.15 K = 412.33395323186807 kJ/kg\r\n======================================================================\r\n\r\nTestProps.py:24: DeprecationWarning: This is a deprecation message that is not filtered.\r\n  warnings.warn(\"This is a deprecation message that is not filtered.\", DeprecationWarning)\r\ndone.\r\n```\r\n\r\n### Applicable Issues\r\n\r\nCloses #1734 \r\n"},"comment":{"url":"https://api.github.com/repos/CoolProp/CoolProp/issues/comments/427900902","html_url":"https://github.com/CoolProp/CoolProp/pull/1743#issuecomment-427900902","issue_url":"https://api.github.com/repos/CoolProp/CoolProp/issues/1743","id":427900902,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzkwMDkwMg==","user":{"login":"ibell","id":1859947,"node_id":"MDQ6VXNlcjE4NTk5NDc=","avatar_url":"https://avatars2.githubusercontent.com/u/1859947?v=4","gravatar_id":"","url":"https://api.github.com/users/ibell","html_url":"https://github.com/ibell","followers_url":"https://api.github.com/users/ibell/followers","following_url":"https://api.github.com/users/ibell/following{/other_user}","gists_url":"https://api.github.com/users/ibell/gists{/gist_id}","starred_url":"https://api.github.com/users/ibell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibell/subscriptions","organizations_url":"https://api.github.com/users/ibell/orgs","repos_url":"https://api.github.com/users/ibell/repos","events_url":"https://api.github.com/users/ibell/events{/privacy}","received_events_url":"https://api.github.com/users/ibell/received_events","type":"User","site_admin":false},"created_at":"2018-10-08T16:37:16Z","updated_at":"2018-10-08T16:37:16Z","author_association":"CONTRIBUTOR","body":"This looks fine!  Any chance of putting the explanation of how to silence the rather ridiculous number of warnings into the Python page in the docs?"}}
{"actor":{"display_login":"ibell"}}