cscs Posted October 7 Share Posted October 7 Dear Community, I came across this guide and i am successfully using it for the general case, i.e. to replace a local file CSV data source with another one: How to replace the File DataSource of a Data Table in Spotfire® Using IronPython Scripting However, i see some limitation which i was not able to overcome yet. When originally loading the data, in some data table some column types were manually changed. This happened let's say because based on the sampled rows Spotfire defaulted some Reals to Integers, or some well-formatted DateTimes to Strings. When the script changes the source, these settings are neglected, i.e. the selected columns return to their wrong defaults, instead of the manually set correct ones. I would expect i could find this data type modification step somewhere, and i would be able to add it as a transformation step at DataFlowBuilder.AddTransformation(...). I was trying to find the data type modification step at sourceView.OperationsSupportingTransformations and at different types of sourceView.GetAllOperations[...](), but it just did not appear anywhere. Am i trying to find this at the wrong place? Is this transformation object reachable anyhow? Is there even a way to achieve my goal programmatically? Thank you for your suggestions! Link to comment Share on other sites More sharing options...
David Boot-Olazabal Posted October 8 Share Posted October 8 Hi cscs, You may want to have a look at similar questions, it may solve your issue. Kind regards, David Link to comment Share on other sites More sharing options...
cscs Posted October 9 Author Share Posted October 9 Hi David, thank you for your reply and for the suggestions. I was searching for replacing data tables, probably that is why these were not displayed (among the ~6000, mostly irrelevant topics :) ) I think i will be able to apply the above for my use-case However, if i need to manually add a column types changing transformation each time i replace the source, it implies further questions: Why are the originally set column types disregarded when only the source is changed, but not any more of the transformations? And, more importantly, why is the column type changing transformation not exposed at all for my existing table, so i could at least reuse it when changing the source? Would it somehow be possible to programmatically expose this? I'm asking because otherwise some column names need to be hardcoded into the script, which is not ideal. Thank you again, Csaba Link to comment Share on other sites More sharing options...
Solution cscs Posted 17 hours ago Author Solution Share Posted 17 hours ago Solution was to: Read the current data types # Get the current column types colTypes = {} for col in table.Columns: if col.Properties.ColumnType == DataColumnType.Imported: colTypes[col.Name] == str(col.DataType) Replace the data table's source file (this resets the data types to string) As discussed in the original article Apply the formerly read data types, As described by Gaia in the other article linked above, just doing the loop on the dictionary created in step1 above Thank you again 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now