1717
1818from datetime import datetime as dt
1919import pyarrow as pa
20- from pyarrow .vendored .version import Version
2120import pytest
2221
2322try :
@@ -122,9 +121,6 @@ def test_offset_of_sliced_array():
122121 ]
123122)
124123def test_pandas_roundtrip (uint , int , float , np_float_str ):
125- if Version (pd .__version__ ) < Version ("1.5.0" ):
126- pytest .skip ("__dataframe__ added to pandas in 1.5.0" )
127-
128124 arr = [1 , 2 , 3 ]
129125 table = pa .table (
130126 {
@@ -153,9 +149,6 @@ def test_pandas_roundtrip(uint, int, float, np_float_str):
153149@pytest .mark .pandas
154150def test_pandas_roundtrip_string ():
155151 # See https://github.com/pandas-dev/pandas/issues/50554
156- if Version (pd .__version__ ) < Version ("1.6" ):
157- pytest .skip ("Column.size() bug in pandas" )
158-
159152 arr = ["a" , "" , "c" ]
160153 table = pa .table ({"a" : pa .array (arr )})
161154
@@ -182,46 +175,32 @@ def test_pandas_roundtrip_string():
182175@pytest .mark .pandas
183176def test_pandas_roundtrip_large_string ():
184177 # See https://github.com/pandas-dev/pandas/issues/50554
185- if Version (pd .__version__ ) < Version ("1.6" ):
186- pytest .skip ("Column.size() bug in pandas" )
187-
188178 arr = ["a" , "" , "c" ]
189179 table = pa .table ({"a_large" : pa .array (arr , type = pa .large_string ())})
190180
191181 from pandas .api .interchange import (
192182 from_dataframe as pandas_from_dataframe
193183 )
194184
195- if Version (pd .__version__ ) >= Version ("2.0.1" ):
196- pandas_df = pandas_from_dataframe (table )
197- result = pi .from_dataframe (pandas_df )
198-
199- assert result ["a_large" ].to_pylist () == table ["a_large" ].to_pylist ()
200- assert pa .types .is_large_string (table ["a_large" ].type )
201- assert pa .types .is_large_string (result ["a_large" ].type )
185+ pandas_df = pandas_from_dataframe (table )
186+ result = pi .from_dataframe (pandas_df )
202187
203- table_protocol = table .__dataframe__ ()
204- result_protocol = result .__dataframe__ ()
188+ assert result ["a_large" ].to_pylist () == table ["a_large" ].to_pylist ()
189+ assert pa .types .is_large_string (table ["a_large" ].type )
190+ assert pa .types .is_large_string (result ["a_large" ].type )
205191
206- assert table_protocol .num_columns () == result_protocol .num_columns ()
207- assert table_protocol .num_rows () == result_protocol .num_rows ()
208- assert table_protocol .num_chunks () == result_protocol .num_chunks ()
209- assert table_protocol .column_names () == result_protocol .column_names ()
192+ table_protocol = table .__dataframe__ ()
193+ result_protocol = result .__dataframe__ ()
210194
211- else :
212- # large string not supported by pandas implementation for
213- # older versions of pandas
214- # https://github.com/pandas-dev/pandas/issues/52795
215- with pytest .raises (AssertionError ):
216- pandas_from_dataframe (table )
195+ assert table_protocol .num_columns () == result_protocol .num_columns ()
196+ assert table_protocol .num_rows () == result_protocol .num_rows ()
197+ assert table_protocol .num_chunks () == result_protocol .num_chunks ()
198+ assert table_protocol .column_names () == result_protocol .column_names ()
217199
218200
219201@pytest .mark .pandas
220202def test_pandas_roundtrip_string_with_missing ():
221203 # See https://github.com/pandas-dev/pandas/issues/50554
222- if Version (pd .__version__ ) < Version ("1.6" ):
223- pytest .skip ("Column.size() bug in pandas" )
224-
225204 arr = ["a" , "" , "c" , None ]
226205 table = pa .table ({"a" : pa .array (arr ),
227206 "a_large" : pa .array (arr , type = pa .large_string ())})
@@ -230,29 +209,20 @@ def test_pandas_roundtrip_string_with_missing():
230209 from_dataframe as pandas_from_dataframe
231210 )
232211
233- if Version (pd .__version__ ) >= Version ("2.0.2" ):
234- pandas_df = pandas_from_dataframe (table )
235- result = pi .from_dataframe (pandas_df )
212+ pandas_df = pandas_from_dataframe (table )
213+ result = pi .from_dataframe (pandas_df )
236214
237- assert result ["a" ].to_pylist () == table ["a" ].to_pylist ()
238- assert pa .types .is_string (table ["a" ].type )
239- assert pa .types .is_large_string (result ["a" ].type )
215+ assert result ["a" ].to_pylist () == table ["a" ].to_pylist ()
216+ assert pa .types .is_string (table ["a" ].type )
217+ assert pa .types .is_large_string (result ["a" ].type )
240218
241- assert result ["a_large" ].to_pylist () == table ["a_large" ].to_pylist ()
242- assert pa .types .is_large_string (table ["a_large" ].type )
243- assert pa .types .is_large_string (result ["a_large" ].type )
244- else :
245- # older versions of pandas do not have bitmask support
246- # https://github.com/pandas-dev/pandas/issues/49888
247- with pytest .raises (NotImplementedError ):
248- pandas_from_dataframe (table )
219+ assert result ["a_large" ].to_pylist () == table ["a_large" ].to_pylist ()
220+ assert pa .types .is_large_string (table ["a_large" ].type )
221+ assert pa .types .is_large_string (result ["a_large" ].type )
249222
250223
251224@pytest .mark .pandas
252225def test_pandas_roundtrip_categorical ():
253- if Version (pd .__version__ ) < Version ("2.0.2" ):
254- pytest .skip ("Bitmasks not supported in pandas interchange implementation" )
255-
256226 arr = ["Mon" , "Tue" , "Mon" , "Wed" , "Mon" , "Thu" , "Fri" , "Sat" , None ]
257227 table = pa .table (
258228 {"weekday" : pa .array (arr ).dictionary_encode ()}
@@ -299,21 +269,14 @@ def test_pandas_roundtrip_categorical():
299269@pytest .mark .pandas
300270@pytest .mark .parametrize ("unit" , ['s' , 'ms' , 'us' , 'ns' ])
301271def test_pandas_roundtrip_datetime (unit ):
302- if Version (pd .__version__ ) < Version ("1.5.0" ):
303- pytest .skip ("__dataframe__ added to pandas in 1.5.0" )
304272 from datetime import datetime as dt
305273
306274 # timezones not included as they are not yet supported in
307275 # the pandas implementation
308276 dt_arr = [dt (2007 , 7 , 13 ), dt (2007 , 7 , 14 ), dt (2007 , 7 , 15 )]
309277 table = pa .table ({"a" : pa .array (dt_arr , type = pa .timestamp (unit ))})
310278
311- if Version (pd .__version__ ) < Version ("1.6" ):
312- # pandas < 2.0 always creates datetime64 in "ns"
313- # resolution
314- expected = pa .table ({"a" : pa .array (dt_arr , type = pa .timestamp ('ns' ))})
315- else :
316- expected = table
279+ expected = table
317280
318281 from pandas .api .interchange import (
319282 from_dataframe as pandas_from_dataframe
@@ -337,9 +300,6 @@ def test_pandas_roundtrip_datetime(unit):
337300 "np_float_str" , ["float32" , "float64" ]
338301)
339302def test_pandas_to_pyarrow_with_missing (np_float_str ):
340- if Version (pd .__version__ ) < Version ("1.5.0" ):
341- pytest .skip ("__dataframe__ added to pandas in 1.5.0" )
342-
343303 np_array = np .array ([0 , np .nan , 2 ], dtype = np .dtype (np_float_str ))
344304 datetime_array = [None , dt (2007 , 7 , 14 ), dt (2007 , 7 , 15 )]
345305 df = pd .DataFrame ({
@@ -359,9 +319,6 @@ def test_pandas_to_pyarrow_with_missing(np_float_str):
359319
360320@pytest .mark .pandas
361321def test_pandas_to_pyarrow_float16_with_missing ():
362- if Version (pd .__version__ ) < Version ("1.5.0" ):
363- pytest .skip ("__dataframe__ added to pandas in 1.5.0" )
364-
365322 # np.float16 errors if ps.is_nan is used
366323 # pyarrow.lib.ArrowNotImplementedError: Function 'is_nan' has no kernel
367324 # matching input types (halffloat)
@@ -482,9 +439,6 @@ def test_nan_as_null():
482439
483440@pytest .mark .pandas
484441def test_allow_copy_false ():
485- if Version (pd .__version__ ) < Version ("1.5.0" ):
486- pytest .skip ("__dataframe__ added to pandas in 1.5.0" )
487-
488442 # Test that an error is raised when a copy is needed
489443 # to create a bitmask
490444
@@ -501,9 +455,6 @@ def test_allow_copy_false():
501455
502456@pytest .mark .pandas
503457def test_allow_copy_false_bool_categorical ():
504- if Version (pd .__version__ ) < Version ("1.5.0" ):
505- pytest .skip ("__dataframe__ added to pandas in 1.5.0" )
506-
507458 # Test that an error is raised for boolean
508459 # and categorical dtype (copy is always made)
509460
0 commit comments