tabmat icon indicating copy to clipboard operation
tabmat copied to clipboard

Use `slice(None)` instead of `None` for non-existant row and col filters.

Open tbenthompson opened this issue 4 years ago • 4 comments

As an alternative to the if clause, you could replace None with slice(None). You could then use it for indexing and it wouldn't return a copy. I don't know where else in the code base you use setup_restrictions, but it could generalize.

Originally posted by @lbittarello in https://github.com/Quantco/quantcore.matrix/pull/89#discussion_r663096417

tbenthompson avatar Jul 02 '21 16:07 tbenthompson

My comment from the PR: I like the idea. But, I'd also like to leave this as is for now. I worry that it'll be a big quagmire of having to change essentially every method down the tree because rows and cols get passed to self.mat.sandwich and self.mat.transpose_matvec. I'll split this out into an issue. Feel free to close it if you don't think it's worth having an issue.

Another question here: is there an easy way to handle slice(None) in Cython code?

tbenthompson avatar Jul 06 '21 18:07 tbenthompson

I don't know any Cython. :T @xhochy?

lbittarello avatar Jul 07 '21 10:07 lbittarello

I have no idea about this but this is probably somewhere in the pandas code. There you often have slice(None) and a lot of Cython.

xhochy avatar Jul 07 '21 11:07 xhochy

Apologies! I didn't mean to make this into a public discussion eating up people's time -- just sort of some notes to myself since I think I'm the mostly likely person to make these changes. I'll make that more clear next time.

Thanks for the suggestion on looking at pandas.

tbenthompson avatar Jul 07 '21 11:07 tbenthompson