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

Future warning when trying to find intersection between non overlapping ranges #345

Open
GH-MStamboulian opened this issue Jul 7, 2023 · 9 comments

Comments

@GH-MStamboulian
Copy link

m using pandas 1.5.0 & pyranges 0.0.127
this warning only arrises when there is no intersection between the two number intervals, for example the following code would trigger this warning:

import pyranges as pr

gr1 = pr.from_dict({"Chromosome": [1, 1], "Start": [1, 4], "End": [2, 27],}) 

gr2 = pr.from_dict({"Chromosome": [1, 1], "Start": [28, 35], "End": [40, 45]}) 
gr1.intersect(gr2)

The part of the implementation that is triggering this warning (inside the pyranges package) is the following segment:

pd.options.mode.chained_assignment = None  # default='warn'
scdf.loc[:, "Start"] = new_starts
scdf.loc[:, "End"] = new_ends
pd.options.mode.chained_assignment = "warn"

I could suppress this warning however im wondering if I should actually not be ignoring it or if the codes behavior might change at some point in the future.

when I calculate the overlap between the same two ranges I do not get this warning.

gr1.overlap(gr2)

can you please help me understand what this warning message would be and if there is a risk for it to mutate any of my ranges gr1 or gr2 in future? Thank you!

@GH-MStamboulian
Copy link
Author

@marco-mariotti

@endrebak
Copy link
Collaborator

endrebak commented Jul 8, 2023

I can have a look on Monday. Thanks.

@endrebak
Copy link
Collaborator

There is no risk here that the object passed in will be changed.

reindex creates new objects:

scdf, ocdf = scdf.reindex(_self_indexes), ocdf.reindex(_other_indexes)

@GH-MStamboulian
Copy link
Author

@endrebak thank you for looking into this. So what would be the most appropriate way to get rid of this warning? should I just suppress it?

@endrebak
Copy link
Collaborator

I am a bit surprised that it shows up. If you look at the code, you see that I turn off the warning.

@GH-MStamboulian
Copy link
Author

yes I have no idea why its still complaining. what pandas version are you using?

@endrebak
Copy link
Collaborator

2.0.1

@GH-MStamboulian
Copy link
Author

@endrebak I see, and do you still get this warning too with the newer pandas version?

@cmatKhan
Copy link

cmatKhan commented Nov 6, 2023

I believe I am seeing this, also, though I'm not sure it is the same FutureWarning.

test_gtf.txt

x = pr.read_gtf('test_gtf.txt')

x.features.introns(by='transcript').intersect(x[x.Feature=='exon'],strandedness='same', how='containment')

result:

	Chromosome	Source	Feature	Start	End	Score	Strand	Frame	gene_id	transcript_id
0	chr1	unknown	intron	15	19	.	+	.	gene1	transcript_1
1	chr1	unknown	intron	15	19	.	+	.	gene1	transcript_1

FutureWarning: The `inplace` parameter in pandas.Categorical.add_categories is deprecated and will be removed in a future version. Removing unused categories will always return a new Categorical object.
  introns.Feature.cat.add_categories(["intron"], inplace=True)

FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  introns.loc[:, "Feature"] = "intron"

pyranges version info:

{'pyranges version': '0.0.120', 'pandas version': '1.5.2', 'numpy version': '1.23.0', 'python version': sys.version_info(major=3, minor=9, micro=18, releaselevel='final', serial=0), 'ncls': '0.0.65', 'sorted_nearest': '0.0.37', 'pyrle': '0.0.35', 'ray': 'not installed', 'bamread': 'not installed', 'pyranges_db': 'not installed', 'pybigwig': 'not installed', 'hypothesis': 'not installed'}

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