[
https://issues.apache.org/jira/browse/ARROW-1768?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239670#comment-16239670
]
ASF GitHub Bot commented on ARROW-1768:
---------------------------------------
cpcloud commented on a change in pull request #1286: ARROW-1768: [Python] Fix
suppressed exception in ParquetWriter.__del__
URL: https://github.com/apache/arrow/pull/1286#discussion_r148965743
##########
File path: python/pyarrow/parquet.py
##########
@@ -231,6 +231,8 @@ class ParquetWriter(object):
{0}
""".format(_parquet_writer_arg_docs)
+ is_open = False
Review comment:
I don't think this is the correct solution. It looks like we're defining
`__del__` which will be called if `__init__` raises an exception. If `__init__`
raises an exception *before* defining `self.is_open` then you'll get an
`AttributeError` exception in `__del__` when it's called.
We really should *not* be opening files in constructors, since Python
doesn't have the same guarantees as C++ around resource initialization and
destruction. We should be using a context manager here since that provides
clear semantics and guarantees when `__enter__` and `__exit__` will run.
For now, though, can you do this instead?
```python
def __del__(self):
if getattr(self, 'is_open', False):
self.close()
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [Python] Fix suppressed exception in ParquetWriter.__del__
> ----------------------------------------------------------
>
> Key: ARROW-1768
> URL: https://issues.apache.org/jira/browse/ARROW-1768
> Project: Apache Arrow
> Issue Type: Bug
> Components: Python
> Reporter: Wes McKinney
> Labels: pull-request-available
> Fix For: 0.8.0
>
>
> {code}
> pyarrow-test-2.7/lib/python2.7/site-packages/pyarrow/tests/test_parquet.py::test_coerce_timestamps
> Exception AttributeError: "'ParquetWriter' object has no attribute
> 'is_open'" in <bound method ParquetWriter.__del__ of
> <pyarrow.parquet.ParquetWriter object at 0x11bc1f4d0>> ignored
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)