get_axes not present?
Hi I am using the following versions >>> import matplotlib >>> print(matplotlib. __version__) 3.3.4 >>> import pandas as pd >>> print(pd.__version__) 1.2.3 >>> import sys >>> sys.version_info sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0) In my code, I use axes in Pandas plot() like this (note that I omit some variables in this snippet to highlight the problem): def plot_dataframe(df, cnt, axes): plt.subplot(2, 1, 1) ax1 = row.plot( fontsize=font_size, linewidth=line_width, markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] ) def plot_kernels(my_dict2): fig,axes = plt.subplots(2,1, figsize=(20, 15)) should_plot = plot_dataframe(df, cnt, axes=axes) for ax in axes: ax.legend() plt.show() However, I get this error: Traceback (most recent call last): File "process_csv.py", line 174, in plot_kernels( my_dict2 ) File "process_csv.py", line 62, in plot_kernels should_plot = plot_dataframe(df, cnt, axes=axes) File "process_csv.py", line 34, in plot_dataframe ax1 = row.plot( fontsize=font_size, linewidth=line_width, markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] ) File "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_core.py", line 955, in __call__ return plot_backend.plot(data, kind=kind, **kwargs) File "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py", line 61, in plot plot_obj.generate() File "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py", line 283, in generate self._adorn_subplots() File "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py", line 483, in _adorn_subplots all_axes = self._get_subplots() File "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py", line 903, in _get_subplots ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot) AttributeError: 'NoneType' object has no attribute 'get_axes' I guess there is a mismatch between versions. Is there any workaround for that? Regards, Mahmood -- https://mail.python.org/mailman/listinfo/python-list
Re: Advantages of Default Factory in Dataclasses
On Tue, Nov 16, 2021 at 06:24:43PM -0500, Alan Bawden wrote: >```python >def add_to(elem, inlist=[]): >inlist.append(elem) >return inlist > >list1 = add_to(1) >list2 = add_to(2) >print(list1) # prints [1] >print(list2) # prints [1, 2], potentially confusing >``` > > Not only does it not print what "most people" expect. It also doesn't > print what _you_ expect! (But you made your point.) Haha, you're right. I would guess that I reordered the statements when I quickly checked this in the interpreter. But indeed, both list1 and list2 point to inlist, and thus are the same. Whoops! - DLD -- https://mail.python.org/mailman/listinfo/python-list
Re: get_axes not present?
On 11/18/21 02:49, Mahmood Naderan via Python-list wrote: File "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py", line 903, in _get_subplots ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot) AttributeError: 'NoneType' object has no attribute 'get_axes' I guess there is a mismatch between versions. Is there any workaround for that? It's not saying get_axes doesn't exist because of version skew, it's saying that the object returned by the call to the left of it (get_figure()) returned None, and None doesn't have methods Something isn't set up right, but you'll have to trace that through. -- https://mail.python.org/mailman/listinfo/python-list
Re: get_axes not present?
>It's not saying get_axes doesn't exist because of version skew, it's >saying that the object returned by the call to the left of it >(get_figure()) returned None, and None doesn't have methods > >Something isn't set up right, but you'll have to trace that through. Do you think the following statement is correct? ax1 = row.plot( fontsize=font_size, linewidth=line_width, markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] ) ax1.set_ylabel( yax_label, fontsize=font_size ) As you can see I put the result of plot() to ax1 and then use some functions, e.g. set_ylabel(). On the other hand, I have specified `label` and `ax` in plot(), too. Regards, Mahmood -- https://mail.python.org/mailman/listinfo/python-list
Re: get_axes not present?
On 11/18/21 10:54 AM, Mahmood Naderan via Python-list wrote: > As you can see I put the result of plot() to ax1 and then use some functions, > e.g. set_ylabel(). And what is the result of plot()? Is it a valid object, or is it None? -- https://mail.python.org/mailman/listinfo/python-list
news to me today: RIP Aahz
Aahz, co-author of Python for Dummies with Stef Maruch, recently passed away. Tiny death notice (with name typo) from the wilds of the Internet: http://file770.com/pixel-scroll-10-15-21-i-know-what-pixel-you-scrolled-last-summer/ (12) AAHZ MARUCH (1967-2021). [Item by James Davis Nicoll.] Python programmer, whose fannish activities date back at least as far as classic USENET (alt.poly and other groups), died October 14 following several years of ill health. Survived by partner Steph Maruch. Editor's postscript: Alan Prince Winston earlier this year described him as "an unstoppable-seeming guy" who "became a contra and square dance caller and choreographer despite really severe hearing impairment." I met Aahz once. He always wanted to be a mononym person, and used his partner's surname only reluctantly. Elijah -- Aahz's rule6 website seems to be held by a squatter now -- https://mail.python.org/mailman/listinfo/python-list
import question
hello one and all, are there any other ways to import a module or package other then the "import" or "from...import..." statements? i ask because i'm allowing programming on my web2py website and i don't want any accessing packages like os or sys. thank you in advance and have a great day, lucas -- https://mail.python.org/mailman/listinfo/python-list
several issues with pyinstaller on Windows 10
On Windows 10 I have installed: P:\W10>python --version Python 3.10.0 P:\W10>pyinstaller --version 4.7 I can compile a VERY simple Python program: P:\W10>type argv.pv #!/usr/bin/python3 import sys for a in sys.argv: print("["+a+"]") P:\W10>pyinstaller.exe --onefile tcpbm.py But I can run it only once: P:\W10\dist>argv a b [dist\argv] [a] [b] P:\W10\dist>argv a b The process cannot access the file because it is being used by another process. P:\W10\dist>argv 1 2 zzz The process cannot access the file because it is being used by another process. Compiling a little more complex program (with net IO) fails: P:\W10>pyinstaller.exe --onefile tcpbm.py 140 INFO: PyInstaller: 4.7 140 INFO: Python: 3.10.0 171 INFO: Platform: Windows-10-10.0.19041-SP0 171 INFO: wrote P:\W10\tcpbm.spec 171 INFO: UPX is not available. 203 INFO: Extending PYTHONPATH with paths ['P:\\W10'] 531 INFO: checking Analysis 547 INFO: Building Analysis because Analysis-00.toc is non existent 547 INFO: Initializing module dependency graph... 562 INFO: Caching module graph hooks... 593 INFO: Analyzing base_library.zip ... 4656 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'. 4656 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib' 5781 INFO: Caching module dependency graph... 6031 INFO: running Analysis Analysis-00.toc 6031 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by C:\Users\admin\AppData\Local\Programs\Python\Python310\python.exe 6187 INFO: Analyzing P:\W10\tcpbm.py 6250 INFO: Processing module hooks... 6250 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6250 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6250 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6250 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6390 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6390 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6484 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6484 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6484 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6484 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6500 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6546 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'... 6734 INFO: checking Tree 6734 INFO: Building Tree because Tree-00.toc is non existent 6749 INFO: Building Tree Tree-00.toc 6890 INFO: checking Tree 6890 INFO: Building Tree because Tree-01.toc is non existent 6890 INFO: Building Tree Tree-01.toc 7031 INFO: checking Tree 7031 INFO: Building Tree because Tree-02.toc is non existent 7031 INFO: Building Tree Tree-02.toc 7062 INFO: Looking for ctypes DLLs 7078 INFO: Analyzing run-time hooks ... 7093 INFO: Including run-time hook 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py' 7093 INFO: Including run-time hook 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py' 7109 INFO: Including run-time hook 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py' 7109 INFO: Looking for dynamic libraries 7546 INFO: Looking for eggs 7546 INFO: Using Python library C:\Users\admin\AppData\Local\Programs\Python\Python310\python310.dll 7562 INFO: Found binding redirects: [] 7562 INFO: Warnings written to P:\W10\build\tcpbm\warn-tcpbm.txt 76
Re: import question
On Fri, Nov 19, 2021 at 7:09 AM lucas wrote: > > hello one and all, > > are there any other ways to import a module or package other then the > "import" or "from...import..." statements? i ask because i'm allowing > programming on my web2py website and i don't want any accessing packages like > os or sys. > > thank you in advance and have a great day, lucas > Yes, there are many. For starters, the importlib module can do anything that importing can do, as can the __import__ function. Plus, with Python code, you could open the file, read from it, and exec it. There are myriad ways to fetch up code, and it's even possible to break out of a sandbox without ever using a single underscore. If you're trying to make a Python-in-Python sandbox, I recommend not. Instead, use an OS-level sandbox (a chroot, probably some sort of CPU usage limiting, etc), and use that to guard the entire Python process. Python-in-Python will basically *never* be secure. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to support annotations for a custom type in a C extension?
It works. Thanks a lot. On Sun, 19 Sept 2021 at 19:23, Serhiy Storchaka wrote: > > 19.09.21 05:59, MRAB пише: > > On 2021-09-18 16:09, Serhiy Storchaka wrote: > >> "(PyCFunction)" is redundant, Py_GenericAlias already has the right > >> type. Overuse of casting to PyCFunction can hide actual bugs. > >> > > I borrowed that from listobject.c, which does have the cast. > > Fixed. https://github.com/python/cpython/pull/28450 > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: import question
On Thu, Nov 18, 2021 at 12:21 PM Chris Angelico wrote: > If you're trying to make a Python-in-Python sandbox, I recommend not. > Instead, use an OS-level sandbox (a chroot, probably some sort of CPU > usage limiting, etc), and use that to guard the entire Python process. > Python-in-Python will basically *never* be secure. > Good advice to not try to sandbox python. But chroot can sometimes be broken out of. It isn't a cure-all. -- https://mail.python.org/mailman/listinfo/python-list
Re: import question
On 2021-11-17, lucas wrote: > are there any other ways to import a module or package other then > the "import" or "from...import..." statements? i ask because i'm > allowing programming on my web2py website and i don't want any > accessing packages like os or sys. Safely allowing people to enter/upload and then execute Python code is very difficult. From my brief research into that question a little while (a year or two) ago, the answer was that can't really be done in any general way. IIRC, some promising work was done in PyPy to address this problem, but the sandbox stuff never got moved to Py3? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: several issues with pyinstaller on Windows 10
On 11/18/21, Ulli Horlacher wrote: > > P:\W10\dist>argv a b > The process cannot access the file because it is being used by another > process. Try searching for open handles for "argv.exe" using Sysinternals Process Explorer [1]. Terminate the offending process. Since you're inexperienced with Windows, here's a brief explanation of ERROR_SHARING_VIOLATION (32). File objects that are opened for filesystem files have a read-write-delete sharing mode if the open requests any read-write-delete data access, but not if the open only has metadata access (e.g. timestamps, ID, attributes, extended attributes, security). Note that delete access includes the right to rename a file. The share mode flags and associated data access rights are as follows: FILE_SHARE_READ - FILE_READ_DATA | FILE_EXECUTE FILE_SHARE_WRITE - FILE_WRITE_DATA | FILE_APPEND_DATA FILE_SHARE_DELETE - DELETE For example, if an existing open for a file has any data access and doesn't share read access, then trying to open the file with execute access will fail as a sharing violation. The security context of the open request doesn't matter. For example, SYSTEM and administrators aren't privileged to bypass the sharing mode. It can only be bypassed from the kernel. Unfortunately the system error message for ERROR_SHARING_VIOLATION is misleading. The sharing mode has nothing to do with processes. It's strictly a function of the File objects that are opened for the file. Python's open() and os.open() functions share read and write access, but they do not share delete access. For example, overlapping calls to open('spam.txt', 'w') are allowed. For os.stat(), the share mode of existing opens doesn't matter because it opens the file with metadata access only. Sharing data access can get messy. Each open has its own file pointer in the associated OS file object. For example, say an open writes 10 bytes and flushes the buffer. Then a second open(..., 'w') call overwrites the file, truncating it to 0 bytes. When the original open writes to the file again, the OS will back fill the file with 10 null bytes. Windows also provides byte-range shared and exclusive locking that can exceed the current size of the file. A byte-range lock doesn't prevent opening the file with read, write, or delete access, and it doesn't prevent deleting the file. It causes write or read-write operations on the range to fail with ERROR_LOCK_VIOLATION (33). > win32ctypes.pywin32.pywintypes.error: (110, 'EndUpdateResourceW', > 'The system cannot open the device or file specified.') This is likely due to a sharing violation. EndUpdateResourceW() [2] requires exclusive access to the target file. If its internal open fails for any reason, it maps all errors to this generic ERROR_OPEN_FAILED (110) error code. --- [1] https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer [2] https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-endupdateresourcew -- https://mail.python.org/mailman/listinfo/python-list
Re: import question
On Fri, Nov 19, 2021 at 11:24 AM Dan Stromberg wrote: > > > On Thu, Nov 18, 2021 at 12:21 PM Chris Angelico wrote: >> >> If you're trying to make a Python-in-Python sandbox, I recommend not. >> Instead, use an OS-level sandbox (a chroot, probably some sort of CPU >> usage limiting, etc), and use that to guard the entire Python process. >> Python-in-Python will basically *never* be secure. > > > Good advice to not try to sandbox python. > > But chroot can sometimes be broken out of. It isn't a cure-all. > That's true, but it's way better than attempting Python-in-Python sandboxing. In any case, all the options worth investigating will be at the OS level. (Or maybe higher, but I can't imagine it being practical to create individual VMs for each client who comes to the web site.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Unexpected behaviour of math.floor, round and int functions (rounding)
Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This implies that int() function is rounding, which doesn't appear to be expected (documentation doesn't say anything about it). Looking further i noticed that 0.5+0.49994 returns 1. This seems to be related to double numbers' operations in C language, where 0.49994 is the greatest floating-point value less than 0.5. Counting on this several examples can be deduced, like: round(0+0.49994) returns 0, and round(1+0.49994) returns 2 This seems to be a known issue in Java (see reference) Reference: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6430675 I hope this information is helpful, thanks in advance for reading this, Kind regards, René -- https://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of math.floor, round and int functions (rounding)
On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: > Hello, I would like to report the following issue: > > Working with floats i noticed that: > > int(23.99/12) returns 1, and > int(23.999/12) returns 2 > > This implies that int() function is rounding ... It's not int() that's doing the rounding; that second numerator is being rounded before being divided by 12: Python 3.9.7 (default, Oct 10 2021, 15:13:22) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 23.999 24.0 >>> (23.999).hex() '0x1.8p+4' -- https://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of math.floor, round and int functions (rounding)
On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This implies that int() function is rounding ... It's not int() that's doing the rounding; that second numerator is being rounded before being divided by 12: Python 3.9.7 (default, Oct 10 2021, 15:13:22) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 23.999 24.0 >>> (23.999).hex() '0x1.8p+4' I think this is a bit clearer because it shows that it's not just being rounded for display: Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 23.99 == 24 False >>> 23.999 == 24 True -- https://mail.python.org/mailman/listinfo/python-list
Re: import question
On Thu, Nov 18, 2021 at 6:19 PM Chris Angelico wrote: > On Fri, Nov 19, 2021 at 11:24 AM Dan Stromberg > wrote: > > > > > > On Thu, Nov 18, 2021 at 12:21 PM Chris Angelico > wrote: > >> > >> If you're trying to make a Python-in-Python sandbox, I recommend not. > >> Instead, use an OS-level sandbox (a chroot, probably some sort of CPU > >> usage limiting, etc), and use that to guard the entire Python process. > >> Python-in-Python will basically *never* be secure. > > > > > > Good advice to not try to sandbox python. > > > > But chroot can sometimes be broken out of. It isn't a cure-all. > > > > That's true, but it's way better than attempting Python-in-Python > sandboxing. In any case, all the options worth investigating will be > at the OS level. > > (Or maybe higher, but I can't imagine it being practical to create > individual VMs for each client who comes to the web site.) > Actually, there are ports of CPython and Micropython that run inside a web browser over WASM. Going with one of these might be safer. -- https://mail.python.org/mailman/listinfo/python-list
Re: import question
On Fri, Nov 19, 2021 at 3:00 PM Dan Stromberg wrote: > > > On Thu, Nov 18, 2021 at 6:19 PM Chris Angelico wrote: >> >> On Fri, Nov 19, 2021 at 11:24 AM Dan Stromberg wrote: >> > >> > >> > On Thu, Nov 18, 2021 at 12:21 PM Chris Angelico wrote: >> >> >> >> If you're trying to make a Python-in-Python sandbox, I recommend not. >> >> Instead, use an OS-level sandbox (a chroot, probably some sort of CPU >> >> usage limiting, etc), and use that to guard the entire Python process. >> >> Python-in-Python will basically *never* be secure. >> > >> > >> > Good advice to not try to sandbox python. >> > >> > But chroot can sometimes be broken out of. It isn't a cure-all. >> > >> >> That's true, but it's way better than attempting Python-in-Python >> sandboxing. In any case, all the options worth investigating will be >> at the OS level. >> >> (Or maybe higher, but I can't imagine it being practical to create >> individual VMs for each client who comes to the web site.) > > > Actually, there are ports of CPython and Micropython that run inside a web > browser over WASM. Going with one of these might be safer. > Hmm, interesting point. I'd mentally ruled out the in-browser options since the performance hit is usually far too costly, but if this is basically an educational site, it MAY be sufficient (people won't need spectacular performance when they're just learning the basics). ChrisA -- https://mail.python.org/mailman/listinfo/python-list