Skip to content

Rename column strat#488

Open
SmartMonkey-git wants to merge 7 commits into
mainfrom
rr/col_renaming
Open

Rename column strat#488
SmartMonkey-git wants to merge 7 commits into
mainfrom
rr/col_renaming

Conversation

@SmartMonkey-git

Copy link
Copy Markdown
Collaborator

No description provided.

@SmartMonkey-git SmartMonkey-git self-assigned this May 21, 2026

@psnairne psnairne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only real issue is how the strategy interacts with Multi/Regex Identifiers.

Like I say below, I'm not convinced this strategy is worth the effort, but it's up to you!

/// The table
///
/// ```csv
/// PatientId, conditions, dob

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be more useful if you gave an example that renamed a column name like "little interest or pleasure in doing things" to "HP:1234567". In other words, the example you have in mind.

Then you could add a comment somewhere that this should be used when a column has HpoInHeader context (or in general when the header is relevant for collection, if you want to be less specific)

&self,
tables: &mut [&mut ContextualizedDataFrame],
) -> Result<(), StrategyError> {
for (old, new) in self.renaming.iter() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(old_header,new_header) would be more helpful)

let (new_sc, old_id) = if let Some(old_sc) = table.get_sc_by_col_name(old) {
(
SeriesContext::new(
Identifier::Single(new.to_string()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the identifier of the old_sc was Multi or Regex? The Multi situation, can be fixed easily, the Regex situation can't.

Suppose we have a bunch of columns all with HpoInHeader context, covered by a Regex (in fact this was one of the use-cases of this context right?). If for whatever reason you need to rename one of them, then your current code would mean the rest of them wouldn't be collected.

My personal feeling, is that column renaming should be done before PhenoXtract, because of difficulties like this, and because each strategy we make requires upkeep

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the same applies to the MultiContextSplitter strategy you were describing to me earlier, but IMO column names can be easily changed by the user if they need to be. Especially since it's the same amount of effort to write out the aliases in the config, as it is just to rename the columns in the original table

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have strong feelings about this though, the strategy can stay since it doesn't affect the rest of the code, but maybe the documentation can be reworded to reflect how it interacts with Single/Multi etc. Maybe you just need to say "only do this for columns identified by an SC with Identifier of single type"

let names: HashSet<&String> = renaming.values().collect();
if names.len() < renaming.len() {
return Err(ConstructionError::DuplicateColumnNames {
reason: "Configured ColumnRenamingStrategy does feature duplicates."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "Configured ColumnRenamingStrategy has duplicate column names"

}

#[rstest]
fn test_empty_renaming_map_is_noop() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noop?

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

Successfully merging this pull request may close these issues.

2 participants