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

Update reciprocalspaceship to support pandas 1.3.0 #71

Merged
merged 4 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions reciprocalspaceship/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def set_index(self, keys, drop=True, append=False, inplace=False, verify_integri
else:
raise ValueError(f"{key} is not an instance of type str, np.ndarray, pd.Index, pd.Series, or list")

return super().set_index(keys, drop, append, inplace, verify_integrity)
return super().set_index(keys, drop=drop, append=append, inplace=inplace, verify_integrity=verify_integrity)

def reset_index(self, level=None, drop=False, inplace=False, col_level=0, col_fill=''):
"""
Expand Down Expand Up @@ -289,11 +289,11 @@ def _handle_cached_dtypes(dataset, columns, drop):
return dataset

if inplace:
super().reset_index(level, drop, inplace, col_level, col_fill)
super().reset_index(level, drop=drop, inplace=inplace, col_level=col_level, col_fill=col_fill)
_handle_cached_dtypes(self, columns, drop)
return
else:
dataset = super().reset_index(level, drop, inplace, col_level, col_fill)
dataset = super().reset_index(level, drop=drop, inplace=inplace, col_level=col_level, col_fill=col_fill)
dataset._index_dtypes = dataset._index_dtypes.copy()
dataset = _handle_cached_dtypes(dataset, columns, drop)
return dataset
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def getVersionNumber():
python_requires=">3.6",
install_requires=[
"gemmi >= 0.4.2",
"pandas >= 1.2.0, < 1.3",
"pandas >= 1.2.0, <= 1.3.0",
"numpy",
"scipy",
"ipython",
Expand Down
2 changes: 1 addition & 1 deletion tests/algorithms/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_merge(hewl_unmerged, hewl_merged, keys, sort):
assert merged.merged
assert merged.spacegroup.xhm() == hewl_merged.spacegroup.xhm()
assert merged.cell.a == hewl_merged.cell.a
assert merged.index.is_lexsorted() == sort
assert merged.index.is_monotonic_increasing == sort

# Note: AIMLESS zero-fills empty observations, whereas we use NaNs
for key in merged.columns:
Expand Down
6 changes: 3 additions & 3 deletions tests/algorithms/test_scale_merged_intensities.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ def test_fw_posterior_quad(ref_method, data_fw_cctbx, data_fw_mcmc):
"""
if ref_method == 'cctbx':
I,SigI,Sigma,J,SigJ,F,SigF,Centric = data_fw_cctbx.to_numpy(np.float64).T
Centric = Centric.astype(np.bool)
Centric = Centric.astype(bool)
rtol = 0.06
rs_J,rs_SigJ,rs_F,rs_SigF = _french_wilson_posterior_quad(I, SigI, Sigma, Centric)
elif ref_method == 'mcmc':
I,SigI,Sigma,J,SigJ,F,SigF,Centric = data_fw_mcmc.to_numpy(np.float64).T
Centric = Centric.astype(np.bool)
Centric = Centric.astype(bool)
rtol = 0.025
rs_J,rs_SigJ,rs_F,rs_SigF = _french_wilson_posterior_quad(I, SigI, Sigma, Centric)
elif ref_method == 'mcmc vs cctbx':
I,SigI,Sigma,J,SigJ,F,SigF,Centric = data_fw_mcmc.to_numpy(np.float64).T
Centric = Centric.astype(np.bool)
Centric = Centric.astype(bool)
_,_,_,rs_J,rs_SigJ,rs_F,rs_SigF,_ = data_fw_cctbx.to_numpy(np.float64).T
rtol = 0.06

Expand Down
32 changes: 3 additions & 29 deletions tests/dtypes/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,43 +156,17 @@ def all_boolean_reductions(request):
"""
return request.param

array = {
# Integer dtypes
"HKL": rs.dtypes.hklindex.HKLIndexArray,
"MTZInt": rs.dtypes.mtzint.MTZIntArray,
"Batch": rs.dtypes.batch.BatchArray,
"M/ISYM": rs.dtypes.m_isym.M_IsymArray,

# Float32 dtypes
"Intensity": rs.dtypes.intensity.IntensityArray,
"SFAmplitude": rs.dtypes.structurefactor.StructureFactorAmplitudeArray,
"AnomalousDifference": rs.dtypes.anomalousdifference.AnomalousDifferenceArray,
"Stddev": rs.dtypes.stddev.StandardDeviationArray,
"FriedelSFAmplitude": rs.dtypes.structurefactor.FriedelStructureFactorAmplitudeArray,
"StddevFriedelSF": rs.dtypes.stddev.StandardDeviationFriedelSFArray,
"FriedelIntensity": rs.dtypes.intensity.FriedelIntensityArray,
"StddevFriedelI": rs.dtypes.stddev.StandardDeviationFriedelIArray,
"NormalizedSFAmplitude": rs.dtypes.structurefactor.NormalizedStructureFactorAmplitudeArray,
"Phase": rs.dtypes.phase.PhaseArray,
"Weight": rs.dtypes.weight.WeightArray,
"HendricksonLattman": rs.dtypes.phase.HendricksonLattmanArray,
"MTZReal": rs.dtypes.mtzreal.MTZRealArray
}

@pytest.fixture
def data_int(dtype_ints):
return array[dtype_ints[0].name]._from_sequence(np.arange(0, 100),
dtype=dtype_ints[0]())
return pd.array(np.arange(0, 100), dtype=dtype_ints[0]())

@pytest.fixture
def data_float(dtype_floats):
return array[dtype_floats[0].name]._from_sequence(np.arange(0, 100),
dtype=dtype_floats[0]())
return pd.array(np.arange(0, 100), dtype=dtype_floats[0]())

@pytest.fixture
def data_all(dtype_all):
return array[dtype_all[0].name]._from_sequence(np.arange(0, 100),
dtype=dtype_all[0]())
return pd.array(np.arange(0, 100), dtype=dtype_all[0]())

@pytest.fixture(params=[None, lambda x: x])
def sort_by_key(request):
Expand Down
28 changes: 6 additions & 22 deletions tests/dtypes/test_floats_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@
import pandas as pd
from pandas.tests.extension import base

array = {
"Intensity": rs.dtypes.intensity.IntensityArray,
"SFAmplitude": rs.dtypes.structurefactor.StructureFactorAmplitudeArray,
"AnomalousDifference": rs.dtypes.anomalousdifference.AnomalousDifferenceArray,
"Stddev": rs.dtypes.stddev.StandardDeviationArray,
"FriedelSFAmplitude": rs.dtypes.structurefactor.FriedelStructureFactorAmplitudeArray,
"StddevFriedelSF": rs.dtypes.stddev.StandardDeviationFriedelSFArray,
"FriedelIntensity": rs.dtypes.intensity.FriedelIntensityArray,
"StddevFriedelI": rs.dtypes.stddev.StandardDeviationFriedelIArray,
"NormalizedSFAmplitude": rs.dtypes.structurefactor.NormalizedStructureFactorAmplitudeArray,
"Phase": rs.dtypes.phase.PhaseArray,
"Weight": rs.dtypes.weight.WeightArray,
"HendricksonLattman": rs.dtypes.phase.HendricksonLattmanArray,
"MTZReal": rs.dtypes.mtzreal.MTZRealArray
}

@pytest.fixture(
params=[
rs.IntensityDtype,
Expand All @@ -47,23 +31,23 @@ def dtype(request):

@pytest.fixture
def data(dtype):
return array[dtype.name]._from_sequence(np.arange(0, 100), dtype=dtype)
return pd.array(np.arange(0, 100), dtype=dtype)

@pytest.fixture
def data_for_twos(dtype):
return array[dtype.name]._from_sequence(np.ones(100) * 2, dtype=dtype)
return pd.array(np.ones(100) * 2, dtype=dtype)

@pytest.fixture
def data_missing(dtype):
return array[dtype.name]._from_sequence([np.nan, 1.], dtype=dtype)
return pd.array([np.nan, 1.], dtype=dtype)

@pytest.fixture
def data_for_sorting(dtype):
return array[dtype.name]._from_sequence([1., 2., 0.], dtype=dtype)
return pd.array([1., 2., 0.], dtype=dtype)

@pytest.fixture
def data_missing_for_sorting(dtype):
return array[dtype.name]._from_sequence([1., np.nan, 0.], dtype=dtype)
return pd.array([1., np.nan, 0.], dtype=dtype)

@pytest.fixture(params=['data', 'data_missing'])
def all_data(request, data, data_missing):
Expand All @@ -79,7 +63,7 @@ def data_for_grouping(dtype):
a = 0
c = 2
na = np.nan
return array[dtype.name]._from_sequence([b, b, na, na, a, a, b, c], dtype=dtype)
return pd.array([b, b, na, na, a, a, b, c], dtype=dtype)

class TestCasting(base.BaseCastingTests):
pass
Expand Down
19 changes: 6 additions & 13 deletions tests/dtypes/test_ints_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
import reciprocalspaceship as rs
from pandas.tests.extension import base

array = {
"HKL": rs.dtypes.hklindex.HKLIndexArray,
"MTZInt": rs.dtypes.mtzint.MTZIntArray,
"Batch": rs.dtypes.batch.BatchArray,
"M/ISYM": rs.dtypes.m_isym.M_IsymArray
}

@pytest.fixture(
params=[
rs.HKLIndexDtype,
Expand All @@ -24,23 +17,23 @@ def dtype(request):

@pytest.fixture
def data(dtype):
return array[dtype.name]._from_sequence(np.arange(0, 100), dtype=dtype)
return pd.array(np.arange(0, 100), dtype=dtype)

@pytest.fixture
def data_for_twos(dtype):
return array[dtype.name]._from_sequence(np.ones(100) * 2, dtype=dtype)
return pd.array(np.ones(100) * 2, dtype=dtype)

@pytest.fixture
def data_missing(dtype):
return array[dtype.name]._from_sequence([np.nan, 1.], dtype=dtype)
return pd.array([np.nan, 1.], dtype=dtype)

@pytest.fixture
def data_for_sorting(dtype):
return array[dtype.name]._from_sequence([1., 2., 0.], dtype=dtype)
return pd.array([1., 2., 0.], dtype=dtype)

@pytest.fixture
def data_missing_for_sorting(dtype):
return array[dtype.name]._from_sequence([1., np.nan, 0.], dtype=dtype)
return pd.array([1., np.nan, 0.], dtype=dtype)

@pytest.fixture(params=['data', 'data_missing'])
def all_data(request, data, data_missing):
Expand All @@ -56,7 +49,7 @@ def data_for_grouping(dtype):
a = 0
c = 2
na = np.nan
return array[dtype.name]._from_sequence([b, b, na, na, a, a, b, c], dtype=dtype)
return pd.array([b, b, na, na, a, a, b, c], dtype=dtype)

class TestCasting(base.BaseCastingTests):
pass
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_compute_dHKL(dataset_hkl, cell):
gemmi.UnitCell(291., 423., 315., 90., 100., 90.),
gemmi.UnitCell(30., 50., 90., 75., 80., 106.),
])
@pytest.mark.parametrize("dtype", [np.float, np.int32, np.int])
@pytest.mark.parametrize("dtype", [float, np.int32, int])
def test_generate_reciprocal_cell(cell, dtype):
"""Test rs.utils.generate_reciprocal_cell"""
dmin = 5.0
Expand Down