@@ -3182,3 +3182,53 @@ def test_nunique(setup, method, chunked, axis):
31823182 raw_df .nunique (axis = axis ),
31833183 mdf .nunique (axis = axis , method = method ).execute ().fetch (),
31843184 )
3185+
3186+
3187+ @pytest .mark .parametrize ("chunk_size" , [None , 10 ])
3188+ def test_copy_deep (setup , chunk_size ):
3189+ ns = np .random .RandomState (0 )
3190+ df = pd .DataFrame (ns .rand (100 , 10 ), columns = ["a" + str (i ) for i in range (10 )])
3191+ mdf = from_pandas_df (df , chunk_size = chunk_size )
3192+
3193+ # test case that there is no other result between copy and origin data
3194+ res = mdf .copy ()
3195+ res ["a0" ] = res ["a0" ] + 1
3196+ dfc = df .copy (deep = True )
3197+ dfc ["a0" ] = dfc ["a0" ] + 1
3198+ pd .testing .assert_frame_equal (res .execute ().fetch (), dfc )
3199+ pd .testing .assert_frame_equal (mdf .execute ().fetch (), df )
3200+
3201+ s = pd .Series (ns .randint (0 , 100 , size = (100 ,)))
3202+ ms = from_pandas_series (s , chunk_size = chunk_size )
3203+
3204+ res = ms .copy ()
3205+ res .iloc [0 ] = 111.0
3206+ sc = s .copy (deep = True )
3207+ sc .iloc [0 ] = 111.0
3208+ pd .testing .assert_series_equal (res .execute ().fetch (), sc )
3209+ pd .testing .assert_series_equal (ms .execute ().fetch (), s )
3210+
3211+ index = pd .Index ([i for i in range (100 )], name = "test" )
3212+ m_index = from_pandas_index (index , chunk_size = chunk_size )
3213+
3214+ res = m_index .copy ()
3215+ assert res is not m_index
3216+ pd .testing .assert_index_equal (res .execute ().fetch (), index .copy ())
3217+ pd .testing .assert_index_equal (m_index .execute ().fetch (), index )
3218+
3219+ res = m_index .copy (name = "abc" )
3220+ pd .testing .assert_index_equal (res .execute ().fetch (), index .copy (name = "abc" ))
3221+ pd .testing .assert_index_equal (m_index .execute ().fetch (), index )
3222+
3223+ # test case that there is other ops between copy and origin data
3224+ xdf = (mdf + 1 ) * 2 / 7
3225+ expected = (df + 1 ) * 2 / 7
3226+ pd .testing .assert_frame_equal (xdf .execute ().fetch (), expected )
3227+
3228+ xdf_c = xdf .copy ()
3229+ expected_c = expected .copy (deep = True )
3230+ pd .testing .assert_frame_equal (xdf_c .execute ().fetch (), expected )
3231+ xdf_c ["a1" ] = xdf_c ["a1" ] + 0.8
3232+ expected_c ["a1" ] = expected_c ["a1" ] + 0.8
3233+ pd .testing .assert_frame_equal (xdf_c .execute ().fetch (), expected_c )
3234+ pd .testing .assert_frame_equal (xdf .execute ().fetch (), expected )
0 commit comments