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

Updated df.applymap to df.map to silence FutureWarning #42

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

ray-berkeley
Copy link
Contributor

Small change to silence a FutureWarning that is thrown by newer versions of Pandas

@alisterburt
Copy link
Collaborator

Right on, thanks for the PR! Is this change backwards compatible or does it break with slightly older pandas versions? If the latter can you update the pandas requirement to >=the minimum version?

Once this is done I'll merge and push out a release, thanks again!!

@alisterburt
Copy link
Collaborator

Looks like the pandas version required is not released on 3.8 - I'm happy to drop 3.8 support here too and will remove it from the test matrix

@ray-berkeley
Copy link
Contributor Author

Thanks for taking a look at it! I made the change you suggested to setup.cfg and verified it with a test install.

The pandas docs suggest that df.map() is backwards-compatible to 2.1.0–I was able to test it back to 2.1.1, but I get a separate error from pandas when trying to read a starfile using pandas 2.1.0 and python 3.11 or 3.9. I tried it with a few different starfiles and got a similar error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.9/site-packages/starfile/functions.py", line 26, in read
    parser = StarParser(filename, n_blocks_to_read=read_n_blocks)
  File ".../python3.9/site-packages/starfile/parser.py", line 40, in __init__
    self.parse_file()
  File ".../python3.9/site-packages/starfile/parser.py", line 51, in parse_file
    block_name, block = self._parse_data_block()
  File ".../python3.9/site-packages/starfile/parser.py", line 65, in _parse_data_block
    return block_name, self._parse_loop_block()
  File ".../python3.9/site-packages/starfile/parser.py", line 117, in _parse_loop_block
    df.columns = loop_column_names
  File ".../python3.9/site-packages/pandas/core/generic.py", line 6216, in __setattr__
    return object.__setattr__(self, name, value)
  File "properties.pyx", line 69, in pandas._libs.properties.AxisProperty.__set__
  File ".../python3.9/site-packages/pandas/core/generic.py", line 767, in _set_axis
    self._mgr.set_axis(axis, labels)
  File ".../python3.9/site-packages/pandas/core/internals/managers.py", line 227, in set_axis
    self._validate_set_axis(axis, new_labels)
  File ".../python3.9/site-packages/pandas/core/internals/base.py", line 85, in _validate_set_axis
    raise ValueError(
ValueError: Length mismatch: Expected axis has 25 elements, new values have 12 elements

@alisterburt
Copy link
Collaborator

@ray-berkeley tests are passing for me locally and in the test matrix on >3.8 - could you paste the contents of your file so I can double check it myself? Hopefully it's a local issue for you... if I don't hear back in a couple of days I'll merge here and if it breaks I'm sure I'll hear about it :-)

Thanks again for the PR!

@ray-berkeley
Copy link
Contributor Author

Sure! Here's a minimal starfile that should reproduce the error. It only seems to be a problem with Pandas 2.1.0:

# version 30001

data_optics

loop_ 
_rlnOpticsGroup #1 
_rlnOpticsGroupName #2 
_rlnAmplitudeContrast #3 
_rlnBeamTiltX #4 
_rlnBeamTiltY #5 
_rlnSphericalAberration #6 
_rlnVoltage #7 
_rlnImagePixelSize #8 
_rlnMicrographOriginalPixelSize #9 
_rlnImageSize #10 
_rlnImageDimensionality #11 
_rlnOddZernike #12 
_rlnEvenZernike #13 
           1 opticsGroup1     0.100000     0.296532     -0.11369     2.700000   200.000000     2.240000     0.560000           96            2 [-0.512329168678,1.33476636873,-0.443026555711,0,0,1.04243806264] [1.46288490105,0.370363079954,2.44605608265,-1.89801788564,-3.14098732609,0.117745343458,1.03266007965,-0.841780044036,3.04355953351] 
           2 opticsGroup2     0.100000     -0.21438     0.161131     2.700000   200.000000     2.240000     0.560000           96            2 [0.709153648516,-0.955645680221,9.97627294315,0,0,-10.1434434973] [0.75276733627,0.837454240706,1.31038420099,-1.20886925188,-2.59055495481,0.265832972474,0.598879387485,-0.553876811671,-8.2646276172] 
           3 opticsGroup3     0.100000     0.143370     -0.14056     2.700000   200.000000     2.240000     0.566000           96            2 [-0.611693882648,1.08746776327,-0.504494994403,0,0,-3.2349096551] [1.54077504279,1.66789488846,2.58486712372,-7.62783630324,6.02593490545,0.589969463855,1.104075202,-2.89198279973,7.76718046708] 
 

# version 30001

data_particles

loop_ 
_rlnCoordinateX #1 
_rlnCoordinateY #2 
_rlnClassNumber #3 
_rlnAutopickFigureOfMerit #4 
_rlnAnglePsi #5 
_rlnImageName #6 
_rlnMicrographName #7 
_rlnCtfMaxResolution #8 
_rlnCtfFigureOfMerit #9 
_rlnDefocusU #10 
_rlnDefocusV #11 
_rlnDefocusAngle #12 
_rlnCtfBfactor #13 
_rlnCtfScalefactor #14 
_rlnPhaseShift #15 
_rlnGroupNumber #16 
_rlnAngleRot #17 
_rlnAngleTilt #18 
_rlnNormCorrection #19 
_rlnLogLikeliContribution #20 
_rlnMaxValueProbDistribution #21 
_rlnNrOfSignificantSamples #22 
_rlnRandomSubset #23 
_rlnBeamTiltClass #24 
_rlnOpticsGroup #25 
_rlnOriginXAngst #26 
_rlnOriginYAngst #27 
_rlnSphericalAberration #28 
  207.000000   207.000000            1     1.000000   -132.17428 000001@calibration_grid.mrcs Micrographs/calibration_grid/D1.mrc     2.634397     0.425778 13241.734375 13064.365234    -58.88372     0.000000     1.000000     0.000000            1    10.768136    56.799662     0.534664 25220.411190     0.514471           89            1            3            2     -4.34431     6.855688     2.700000 
  207.000000   363.000000            2     1.000000   -155.95937 000002@calibration_grid.mrcs Micrographs/calibration_grid/D2.mrc     2.634397     0.425778 13241.734375 13064.365234    -58.88372     0.000000     1.000000     0.000000            1   146.715904    51.023781     0.444846 25447.427149     0.457400          955            2            3            2     -4.34431     -2.10431     2.700000 
  207.000000   518.000000            2     1.000000   -142.54589 000003@calibration_grid.mrcs Micrographs/calibration_grid/D3.mrc     2.634397     0.425778 13241.734375 13064.365234    -58.88372     0.000000     1.000000     0.000000            1    90.926684    60.188403     0.446103 25403.345273     0.203695          440            1            3            2     -2.10431     -2.10431     2.700000 

@alisterburt
Copy link
Collaborator

thanks! this is working with the version of pandas that is currently installed in >=3.9 so I'll merge and recommend updating pandas if anyone has issues :-)

@alisterburt alisterburt merged commit 5d93598 into teamtomo:main Jan 15, 2024
4 checks passed
@ray-berkeley
Copy link
Contributor Author

Sweet, thank you!

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