pandas-plink
pandas-plink copied to clipboard
write_plink1_bin() gives error "TypeError: to_csv() got an unexpected keyword argument 'line_terminator'".
I have Python 3.9.18 and Pandas 2.1.1. My pandas-Plink version is 2.2.9
**The command: write_plink1_bin(G_sample1, "sample1.bed")
gives this error output: "TypeError: to_csv() got an unexpected keyword argument 'line_terminator'". The current Pandas version has changed the "line_terminator" parameter to "lineterminator"**
Do I need to downgrade my Pandas version to use pandas_plink?
Thank you
write_plink1_bin(G_sample1, "sample1.bed") Writing BED: 100%|██████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 5.54it/s] Writing FAM...
TypeError Traceback (most recent call last) Cell In[86], line 1 ----> 1 write_plink1_bin(G_sample1, "sample1.bed")
File ~/miniforge3/envs/Genomics/lib/python3.9/site-packages/pandas_plink/_write.py:183, in write_plink1_bin(G, bed, bim, fam, major, verbose) 180 write_bed(bed, G, major, verbose) 182 _echo("Writing FAM... ", end="", disable=not verbose) --> 183 _write_fam(fam, G) 184 _echo("done.", disable=not verbose) 186 _echo("Writing BIM... ", end="", disable=not verbose)
File ~/miniforge3/envs/Genomics/lib/python3.9/site-packages/pandas_plink/_write.py:261, in _write_fam(filepath, G) 258 df[col] = G.sample[col].values 259 df[col] = df[col].astype(col_type) --> 261 df.to_csv( 262 filepath, 263 index=False, 264 sep="\t", 265 header=False, 266 encoding="ascii", 267 line_terminator="\n", 268 )
TypeError: to_csv() got an unexpected keyword argument 'line_terminator'
Hello, would appreciate a response on the above. I really need to be able to write back to new bed/bim/fam files using plink. And it is throwing up the error above
Did you work around this?
I'm seeing the same thing:
- Python 3.10.12
- pandas==2.1.4
- pandas-plink==2.2.9
def test_two():
import os
import tempfile
from pandas_plink import get_data_folder, read_plink1_bin, write_plink1_bin
tmp_path = tempfile.mkdtemp()
filename = "chr11.bed"
filename = os.path.join(get_data_folder(), filename)
G = read_plink1_bin(filename, verbose=False)
print(G)
write_plink1_bin(G, f"{tmp_path}/sample1.bed")
if __name__ == "__main__":
test_two()
$ python test-plink.py
<xarray.DataArray 'genotype' (sample: 14, variant: 779)>
dask.array<transpose, shape=(14, 779), dtype=float32, chunksize=(14, 779), chunktype=numpy.ndarray>
Coordinates: (12/14)
* sample (sample) object 'B001' 'B002' 'B003' ... 'B012' 'B013' 'B014'
* variant (variant) <U10 'variant0' 'variant1' ... 'variant777' 'variant778'
fid (sample) object 'B001' 'B002' 'B003' ... 'B012' 'B013' 'B014'
iid (sample) object 'B001' 'B002' 'B003' ... 'B012' 'B013' 'B014'
father (sample) object '0' '0' '0' '0' '0' '0' ... '0' '0' '0' '0' '0' '0'
mother (sample) object '0' '0' '0' '0' '0' '0' ... '0' '0' '0' '0' '0' '0'
... ...
chrom (variant) object '11' '11' '11' '11' '11' ... '11' '11' '11' '11'
snp (variant) object '316849996' '316874359' ... '345698259'
cm (variant) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
pos (variant) int32 157439 181802 248969 ... 28937375 28961091 29005702
a0 (variant) object 'C' 'G' 'G' 'C' 'C' 'T' ... 'A' 'C' 'A' 'A' 'T'
a1 (variant) object 'T' 'C' 'C' 'T' 'T' 'A' ... 'G' 'T' 'G' 'C' 'C'
Writing BED: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 617.35it/s]
Writing FAM... Traceback (most recent call last):
File "/home/dan/Work/Nomaly/Integration/test-plink.py", line 60, in <module>
test_two()
File "/home/dan/Work/Nomaly/Integration/test-plink.py", line 56, in test_two
write_plink1_bin(G, f"{tmp_path}/sample1.bed")
File "/home/dan/Work/Nomaly/Integration/.venv/lib/python3.10/site-packages/pandas_plink/_write.py", line 183, in write_plink1_bin
_write_fam(fam, G)
File "/home/dan/Work/Nomaly/Integration/.venv/lib/python3.10/site-packages/pandas_plink/_write.py", line 261, in _write_fam
df.to_csv(
TypeError: NDFrame.to_csv() got an unexpected keyword argument 'line_terminator'
Here is the fix: https://github.com/limix/pandas-plink/pull/31