rs-station / reciprocalspaceship

Tools for exploring reciprocal space
https://rs-station.github.io/reciprocalspaceship/
MIT License
28 stars 11 forks source link

write_mtz SettingWithCopyWarning #248

Closed DHekstra closed 3 months ago

DHekstra commented 3 months ago

when writing MTZs, the syntax in dataset.py may be a bit out of date. Not a problem right now, but just registering some example warnings.

/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:310: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[key] = dataset[key].astype(dtype)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1241: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[["H", "K", "L"]] = asu_hkls[inverse]
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1242: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[["H", "K", "L"]] = dataset[["H", "K", "L"]].astype("HKL")
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1257: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset["M/ISYM"] = DataSeries(m_isym, dtype="M/ISYM", index=dataset.index)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1258: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset.drop(columns="PARTIAL", inplace=True)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:310: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[key] = dataset[key].astype(dtype)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1325: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self["PARTIAL"] = (self[m_isym] / 256).astype(int) != 0
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1326: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self.drop(columns=m_isym, inplace=True)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1334: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self[["H", "K", "L"]] = observed_hkls
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1335: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self[["H", "K", "L"]] = self[["H", "K", "L"]].astype("HKL")
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:310: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[key] = dataset[key].astype(dtype)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1241: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[["H", "K", "L"]] = asu_hkls[inverse]
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1242: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[["H", "K", "L"]] = dataset[["H", "K", "L"]].astype("HKL")
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1257: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset["M/ISYM"] = DataSeries(m_isym, dtype="M/ISYM", index=dataset.index)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1258: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset.drop(columns="PARTIAL", inplace=True)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:310: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dataset[key] = dataset[key].astype(dtype)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1325: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self["PARTIAL"] = (self[m_isym] / 256).astype(int) != 0
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1326: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self.drop(columns=m_isym, inplace=True)
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1334: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self[["H", "K", "L"]] = observed_hkls
/n/home12/dhekstra/ipython_notebooks/reciprocalspaceship/reciprocalspaceship/dataset.py:1335: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self[["H", "K", "L"]] = self[["H", "K", "L"]].astype("HKL")
JBGreisman commented 3 months ago

Hi -- I'm not able to reproduce this issue using the latest rs and the MTZ files in our tests:

In [1]: import reciprocalspaceship as rs

In [2]: ds = rs.read_mtz("data_merged.mtz")

In [3]: ds.write_mtz("/tmp/test_merged.mtz")

In [4]: ds = rs.read_mtz("data_unmerged.mtz")

In [5]: ds.write_mtz("/tmp/test_unmerged.mtz")

In [6]: rs.__version__
Out[6]: '1.0.1'

I have a hunch this means that the DataSet object you were working with may have had the relevant problem, rather than the code for writing out MTZs. you could probably include a ds = ds.copy() prior to ds.write_mtz() to avoid the warnings, but it also might be worth looking into your code to confirm all the relevant steps are working as intended.

If you still think this is an issue with rs, please include a short example that can be used to reproduce the issue.

JBGreisman commented 3 months ago

I'm going to close this issue, but please feel free to re-open it with a short example snippet if it's still an issue