Skip to content
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

Invalid Namespace URI #54

Open
jcs-01 opened this issue Jun 4, 2024 · 6 comments
Open

Invalid Namespace URI #54

jcs-01 opened this issue Jun 4, 2024 · 6 comments

Comments

@jcs-01
Copy link

jcs-01 commented Jun 4, 2024

When I reach the step of saving the .xml file in the ReadMe (Model.save_predictions(folderpath + 'MyResults') , I get the following error message. Has anyone else experienced this or know how to fix it? Thank you!

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[9], line 1
----> 1 Model.save_predictions(folderpath + 'MyResults')

File ~\conda\envs\envdeepslice\Lib\site-packages\DeepSlice\main.py:198, in DSModel.save_predictions(self, filename)
194 self.predictions.to_csv(filename + ".csv", index=False)
195 QuickNII_functions.write_QUINT_JSON(
196 df=self.predictions, filename=filename, aligner=aligner, target=target
197 )
--> 198 QuickNII_functions.write_QuickNII_XML(
199 df=self.predictions, filename=filename, aligner=aligner
200 )

File ~\conda\envs\envdeepslice\Lib\site-packages\DeepSlice\read_and_write\QuickNII_functions.py:45, in write_QuickNII_XML(df, filename, aligner)
17 out_df = pd.DataFrame(
18 {
19 "anchoring": "ox="
(...)
41 }
42 )
43 print(f"saving to {filename}.xml")
---> 45 out_df.to_xml(
46 filename + ".xml",
47 index=False,
48 root_name="series",
49 row_name="slice",
50 attr_cols=list(out_df.columns),
51 namespaces={
52 "first": df_temp.nr.values[0],
53 "last": df_temp.nr.values[-1],
54 "name": filename,
55 "aligner": aligner,
56 "": "",
57 },
58 )

File ~\conda\envs\envdeepslice\Lib\site-packages\pandas\util_decorators.py:333, in deprecate_nonkeyword_arguments..decorate..wrapper(*args, **kwargs)
327 if len(args) > num_allow_args:
328 warnings.warn(
329 msg.format(arguments=_format_argument_list(allow_args)),
330 FutureWarning,
331 stacklevel=find_stack_level(),
332 )
--> 333 return func(*args, **kwargs)

File ~\conda\envs\envdeepslice\Lib\site-packages\pandas\core\frame.py:3643, in DataFrame.to_xml(self, path_or_buffer, index, root_name, row_name, na_rep, attr_cols, elem_cols, namespaces, prefix, encoding, xml_declaration, pretty_print, parser, stylesheet, compression, storage_options)
3622 raise ValueError("Values for parser can only be lxml or etree.")
3624 xml_formatter = TreeBuilder(
3625 self,
3626 path_or_buffer=path_or_buffer,
(...)
3640 storage_options=storage_options,
3641 )
-> 3643 return xml_formatter.write_output()

File ~\conda\envs\envdeepslice\Lib\site-packages\pandas\io\formats\xml.py:338, in _BaseXMLFormatter.write_output(self)
336 @Final
337 def write_output(self) -> str | None:
--> 338 xml_doc = self._build_tree()
340 if self.path_or_buffer is not None:
341 with get_handle(
342 self.path_or_buffer,
343 "wb",
(...)
346 is_text=False,
347 ) as handles:

File ~\conda\envs\envdeepslice\Lib\site-packages\pandas\io\formats\xml.py:464, in LxmlXMLFormatter._build_tree(self)
452 """
453 Build tree from data.
454
455 This method initializes the root and builds attributes and elements
456 with optional namespaces.
457 """
458 from lxml.etree import (
459 Element,
460 SubElement,
461 tostring,
462 )
--> 464 self.root = Element(f"{self.prefix_uri}{self.root_name}", nsmap=self.namespaces)
466 for d in self.frame_dicts.values():
467 elem_row = SubElement(self.root, f"{self.prefix_uri}{self.row_name}")

File src\lxml\etree.pyx:3092, in lxml.etree.Element()

File src\lxml\apihelpers.pxi:138, in lxml.etree._makeElement()

File src\lxml\apihelpers.pxi:125, in lxml.etree._makeElement()

File src\lxml\apihelpers.pxi:222, in lxml.etree._setNodeNamespaces()

File src\lxml\apihelpers.pxi:1752, in lxml.etree._uriValidOrRaise()

ValueError: Invalid namespace URI`

@jcs-01
Copy link
Author

jcs-01 commented Jun 5, 2024

Looks like the error is lines 52-56 in QuickNII_functions.py

@PolarBean
Copy link
Owner

I can't replicate this issue but lxml has caused problems in the past. I will remove the ability to save as xml for now.

@PolarBean
Copy link
Owner

please update DeepSlice and let me know whether your problem persists

@jcs-01
Copy link
Author

jcs-01 commented Jun 18, 2024

That does solve the namespace URI issue, but I really need the xml file output unfortunately

@PolarBean
Copy link
Owner

The json has all the same information. What do you need the XML for?

@rdaggs
Copy link

rdaggs commented Jun 25, 2024

Hi, I've had this same problem and it occurred due to the naming convention of my folder path....it had spaces in it. After a while I thought to change spaces with underscores and the 'Invalid namespace URI' error went away. Let me know if this works for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants