-
-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dataset.filename is a BytesIO for Deflated Explicit VR Little Endian objects, breaking codify and other uses #1937
Comments
A naive "fix" would be to attach the original filename to the If the maintainers are interested in addressing this issue (either the root "problem" or the "codify" problem specifically), and have a preferred direction, I'd likely be available to implement. |
You are right, this is indeed intended to be able to handle data streams or data coming from zip or tar files. The name |
Understood. The jerk in me suggests that abusing an attribute called On a more serious note, I may not be doing a sufficiently rigorous search, but it seems to me that the
The last one looks to me to be the biggest cause for concern. Am I close? Unless the concern (valid, IMO) is that some clients will have begun to expect a non-filename filename attribute in the cases where it's currently a |
True. That was in the name of upwards compatibility, I guess, which is now, before a major version change, not that much of a concern. In principle, I'm not against two separate attributes, and/or separate methods for the different use cases. I'm just not sure if there isn't a better solution design-wise - waiting for @darcymason or @scaramallion to chime in... |
So, yeah, this is kind of a case of getting "caught" doing something purely for convenience (way way back carrying the filename along) and not really thinking through the "API" consequences. Likewise the The comments about However, my first thoughts are to try to change the deflated dataset behavior. Seems like it should be relatively simple to keep |
Describe the bug
When opening a Deflated Explicit VR Little Endian (1.2.840.10008.1.2.1.99) object from a file (or even from pydicom internal test data), the dataset.filename is not a filename, but is a BytesIO object. First noticed in the context of blairconrad/dicognito#159, where I was relying on the
.filename
to report to the user which file failed to anonymize, but then I noticed that it breakspydicom codify
as well.Expected behavior
dataset.filename
should, when the dataset was read from a file at least, contain the filename.Steps To Reproduce
Load any Deflated Explicit VR Little Endian dataset from a file and examine
.filename
.More unsettling (and possibly the subject of a separate issue) is how this breaks codify:
I don't blame codify for thinking that
filename
is the name of a file…Your environment
$ git log -1 --oneline 335934d5a (HEAD -> main, origin/main, origin/HEAD) Bump mypy from 1.5.1 to 1.6.1
occurs with many recent and older released versions as well
Now this may all be intentional and I'm wasting your time. Heck, it's even accounted for, in some sense:
pydicom/src/pydicom/dataset.py
Lines 2767 to 2769 in af5f54e
and we can see the the
BytesIO
object was created from the inflated content:pydicom/src/pydicom/filereader.py
Lines 851 to 863 in af5f54e
The text was updated successfully, but these errors were encountered: